Commit graph

2848 commits

Author SHA1 Message Date
Dmitry Goncharov
bb21dd4d2d [SV 62278] Only expand the first pattern during secondary expansion
During normal pattern rule expansion only the first pattern (%) is
expanded; however during secondary expansion all patterns were
expanded.  Modify secondary expansion to match the behavior of normal
expansion.

Implementation tweaked by Paul Smith <psmith@gnu.org>

* src/file.c (expand_deps): Don't use subst_expand() which replaces
all % with $*: instead replace only the first one, by hand.
Fix a memory leak where the dep structure was not always freed.
* tests/scripts/features/statipattrules: Use .RECIPEPREFIX not TAB.
Add a series of tests verifying that static pattern rules with and
without secondary expansion both return the same results.
2022-04-24 10:39:32 -04:00
Paul Smith
93fd0c0c9a * src/commands.h: [SV 62213] Forward-declare struct file / child 2022-04-24 10:39:32 -04:00
Paul Smith
cf56036c60 * tests/test_driver.pl (toplevel): [SV 62174] Enforce the C locale 2022-04-24 10:39:32 -04:00
Paul Smith
88ceff8b2f [SV 62173] Fix archive tests for non-GNU systems
Original patch from Dmitry Goncharov <dgoncharov@users.sf.net>

Fix the ar flags to match the default values in make.  If the
U option is supported, add it to the end not the beginning,
since ARFLAGS now starts with a "-".

* tests/test_driver.pl: Add defaults for global variables.
(get_osname): Preserve $osname if it's set from $^O
* tests/scripts/features/archive: Set the default arflags.
If "U" is available add it to the end of the flags.
2022-04-24 10:39:32 -04:00
Dmitry Goncharov
9755d4c09c * tests/scripts/options/dash-l: [SV 62172] Skip if not available 2022-04-24 10:39:32 -04:00
Dmitry Goncharov
634ef057ad * src/read.c (check_specials): [SV 62171] Reset ARFLAGS under .POSIX 2022-04-24 10:39:32 -04:00
Dmitry Goncharov
949c0464a9 [SV 62145] Remove a stdin temp file on re-exec failure.
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.
2022-04-24 10:39:32 -04:00
Paul Smith
416664b1e7 * tests/scripts/features/errors: Fix Perl warnings
* tests/scripts/options/dash-f: Ditto.
2022-04-18 16:57:06 -04:00
Paul Smith
667d70eac2 [SV 62118] Correctly handle -f- options on re-exec
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>.
2022-02-27 18:01:13 -05:00
Paul Smith
b9078e5bd3 * tests/scripts/variables/MAKE_RESTARTS: Remove TAB chars 2022-02-27 18:01:13 -05:00
Paul Smith
0de7b74896 * README.git: Fix compiler options for ASAN 2022-02-27 18:01:13 -05:00
Paul Smith
236589642e Remove extraneous characters from fatal() calls
The fatal() method adds ".  Stop.\n" to every message.

* src/amiga.c (MyExecute): Remove newline from fatal() message.
* src/job.c (<various>): Ditto.
* src/file.c (snap_deps): Remove "." from fatal() message.
* src/main.c (main): Ditto.
* src/load.c: Ditto.
* tests/scripts/targets/NOTINTERMEDIATE: Fix expected output.
2022-02-27 18:01:13 -05:00
Paul Smith
cb9ac2b0cc * src/main.c: Ensure the stdin temp file is deleted when dying. 2022-02-27 18:01:13 -05:00
Dmitry Goncharov
40a6751abf [SV 62088] Avoid re-exec due to stdin.
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.
2022-02-27 18:00:47 -05:00
Paul Smith
1bc35a7ae7 tests: Allow run_make_test() to avoid passing -f
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.
2022-02-27 17:47:42 -05:00
Paul Smith
8cdaabbf8e tests: Preserve Windows temp environment variables
* 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.
2022-02-27 17:47:19 -05:00
Paul Smith
2be8661433 * tests/test_driver.pl: Support STDIN redirection.
Before running tests, duplicate STDIN then reset it after the test
completes.  Also when -keep is provided, preserve the base and run
files.
2022-02-26 17:19:26 -05:00
Paul Smith
8b3e678ace Ensure buffers are large enough for integer values
Issue raised by Sergei Trofimovich <siarheit@google.com>

* src/makeint.h (INTSTR_LENGTH): Update for unsigned values.
* src/function.c (func_lastword): Use INTSTR_LENGTH as buffer size.
(shell_function_completed): Ditto.
(func_call): Ditto.
* src/remote-cstms.c (start_remote_job): Ditto.
2022-02-21 09:29:41 -05:00
Paul Smith
ec09ec775a * <all>: Update copyright notices. 2022-02-10 14:48:26 -05:00
Paul Smith
bdaeca49e9 * doc/make.1: Use "target" from the SYNOPSIS.
Reported by Helge Kreutzmann <debian@helgefjell.de>
2022-02-06 18:46:32 -05:00
Paul Smith
342a9bb54b Don't write $(shell ...) stdout to stderr on failure
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.
2022-02-06 18:46:32 -05:00
Paul Smith
6761122be0 * Basic.mk.template: Allow arguments to the check target. 2022-02-06 18:46:32 -05:00
Dmitry Goncharov
1fd0bfaf1e [SV 61805] Support quoted whitespace in .SHELLFLAGS with .ONESHELL
* src/job.c (construct_command_argv_internal): Call recursively to
parse .SHELLFLAGS when .ONESHELL is active.
* tests/scripts/targets/ONESHELL: Add tests.
2022-02-06 18:46:32 -05:00
Paul Smith
8eb171e469 * tests/scripts/features/double_colon: Update for modern tests. 2022-02-06 18:46:32 -05:00
Paul Smith
7154e316b7 * tests/scripts/features/implicit_search: Add -r for safety. 2022-02-06 18:46:32 -05:00
Dmitry Goncharov
f3e345c869 [SV 48643] Add more tests of intermediates and unrelated targets
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.
2022-02-06 18:46:32 -05:00
Dmitry Goncharov
d34f46c1f3 [SV 48643] Make prereqs mentioned in unrelated rules explicit
* src/implicit.c (pattern_search): Set is_explicit when a prereq
is mentioned in an unrelated rule.
2022-02-06 18:46:32 -05:00
Dmitry Goncharov
f0ab709640 * src/implicit.c (pattern_search): [SV 61864] Fix debug output. 2022-02-06 18:46:32 -05:00
Paul Smith
5f2d114c6d Avoid interleaved $(info ) output
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.
2022-02-06 18:46:32 -05:00
Paul Smith
cbe0d2e47f * tests/scripts/features/implicit_search: [SV 48643] Cleanups. 2022-02-06 18:46:32 -05:00
Paul Smith
f485881d4a * src/implicit.c (pattern_search): Use const ptrs when possible.
Change suggested by Joe Filion <joefilion4@gmail.com>
2022-02-06 18:46:32 -05:00
Paul Smith
15db387f18 * src/job.c (load_too_high): Re-enable Linux /proc/loadavg checks.
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.
2022-02-06 18:46:32 -05:00
Paul Smith
aab51f7ef2 * doc/make.texi (Using One Shell): Correct example to use $<. 2022-02-06 18:46:29 -05:00
Jouke Witteveen
2b25eac587 * src/function.c (parse_textint): Handle ints without 0 properly.
* tests/scripts/functions/intcmp: Add tests for values without 0.
2022-01-17 19:11:59 -05:00
Paul Smith
e72c5e021f [SV 61226] Revert changes to detect missing included files
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.
2022-01-17 18:45:47 -05:00
Paul Smith
b6a779d262 Ensure that loaded functions increment the command count
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.
2022-01-17 18:45:47 -05:00
Paul Smith
26f4bb89bd * src/read.c (tilde_expand): Put back '/' before returning.
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.
2022-01-17 18:38:32 -05:00
Paul Smith
320714ae85 * tests/scripts/targets/INTERMEDIATE: Rewrite for new test method 2021-12-29 15:27:04 -05:00
Paul Smith
6682fbc2cb Do not force targets to be SECONDARY
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
2021-12-29 15:26:56 -05:00
Dmitry Goncharov
f2b130bda8 [SV 48643] Preserve target-specific variables on intermediate files
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.
2021-12-29 15:26:56 -05:00
Paul Smith
8aba33a8bd * README.template: Clean up patch submission information 2021-12-29 15:26:54 -05:00
Jouke Witteveen
d365bdfdbc * src/read.c (find_percent_cached): [SV 60798] Silence GCC11 warnings 2021-12-19 16:55:50 -05:00
Jouke Witteveen
f440c3ebe2 [SV 60798] Silence bogus GCC10 and GCC11 warnings
* 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.
2021-12-19 16:55:50 -05:00
Paul Smith
3efba8a145 Update documentation with instructions for patch submission
* README.template: Add notes on how to submit patches.
* README.git: Point to the README.
* doc/make.texi: Ditto.
2021-12-19 16:55:50 -05:00
Paul Smith
e7b2f6818c Change HTTP URLs to use HTTPS instead
Also remove unnecessary tests/COPYING file.

* README.template: Change http: to https:
* README.git: Ditto
* doc/make.texi: Ditto
* doc/make.1: Ditto
* src/main.c: Ditto
* maintMakefile: Remove invalid URL
2021-12-19 16:55:50 -05:00
Paul Smith
c90db9276a * src/makeint.h: Compute INTSTR_LENGTH based on size of intmax_t
Math suggested by Edward Welbourne <edward.welbourne@qt.io>
2021-12-19 16:55:47 -05:00
Paul Eggert
7192d0ec4a Remove arbitrary limits on intcmp integers
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.
2021-12-19 16:34:19 -05:00
Paul Smith
9230bfb9ae Use a well-known error string for out-of-bound function arguments
* 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.
2021-12-19 16:34:19 -05:00
Paul Smith
55b993ae09 * doc/make.text (Wildcards): Document that glob results are sorted. 2021-12-19 16:34:19 -05:00
Paul Smith
1d20aa7247 [SV 61621] Don't use POSIX_SPAWN_RESETIDS with posix_spawn()
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.
2021-12-19 16:34:10 -05:00