bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: working with locally modified or augmented gnulib repositories


From: Bruno Haible
Subject: Re: working with locally modified or augmented gnulib repositories
Date: Mon, 28 Aug 2006 17:12:03 +0200
User-agent: KMail/1.9.1

Hello Simon,

> Except that I have to specify --local-dir every time I use --import.
> Is this the intended behaviour?  Maybe the --local-dir value could be
> cached, just like --source-base etc.  What do you think?

You're right, it's cumbersome for --import. Also, --update would not do
the right thing if it doesn't know about the local-dir. The patch below
should fix it.

Bruno


2006-08-26  Bruno Haible  <address@hidden>

        * gnulib-tool (func_relativize, func_relconcat): New functions.
        Give an error if --local-dir is given with --update.
        Remove trailing slashes from $local_gnulib_dir.
        (func_import): Store the relativized $local_gnulib_dir in
        gnulib-cache.m4, and read it from there if not specified explicitly.

*** gnulib-tool.bak     2006-08-26 23:21:27.000000000 +0200
--- gnulib-tool 2006-08-27 01:48:40.000000000 +0200
***************
*** 246,251 ****
--- 246,344 ----
    fi
  }
  
+ # func_relativize DIR1 DIR2
+ # computes a relative pathname RELDIR such that DIR1/RELDIR = DIR2.
+ # Input:
+ # - DIR1            relative pathname, relative to the current directory
+ # - DIR2            relative pathname, relative to the current directory
+ # Output:
+ # - reldir          relative pathname of DIR2, relative to DIR1
+ func_relativize ()
+ {
+   dir0=`pwd`
+   dir1="$1"
+   dir2="$2"
+   sed_first='s,^\([^/]*\)/.*$,\1,'
+   sed_rest='s,^[^/]*/*,,'
+   sed_last='s,^.*/\([^/]*\)$,\1,'
+   sed_butlast='s,/*[^/]*$,,'
+   while test -n "$dir1"; do
+     first=`echo "$dir1" | sed -e "$sed_first"`
+     if test "$first" != "."; then
+       if test "$first" = ".."; then
+         dir2=`echo "$dir0" | sed -e "$sed_last"`/"$dir2"
+         dir0=`echo "$dir0" | sed -e "$sed_butlast"`
+       else
+         first2=`echo "$dir2" | sed -e "$sed_first"`
+         if test "$first2" = "$first"; then
+           dir2=`echo "$dir2" | sed -e "$sed_rest"`
+         else
+           dir2="../$dir2"
+         fi
+         dir0="$dir0"/"$first"
+       fi
+     fi
+     dir1=`echo "$dir1" | sed -e "$sed_rest"`
+   done
+   reldir="$dir2"
+ }
+ 
+ # func_relconcat DIR1 DIR2
+ # computes a relative pathname DIR1/DIR2, with obvious simplifications.
+ # Input:
+ # - DIR1            relative pathname, relative to the current directory
+ # - DIR2            relative pathname, relative to DIR1
+ # Output:
+ # - relconcat       DIR1/DIR2, relative to the current directory
+ func_relconcat ()
+ {
+   dir1="$1"
+   dir2="$2"
+   sed_first='s,^\([^/]*\)/.*$,\1,'
+   sed_rest='s,^[^/]*/*,,'
+   sed_last='s,^.*/\([^/]*\)$,\1,'
+   sed_butlast='s,/*[^/]*$,,'
+   while true; do
+     first=`echo "$dir2" | sed -e "$sed_first"`
+     if test "$first" = "."; then
+       dir2=`echo "$dir2" | sed -e "$sed_rest"`
+       if test -z "$dir2"; then
+         relconcat="$dir1"
+         break
+       fi
+     else
+       last=`echo "$dir1" | sed -e "$sed_last"`
+       while test "$last" = "."; do
+         dir1=`echo "$dir1" | sed -e "$sed_butlast"`
+         last=`echo "$dir1" | sed -e "$sed_last"`
+       done
+       if test -z "$dir1"; then
+         relconcat="$dir2"
+         break
+       fi
+       if test "$first" = ".."; then
+         if test "$last" = ".."; then
+           relconcat="$dir1/$dir2"
+           break
+         fi
+         dir1=`echo "$dir1" | sed -e "$sed_butlast"`
+         dir2=`echo "$dir2" | sed -e "$sed_rest"`
+         if test -z "$dir1"; then
+           relconcat="$dir2"
+           break
+         fi
+         if test -z "$dir2"; then
+           relconcat="$dir1"
+           break
+         fi
+       else
+         relconcat="$dir1/$dir2"
+         break
+       fi
+     fi
+   done
+ }
+ 
  # Command-line option processing.
  # Removes the OPTIONS from the arguments. Sets the variables:
  # - mode            list or import or create-testdir or create-megatestdir
***************
*** 465,471 ****
        echo "you need to use 'gnulib --import' - at your own risk!" 1>&2
        exit 1
      fi
!     if test -n "$supplied_libname" || test -n "$sourcebase" || test -n 
"$m4base" \
         || test -n "$docbase" || test -n "$testsbase" || test -n "$auxdir" \
         || test -n "$inctests" || test -n "$avoidlist" || test -n "$lgpl" \
         || test -n "$macro_prefix"; then
--- 558,565 ----
        echo "you need to use 'gnulib --import' - at your own risk!" 1>&2
        exit 1
      fi
!     if test -n "$local_gnulib_dir" || test -n "$supplied_libname" \
!        || test -n "$sourcebase" || test -n "$m4base" \
         || test -n "$docbase" || test -n "$testsbase" || test -n "$auxdir" \
         || test -n "$inctests" || test -n "$avoidlist" || test -n "$lgpl" \
         || test -n "$macro_prefix"; then
***************
*** 530,535 ****
--- 624,632 ----
    # Remove trailing slashes from the directory names. This is necessary for
    # m4base (to avoid an error in func_import) and optional for the others.
    sed_trimtrailingslashes='s,\([^/]\)//*$,\1,'
+   case "$local_gnulib_dir" in
+     */ ) sourcebase=`echo "$local_gnulib_dir" | sed -e 
"$sed_trimtrailingslashes"` ;;
+   esac
    case "$sourcebase" in
      */ ) sourcebase=`echo "$sourcebase" | sed -e "$sed_trimtrailingslashes"` 
;;
    esac
***************
*** 1075,1080 ****
--- 1172,1178 ----
  func_import ()
  {
    # Get the cached settings.
+   cached_local_gnulib_dir=
    cached_specified_modules=
    cached_avoidlist=
    cached_sourcebase=
***************
*** 1092,1097 ****
--- 1190,1198 ----
        s,#.*$,,
        s,^dnl .*$,,
        s, dnl .*$,,
+       /gl_LOCAL_DIR(/ {
+         s,^.*gl_LOCAL_DIR([[ ]*\([^])]*\).*$,cached_local_gnulib_dir="\1",p
+       }
        /gl_MODULES(/ {
          s,^.*gl_MODULES([[ ]*\([^])]*\).*$,cached_specified_modules="\1",p
        }
***************
*** 1150,1155 ****
--- 1251,1274 ----
    if test -n "$cached_m4base" && test "$cached_m4base" != "$m4base"; then
      func_fatal_error "$m4base/gnulib-cache.m4 is expected to contain 
gl_M4_BASE([$m4base])"
    fi
+   # The local_gnulib_dir defaults to the cached one. Recall that the cached 
one
+   # is relative to $destdir, whereas the one we use is relative to . or 
absolute.
+   if test -z "$local_gnulib_dir"; then
+     if test -n "$cached_local_gnulib_dir"; then
+       case "$destdir" in
+         /*)
+           local_gnulib_dir="$destdir/$cached_local_gnulib_dir" ;;
+         *)
+           case "$cached_local_gnulib_dir" in
+             /*)
+               local_gnulib_dir="$destdir/$cached_local_gnulib_dir" ;;
+             *)
+               func_relconcat "$destdir" "$cached_local_gnulib_dir"
+               local_gnulib_dir="$relconcat" ;;
+           esac ;;
+       esac
+     fi
+   fi
    # Append the cached and the specified module names. So that
    # "gnulib-tool --import foo" means to add the module foo.
    specified_modules="$cached_specified_modules $1"
***************
*** 1496,1501 ****
--- 1615,1634 ----
      echo "#   $actioncmd"
      echo
      echo "# Specification in the form of a few gnulib-tool.m4 macro 
invocations:"
+     # Store the local_gnulib_dir relative to destdir.
+     case "$local_gnulib_dir" in
+       "" | /*)
+         relative_local_gnulib_dir="$local_gnulib_dir" ;;
+       * )
+         case "$destdir" in
+           /*) relative_local_gnulib_dir="$local_gnulib_dir" ;;
+           *)
+             # destdir, local_gnulib_dir are both relative.
+             func_relativize "$destdir" "$local_gnulib_dir"
+             relative_local_gnulib_dir="$reldir" ;;
+         esac ;;
+     esac
+     echo "gl_LOCAL_DIR([$relative_local_gnulib_dir])"
      echo "gl_MODULES(["`echo $specified_modules`"])"
      echo "gl_AVOID([$avoidlist])"
      echo "gl_SOURCE_BASE([$sourcebase])"




reply via email to

[Prev in Thread] Current Thread [Next in Thread]