>From 1762e46e97c4842b2045fd10f4514649e44247bd Mon Sep 17 00:00:00 2001 Message-Id: In-Reply-To: References: From: Stefano Lattarini Date: Mon, 26 Dec 2011 10:06:18 +0100 Subject: [PATCH 2/3] 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, 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 | 10 ++++++ lib/m4sugar/m4sh.m4 | 22 +++++++++++++ tests/m4sh.at | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 119 insertions(+), 0 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1e9fdce..8e3b881 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,15 @@ 2011-12-26 Stefano Lattarini + 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, 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 + 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 a0c9b1f..9518a52 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 a5ef905..cdd0e7e 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 . +## --------------------------- ## +## 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 '' '&' '!;*' '<(address@hidden:@)>,' 'x +y z +1 2 3')], [0], +[Fake shell executed. +nargs = 5 + :: + :&: + :!;*: + :<(address@hidden:@)>,: + :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. ## ## ------------------- ## -- 1.7.7.3