summaryrefslogtreecommitdiff
path: root/usr.bin/make/compat.c
AgeCommit message (Collapse)Author
2023-05-04Compat_RunCommand mark bp volatilesjg
gcc 4.8.5 (NetBSD 7.2) gets upset about bp.
2023-03-18make: handle .PHONY consitently on interruptsjg
JobDeleteTarget skips .PHONY targets CompatDeleteTarget should do the same This addresses https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=269663
2023-02-14make: clean up calls to Var_Substrillig
None of the calls to Var_Subst used the return value, and the return value was always VPR_OK. No functional change.
2023-01-17Accept whitespace between command specifiers @+- like gmake does. New binutilschristos
does this.
2022-12-07make: clean up commentsrillig
2022-10-10make: change return type of unlink_file back to intrillig
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-08-17make: fix exit status for '-q' (since 1994)rillig
2022-05-07make: allow to randomize build order of targetsrillig
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-07make: rename Compat_Run to Compat_MakeAllrillig
No functional change.
2022-01-22make: add missing newline after "cannot continue" messagerillig
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-08make: remove redundant bracesrillig
No binary change, except for assertion line numbers.
2022-01-07make: rename and inline Targ_Preciousrillig
No functional change.
2021-12-27make: remove unnecessary words from command line optionsrillig
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-27make: rename eunlink to unlink_filerillig
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-15make: amend leftover cleanups from the previous commitsrillig
No functional change.
2021-12-15make: format comments according to /usr/share/misc/stylerillig
Assisted by indent(1), with manual corrections due to its many remaining bugs. No functional change.
2021-12-15make: use consistent indentation for statements and continuationsrillig
No binary change, except for line numbers in assertions in suff.c.
2021-12-15make: change return type of Compat_RunCommand from int to boolrillig
The documentation was wrong before since status was not restricted to only 0 or 1. No functional change.
2021-11-28make: fix a few lint warnings about type mismatch in enum comparisonsrillig
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-28make: convert GNodeFlags from enum into bit-fieldsrillig
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-04-27add constchristos
2021-04-04make: rename a few functions to be more descriptiverillig
No functional change.
2021-04-03make: use C99 bool type instead of defining its ownrillig
No functional change.
2021-02-05make: in the Var_ functions, move the scope to the frontrillig
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-04make: rename context and ctxt to scoperillig
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-02make: when exiting due to an error, print graph informationrillig
The code now does what the manual page has been promising since at least 1993.
2021-02-01make: always use vfork, never forkrillig
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-01-19make(1): remove do-not-format markers from commentsrillig
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-10make(1): consistently use boolean expressions in conditionsrillig
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.
2020-12-30make(1): format multi-line commentsrillig
2020-12-27make(1): re-export variables from the actual make processrillig
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-20make(1): omit linear search for command in Compat_RunCommandrillig
2020-12-13make(1): fix .ERROR_TARGET in compat -k mode (since 2010-04-07)rillig
2020-12-13make(1): document variable expansion in the .END noderillig
2020-12-13fix commentchristos
2020-12-13make(1): add comments for strange error handling in Compat_Runrillig
2020-12-13make(1): extract InitSignals from Compat_Runrillig
2020-12-13make(1): extract MakeBeginNode from Compat_Runrillig
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-13make(1): extract UseShell from Compat_RunCommandrillig
2020-12-12make(1): rename Var_ExportVars to Var_ReexportVarsrillig
2020-12-12make(1): remove const from function parametersrillig
These have been left-overs from refactoring, when these pieces were extracted to separate functions.
2020-12-12make(1): inline Targ_Ignore and Targ_Silentrillig
Each of these functions was only used 2 times, and each of these calls used a different part of the whole expression.
2020-12-10make(1): split JobFlags into separate fieldsrillig
Having all these flags in a single bitmask makes it harder to see where exactly they can possibly be used since their state could also be modified using the unsuspicious job->flags = 0. Using individual names just leaves the single memset, and that is only used during initialization.
2020-12-07make(1): fix wrong exit status for multiple failed main targetsrillig
2020-12-07make(1): add test for wrong exit status 0 after failed targets with -krillig
2020-12-07make(1): merge local variables in Compat_Runrillig
2020-12-07make(1): clean up Compat_Runrillig
Now that errors in the main targets and in their dependencies have the same effect on the .END node and its dependencies, the two variables can be merged.
2020-12-07make(1): don't make .END if the main targets already failedrillig
This only applies to -k mode. By default, make exits earlier and skips the .END node as well if an error occurs.
2020-12-07make(1): fix exit status in -k mode if a dependency failsrillig
Whether in -k mode or not, the exit status tells whether all requested targets were made or not. If a dependency could not be made, the main target was not made as well, therefore the exit status must be nonzero in such a case. This part of the code lacked proper unit tests until today. The unit test deptgt-end-fail.mk is compatible with make>=2003 at least, allowing to compare the output over time. In 2003, in the ok-ok-ok-ok case, "Making all from all-dep." was printed twice in a row, for whatever reason ... (40 minutes later) ... If I had just made the two commands for 'all' and '.END' more distinguishable. Back in 2003, the local variables for .END had not been initialized, instead the .END node was run with the local variables of the last preceding node. In this case, that node was 'all', therefore ${.TARGET} had obviously expanded to 'all'. Somewhere in 2004, the shell commands were no longer run with the -e flag, which resulted in the "exit status $?" line to be printed in cases that had stopped early before. Somewhere in 2005, the local variables for the .END node had been fixed. The variable ${.TARGET} now had the value '.END', just as expected. In addition, the dependencies for the .END node were made, although without getting their proper local variables. This resulted in the output "Making out of nothing" instead of the expected "Making end-dep out of nothing". Still in 2005, in the test case "all=ok all-dep=ok end=ok end-dep=ERR", the error code of the failed 'end-dep' was first reported as "*** Error code 1 (continuing)". To compensate for this improvement, a new bug had been introduced. The test case "all=ok all-dep=ok end=ERR end-dep=ERR" had properly exited with status 1 on 2005-01-01, but on 2006-01-01 it exited with status 0, thereby ignoring errors in the .END node. Somewhere in 2008, some of the error messages (but not all) were directed to stderr instead of stdout. The actual output stayed the same though. Somewhere in 2011, the dependency of the .END node got its own local variables, and ${.TARGET} now expanded to 'end-dep', as expected. Somewhere in 2016, the two empty lines between the "*** Error code 1 (continuing)" and the "Stop." got compressed into a single empty line. On 2020-12-07 (that is, today), the exit status 1 has been restored in the error cases, after it had been wrong for at least 14 years.
2020-12-06make(1): refactor Compat_Run to show the error condition more clearlyrillig
This refactoring allows to gradually change the conditions for the "Stop." error message, to demonstrate which cases are affected by each tiny change.