]> git.ipfire.org Git - thirdparty/autoconf.git/commitdiff
m4sh: allow forced re-execution with $CONFIG_SHELL, if it's set
authorStefano Lattarini <stefano.lattarini@gmail.com>
Mon, 26 Dec 2011 09:06:18 +0000 (10:06 +0100)
committerStefano Lattarini <stefano.lattarini@gmail.com>
Mon, 26 Dec 2011 21:15:38 +0000 (22:15 +0100)
* lib/m4sugar/m4sh.m4 (_AS_DETECT_BETTER_SHELL): If the m4sh client
has defined the macro `_AS_FORCE_REEXEC_WITH_CONFIG_SHELL' to
"yes", emit code to always re-execute the current script with
$CONFIG_SHELL, if that's set.
* tests/m4sh.at: Add tests for the new and old semantics, in ...
(Re-exec with CONFIG_SHELL, Forced re-exec with CONFIG_SHELL): ...
these new test groups.

ChangeLog
lib/m4sugar/m4sh.m4
tests/m4sh.at

index 6fd538e156c30eaea59d652efc15062be3a9fbe2..a91c5f085a6b963a2edb929a333cfb7d880a3aee 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2011-12-26  Stefano Lattarini  <stefano.lattarini@gmail.com>
+
+       m4sh: allow forced re-execution with $CONFIG_SHELL, if it's set
+       * lib/m4sugar/m4sh.m4 (_AS_DETECT_BETTER_SHELL): If the m4sh client
+       has defined the macro `_AS_FORCE_REEXEC_WITH_CONFIG_SHELL' to
+       "yes", emit code to always re-execute the current script with
+       $CONFIG_SHELL, if that's set.
+       * tests/m4sh.at: Add tests for the new and old semantics, in ...
+       (Re-exec with CONFIG_SHELL, Forced re-exec with CONFIG_SHELL): ...
+       these new test groups.
+
 2011-12-26  Stefano Lattarini  <stefano.lattarini@gmail.com>
 
        m4sh: refactor _AS_DETECT_BETTER_SHELL, for future changes
index a92cd229cb0b4f6ca36b1ee37239676c8ad731c0..2bffee8c36e1b311e7decdd8ceda96e9415b2986 100644 (file)
@@ -192,6 +192,28 @@ m4_define([_AS_DETECT_SUGGESTED_PRUNE],
 #
 # This code is run outside any trap 0 context, hence we can simplify AS_EXIT.
 m4_defun([_AS_DETECT_BETTER_SHELL],
+dnl
+dnl By default, do not force re-execution of the script just because
+dnl the user has pre-set $CONFIG_SHELL; do so only if the m4sh client has
+dnl defined the internal variable `_AS_FORCE_REEXEC_WITH_CONFIG_SHELL' to
+dnl "yes".
+dnl FIXME: This interface is acceptable for the moment, as a private,
+dnl FIXME: internal one; but if we want to make the "always re-execute"
+dnl FIXME: feature public, we should find a better interface!
+[m4_if(_AS_FORCE_REEXEC_WITH_CONFIG_SHELL, [yes],
+  [# Use a proper internal environment variable to ensure we don't fall
+  # into an infinite loop, continuously re-executing ourselves.
+  if test x"${_as_can_reexec}" != xno && test "x$CONFIG_SHELL" != x; then
+    _as_can_reexec=no; export _as_can_reexec;
+    _AS_REEXEC_WITH_SHELL([$CONFIG_SHELL])
+  fi
+  # We don't want this to propagate to other subprocesses.
+  dnl This might be especially important in case an m4sh-generated script
+  dnl is used to later execute other m4sh-generated scripts.  This happens
+  dnl for example in autoconf's own testsuite (and happens *a lot* there,
+  dnl in fact).
+  AS_UNSET([_as_can_reexec])
+])]dnl
 dnl Remove any tests from suggested that are also required
 [m4_set_map([_AS_DETECT_SUGGESTED_BODY], [_AS_DETECT_SUGGESTED_PRUNE])]dnl
 [m4_pushdef([AS_EXIT], [exit m4_default(]m4_dquote([$][1])[, 1)])]dnl
index a5ef905b638ff89c851e500286f77c8081fef59d..cdd0e7ecb56c1b5192713a11ff2404a5a10afc14 100644 (file)
@@ -17,6 +17,93 @@ AT_BANNER([M4sh.])
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+## --------------------------- ##
+## Re-exec with CONFIG_SHELL.  ##
+## --------------------------- ##
+
+AT_SETUP([No extra re-exec with CONFIG_SHELL])
+AT_KEYWORDS([CONFIG_SHELL])
+AT_DATA_M4SH([script.as],
+[[
+dnl We have to muck with internal details to goad the script into
+dnl thinking that the default shell is always good enough.
+m4_define([_AS_DETECT_REQUIRED_BODY], [])dnl
+m4_define([_AS_DETECT_SUGGESTED_BODY], [])dnl
+AS_INIT
+echo foo > ok
+]])
+AT_CHECK_M4SH
+AT_CHECK([CONFIG_SHELL=/bin/false ./script], [0], [], [])
+AT_CHECK([test -f ok], [0])
+rm -f ok
+
+AT_CLEANUP
+
+AT_SETUP([Forced re-exec with CONFIG_SHELL])
+AT_KEYWORDS([CONFIG_SHELL])
+
+AT_DATA_M4SH([script.as],
+[[m4_define([_AS_FORCE_REEXEC_WITH_CONFIG_SHELL], [yes])
+AS_INIT
+echo foo > sentinel
+]])
+AT_CHECK_M4SH
+
+AT_DATA([fake-shell],
+[[#!/bin/sh
+echo 'Fake shell executed.'
+shift # fake shell
+echo "nargs = @S|@#"
+for i
+do
+  printf ' :%s:\n' "$i"
+done
+]])
+chmod a+x fake-shell
+
+AT_CHECK([CONFIG_SHELL=./fake-shell ./script 1 2 4 8], [0],
+[Fake shell executed.
+nargs = 4
+ :1:
+ :2:
+ :4:
+ :8:
+], [])
+AT_CHECK([test ! -f sentinel], [0])
+test ! -f sentinel || rm -f sentinel # Cleanup for next test.
+
+AT_CHECK(
+[CONFIG_SHELL=`pwd`/fake-shell sh script a 'b  c' '  d         e '],
+[0],
+[Fake shell executed.
+nargs = 3
+ :a:
+ :b  c:
+ :  d          e :
+], [])
+AT_CHECK([test ! -f sentinel], [0])
+test ! -f sentinel || rm -f sentinel # Cleanup for next test.
+
+AT_CHECK([(PATH=`pwd`:$PATH; export PATH;
+CONFIG_SHELL=fake-shell script '' '&' '!;*' '<($[]@%:@)>,' 'x
+y  z
+1 2 3')], [0],
+[Fake shell executed.
+nargs = 5
+ ::
+ :&:
+ :!;*:
+ :<($[]@%:@)>,:
+ :x
+y  z
+1 2 3:
+], [])
+AT_CHECK([test ! -f sentinel], [0])
+test ! -f sentinel || rm -f sentinel # Cleanup for next test.
+
+AT_CLEANUP
+
+
 ## ------------------- ##
 ## AS_WARN, AS_ERROR.  ##
 ## ------------------- ##