bug-gnulib
[Top][All Lists]
Advanced

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

Re: gnulib-tool: new options --add-import, --remove-import


From: Bruno Haible
Subject: Re: gnulib-tool: new options --add-import, --remove-import
Date: Sat, 4 Sep 2010 18:44:32 +0200
User-agent: KMail/1.9.9

Eric Blake wrote:
> > I would propose to
> >    - Rename the current --import option to --add-import,
> >    - Introduce a new --import option, that is like the previous --import
> >      option except that it ignores the contents of gnulib-cache.m4,
> >    - Add a --remove-import option that can be used to remove a module
> >      from the list of modules (before dependency computation).
> >
> > 'bootstrap' would not have to change, because it already invokes
> > 'gnulib-tool --import'.
> >
> > Opinions? Objections?
> 
> Sounds good to me.  It would certainly help both camps of users.

OK, I'm changing gnulib-tool as described, along with the documentation,
to answer the concern you made in
<http://lists.gnu.org/archive/html/bug-gnulib/2010-09/msg00055.html>.


2010-09-04  Bruno Haible  <address@hidden>

        gnulib-tool: Change --import. New options --add/remove-import.
        * gnulib-tool: New options --add-import, --remove-import.
        (func_usage): Document them.
        (have_associative): Define always.
        (func_import): In import mode, don't merge the specified settings with
        the cached settings. Implement remove-import mode.
        * doc/gnulib-tool.texi (Modified imports): Mention the new options.
        Explain when to use them versus --import.
        (Simple update): Use --add-import instead of --import.
        * NEWS: Mention the change.

diff --git a/NEWS b/NEWS
index 2015502..e062efa 100644
--- a/NEWS
+++ b/NEWS
@@ -1,6 +1,12 @@
 Important notes
 ---------------
 
+2010-09-04  gnulib-tool     The option '--import' is no longer cumulative; it
+                            now expects the complete list of modules and other
+                            options on the command line. If you want to
+                            augment (not set) the list of modules, use the
+                            new option '--add-import' instead of '--import'.
+
 User visible incompatible changes
 ---------------------------------
 
diff --git a/doc/gnulib-tool.texi b/doc/gnulib-tool.texi
index e9c376e..e4908e8 100644
--- a/doc/gnulib-tool.texi
+++ b/doc/gnulib-tool.texi
@@ -302,30 +302,48 @@ is built from the contents of a different variable, 
usually
 
 You can at any moment decide to use Gnulib differently than the last time.
 
-If you only want to use more Gnulib modules, simply invoke
address@hidden --import @var{new-modules}}.  @code{gnulib-tool}
-remembers which modules were used last time.  The list of modules that
-you pass after @samp{--import} is @emph{added} to the previous list of
-modules.
+There are two ways to change how Gnulib is used.  Which one you'll use,
+depends on where you keep track of options and module names that you pass
+to @code{gnulib-tool}.
 
-For most changes, such as added or removed modules, or even different
-choices of @samp{--lib}, @samp{--source-base} or @samp{--aux-dir}, there
-are two ways to perform the change.
-
-The standard way is to modify manually the file @file{gnulib-cache.m4}
-in the M4 macros directory, then launch @samp{gnulib-tool --import}.
address@hidden @bullet
address@hidden
+If you store the options and module names in a file under your own
+control, such as @file{autogen.sh}, @file{bootstrap},
address@hidden, or similar, simply invoke @command{gnulib-tool}
+again, with modified options and more or fewer module names.
 
-The other way is to call @command{gnulib-tool} again, with the changed
-command-line options.  Note that this doesn't let you remove modules,
-because as you just learned, the list of modules is always cumulated.
-Also this way is often impractical, because you don't remember the way
-you invoked @code{gnulib-tool} last time.
address@hidden
address@hidden remembers which modules were used last time.  If you
+want to rely on @code{gnulib-tool}'s own memory of the last used
+options and module names, you can use the commands
address@hidden --add-import} and
address@hidden --remove-import}.
+
+So, if you only want to use more Gnulib modules, simply invoke
address@hidden --add-import @var{new-modules}}.  The list of
+modules that you pass after @samp{--add-import} is @emph{added} to the
+previous list of modules.
+
+Similarly, if you want to use fewer Gnulib modules, simply invoke
address@hidden --remove-import @var{unneeded-modules}}.  The list
+of modules that you pass after @samp{--remove-import} is @emph{removed}
+from the previous list of modules.  Note that if a module is then still
+needed as dependency of other modules, it will be used nevertheless.
+If you want to @emph{really} not use a module any more, regardless of
+whether other modules may need it, you need to use the @samp{--avoid}
+option.
+
+For other changes, such as different choices of @samp{--lib},
address@hidden or @samp{--aux-dir}, the normal way is to
+modify manually the file @file{gnulib-cache.m4} in the M4 macros
+directory, then launch @samp{gnulib-tool --add-import}.
 
 The only change for which this doesn't work is a change of the
 @samp{--m4-base} directory.  Because, when you pass a different value of
 @samp{--m4-base}, @code{gnulib-tool} will not find the previous
address@hidden file any more... A possible solution is to manually
-copy the @file{gnulib-cache.m4} into the new M4 macro directory.
address@hidden file any more...  A possible solution is to
+manually copy the @file{gnulib-cache.m4} into the new M4 macro directory.
 
 In the @file{gnulib-cache.m4}, the macros have the following meaning:
 @table @code
@@ -372,6 +390,7 @@ The argument is the prefix to use for macros in the 
@file{gnulib-comp.m4}
 file.  Corresponds to the @samp{--macro-prefix} command line argument.
 @end table
 
address@hidden itemize
 
 @node Simple update
 @section Simple update
@@ -381,7 +400,7 @@ changing the list of modules or other parameters, a simple 
call
 does it:
 
 @smallexample
-$ gnulib-tool --import
+$ gnulib-tool --add-import
 @end smallexample
 
 @noindent
diff --git a/gnulib-tool b/gnulib-tool
index b809dd1..a0a0112 100755
--- a/gnulib-tool
+++ b/gnulib-tool
@@ -127,6 +127,8 @@ func_usage ()
 Usage: gnulib-tool --list
        gnulib-tool --find filename
        gnulib-tool --import [module1 ... moduleN]
+       gnulib-tool --add-import [module1 ... moduleN]
+       gnulib-tool --remove-import [module1 ... moduleN]
        gnulib-tool --update
        gnulib-tool --create-testdir --dir=directory [module1 ... moduleN]
        gnulib-tool --create-megatestdir --dir=directory [module1 ... moduleN]
@@ -151,9 +153,13 @@ Usage: gnulib-tool --list
 Operation modes:
       --list                print the available module names
       --find                find the modules which contain the specified file
-      --import              import the given modules into the current package;
+      --import              import the given modules into the current package
+      --add-import          augment the list of imports from gnulib into the
+                            current package, by adding the given modules;
                             if no modules are specified, update the current
                             package from the current gnulib
+      --remove-import       reduce the list of imports from gnulib into the
+                            current package, by removing the given modules
       --update              update the current package, restore files omitted
                             from version control
       --create-testdir      create a scratch package with the given modules
@@ -861,7 +867,8 @@ fi
 
 # Command-line option processing.
 # Removes the OPTIONS from the arguments. Sets the variables:
-# - mode            list or import or create-testdir or create-megatestdir
+# - mode            list or import or add-import or remove-import or update
+#                   or create-testdir or create-megatestdir
 # - destdir         from --dir
 # - local_gnulib_dir  from --local-dir
 # - modcache        true or false, from --cache-modules/--no-cache-modules
@@ -957,6 +964,12 @@ fi
       --import | --impor | --impo | --imp | --im | --i )
         mode=import
         shift ;;
+      --add-import | --add-impor | --add-impo | --add-imp | --add-im | --add-i 
| --add- | --add | --ad )
+        mode=add-import
+        shift ;;
+      --remove-import | --remove-impor | --remove-impo | --remove-imp | 
--remove-im | --remove-i | --remove- | --remove | --remov | --remo | --rem | 
--re | --r )
+        mode=remove-import
+        shift ;;
       --update | --updat | --upda | --upd | --up | --u )
         mode=update
         shift ;;
@@ -1214,10 +1227,10 @@ fi
     esac
   done
 
-  if test "$mode" = import; then
+  if case "$mode" in import | add-import | remove-import) true;; *) false;; 
esac; then
     if test -n "$excl_cxx_tests" || test -n "$excl_longrunning_tests" \
        || test -n "$excl_privileged_tests" || test -n 
"$excl_unportable_tests"; then
-      echo "gnulib-tool: invalid options for 'import' mode" 1>&2
+      echo "gnulib-tool: invalid options for '$mode' mode" 1>&2
       echo "Try 'gnulib-tool --help' for more information." 1>&2
       func_exit 1
     fi
@@ -1264,7 +1277,8 @@ fi
   DEFAULT_AUTOCONF_MINVERSION="2.59"
   autoconf_minversion=
   configure_ac=
-  if { test "$mode" = import || test "$mode" = update; } && test -n 
"$destdir"; then
+  if case "$mode" in import | add-import | remove-import | update) true;; *) 
false;; esac \
+     && test -n "$destdir"; then
     if test -f "$destdir"/configure.ac; then
       configure_ac="$destdir/configure.ac"
     else
@@ -1350,6 +1364,15 @@ for signal in 1 2 3 13 15; do
 done
 signal=0
 
+# Note: The 'eval' silences stderr output in dash.
+if (declare -A x && { x[f/2]='foo'; x[f/3]='bar'; eval test '${x[f/2]}' = foo; 
}) 2>/dev/null; then
+  # Zsh 4 and Bash 4 have associative arrays.
+  have_associative=true
+else
+  # For other shells, use 'eval' with computed shell variable names.
+  have_associative=false
+fi
+
 # func_lookup_file file
 # looks up a file in $local_gnulib_dir or $gnulib_dir, or combines it through
 # 'patch'.
@@ -1533,15 +1556,6 @@ sed_extract_field_header='
 
 if $modcache; then
 
-  # Note: The 'eval' silences stderr output in dash.
-  if (declare -A x && { x[f/2]='foo'; x[f/3]='bar'; eval test '${x[f/2]}' = 
foo; }) 2>/dev/null; then
-    # Zsh 4 and Bash 4 have associative arrays.
-    have_associative=true
-  else
-    # For other shells, use 'eval' with computed shell variable names.
-    have_associative=false
-  fi
-
   if $have_associative; then
 
     # Declare the associative arrays.
@@ -3308,6 +3322,7 @@ func_emit_initmacro_done ()
 
 # func_import modules
 # Uses also the variables
+# - mode            import or add-import or remove-import or update
 # - destdir         target directory
 # - local_gnulib_dir  from --local-dir
 # - modcache        true or false, from --cache-modules/--no-cache-modules
@@ -3351,6 +3366,8 @@ func_emit_initmacro_done ()
 func_import ()
 {
   # Get the cached settings.
+  # In 'import' mode, we read them only for the purpose of knowing the old
+  # installed file list, and don't use them as defaults.
   cached_local_gnulib_dir=
   cached_specified_modules=
   cached_incobsolete=
@@ -3480,6 +3497,11 @@ func_import ()
     fi
   fi
 
+  if test "$mode" = import; then
+    # In 'import' mode, the new set of specified modules overrides the cached
+    # set of modules. Ignore the cached settings.
+    specified_modules="$1"
+  else
   # Merge the cached settings with the specified ones.
   # The m4base must be the same as expected from the pathname.
   if test -n "$cached_m4base" && test "$cached_m4base" != "$m4base"; then
@@ -3503,9 +3525,47 @@ func_import ()
       esac
     fi
   fi
+    case $mode in
+      add-import)
   # Append the cached and the specified module names. So that
-  # "gnulib-tool --import foo" means to add the module foo.
+        # "gnulib-tool --add-import foo" means to add the module foo.
   specified_modules="$cached_specified_modules $1"
+        ;;
+      remove-import)
+        # Take the cached module names, minus the specified module names.
+        specified_modules=
+        if $have_associative; then
+          # Use an associative array, for O(N) worst-case run time.
+          declare -A to_remove
+          for m in $1; do
+            to_remove[$m]=yes
+          done
+          for module in $cached_specified_modules; do
+            if test -z "${to_remove[$module]}"; then
+              func_append specified_modules "$module "
+            fi
+          done
+        else
+          # This loop has O(N²) worst-case run time.
+          for module in $cached_specified_modules; do
+            to_remove=
+            for m in $1; do
+              if test "$m" = "$module"; then
+                to_remove=yes
+                break
+              fi
+            done
+            if test -z "$to_remove"; then
+              func_append specified_modules "$module "
+            fi
+          done
+        fi
+        ;;
+      update)
+        # Take the cached module names. There are no specified module names.
+        specified_modules="$cached_specified_modules"
+        ;;
+    esac
   # Included obsolete modules among the dependencies if specified either way.
   if test -z "$incobsolete"; then
     incobsolete="$cached_incobsolete"
@@ -3527,11 +3587,6 @@ func_import ()
   if test -z "$inc_all_tests"; then
     inc_all_tests="$cached_inc_all_tests"
   fi
-  # --without-*-tests options are not supported here.
-  excl_cxx_tests=
-  excl_longrunning_tests=
-  excl_privileged_tests=
-  excl_unportable_tests=
   # Append the cached and the specified avoidlist. This is probably better
   # than dropping the cached one when --avoid is specified at least once.
   avoidlist=`for m in $cached_avoidlist $avoidlist; do echo $m; done | 
LC_ALL=C sort -u`
@@ -3604,6 +3659,12 @@ func_import ()
   if test -z "$vc_files"; then
     vc_files="$cached_vc_files"
   fi
+  fi
+  # --without-*-tests options are not supported here.
+  excl_cxx_tests=
+  excl_longrunning_tests=
+  excl_privileged_tests=
+  excl_unportable_tests=
 
   # Canonicalize the list of specified modules.
   specified_modules=`for m in $specified_modules; do echo $m; done | LC_ALL=C 
sort -u`
@@ -5429,7 +5490,7 @@ s/\([.*$]\)/[\1]/g'
     done
     ;;
 
-  import | update )
+  import | add-import | remove-import | update )
 
     # Where to import.
     if test -z "$destdir"; then
@@ -5469,6 +5530,18 @@ s/\([.*$]\)/[\1]/g'
     fi
 
     # Determine where to apply func_import.
+    if test "$mode" = import; then
+      # Apply func_import to a particular gnulib directory.
+      # The command line contains the complete specification; don't look at
+      # the contents of gnulib-cache.m4.
+      test -n "$supplied_libname" || supplied_libname=true
+      test -n "$sourcebase" || sourcebase="lib"
+      test -n "$m4base" || m4base="m4"
+      test -n "$docbase" || docbase="doc"
+      test -n "$testsbase" || testsbase="tests"
+      test -n "$macro_prefix" || macro_prefix="gl"
+      func_import "$*"
+    else
     if test -n "$m4base"; then
       # Apply func_import to a particular gnulib directory.
       # Any number of additional modules can be given.
@@ -5563,6 +5636,7 @@ s/\([.*$]\)/[\1]/g'
         fi
       fi
     fi
+    fi
     ;;
 
   create-testdir )



reply via email to

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