libtool-patches
[Top][All Lists]
Advanced

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

Re: shell portability: don't use `set --'


From: Ralf Wildenhues
Subject: Re: shell portability: don't use `set --'
Date: Tue, 28 Dec 2004 14:52:30 +0100
User-agent: Mutt/1.4.1i

* Gary V. Vaughan wrote on Fri, Dec 24, 2004 at 03:28:34PM CET:
> Ralf Wildenhues wrote:
> >If so, OK to apply to HEAD and branch-2-0?
> >
> >     * Makefile.am, bootstrap, clcommit.m4sh, libtoolize.m4sh,
> >     config/ltmain.m4sh: Replace `set --' with `set x [...]; shift'
> >     for portability.
> 
> Actually, it is probably my fault for having let the -- idiom creep into
> libtool.  Up until 1.5 `set dummy ...' was used consistently throughout.
> 
> I think we should continue in the same vein.  So, yes, but using dummy
> instead of x.  While we're at it, adding something akin to the following
> to sh.test should stop us (me!) accidentally doing it again:

Thanks.  I applied the following, slightly simpler patch (including your
test) to HEAD and branch-2-0.

Regards,
Ralf


2004-12-28  Ralf Wildenhues  <address@hidden>,
            Gary V. Vaughan <address@hidden>
 
        * Makefile.am, bootstrap, clcommit.m4sh, libtoolize.m4sh,
        config/ltmain.m4sh: Replace `set --' with `set dummy [...]; shift'
        for portability.  tests/sh.test: Test for this.

Index: Makefile.am
===================================================================
RCS file: /cvsroot/libtool/libtool/Makefile.am,v
retrieving revision 1.137
diff -u -r1.137 Makefile.am
--- Makefile.am 20 Dec 2004 13:08:33 -0000      1.137
+++ Makefile.am 28 Dec 2004 13:45:06 -0000
@@ -46,7 +46,7 @@
        -e 's,@prefix\@,$(prefix),g' \
        -e "s,@configure_input\@,Generated from $$input; do not edit by hand,g"
 
-timestamp = set -- `$(MKSTAMP) < $(top_srcdir)/ChangeLog`; \
+timestamp = set dummy `$(MKSTAMP) < $(top_srcdir)/ChangeLog`; shift; \
        case $(VERSION) in \
          *[acegikmoqsuwy]) TIMESTAMP=" $$1 $$2 $$3" ;; \
          *) TIMESTAMP="" ;; \
@@ -101,7 +101,7 @@
 MKSTAMP = $(SHELL) $(top_srcdir)/config/mkstamp
 $(top_srcdir)/stamp-vcl: vcl-tmp clean-ltmain-sh ChangeLog
 vcl-tmp:
-       @set -- `$(MKSTAMP) < $(top_srcdir)/ChangeLog`; \
+       @set dummy `$(MKSTAMP) < $(top_srcdir)/ChangeLog`; shift; \
        echo "$$1" > vcl.tmp; \
        cmp -s vcl.tmp $(top_srcdir)/stamp-vcl \
          || (echo "Updating stamp-vcl"; cp vcl.tmp $(top_srcdir)/stamp-vcl)
@@ -124,7 +124,7 @@
 # how ltversion.m4 appears in our dependencies.
 EXTRA_DIST += m4/ltversion.in m4/ltversion.m4
 $(top_srcdir)/m4/ltversion.m4: m4/ltversion.in configure.ac 
$(top_srcdir)/stamp-vcl
-       set -- `$(MKSTAMP) < $(top_srcdir)/ChangeLog`; \
+       set dummy `$(MKSTAMP) < $(top_srcdir)/ChangeLog`; shift; \
        cd $(top_srcdir); \
        rm -f m4/ltversion.tmp; \
        serial=`echo $$1 | sed 's,^1[.],,g'`; \
Index: bootstrap
===================================================================
RCS file: /cvsroot/libtool/libtool/bootstrap,v
retrieving revision 1.55
diff -u -r1.55 bootstrap
--- bootstrap   24 Nov 2004 14:55:54 -0000      1.55
+++ bootstrap   28 Dec 2004 13:45:06 -0000
@@ -49,7 +49,8 @@
 fi
 
 # Extract the package name and version number from configure.ac:
-set -- `sed '/AC_INIT/{s/[][,()]/ /g; p;};d' configure.ac`
+set dummy `sed '/AC_INIT/{s/[][,()]/ /g; p;};d' configure.ac`
+shift
 
 # Whip up some dirty Makefiles:
 makefiles=
Index: clcommit.m4sh
===================================================================
RCS file: /cvsroot/libtool/libtool/clcommit.m4sh,v
retrieving revision 1.6
diff -u -r1.6 clcommit.m4sh
--- clcommit.m4sh       19 Nov 2004 17:04:22 -0000      1.6
+++ clcommit.m4sh       28 Dec 2004 13:45:06 -0000
@@ -130,7 +130,7 @@
                        set -x
                        ;;
 
-      --fast)          set -- --force --first ${1+"$@"}        ;;
+      --fast)          set dummy --force --first ${1+"$@"}; shift      ;;
 
       -f|--force)      opt_update=false; PAGER=cat             ;;
 
@@ -200,7 +200,8 @@
                        fi
                        # The funny quoting allows keeping one option per
                        # line in $rc_file:
-                       eval set -- `echo \`cat $rc_file\` 
\\\${1+\"address@hidden"}`
+                       eval set dummy `echo \`cat $rc_file\` 
\\\${1+\"address@hidden"}`
+                       shift
                        ;;
 
       -s|--sendmail)   test $# = 0 && func_missing_arg $opt && break
@@ -246,21 +247,24 @@
       --*=*)
                        arg=`echo "$opt" | $SED "$my_sed_long_arg"`
                        opt=`echo "$opt" | $SED "$my_sed_long_opt"`
-                       set -- "$opt" "$arg" ${1+"$@"}
+                       set dummy "$opt" "$arg" ${1+"$@"}
+                       shift
                        ;;
 
       # Separate optargs to short options:
       -m*|-F*|-C*|-S*|-s*|-z*)
                        arg=`echo "$opt" |$SED "$my_sed_single_rest"`
                        opt=`echo "$opt" |$SED "$my_sed_single_opt"`
-                       set -- "$opt" "$arg" ${1+"$@"}
+                       set dummy "$opt" "$arg" ${1+"$@"}
+                       shift
                        ;;
 
       # Separate non-argument short options:
       -f*|-1*|-n*|-q*)
                        rest=`echo "$opt" |$SED "$my_sed_single_rest"`
                        opt=`echo "$opt" |$SED "$my_sed_single_opt"`
-                       set -- "$opt" "-$rest" ${1+"$@"}
+                       set dummy "$opt" "-$rest" ${1+"$@"}
+                       shift
                        ;;
 
       -\?|-h)          func_usage                                      ;;
@@ -268,7 +272,7 @@
       --version)       func_version                                    ;;
       --)              break                                           ;;
       -*)              func_fatal_help "unrecognized option \`$opt'"   ;;
-      *)               set -- "$opt" ${1+"$@"};        break           ;;
+      *)               set dummy "$opt" ${1+"$@"};     shift; break            
;;
     esac
   done
 
Index: libtoolize.m4sh
===================================================================
RCS file: /cvsroot/libtool/libtool/libtoolize.m4sh,v
retrieving revision 1.7
diff -u -r1.7 libtoolize.m4sh
--- libtoolize.m4sh     28 Dec 2004 13:31:10 -0000      1.7
+++ libtoolize.m4sh     28 Dec 2004 13:45:06 -0000
@@ -161,14 +161,16 @@
       --*=*)
                        arg=`$ECHO "X$opt" | $Xsed -e "$my_sed_long_arg"`
                        opt=`$ECHO "X$opt" | $Xsed -e "$my_sed_long_opt"`
-                       set -- "$opt" "$arg" ${1+"$@"}
+                       set dummy "$opt" "$arg" ${1+"$@"}
+                       shift
                        ;;
 
       # Separate non-argument short options:
       -c*|-i*|-f*|-n*|-q*|-v*)
                        rest=`$ECHO "X$opt" | $Xsed -e "$my_sed_single_rest"`
                        opt=`$ECHO "X$opt" | $Xsed -e "$my_sed_single_opt"`
-                       set -- "$opt" "-$rest" ${1+"$@"}
+                       set dummy "$opt" "-$rest" ${1+"$@"}
+                       shift
                        ;;
 
       -\?|-h)          func_usage                                      ;;
Index: config/ltmain.m4sh
===================================================================
RCS file: /cvsroot/libtool/libtool/config/ltmain.m4sh,v
retrieving revision 1.38
diff -u -r1.38 ltmain.m4sh
--- config/ltmain.m4sh  28 Dec 2004 13:31:11 -0000      1.38
+++ config/ltmain.m4sh  28 Dec 2004 13:45:06 -0000
@@ -407,25 +407,25 @@
   # Shorthand for --mode=foo, only valid as the first argument
   case $1 in
   clean|clea|cle|cl)
-    shift; set -- --mode clean ${1+"$@"}
+    shift; set dummy --mode clean ${1+"$@"}; shift
     ;;
   compile|compil|compi|comp|com|co|c)
-    shift; set -- --mode compile ${1+"$@"}
+    shift; set dummy --mode compile ${1+"$@"}; shift
     ;;
   execute|execut|execu|exec|exe|ex|e)
-    shift; set -- --mode execute ${1+"$@"}
+    shift; set dummy --mode execute ${1+"$@"}; shift
     ;;
   finish|finis|fini|fin|fi|f)
-    shift; set -- --mode finish ${1+"$@"}
+    shift; set dummy --mode finish ${1+"$@"}; shift
     ;;
   install|instal|insta|inst|ins|in|i)
-    shift; set -- --mode install ${1+"$@"}
+    shift; set dummy --mode install ${1+"$@"}; shift
     ;;
   link|lin|li|l)
-    shift; set -- --mode link ${1+"$@"}
+    shift; set dummy --mode link ${1+"$@"}; shift
     ;;
   uninstall|uninstal|uninsta|uninst|unins|unin|uni|un|u)
-    shift; set -- --mode uninstall ${1+"$@"}
+    shift; set dummy --mode uninstall ${1+"$@"}; shift
     ;;
   esac
 
@@ -492,21 +492,24 @@
       -dlopen=*|--mode=*|--tag=*)
                        arg=`$ECHO "X$opt" | $Xsed -e "$my_sed_long_arg"`
                        opt=`$ECHO "X$opt" | $Xsed -e "$my_sed_long_opt"`
-                       set -- "$opt" "$arg" ${1+"$@"}
+                       set dummy "$opt" "$arg" ${1+"$@"}
+                       shift
                        ;;
 
       # Separate optargs to short options:
 #      -x*|-y*)
 #                      arg=`$ECHO "X$opt" |$Xsed -e "$my_sed_single_rest"`
 #                      opt=`$ECHO "X$opt" |$Xsed -e "$my_sed_single_opt"`
-#                      set -- "$opt" "$arg" ${1+"$@"}
+#                      set dummy "$opt" "$arg" ${1+"$@"}
+#                      shift
 #                      ;;
 
       # Separate non-argument short options:
 #      -z*|-z*|-y*)
 #                      rest=`$ECHO "X$opt" |$Xsed -e "$my_sed_single_rest"`
 #                      opt=`$ECHO "X$opt" |$Xsed -e "$my_sed_single_opt"`
-#                      set -- "$opt" "-$rest" ${1+"$@"}
+#                      set dummy "$opt" "-$rest" ${1+"$@"}
+#                      shift
 #                      ;;
 
       -\?|-h)          func_usage                                      ;;
Index: tests/sh.test
===================================================================
RCS file: /cvsroot/libtool/libtool/tests/sh.test,v
retrieving revision 1.20
diff -u -r1.20 sh.test
--- tests/sh.test       7 Oct 2004 13:01:36 -0000       1.20
+++ tests/sh.test       28 Dec 2004 13:45:06 -0000
@@ -75,4 +75,10 @@
   status=$EXIT_FAILURE
 fi
 
+# Check for using set -- instead of set dummy
+if $EGREP -n -e 'set[  ]+--[   ]+' $scripts; then
+  echo "use \`set dummy ...' instead of \`set -- ...'"
+  status=$EXIT_FAILURE
+fi
+
 exit $status




reply via email to

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