If the re-exec fails, be sure to remove a temp makefile that was
created to read from stdin.
* src/job.c (exec_command): Return on failure.
(child_execute_job): Call exit if exec_command returns.
* src/job.h (exec_command): Don't mark as NORETURN.
* src/main.c (main): Unlink stdin temporary file if re-exec fails.
* tests/run_make_tests.pl: Get value for ERR_nonexe_file/ERR_exe_dir.
* tests/scripts/features/temp_stdin: Test that temp file unlink works.
The -f, -file, and --makefile options were not properly handled when
re-exec'ing due to makefile updates. This problem, plus a patch and
tests, was reported by Dmitry Goncharov <dgoncharov@users.sf.net>.
While examining this I found another bug: after re-exec we forgot the
batch file was temporary and never deleted it.
I decided to fix all these problems at once using a different fix
than Dmitry's: I created a new internal-only command-line option,
--temp-stdin. When reconstructing the make options for a re-exec,
replace the -f/--file/--makefile option that reads from stdin with
--temp-stdin=<filename> so that the re-exec'd version of make knows
it's a temporary batch file and will delete it.
We no longer need to add the -o options because the re-exec'd make
knows this is a temporary makefile and treats it as such.
To simplify, replace the --file and --makefile options taking a
filename, with just -f<filename> on re-exec.
Some examples of the rewrite:
User command line Re-exec command line
----------------- --------------------
-f- --temp-stdin=<batch>
--file - --temp-stdin=<batch>
-f - --makefile a.mk --temp-stdin=<batch> -fa.mk
--file=a.mk -fa.mk
-fa.mk -fa.mk
-Rf a.mk -Rf a.mk
-Rf- -R --temp-stdin=<batch>
* src/main.c (stdin_offset): Remember the offset into the makefiles
list of the batch file read from stdin. Remove stdin_nm.
(struct command_switch): Create a new --temp-stdin option, which
also updates the makefiles list.
(main): Add the temporary filename to the string cache.
Move the tempfile handling after checking makefile arguments for "-"
so that files provided via --temp-stdin are also handled specially.
When rewriting re-exec options, we may need one more than we had
originally so create a new argv list. Walk through the original
list and convert it to the new list, following the above process.
(decode_switches): Set the stdin_offset flag if we see --temp-stdin.
* tests/scripts/options/dash-f: Add many more tests, provided by
Dmitry Goncharov <dgoncharov@users.sf.net>.
The fix for SV 60595 causes make to re-execute when the makefile is
read from stdin. E.g.
$ printf 'all:; $(info hello)' | make -sf -
Reported by Sergei Trofimovich <siarheit@google.com>
Test added by Paul Smith <psmith@gnu.org>
* src/main.c (main): Set the mtime of the stdin temporary file.
* tests/scripts/features/reinvoke: Add a test.
We already use undef makefile strings to mean "re-use the previous
makefile", so if the string is empty we'll assume it means "don't
use a makefile at all" (don't add -f).
* tests/run_make_tests.pl (run_make_test): If the makefile string
is empty, don't create a makefile or add -f.
* tests/scripts/features/include: Change empty makefile to "\n".
* tests/scripts/misc/close_stdout: Ditto.
* tests/scripts/options/dash-r: Ditto.
* src/main.c (main): Show the temp filename on error. Also on
Windows prefer TMP, then TEMP, and only lastly TMPDIR.
* tests/test_driver.pl: Add TMP, TEMP, and USERPROFILE to the list
of environment variables to preserve.
If a $(shell ...) invocation failed due to a command-not-found error,
make wrote the stdout of that shell to our stderr for some reason.
That seems very wrong.
If the command's stderr was not redirected then its output would have
already been written to its stderr, and if it was redirected then we
shouldn't take it upon ourselves to force it to go to stderr!
* src/function.c (func_shell_base): Append shell stdout even if the
shell command failed.
* tests/run_make_tests.pl: Determine the error generated for
command-not-found situations.
* tests/scripts/functions/shell: Verify that redirecting stderr to
stdout will behave properly if the command is not found.
If a prereq of a pattern is explicitly mentioned as a prereq of an
unrelated rule, it should not be considered an intermediate file.
* tests/scripts/features/double_colon: Add tests mentioning unrelated
explicit targets.
* tests/scripts/features/grouped_targets: Ditto.
* tests/scripts/features/implicit_search: Ditto.
* tests/scripts/features/patternrules: Ditto.
* tests/scripts/features/se_implicit: Ditto.
* tests/scripts/features/statipattrules: Ditto.
Since $(info ) function output is written using two system calls for
the message and the newline, it's possible for output from another
parallel make job to sneak in between them.
Reported by Paul Eggert <eggert@cs.ucla.edu>, who saw the report from
Lars Ingebrigtsen <https://bugs.gnu.org/53358>.
* src/function.c (func_error): Paul provided a fix but instead I
rewrote the entire function: it's not possible for it to be invoked
with anything other than exactly one argument so don't worry about
re-combining the arguments.
Further experimentation shows that my previous thinking that there
was a problem using this was woefully mistaken. The value generated
by the kernel shows runn*ABLE* processes not runn*ING* processes.
* NEWS: Announce the change.
The fix for SV 60595 introduced a backward-incompatibility: rules that
purported to rebuild included files, but didn't actually do so, were
treated as errors whereas before they were ignored. This breaks a
common idiom in makefiles where an empty recipe is created for an
included makefile so make doesn't complain if it doesn't exist.
Unfortunately this means make cannot diagnose some types of errors.
Extra tests supplied by Dmitry Goncharov <dgoncharov@users.sf.net>.
* doc/make.texi (Including Other Makefiles): Clarify this behavior.
* src/main.c (main): Don't run the new check-for-errors behavior.
* tests/scripts/features/reinvoke: Reset tests of the "old" behavior
and add new tests for this situation.
Since we don't know what a loaded function (via Guile or load) may
do, increment the command count just in case.
* src/function.c (struct file_table_entry): New adds_command bool.
(FT_ENTRY): Initialize it to 0 for built-in functions.
(expand_builtin_function): If adds_command, increment the count.
(define_new_function): Set adds_command for loaded functions.
Joe Filion <joefilion4@gmail.com> noted that the string is modified,
and Henrik Carlqvist <hc94@poolhem.se> noticed that it wasn't put
back in all cases.
In SV 43677 we forced targets to be secondary if we found an
intermediate file that was listed as a prerequisite of another
target. This overrides .INTERMEDIATE settings, so doesn't work.
Now that we have an is_explicit flag in targets, use that instead.
* src/implicit.c (pattern_search): Remove setting of secondary.
Preserve the value of the is_explicit flag when creating a new
file target, and consider it when setting the intermediate flag.
* tests/scripts/features/patternrules: Add a test w/out INTERMEDIATE
* tests/scripts/targets/INTERMEDIATE: Add a test with INTERMEDIATE
Target-specific variables used to define the target as "ought to
exist" so they could never be intermediate. Now they can be, so
merge the target-specific variables from the intermediate target
so they're not lost.
* src/implicit.c (pattern_search): Use merge_variable_set_lists
to merge target-specific variables.
* tests/scripts/features/implicit_search: Add tests of target-
specific variable assignments and implicit rules.
* src/main.c (main): Use a separate variable to track final character.
* src/read.c (eval): Track the semicolon position not one beyond it.
* src/variable.c (do_variable_definition): Include a default switch
case to ease the work of the exhaustiveness prover.
We don't need to parse strings into C integer values to compare them.
* src/function.c (parse_textint): Find boundaries of a numeric string.
(func_intcmp): Use parse_textint() to compare integers textually.
* tests/scripts/functions/intcmp: Test with extra-large numbers.
* src/function.c (parse_numeric): Check for empty value and error.
If we find ERANGE just print our own error, not strerror.
(func_word): Use a generic "not good" error message.
(func_wordlist): Ditto
(func_intcmp): Ditto
* tests/run_make_tests.pl: Remove code to find strerror(ERANGE)
* tests/scrips/functions/intcmp: Update the error message.
* tests/scrips/functions/word: Ditto.
When make is invoked in a environment where the user namespace is
restricted, such as under unshare(1) (on GNU/Linux), it won't be able
to find its real UID so the effective UID can't be set to it and
posix_spawn() will fail with EINVAL.
It's not less safe to run recipe jobs using the same UID values that
make was invoked with, so don't worry about this flag.
* src/job.c (child_execute_job): Don't set POSIX_SPAWN_RESETIDS flag.
* tests/scripts/features/errors: Match Windows-specific errors.
* tests/scripts/features/targetvars: Match Windows-specific errors.
* tests/scripts/misc/general4: Match Windows-specific errors.
Modify make functions that parse integer values to use long long
values instead of long: on Windows long is the same as int (4 bytes)
and we don't want behavior to differ between different platforms.
* bootstrap.conf: Change strtol module to strtoll module.
* src/function.c (parse_numeric): Use strtoll() and return long long.
(func_word): Use long long.
(func_wordlist): Use long long. Verify second argument is >= 0.
(func_intcmp): Use long long.
* src/config.ami.template: Don't define HAVE_STRTOLL.
* src/config-vms.template: Define HAVE_STRTOLL.
* src/config.W32.template: Define HAVE_STRTOLL.
* tests/run_make_tests.pl: Set $ERR_out_of_range to the proper string.
* tests/scripts/functions/word: Rework to use the new style and avoid
TAB characters. Verify trailing whitespace is ignored. Add a test
for a negative second argument to wordlist. Add tests for max signed
integer values. Use $ERR_out_of_range for the error string.
* tests/scripts/functions/intcmp: Add tests for min and max signed
integer values. Use $ERR_out_of_range for the error string.
Numbers can come from $(words ...), automatic variables such as
$(MAKELEVEL), from environment variables, or from shell output such as
through $(shell expr ...). The $(intcmp ...) function allows
conditional evaluation controlled by numerical variables.
* NEWS: Announce this feature.
* doc/make.texi (Functions for Conditionals): Document 'intcmp'.
* src/function.c (func_intcmp): Create the 'intcmp' built-in function.
* tests/scripts/functions/intcmp: Test the 'intcmp' built-in function.