Commit Graph

257 Commits

Author SHA1 Message Date
rillig 734fc80208 make: fix memory leak for command strings 2024-05-25 21:07:48 +00:00
rillig cd90f040db make: minimize local variables around a vfork call
Passing all relevant values as arguments allows to remove the 'volatile'
qualifiers.
2024-05-25 15:37:17 +00:00
rillig 873c42efc3 make: provide more context information for parse/evaluate errors 2024-04-20 10:18:55 +00:00
sjg b52179abfc make: record exit status in GNode
SetErrorVars can now set .ERROR_EXIT which allows
a .ERROR target to ignore the case of .ERROR_EXIT == 6
which means failure happened elsewhere.

Reviewed by:
2024-03-10 02:53:37 +00:00
sjg 5b28ac6c57 make: export target scope values
Pass target scope to Var_ReexportVars so that a target process
will see the correct values in its env.
We must then mark any Global scope variable as unexported
so targets without local value get the Global one.
2024-03-01 16:41:42 +00:00
rillig f60719f052 make: miscellaneous cleanups 2024-01-05 23:22:06 +00:00
sjg ece0645989 Move fflush to a point to catch all cases. 2023-12-26 20:09:42 +00:00
sjg 79a3642923 make: fix order of output in compat mode
Ensure that make's output is correctly ordered with the output of the
target's commands, even when the output does not go to a terminal.

Reviewed by: rillig
2023-12-26 17:12:33 +00:00
sjg 94c9d8dd49 Compat_RunCommand call Shell_Init is shellPath is NULL
Since .SHELL is potentially used in compat mode as well,
the man page description should not imply it is only used in jobs mode.

Remove path="sh" from shell-sh unit-test - and it would have detected
this bug.

Reviewed by: rillig
2023-12-24 16:48:30 +00:00
rillig d3b2cbfcdf make: clean up comments
No binary change, except for line numbers in assertions.
2023-12-19 19:33:39 +00:00
sjg ef3bc782c6 Compat_RunCommand mark bp volatile
gcc 4.8.5 (NetBSD 7.2) gets upset about bp.
2023-05-04 22:31:17 +00:00
sjg 8e85e64406 make: handle .PHONY consitently on interrupt
JobDeleteTarget skips .PHONY targets
CompatDeleteTarget should do the same

This addresses https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=269663
2023-03-18 22:20:11 +00:00
rillig a4cbe1d736 make: clean up calls to Var_Subst
None of the calls to Var_Subst used the return value, and the return
value was always VPR_OK.

No functional change.
2023-02-14 21:38:31 +00:00
christos 1934cf4b4f Accept whitespace between command specifiers @+- like gmake does. New binutils
does this.
2023-01-17 21:35:19 +00:00
rillig 6f61b62f59 make: clean up comments 2022-12-07 10:28:48 +00:00
rillig a0a05d5e84 make: change return type of unlink_file back to int
As unlink_file is a wrapper around unlink, use the same encoding for the
possible return values as in the wrapped function.  This consistency is
more important than expressing all possible return values in the return
type 'bool'.

https://mail-index.netbsd.org/tech-toolchain/2022/10/06/msg004155.html

No functional change.
2022-10-10 21:17:25 +00:00
rillig 17ee827525 make: fix exit status for '-q' (since 1994) 2022-08-17 20:10:29 +00:00
rillig 9fb8e00c0f make: allow to randomize build order of targets
In complex dependency structures, when a build fails, a probable cause
is a missing dependency declaration between some files.  In compat mode,
the build order is deterministic, in jobs mode, it is somewhat
deterministic.  To explore more edge cases, add the line ".MAKE.MODE +=
randomize-targets" somewhere in the makefile.

Fixes PR bin/45226 by riastradh.  Reviewed by christos.
2022-05-07 17:49:47 +00:00
rillig 253dceb3e2 make: rename Compat_Run to Compat_MakeAll
No functional change.
2022-05-07 08:01:20 +00:00
rillig 2aba30c909 make: add missing newline after "cannot continue" message
It was wrong of Parse_File to output an unfinished line and hope for
some other code to finish it.  As demonstrated in the test, PrintOnError
did not do that in the case of additional debug output.

To keep the overall behavior as close as possible to before, the other
callers of PrintOnError now have to pass the newline themselves. Passing
strings that start with newlines but don't end with them looked
suspicious anyway.
2022-01-22 18:59:23 +00:00
rillig 93211f8ca3 make: remove redundant braces
No binary change, except for assertion line numbers.
2022-01-08 09:53:44 +00:00
rillig fa9a5efd89 make: rename and inline Targ_Precious
No functional change.
2022-01-07 19:24:27 +00:00
rillig 2d7f7c37dc make: remove unnecessary words from command line options
Several years ago, the command line options were individual global
variables.  The global variable could therefore not be named 'silent'
since that would have conflicted with local variables of the same name.
After moving the global variable to the namespace 'struct CmdOpts',
there is no conflict anymore.

There doesn't seem to be any risk of naming collisions for the names
'touch' and 'query'.

No functional change.
2021-12-27 18:26:22 +00:00
rillig 2a65bef432 make: rename eunlink to unlink_file
The name eunlink suggested a relation with the similarly named functions
emalloc or esnprintf, but that was misleading.  Instead, unlink_file
works like unlink, except that it refuses to remove an empty directory.

No functional change.
2021-12-27 17:18:57 +00:00
rillig e0b778d955 make: amend leftover cleanups from the previous commits
No functional change.
2021-12-15 13:03:33 +00:00
rillig a8e14f3653 make: format comments according to /usr/share/misc/style
Assisted by indent(1), with manual corrections due to its many remaining
bugs.

No functional change.
2021-12-15 12:58:01 +00:00
rillig a53f37541a make: use consistent indentation for statements and continuations
No binary change, except for line numbers in assertions in suff.c.
2021-12-15 12:24:13 +00:00
rillig 68525ebaf6 make: change return type of Compat_RunCommand from int to bool
The documentation was wrong before since status was not restricted to
only 0 or 1.

No functional change.
2021-12-15 10:04:49 +00:00
rillig a9883e8879 make: fix a few lint warnings about type mismatch in enum comparisons
These warnings were triggered with the lint flag '-e', which enables
additional checks on enums.  This check would have detected the type
mismatch from the previous commit.

The check has a few strange warnings though, complaining about
initialization of 'unsigned long' with 'unsigned long', so don't enable
it for the official builds.

No functional change.
2021-11-28 23:12:51 +00:00
rillig e939df1127 make: convert GNodeFlags from enum into bit-fields
Now that Enum_ToString is implemented for each type separately, it's
easy to convert them to bit-fields.  This gets rid of the magic numbers
12 for CYCLE and 13 for DONECYCLE that left a suspicious gap in the
numbers.  This gap was not needed since the code didn't make use of the
relative ordering of the enum constants.

The effects of this conversion are fewer capital letters in the code,
smaller scope for the GNode flags, and clearer code especially when
setting a flag back to false.

One strange thing is that GCC 10.3.0 doesn't optimize GNodeFlags_IsNone
to an single bitmasking instruction, at least on x86_64.  Instead it
generates a testb instruction for each of the flags, even loading bit 8
separately from the others.  Clang 12.0.1 knows this optimization
though and generates the obvious sequence of movzwl, testl, jz.

No functional change.
2021-11-28 19:51:06 +00:00
christos 88ab0eac35 add const 2021-04-27 15:19:25 +00:00
rillig 730db1a03f make: rename a few functions to be more descriptive
No functional change.
2021-04-04 10:05:08 +00:00
rillig 244fd9f4c4 make: use C99 bool type instead of defining its own
No functional change.
2021-04-03 11:08:40 +00:00
rillig 835b4db442 make: in the Var_ functions, move the scope to the front
This change provides for a more natural reading order in the code.
Placing the scope first makes it immediately clear in which context the
remaining parameters are interpreted.

No functional change.
2021-02-05 05:15:12 +00:00
rillig 4dc2cd5c6f make: rename context and ctxt to scope
This continues the previous commit, in which VAR_GLOBAL, VAR_INTERNAL
and VAR_CMDLINE were renamed.

Renaming the variable 'ctxt' was trivial since that word is used nowhere
else.  In the comments though, each occurrence of the word 'context' had
to be checked individually since the word 'context' was not only used
for referring to a variable scope.  It is also used to distinguish
different situations where characters are escaped in a certain way
('parsing context') and in a few other expressions.
2021-02-04 21:42:46 +00:00
rillig 553ee5f131 make: when exiting due to an error, print graph information
The code now does what the manual page has been promising since at least
1993.
2021-02-02 17:47:56 +00:00
rillig af0272c806 make: always use vfork, never fork
Before compat.c 1.217, job.c 1.390 and main.c 1.504 from 2020-12-27, the
exported make variables were exported from each freshly forked child
process.  There was no practical difference though between exporting the
variables from the parent process or the child process since these two
processes share the same address space, except that the forked process
is very limited in what it may actually do.  This limitation was
violated on a regular basis.

When an exported variable referred to a variable that used the :sh
variable modifier, this led to a fork from within vfork, which is not
allowed.  Since 2020-12-27, exporting the variables is done from the
main process, which prevents this situation from ever occurring.

Since that day, there is no need anymore to distinguish between vfork
and fork, which removes any need for the macro.
2021-02-01 21:04:10 +00:00
rillig 85aee7a6f7 make(1): remove do-not-format markers from comments
These markers had been used inconsistently.  Furthermore the source code
had not been formatted automatically before 2020 at all, otherwise there
wouldn't have been any trailing whitespace left.
2021-01-19 20:51:46 +00:00
rillig 31940a95cd make(1): consistently use boolean expressions in conditions
Most of the make code already followed the style of explicitly writing
(ptr != NULL) instead of the shorter (ptr) in conditions.

The remaining 50 instances have been found by an experimental,
unpublished check in lint(1) that treats bool expressions as
incompatible to any other scalar type, just as in Java, C#, Pascal and
several other languages.

The only unsafe operation on Boolean that is left over is (flags &
FLAG), for an enum implementing a bit set.  If Boolean is an ordinary
integer type (the default), some high bits may get lost.  But if Boolean
is the same as _Bool (by compiling with -DUSE_C99_BOOLEAN), C99 6.3.1.2
defines that a conversion from any scalar to the type _Bool acts as a
comparison to 0, which cannot lose any bits.
2021-01-10 21:20:46 +00:00
rillig b754dcb0cc make(1): format multi-line comments 2020-12-30 10:03:16 +00:00
rillig eb9a329939 make(1): re-export variables from the actual make process
Since make uses vfork if available, re-exporting the variables happens
in the address space of the main process anyway, so there is no point in
mentioning anything about "our client process" anywhere.
2020-12-27 05:16:26 +00:00
rillig 5196cc55b0 make(1): omit linear search for command in Compat_RunCommand 2020-12-20 21:07:32 +00:00
rillig 528c699500 make(1): fix .ERROR_TARGET in compat -k mode (since 2010-04-07) 2020-12-13 19:33:53 +00:00
rillig 73287a0b22 make(1): document variable expansion in the .END node 2020-12-13 18:57:44 +00:00
christos 53f65f3d12 fix comment 2020-12-13 18:12:29 +00:00
rillig 61121a11fe make(1): add comments for strange error handling in Compat_Run 2020-12-13 16:47:19 +00:00
rillig a65a89393b make(1): extract InitSignals from Compat_Run 2020-12-13 16:32:57 +00:00
rillig edc3918f88 make(1): extract MakeBeginNode from Compat_Run
The comment "execute the commands" had once been correct but not
anymore.  Since a few years, not only the commands of the .BEGIN and
.END nodes are executed, instead the nodes are made as usual, including
their dependencies.
2020-12-13 16:30:08 +00:00
rillig 67ff6c82cb make(1): extract UseShell from Compat_RunCommand 2020-12-13 16:14:40 +00:00
rillig bd57be24af make(1): rename Var_ExportVars to Var_ReexportVars 2020-12-12 18:53:53 +00:00