autoconf/tests
Zack Weinberg fd633e92cb
AS_IF: Handle else clause being empty after macro expansion (#110369)
AS_IF can emit a syntactically invalid shell if-then-else,

  if CONDITION
  then :
    # ...
  else
  fi

when its IF-FALSE argument consists of macros that don’t produce any
shell code.  This was a documented limitation in AS_IF, but it’s a bad
limitation to have, because macros that *used* to expand to shell
commands might start expanding to nothing in future releases.  For
instance, this broke the libzmq configure script, which did

  AC_PROG_CC
  AX_CHECK_COMPILE_FLAG([-std=gnu11],
    [CFLAGS+=" -std=gnu11"],
    [AC_PROG_CC_C99])

Perfectly valid in 2.69, but in 2.70 AC_PROG_CC_C99 doesn’t produce
any shell code and the script crashes.

We had that limitation for good reason: we can’t just put ‘:’ at the
beginning of the else-clause, like we do for the then-clause, because
that would clobber $? and the IF-FALSE commands might want to inspect
it.  (This doesn’t matter for the then-clause, because $? is always
zero at the beginning of a then-clause anyway.)  The simplest and
least inefficient shell construct I can find that works in this
context is a shell function that does ‘return $?’.  Due to awkward
M4sh initialization ordering constraints (AS_IF gets used before we
can safely use shell functions) an indirection through a shell
variable is necessary.  The structure of a m4sh script is now

  #! /bin/sh
  ## M4sh Initialization
  as_nop=:

  ...
  ## M4sh Shell Functions

  as_fn_nop () { return $?; }
  as_nop=as_fn_nop
  ...

and AS_IF emits

  if CONDITION
  then :
    # ...
  else $as_nop
    # ...
  fi

The uses of AS_IF that appear before the beginning of the M4sh Shell
Functions section are all under our control and they don’t need to
look at $?.

If anyone has a better idea for how to make this work I will be glad
to hear it.

Fixes bug #110369.

* lib/m4sugar/m4sh.m4
  (_AS_IF_ELSE): When $1 is nonempty, invoke _AS_EMPTY_ELSE_PREPARE.
  Emit $as_nop at beginning of else clause.
  (_AS_BOURNE_COMPATIBLE): Initialize as_nop to ‘:’.
  (_AS_EMPTY_ELSE_PREPARE): New macro which emits a definition of
  as_fn_nop and resets as_nop to as_fn_nop.
  (AS_PREPARE, _AS_PREPARE): Invoke _AS_EMPTY_ELSE_PREPARE.
  (_AS_UNSET_PREPARE): Tweak white space.

* tests/m4sh.at (AS_IF and AS_CASE): Test AS_IF’s IF-FALSE argument
  being empty after macro expansion.

* doc/autoconf.texi (AS_IF): Remove warning about use with
  ‘run-if-false’ argument empty after macro expansion.
2020-11-15 14:16:16 -05:00
..
atlocal.in Look harder for a shell whose -n is known to work. 2020-06-29 23:17:15 -07:00
autoscan.at maint: make update-copyright 2020-01-01 11:45:50 -08:00
autotest.at Ignore stderr when testing parallel autotest (#110351). 2020-10-31 09:57:13 -04:00
base.at Support CONFIG_SITE being a list of entries. 2020-11-11 11:19:41 -05:00
c.at Manually sync ChannelDefs.pm from automake. 2020-09-22 15:46:42 -04:00
compile.at tests/compile.at (AC_RUN_IFELSE): typo fix 2020-11-11 11:07:49 -05:00
erlang.at maint: make update-copyright 2020-01-01 11:45:50 -08:00
foreign.at tests: New helper macro AT_CHECK_MAKE. 2020-08-20 14:07:59 -04:00
fortran.at testsuite: Isolate aclocal from third-party macros (#110352). 2020-11-02 11:00:38 -05:00
go.at maint: make update-copyright 2020-01-01 11:45:50 -08:00
local.at Treat msys(2) the same as cygwin when looking at host_os. 2020-10-28 11:07:21 -04:00
local.mk Pass $(MAKE) down to testsuite. 2020-08-26 15:12:12 -04:00
m4sh.at AS_IF: Handle else clause being empty after macro expansion (#110369) 2020-11-15 14:16:16 -05:00
m4sugar.at Manually sync ChannelDefs.pm from automake. 2020-09-22 15:46:42 -04:00
mktests.sh Revert to 2.69-compatible behavior in AC_PROG_LEX (#110346) 2020-11-02 16:56:32 -05:00
semantics.at Revert to 2.69-compatible behavior in AC_PROG_LEX (#110346) 2020-11-02 16:56:32 -05:00
statesave.m4 maint: make update-copyright 2020-01-01 11:45:50 -08:00
suite.at tests/suite.at: m4_include acerlang.at. 2020-08-20 08:51:46 -04:00
tools.at Make ‘forbidden tokens, basic’ test more robust. 2020-11-05 10:24:08 -05:00
torture.at Define AC_REQUIRE_AUX_FILE with AC_DEFUN. 2020-11-05 08:59:46 -05:00
wrapper.as Improve handling of missing aux scripts (autoreconf) 2020-10-20 16:57:01 -04:00