summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefano Lattarini <stefano.lattarini@gmail.com>2011-12-26 10:06:18 +0100
committerStefano Lattarini <stefano.lattarini@gmail.com>2011-12-26 22:15:38 +0100
commiteee6c2224d2f494682ff63f681800811a1aac3f7 (patch)
tree3d380fa6582d5730e1f69e4221e019cda2e92e8f
parent8fb1aafa0d81175f3ca27ed7ed2e0532c8af9902 (diff)
downloadautoconf-eee6c2224d2f494682ff63f681800811a1aac3f7.tar.gz
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.
-rw-r--r--ChangeLog11
-rw-r--r--lib/m4sugar/m4sh.m422
-rw-r--r--tests/m4sh.at87
3 files changed, 120 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index 6fd538e1..a91c5f08 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,16 @@
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
* lib/m4sugar/m4sh.m4 (_AS_DETECT_BETTER_SHELL): Move code to
handle the re-execution of the shell ...
diff --git a/lib/m4sugar/m4sh.m4 b/lib/m4sugar/m4sh.m4
index a92cd229..2bffee8c 100644
--- a/lib/m4sugar/m4sh.m4
+++ b/lib/m4sugar/m4sh.m4
@@ -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
diff --git a/tests/m4sh.at b/tests/m4sh.at
index a5ef905b..cdd0e7ec 100644
--- a/tests/m4sh.at
+++ b/tests/m4sh.at
@@ -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. ##
## ------------------- ##