Set the jobserver pipe to non-blocking before writing tokens; if a
token write fails the user's jobserver value is too large so fail.
Original implementation: Dmitry Goncharov <dgoncharov@users.sf.net>
* src/posixos.c (set_blocking): Split into force_blocking() which
always enables/disables blocking; set_blocking() may call it.
(jobserver_setup): Set the write side of the pipe to non-blocking
before writing tokens. If it fails with EAGAIN we know the pipe
is full: create a fatal error.
* tests/scripts/features/jobserver: Test a too-large jobserver.
Make sure the jobserver named pipe is deleted even if the
jobserver_setup() function calls fatal() and exits early.
* src/main.c (clean_jobserver): Always reset_jobserver().
* src/posixos.c (jobserver_setup): Set job_root up front.
* tests/test_driver.pl: Print out the logfile pathname on error.
For tests with regex matches this might be the only file available.
Don't print the base filename unless one is created.
An explicitly mentioned double-colon target cannot be intermediate.
* src/read.c (record_files): Set file->is_explicit in the case of an
explicitly mentioned file built by a double colon rule.
* src/file.c (print_file): Have print_file print whether a file is
explicitly mentioned.
* tests/scripts/features/patternrules: Add tests.
* src/file.c (remove_intermediates): Fix an error message about a
failure to remove an intermediate file.
* tests/scripts/features/patternrules: Add tests.
Artem Klimov noticed that current shuffle implementation suffers from
probability bias due to a typical bug in the shuffling implementation.
When we consider already shuffled element we slightly bias their
propability.
https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle#The_modern_algorithm
suggests shuffling each "struck" element only once.
Before the change probabilities of 4-element array to land from `i`
index to `j` index are:
0 1 2 3
_____ _____ _____ _____
0 | 25.00 29.30 24.60 21.10
1 | 25.00 22.25 28.13 24.63
2 | 25.00 23.44 22.26 29.30
3 | 25.00 25.01 25.01 24.98
Note that `0->1` probability is almost 29% while `0->3` os only 21%.
After the change probabilities are not as biased:
0 1 2 3
_____ _____ _____ _____
0 | 24.99 24.99 25.01 25.01
1 | 24.99 25.04 24.99 24.99
2 | 25.01 25.00 25.00 24.99
3 | 25.01 24.98 25.00 25.01
* src/shuffle.c (random_shuffle_array): Fix biased shuffle by avoiding
already "struck" elements.
* src/function.c (abspath): len is now ptrdiff_t,
to avoid GCC warning about comparing signed to unsigned.
It really is a pointer difference, after all.
Rejigger comparision to avoid undefined behavior
if dest + len is an invalid pointer.
strncpy is trickier and a bit slower.
* src/function.c (func_realpath, func_abspath):
* src/misc.c (xstrndup):
Prefer memcpy or mempcpy to strncpy when the source length is known.
Add more const to static arrays. On some systems this allows more
data to be placed in RO segments and shared between multiple
instances of the make executable. Anyway more const is good hygiene.
* src/default.c: Add const to arrays.
* src/function.c: Ditto.
* src/hash.c: Ditto.
* src/hash.h: Ditto.
* src/job.c: Ditto.
* src/read.c: Ditto.
* src/remake.c: Ditto.
* src/rule.c: Ditto.
* src/rule.h: Ditto.
* doc/make.texi: Use the newer email address in the manual.
* gl/lib/fnmatch.c: Use a URL instead of a street address.
* gl/lib/fnmatch.in.h: Ditto.
* gl/lib/glob.c: Ditto.
* gl/lib/glob.in.h: Ditto.
Suggested patch by Hannes Domani <ssbssa@yahoo.de>
* src/remake.c (notice_finished_file): When run with -n, mark
also_make targets as updated.
* tests/scripts/options/dash-n: Test pattern and grouped targets.
* src/dep.h (copy_dep): Make a copy of one struct dep.
* src/misc.c (copy_dep): Implement the new function.
(copy_dep_chain): Call copy_dep() for each dep in the chain.
* src/read.c (record_files): Write our own copy loop and omit the
current file from its own also_make list. Since we don't keep
the function's also_make, free it.
Make enters an infinite loop when some option and MAKEFLAGS=<value>
are specified on the command line. For example,
$ make -r MAKEFLAGS=hello=world
If decode_switches() runs handle_non_switch_argument() from within
the getopt() loop, it would recursively call decode_switches() to
enter a new getopt() loop, corrupting the state of the outer loop.
* src/main.c (decode_switches): Save up non-option arguments and run
handle_non_switch_argument() only after we're done with getopt().
* tests/scripts/variables/MAKEFLAGS: Add tests.
Add a warning to control circular dependency detection. Use "warn" as
the default action to be backward-compatible.
* src/warning.h (enum warning_type): Add warning type wt_circular_dep.
* src/warning.c (warn_init): Set default wt_circular_dep to w_warn.
* src/remake.c (update_file_1): Consult the circular-dep warning to
handle circular dependencies.
* tests/scripts/options/warn: Test --warn circular-dep flag.
* tests/scripts/variables/WARNINGS: Test .WARNINGS circular-dep flag.
* doc/make.texi: Document circular-dep warning.
* doc/make.1: Ditto.
Make crashes when -r and MAKEFLAGS= are specified on the command line.
On startup make begins to process command line arguments.
During processing of "MAKEFLAGS=" make calls reset_makeflags, which in
turn calls disable_builtins, which dereferences null suffix_file.
Here is the backtrace.
0 disable_builtins main.c:3482
1 reset_makeflags main.c:3104
2 set_special_var variable.c:1325
3 do_variable_definition variable.c:1693
4 try_variable_definition variable.c:1889
5 handle_non_switch_argument main.c:3021
6 decode_switches main.c:3150
7 main main.c:1621
* src/main.c (disable_builtins): Avoid dereferencing null suffix_file.
* tests/scripts/features/suffixrules: Add a test.
Re-reading this chapter I decided it was time to introduce a complete
rewrite, of at least parts of this. Much of the enhancements added
over the years were in the wrong place or not clear.
* bootstrap.conf: Switch to gnulib stable-202401 branch.
* maintMakefile: Support an EXTRA_CFLAGS variable in maintainer mode.
* README.git: Describe how to use it.
Use intprops.h macros rather than trying to detect integer overflow by
hand, and doing it incorrectly. Example of incorrect behavior:
if val == 3689348814741910323, base == 10, UINTMAX_WIDTH == 64, and
*ptr == '0' then (val*base)+(*ptr-'0') yields 18446744073709551614
which is greater than val even though overflow has occurred.
Fortunately this bug could not be triggered on GNU/Linux hosts,
although it may be possible on platforms (if any) where struct ar_hdr
has members so large that they can represent integers that do not fit
int uintmax_t.
* src/posixos.c (jobserver_setup): Set prefix for FIFO temp file.
Ensure it can't conflict with a "normal" temp file.
* src/w32/w32os.c (os_anontmp): Set prefix for anon temp files.
It turns out that options set on stdout/stderr last after exit.
Leaving append-mode enabled can break other facilities, so reset the
flags on stdout/stderr before we exit.
* src/os.h: Add a new fd_reset_append() to reset flags on FDs.
Modify fd_set_append() to return the old flags.
* src/posixos.c (fd_reset_append): Set provided flags on the FD.
(fd_set_append): Return the previous flags set on the FD.
* src/output.c (output_init): Preserve old flags for stdout/stderr.
(output_close): Reset flags for stdout/stderr.
* src/w32/w32os.c: Implement dummy methods.
GNU Make doesn't use ftime(); we only checked for this to work around
an error in the completely obsolete SCO 3.2 system. Since ftime() is
deprecated, including sys/timeb.h has started throwing warnings on
newer systems so just remove it completely.
Reported by: Collin Funk <collin.funk1@gmail.com>
* configure.ac: Remove the check for sys/timeb.h.
* src/makeint.h: Remove the include of sys/timeb.h.
* src/config.h-vms: Don't define HAVE_SYS_TIMEB_H.
* src/config.h.W32: Ditto.
* src/function.c (func_intcmp): Reverse comparison direction when
both arguments are negative.
* tests/scripts/functions/intcmp: Add tests and remove useless ones.
POSIX requires that a conforming makefile should not use -e if
1) make is invoked with -i
2) A .IGNORE target exists with no prerequisites
3) The current target is a prerequisite of .IGNORE
* src/job.c (start_job_command): Add the target's flags when
constructing argv so it can check (3) above.
(construct_command_argv_internal): Don't set shellflags if it's not
set: this only happens if we're parsing for the slow path and we
don't need them.
(construct_command_argv): Don't allocate buffers if not needed.
When detecting "-ec", check the global ignore_errors_flag and the
current command line flags.
* tests/scripts/targets/IGNORE: Add tests for .IGNORE.
* tests/scripts/targets/POSIX: Add tests for the three cases above.
Appending to a pattern specific variable produces an incorrect value
in the presence of a command line definition or an env override of
the variable. Also, fix pattern/target-specific appending to a
variable with origin override.
* At parse time record_target_var sets the value of a pattern
specific variable to the value defined on command line or to the
value of the env override.
* Later, at build time, recursively_expand_for_file appends this
value of the variable (set in record_target_var) to the command
line value again, regardless of the origin of the variable.
This patch modifies recursively_expand_for_file to avoid appending,
unless the origin of the variable beats or equals the origin of one
of the parent definitions of this variable.
Reported by Rob <robw9739@gmail.com>,
Brian Vandenberg <phantall@gmail.com>,
Markus Oberhumer <markus@oberhumer.com>.
* NEWS: Note the change.
* src/variable.c (do_variable_definition): Avoid merging a
pattern-specific variable with the parent definition when a command
line or env override is present.
* src/expand.c (recursively_expand_for_file): Avoid appending to a
pattern-specific variable, unless the origin of this pattern-specific
variable beats or equals the origin of one of the parent definitions
of this variable.
* doc/make.texi (Override Directive): Add missing cross-reference.
* tests/scripts/variables/append: Add tests.
Ensure the origin of all variables inherited from the environment is
"environment override" if -e is given. Previously only variables
that were set in the makefile had this origin.
PDS: Most of these changes are from Dmitry but I slightly modified
the algorithm: instead of rearranging the way in which MAKEFLAGS is
parsed we reset the env_override value to the default before we
re-parse MAKEFLAGS, then we set the origin of all env vars to the
correct value based on the new setting.
* NEWS: Mention the change for backward-compatibility.
* src/main.c (main): Ensure MAKEFLAGS is always marked special.
(reset_makeflags): Set env_overrides back to default before parsing
MAKEFLAGS.
(decode_switches): Call reset_env_override() to check for changes.
* src/variable.h (reset_env_override): Declare a new function.
* src/variable.c (reset_env_override): Go through all env variables
and ensure the origin is correct based on env_overrides.
(set_env_override): Helper function for the hash.
* tests/scripts/functions/foreach: Fix tests.
* tests/scripts/functions/let: Ditto.
* tests/scripts/functions/origin: Ditto.
* tests/scripts/options/dash-e: Add tests.