bug-gnulib
[Top][All Lists]
Advanced

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

[PATCH 7/N] gnulib-tool: new option --no-cache for old extraction code.


From: Ralf Wildenhues
Subject: [PATCH 7/N] gnulib-tool: new option --no-cache for old extraction code.
Date: Mon, 18 Jan 2010 22:25:24 +0100
User-agent: Mutt/1.5.20 (2009-10-28)

* gnulib-tool: Accept option --no-cache, turning off $do_cache.
Update matching short versions of --no-changelog.
(func_usage): Update.
(sed_extract_cache_prog): Renamed from ...
(sed_extract_prog): ... this; revert to old extraction script.
(func_get_description, func_get_status)
(func_get_notice, func_get_applicability, func_get_filelist)
(func_get_dependencies, func_get_autoconf_early_snippet)
(func_get_autoconf_snippet, func_get_automake_snippet)
(func_get_include_directive, func_get_link_directive)
(func_get_license, func_get_maintainer): If $do_cache is false,
use old, non-caching extraction scripts.
Suggestion by Bruno Haible.
---

This patch re-adds the old, non-caching extraction code and enables it
with --no-cache.

Maybe if time shows that the caching code works well enough, it can be
reverted at some point in the future.

With this patch, --no-cache does not undo the effects of PATCH 2/5,
i.e., going through intermediate shell variables.  Bruno listed this
as one complaint in the feedback for the patch series a year ago:

| 2) Your patches change the generation of code so that it goes through
|    intermediate shell variables. The problem with this is that the
|    transformation from string to standard output is not simple:
|      echo $string
|    outputs the string plus a newline, and 'echo -n' is not portable.

Also undoing the intermediate shell variables for --no-cache would
change many places throughout the script, IMHO hampering readability,
and of course reintroducing many forks.  If you insist on this, I'll
post a patch to this end as well (but your other reply indicated that
you only wanted part 1 revertible, and the shell variables were only
introduced in part 2).

Anyway, I'd argue that, if any of the entries in modules/* files
absolutely required to have trailing newlines treated exactly the way
they were written down in the file, then the database format is not
well-specified.

IOW, whether somebody writes:
  Description:
  A GNU-like <stdio.h>.

  Files:

or:
  Description:
  A GNU-like <stdio.h>.


  Files:

should not cause gnulib-tool to operate differently.  I'm not sure
whether there is any documentation specifying whether this is allowed:
  Description:
  A GNU-like <stdio.h>.
  Files:

but it works well both with the current code as well as with my patch
series.

Cheers,
Ralf

 gnulib-tool |  173 +++++++++++++++++++++++++++++++++++++++++++++++------------
 1 files changed, 139 insertions(+), 34 deletions(-)

diff --git a/gnulib-tool b/gnulib-tool
index 3c389ea..d6714cd 100755
--- a/gnulib-tool
+++ b/gnulib-tool
@@ -165,6 +165,7 @@ General options:
                             up files before looking in gnulib's directory.
       --verbose             Increase verbosity. May be repeated.
       --quiet               Decrease verbosity. May be repeated.
+      --no-cache            Disable module caching optimization.
 
 Options for --import:
       --lib=LIBRARY         Specify the library name.  Defaults to 'libgnu'.
@@ -849,6 +850,7 @@ fi
   destdir=
   local_gnulib_dir=
   verbose=0
+  do_cache=:
   libname=libgnu
   supplied_libname=
   sourcebase=
@@ -929,6 +931,9 @@ fi
       --quiet | --quie | --qui | --qu | --q )
         verbose=`expr $verbose - 1`
         shift ;;
+      --no-cache | --no-cach | --no-cac | --no-ca )
+        do_cache=false
+        shift ;;
       --lib )
         shift
         if test $# = 0; then
@@ -1071,7 +1076,7 @@ fi
       --no-vc-files )
         vc_files=false
         shift ;;
-      --no-changelog | --no-changelo | --no-changel | --no-change | --no-chang 
| --no-chan | --no-cha | --no-ch | --no-c )
+      --no-changelog | --no-changelo | --no-changel | --no-change | --no-chang 
| --no-chan | --no-cha | --no-ch )
         do_changelog=false
         shift ;;
       --dry-run )
@@ -1365,7 +1370,8 @@ else
 fi
 
 # Extract headers from module descriptions.
-sed_extract_prog="
+# NOTE: Keep this in sync with sed_extract_prog below!
+sed_extract_cache_prog="
   s/^Description:[      ]*$/desc/
   s/^Status:[   ]*$/status/
   s/^Notice:[   ]*$/notice/
@@ -1427,7 +1433,7 @@ func_cache_lookup_module ()
 
       :match
       t match
-      '"$sed_extract_prog"'
+      '"$sed_extract_cache_prog"'
       t hdr
       s/'\''/&"'\''"&/g
       :more
@@ -1441,7 +1447,7 @@ func_cache_lookup_module ()
       n
       t clear
       :clear
-      '"$sed_extract_prog"'
+      '"$sed_extract_cache_prog"'
       t hdr2
       s/'\''/&"'\''"&/g
       s/^/'\''/
@@ -1474,6 +1480,31 @@ func_cache_lookup_module ()
   fi
 }
 
+# Extract headers from module descriptions, without caching.
+# NOTE: Keep this in sync with sed_extract_cache_prog above!
+sed_extract_prog=':[    ]*$/ {
+  :a
+    n
+    s/^Description:[    ]*$//
+    s/^Status:[         ]*$//
+    s/^Notice:[         ]*$//
+    s/^Applicability:[  ]*$//
+    s/^Files:[  ]*$//
+    s/^Depends-on:[     ]*$//
+    s/^configure\.ac-early:[    ]*$//
+    s/^configure\.ac:[  ]*$//
+    s/^Makefile\.am:[   ]*$//
+    s/^Include:[        ]*$//
+    s/^Link:[   ]*$//
+    s/^License:[        ]*$//
+    s/^Maintainer:[     ]*$//
+    tb
+    p
+    ba
+  :b
+}'
+
+
 # func_get_description module
 # Input:
 # - local_gnulib_dir  from --local-dir
@@ -1481,8 +1512,13 @@ func_cache_lookup_module ()
 # - module_desc
 func_get_description ()
 {
-  func_cache_lookup_module "$1"
-  eval "module_desc=\"\$${cachevar}_desc\""
+  if $do_cache; then
+    func_cache_lookup_module "$1"
+    eval "module_desc=\"\$${cachevar}_desc\""
+  else
+    func_lookup_file "modules/$1"
+    module_desc=`sed -n -e "/^Description$sed_extract_prog" < "$lookedup_file"`
+  fi
 }
 
 # func_get_status module
@@ -1492,8 +1528,13 @@ func_get_description ()
 # - module_status
 func_get_status ()
 {
-  func_cache_lookup_module "$1"
-  eval "module_status=\"\$${cachevar}_status\""
+  if $do_cache; then
+    func_cache_lookup_module "$1"
+    eval "module_status=\"\$${cachevar}_status\""
+  else
+    func_lookup_file "modules/$1"
+    module_status=`sed -n -e "/^Status$sed_extract_prog" < "$lookedup_file"`
+  fi
 }
 
 # func_get_notice module
@@ -1503,8 +1544,13 @@ func_get_status ()
 # - module_notice
 func_get_notice ()
 {
-  func_cache_lookup_module "$1"
-  eval "module_notice=\"\$${cachevar}_notice\""
+  if $do_cache; then
+    func_cache_lookup_module "$1"
+    eval "module_notice=\"\$${cachevar}_notice\""
+  else
+    func_lookup_file "modules/$1"
+    module_notice=`sed -n -e "/^Notice$sed_extract_prog" < "$lookedup_file"`
+  fi
 }
 
 # func_get_applicability module
@@ -1516,8 +1562,13 @@ func_get_notice ()
 # The expected result is either 'main', or 'tests', or 'all'.
 func_get_applicability ()
 {
-  func_cache_lookup_module "$1"
-  eval module_applicability=\$${cachevar}_applicability
+  if $do_cache; then
+    func_cache_lookup_module "$1"
+    eval module_applicability=\$${cachevar}_applicability
+  else
+    func_lookup_file "modules/$1"
+    module_applicability=`sed -n -e "/^Applicability$sed_extract_prog" < 
"$lookedup_file"`
+  fi
   if test -z "$module_applicability"; then
     # The default is 'main' or 'tests', depending on the module's name.
     case $1 in
@@ -1534,8 +1585,14 @@ func_get_applicability ()
 # - module_files
 func_get_filelist ()
 {
-  func_cache_lookup_module "$1"
-  eval 
"module_files=\"\$${cachevar}_files\"\${nl}m4/00gnulib.m4\${nl}m4/gnulib-common.m4"
+  if $do_cache; then
+    func_cache_lookup_module "$1"
+    eval 
"module_files=\"\$${cachevar}_files\"\${nl}m4/00gnulib.m4\${nl}m4/gnulib-common.m4"
+  else
+    func_lookup_file "modules/$1"
+    module_files=`sed -n -e "/^Files$sed_extract_prog" < "$lookedup_file"`
+    module_files="$module_files${nl}m4/00gnulib.m4${nl}m4/gnulib-common.m4"
+  fi
   case "$autoconf_minversion" in
     2.59)
       module_files="$module_files${nl}m4/onceonly.m4"
@@ -1607,8 +1664,13 @@ func_get_dependencies ()
       ;;
   esac
   # Then the explicit dependencies listed in the module description.
-  func_cache_lookup_module "$1"
-  eval "module_deps=\"\$module_deps\$nl\$${cachevar}_deps\""
+  if $do_cache; then
+    func_cache_lookup_module "$1"
+    eval "module_deps=\"\$module_deps\$nl\$${cachevar}_deps\""
+  else
+    func_lookup_file "modules/$1"
+    module_deps=`sed -n -e "/^Depends-on$sed_extract_prog" < "$lookedup_file"`
+  fi
 }
 
 # func_get_autoconf_early_snippet module
@@ -1618,8 +1680,13 @@ func_get_dependencies ()
 # - module_config_early
 func_get_autoconf_early_snippet ()
 {
-  func_cache_lookup_module "$1"
-  eval "module_config_early=\"\$${cachevar}_config_early\""
+  if $do_cache; then
+    func_cache_lookup_module "$1"
+    eval "module_config_early=\"\$${cachevar}_config_early\""
+  else
+    func_lookup_file "modules/$1"
+    module_config_early=`sed -n -e "/^configure\.ac-early$sed_extract_prog" < 
"$lookedup_file"`
+  fi
 }
 
 # func_get_autoconf_snippet module
@@ -1629,8 +1696,13 @@ func_get_autoconf_early_snippet ()
 # - module_config
 func_get_autoconf_snippet ()
 {
-  func_cache_lookup_module "$1"
-  eval "module_config=\"\$${cachevar}_config\""
+  if $do_cache; then
+    func_cache_lookup_module "$1"
+    eval "module_config=\"\$${cachevar}_config\""
+  else
+    func_lookup_file "modules/$1"
+    module_config=`sed -n -e "/^configure\.ac$sed_extract_prog" < 
"$lookedup_file"`
+  fi
 }
 
 # func_get_automake_snippet module
@@ -1641,8 +1713,13 @@ func_get_autoconf_snippet ()
 func_get_automake_snippet ()
 {
   mymodule=$1
-  func_cache_lookup_module "$mymodule"
-  eval "module_makefile=\"\$${cachevar}_makefile\""
+  if $do_cache; then
+    func_cache_lookup_module "$mymodule"
+    eval "module_makefile=\"\$${cachevar}_makefile\""
+  else
+    func_lookup_file "modules/$1"
+    module_makefile=`sed -n -e "/^Makefile\.am$sed_extract_prog" < 
"$lookedup_file"`
+  fi
   case "$1" in
     *-tests)
       # *-tests module live in tests/, not lib/.
@@ -1667,9 +1744,16 @@ func_get_automake_snippet ()
         ta
       }'
       sed_extract_mentioned_files='s/^lib_SOURCES[      ]*+=[   ]*//p'
-      already_mentioned_files=` \
-        { eval 'echo "$'${cachevar}'_makefile"'; echo; } \
-        | sed -n -e 's/#.*//' -e "$sed_combine_lines" -e 
"$sed_extract_mentioned_files"`
+      if $do_cache; then
+        already_mentioned_files=` \
+          { eval 'echo "$'${cachevar}'_makefile"'; echo; } \
+          | sed -n -e 's/#.*//' -e "$sed_combine_lines" -e 
"$sed_extract_mentioned_files"`
+      else
+        already_mentioned_files=` \
+          sed -n -e "/^Makefile\.am$sed_extract_prog" < "$lookedup_file" \
+          | sed -e "$sed_combine_lines" \
+          | sed -n -e "$sed_extract_mentioned_files" | sed -e 's/#.*//'`
+      fi
       func_get_filelist $1
       all_files=$module_files
       func_filter_filelist lib_files "$nl" "$all_files" 'lib/' '' 'lib/' ''
@@ -1732,9 +1816,15 @@ func_get_automake_snippet ()
 # - module_include
 func_get_include_directive ()
 {
-  func_cache_lookup_module "$1"
-  module_include=`eval "echo \\"\\$${cachevar}_include\\"" | \
-    sed -e 's/^\(["<]\)/#include \1/'`
+  if $do_cache; then
+    func_cache_lookup_module "$1"
+    module_include=`eval "echo \\"\\$${cachevar}_include\\"" | \
+      sed -e 's/^\(["<]\)/#include \1/'`
+  else
+    func_lookup_file "modules/$1"
+    module_include=`sed -n -e "/^Include$sed_extract_prog" < "$lookedup_file" 
| \
+      sed -e 's/^\(["<]\)/#include \1/'`
+  fi
 }
 
 # func_get_link_directive module
@@ -1744,8 +1834,13 @@ func_get_include_directive ()
 # - module_link
 func_get_link_directive ()
 {
-  func_cache_lookup_module "$1"
-  eval "module_link=\"\$${cachevar}_link\""
+  if $do_cache; then
+    func_cache_lookup_module "$1"
+    eval "module_link=\"\$${cachevar}_link\""
+  else
+    func_lookup_file "modules/$1"
+    module_link=`sed -n -e "/^Link$sed_extract_prog" < "$lookedup_file"`
+  fi
 }
 
 # func_get_license module
@@ -1755,8 +1850,13 @@ func_get_link_directive ()
 # - module_license
 func_get_license ()
 {
-  func_cache_lookup_module "$1"
-  eval "module_license=\"\$${cachevar}_license\""
+  if $do_cache; then
+    func_cache_lookup_module "$1"
+    eval "module_license=\"\$${cachevar}_license\""
+  else
+    func_lookup_file "modules/$1"
+    module_license=`sed -n -e "/^License$sed_extract_prog" < "$lookedup_file"`
+  fi
   # The default is GPL.
   case $module_license in
     *[!\       \ ]*) ;;
@@ -1771,8 +1871,13 @@ func_get_license ()
 # - module_maint
 func_get_maintainer ()
 {
-  func_cache_lookup_module "$1"
-  eval "module_maint=\"\$${cachevar}_maint\""
+  if $do_cache; then
+    func_cache_lookup_module "$1"
+    eval "module_maint=\"\$${cachevar}_maint\""
+  else
+    func_lookup_file "modules/$1"
+    module_maint=`sed -n -e "/^Maintainer$sed_extract_prog" < "$lookedup_file"`
+  fi
 }
 
 # func_get_tests_module module
-- 
1.6.6.244.g4b0c





reply via email to

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