Commit Graph

16677 Commits

Author SHA1 Message Date
rillig
6357e11169 make(1): format function definitions consistently 2020-12-15 21:19:47 +00:00
rillig
a44c2b10bb make(1): indent nonints.h and util.c with tabs instead of spaces 2020-12-15 20:39:15 +00:00
rillig
b4c26ca2e4 make(1): indent make.c with tabs instead of spaces 2020-12-15 20:17:08 +00:00
rillig
cf28122d70 make(1): extract MakeChildren from MakeStartJobs 2020-12-15 19:47:02 +00:00
rillig
77e9059c21 make(1): indent job.h with tabs instead of spaces 2020-12-15 16:30:55 +00:00
rillig
6c432fc224 make(1): indent for.c using tabs instead of spaces 2020-12-15 16:24:17 +00:00
rillig
b1d7af486a make(1): clean up hash function for HashTable
Expressing a multiplication as a bit shifts and subtraction is the job
of the compiler.  For humans, a multiplication is easier to read.
2020-12-15 15:20:05 +00:00
rillig
4743be9ab6 make(1): indent hash.h and make_malloc.h with tabs instead of spaces 2020-12-15 01:23:55 +00:00
rillig
f779f26a46 make(1): document how to detect typos in .elif directives 2020-12-15 00:32:26 +00:00
rillig
623f275b16 make(1): clean up ParseReadLine
In function names, the word "get" was not used consistently to look up
or compute data, in several cases "get" was a synonym for "read", just
like in the standard C library (fgetc).

The really confusing part is that there are two functions now, called
ParseGetLine and ParseReadLine, and both were underdocumented.
2020-12-14 23:48:03 +00:00
rillig
a1af58d13b make(1): error out on .else with extraneous text 2020-12-14 22:17:11 +00:00
rillig
bb1cb5b505 make(1): error out if an '.endif' contains extraneous text 2020-12-14 21:56:17 +00:00
rillig
4d12251138 make(1): make structure of the code in Cond_EvalLine clearer 2020-12-14 21:35:21 +00:00
rillig
2f1b70eeeb make(1): add tests for parsing .if conditions 2020-12-14 21:02:25 +00:00
rillig
1eeb87db64 make(1): add more tests for parsing .endif 2020-12-14 20:57:31 +00:00
rillig
fa6ec3776b make(1): don't pretend to expand CondParser_Eval
At that point, the variable expression has already been expanded.  To
avoid the impression that the token might be relevant, pass FALSE
instead of TRUE.  No change of behavior.
2020-12-14 20:39:35 +00:00
rillig
da444aa84e make(1): add test for variable expressions after a parse error
These variable expressions don't need to be expanded, and they aren't.
2020-12-14 20:28:09 +00:00
rillig
22b3e4f8b0 make(1): add test for parsing the end of a condition 2020-12-14 20:23:49 +00:00
rillig
ed7166493f make(1): replace %zu with %u in printf calls
This is needed to compile bmake with GCC 2.8.1 on SunOS 5.9.

To support ancient systems like this, the whole code of usr.bin/make is
supposed to use only ISO C90 features, except for filemon, which is not
used on these systems.
2020-12-13 21:27:45 +00:00
rillig
ac4393a924 make(1): rename Vector.priv_cap to cap
There is no use case for accessing or even modifying the capacity of a
vector, therefore there is no need to hide it using the prefix "priv_".
This way, the member names are aligned between Buffer and Vector.
2020-12-13 20:57:17 +00:00
rillig
7f604d4793 make(1): add str_basename to reduce duplicate code
The function basename from POSIX has a few unfortunate properties, it is
allowed to return a pointer to static memory.  This is too unreliable,
therefore this trivial own implementation.
2020-12-13 20:14:48 +00:00
rillig
9ab63ee0aa make(1): constify progname 2020-12-13 20:09:02 +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
95fe5be41c make(1): add tests for variable expansion in .ERROR handling 2020-12-13 19:08:20 +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
6d3aa3c8ae make(1): demonstrate wrong error handling in compat mode 2020-12-13 17:44:31 +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
sjg
a39ab01a94 Prune job debug output that may appear out of order.
A race between child and parent means that we cannot
guarantee whether all child output is seen before we call
JobClosePipes, thus intervening debug output can appear
before or after the last child output.
2020-12-13 05:13:38 +00:00
rillig
2eebef5d2b make(1): remove dead code from GetVarnamesToUnexport
Now that the parsing of the directives is unified and strict, there is
no need anymore for the dispatched functions to check for unknown
directives.  These functions don't even get the information to decide
that since this decision is already done.
2020-12-13 02:15:49 +00:00
sjg
aefb247373 Avoid noise when csh does not exist 2020-12-13 02:09:55 +00:00
sjg
5f5af6046f Ensure we have a value for .MAKE.UID 2020-12-13 02:09:33 +00:00
rillig
e774dc5acc make(1): replace *line with line[0]
Since a line is not an iterator and since the expression *line typically
means "the current element", not "the first character", replacing *line
with line[0] more directly expresses the idea of accessing the first
character of a string.
2020-12-13 02:01:43 +00:00
rillig
40711a6e7b make(1): clean up comment for ParseDirective 2020-12-13 01:51:08 +00:00
rillig
b506ce346a make(1): clean up Var_Export 2020-12-13 01:41:12 +00:00
rillig
80fcd08175 make(1): replace bitset VarExportFlags with enum VarExportMode
The previous flags were not combined at all.
2020-12-13 01:33:17 +00:00
rillig
b02ee7708d make(1): adjust timestamps in unit tests
These could not be known before the previous commit.
2020-12-13 01:10:22 +00:00
rillig
f00bc469bf make(1): error out on misspelled directives
Before, make accepted misspellings like .warnings, .export-literally and
a few others, all of which are unlikely to occur in practice.  See the
test directive-misspellings.mk for further details.
2020-12-13 01:07:54 +00:00
rillig
7b010c3449 make(1): add test for misspelled directives
This test allows the other directive-* tests to focus on the purpose of
the individual directive, allowing these tests to continue after
parsing, without errors.
2020-12-13 00:46:25 +00:00
rillig
6188dab3ce make(1): reduce indentation of ParseDirective 2020-12-12 21:35:21 +00:00
rillig
ffcddf1eb1 make(1): eliminate boolean argument of Var_Export 2020-12-12 21:20:30 +00:00
rillig
63402ea177 make(1): extract ExportVarsExpand from Var_Export 2020-12-12 20:00:51 +00:00
rillig
d32acaa90f make(1): fix undefined behavior when exporting ${:U } 2020-12-12 19:39:34 +00:00
rillig
32590eee1b make(1): extract ExportVars from Var_Export 2020-12-12 19:31:17 +00:00
rillig
ab1d2fd5b0 make(1): remove redundant call to strlen in Str_Words 2020-12-12 19:13:47 +00:00
rillig
bd57be24af make(1): rename Var_ExportVars to Var_ReexportVars 2020-12-12 18:53:53 +00:00
rillig
6f740ba472 make(1): error out on misspelled .export directives 2020-12-12 18:11:42 +00:00
rillig
2997f3b2f1 make(1): error out on misspelled .unexport-env 2020-12-12 18:00:18 +00:00
rillig
dc6cc25fbe make(1): add number of uncovered lines to coverage report 2020-12-12 16:54:20 +00:00
rillig
e7e184a2e8 make(1): add target test-coverage 2020-12-12 16:06:27 +00:00
rillig
e667d310c7 make(1): add test for a shell with error control
None of the predefined shells has error control, and the corresponding
code had not been covered by the existing unit tests.
2020-12-12 15:06:11 +00:00
rillig
9b6628dd29 make(1): clean up comments around JobPrintSpecials 2020-12-12 13:13:34 +00:00
rillig
322623ce41 make(1): rename ParseRunOptions to ParseCommandFlags 2020-12-12 12:56:56 +00:00
rillig
51a24315f9 make(1): extract ShellWriter_ErrOn from JobPrintCommand
It had been conceptually wrong to modify cmdFlags.echo just to suppress
echoing while enabling error checking.

Now the code in JobPrintCommand speaks for itself and no longer needs
any comments.  The few lines at the end have the sole purpose of
restoring the default state (echo + errChk) in the shell file.
2020-12-12 12:54:58 +00:00
rillig
52b5fecfcb make(1): fix typo in comment of JobPrintCommand 2020-12-12 12:28:06 +00:00
rillig
8538421bd4 make(1): reduce number of test cases in sh-flags.mk
The field job->echo is initialized in JobStart (and in JobOpenTmpFile).
After that, it is not modified anymore.  Therefore it is not necessary
to run these test cases redundantly.

The field job->ignerr, on the other hand, is modified later on.  For
these cases, the many remaining test cases are still needed.
2020-12-12 12:19:18 +00:00
rillig
c9c491710a make(1): demonstrate that -s and .SILENT have the same effect 2020-12-12 12:13:12 +00:00
rillig
a3c2b1275d make(1): make Job_Touch simpler 2020-12-12 11:33:10 +00:00
rillig
2a405df44e make(1): split JobFinishDone into smaller functions 2020-12-12 11:28:29 +00:00
rillig
5ea7eea1c6 make(1): extract JobFinishDone from JobFinish 2020-12-12 11:03:43 +00:00
rillig
83fedb2d4a make(1): clean up comments in JobFinish 2020-12-12 10:58:13 +00:00
rillig
e924b5d63d make(1): inline ShellWriter_PrintCmd
The parameter name escCmd was wrong for the call in JobPrintCommand.
2020-12-12 10:45:24 +00:00
rillig
1702e7bd48 make(1): rename Shell.exitFlag to errFlag
Now its name matches the user-visible .SHELL parameter again, reducing a
tiny bit of that mapping chaos.
2020-12-12 10:40:42 +00:00
rillig
e0fa644c43 make(1): move Job.xtraced to ShellWriter
This flag was placed wrong in the Job since it is only necessary as long
as the shell commands are written to the shell file.

Resetting it in JobStart and JobExec was completely misguided since that
is far away from writing the shell commands; this should have been done
in JobPrintCommands instead.

The status of this flag doesn't need to be printed in debugging mode
since it is controlled by a single command line option (-dx) and does
not interact with all the other switches.
2020-12-12 10:21:50 +00:00
rillig
b48717edf1 make(1): in jobs mode, extract echo control into separate functions
This removes the clutter from the code that calls these functions.  That
code is still complicated enough since it modifies variables it
shouldn't.
2020-12-12 10:05:15 +00:00
rillig
38e8ece1e7 make(1): make printing of shell commands independent from the job 2020-12-12 02:03:36 +00:00
rillig
8db63e3598 make(1): in jobs mode, extract writing of shell commands
Right now, the test sh-flags.mk demonstrates many variants to configure
echoing of the shell commands (-s, .SILENT, '@'), error handling (-i,
.IGNORE, '-') and whether the commands are run (-n, -N, .MAKE,
.RECURSIVE, '+').

Even more variants are possible by configuring the shell to have error
control.  None of the built-in shell definitions has error control, so
it is unlikely that anybody uses them, but who knows.

Being able to configure these details at 3 levels is good, but what
makes all this really hard to understand is that some of these switches
interact in non-obvious ways.  For example, in jobs mode, a single
command can change job->ignerr (in JobPrintSpecialsEchoCtl), which will
affect all further commands of that job.

The goal of this refactoring is to make the code easier to understand by
making the switches on the job level constant and by moving all
modifications to them to the ShellWriter.
2020-12-12 01:42:33 +00:00
rillig
27790ccd7f make(1): inline local variable in ApplyModifiersIndirect 2020-12-12 00:53:23 +00:00
rillig
741fced9be make(1): in ApplyModifiersIndirect, rename local variable
In other places, the parsing position is abbreviated as pp as well.
2020-12-12 00:42:35 +00:00
rillig
df6fa3cc00 make(1): remove const from function parameters
These have been left-overs from refactoring, when these pieces were
extracted to separate functions.
2020-12-12 00:33:25 +00:00
rillig
f650bd93fa make(1): inline Targ_Ignore and Targ_Silent
Each of these functions was only used 2 times, and each of these calls
used a different part of the whole expression.
2020-12-12 00:05:05 +00:00
rillig
ad7305d632 make(1): clean up comments for command line options 2020-12-11 23:00:59 +00:00
rillig
a4123952e2 make(1): fix documentation of POSIX configuration
Empty commands are always allowed, whether in POSIX mode or not.
2020-12-11 22:53:08 +00:00
rillig
fd30830cf1 make(1): remove DEFMAXLOCAL and DEFMAXJOBS
These have been hard-wired all the time.  The word LOCAL doesn't make
sense anymore since the code for running jobs remotely has gone.
2020-12-11 22:48:31 +00:00
rillig
6bf5f23d39 make(1): mark strange code that calls exit(signo)
In other places, the exit status of make is carefully chosen to be 0
(success), 1 (did not make everything), 2 (other error).  Using a signal
number is not guaranteed to be consistent among operating systems and is
therefore a weird choice.
2020-12-11 22:33:06 +00:00
simonb
28c9f023c7 Add ${LIBUTIL} to DPADD. 2020-12-11 07:24:38 +00:00
rillig
4ea80e710c make(1): document why runIgnImpl is used in jobs mode 2020-12-11 01:08:51 +00:00
rillig
428f1d7ff5 make(1): add tests for comments and non-comments in jobs mode 2020-12-11 01:06:10 +00:00
rillig
7700639ac4 make(1): rename shell flags in struct Shell
The previous name 'echo' was too unspecific, given that the other fields
in the same struct are called echoOff, echoOn, echoTmpl.
2020-12-11 00:29:01 +00:00
rillig
c3ac7df32f make(1): clean up comments for struct Shell 2020-12-11 00:22:23 +00:00
rillig
2ef0fcb76c make(1): name Shell fields consistently
They are all templates with a single %s placeholder, so embed this
unambiguously in the variable name.  The previous variable names didn't
provide any clue that echoCmd, execIgnore and errExit had a lot in
common.
2020-12-10 23:54:41 +00:00
rillig
5a661125e0 make(1): clean up JobPrintCommand
The local variable 'cmd' had been used for both the unexpanded and the
expanded command.  This in turn had required the parameter to be
non-const.
2020-12-10 23:36:20 +00:00
rillig
b49a832956 make(1): eliminate global variable numCommands
It had only been used in a very small scope.  The elimination of
Lst_ForEach made it easy to turn this global variable into a local
variable.
2020-12-10 23:12:59 +00:00
rillig
db56543590 make(1): extract JobOpenTmpFile from JobStart 2020-12-10 23:03:00 +00:00
rillig
59fc03e088 make(1): rename RunFlags to CommandFlags
Flags of similar names are also available in CmdOpts (global command
line options) and Job.  The new name CommandFlags emphasizes that these
flags apply to the smallest scope possible, which is a single command,
as opposed to the whole GNode/Job.
2020-12-10 22:45:30 +00:00
rillig
cdd16e62bf make(1): split Job.errOffOrExecIgnore into separate fields
Like errOnOrEcho, these two fields were completely unrelated.  One of
them expected a %s placeholder, the other didn't.
2020-12-10 22:34:39 +00:00
rillig
f4364e07ec make(1): split Job.errOnOrEcho into separate fields
They have never been related.  Furthermore, Job.errOn is really tricky
to reach at all.  To do that, one has to define a custom shell and set
hasErrCtl=true.  The manual page has an example for that, but it's
probably not use in practice, just like the possibility to use the C
shell for all commands.
2020-12-10 22:17:37 +00:00
rillig
ec213df12c make(1): negate Job.silent to echo
This gets rid of a few explicit negations and an implicit negation in
the variable name.
2020-12-10 21:41:35 +00:00
rillig
a6d2ec5914 make(1): unpack struct JobFlags
The job flags are only used individually.
2020-12-10 21:33:25 +00:00
rillig
e6318f0347 make(1): rename commandShell to shell
The word 'command' was not necessary for understanding the variable.
2020-12-10 21:09:58 +00:00
rillig
c2147f488d make(1): split JobFlags into separate fields
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-10 20:49:11 +00:00
rillig
6d74c4fd10 make(1): in JobStart, negate 'noExec' to 'run' 2020-12-10 20:14:35 +00:00
rillig
8d426fd34d make(1): fix theoretical type mismatch for Job_Touch 2020-12-10 20:10:03 +00:00
rillig
13e47b6b33 make(1): fix test for command flags
The "false" is supposed to be run not only if the command has the '-'
flag, but also if the target is marked as .IGNORE or if the command line
option -i is given.

After the failed command, the remaining commands are skipped, therefore
the final echo for the empty line had to be moved up, at the beginning
of the target.
2020-12-10 17:55:30 +00:00
rillig
57bbdba1d0 make(1): test all combinations of switches for running commands
The code in JobPrintSpecials is rather complicated and contains
surprising interaction between some of the switches.

To see the exact effects of the switches, record the current state and
its output, to prevent accidental breakage during the upcoming
refactorings.
2020-12-10 17:06:13 +00:00
rillig
2e131e6594 make(1): document limitations of deferred '$' in ':?' modifier 2020-12-10 16:47:42 +00:00
rillig
a108871569 make(1): add test demonstrating how to defer evaluation in :? modifier 2020-12-10 16:36:47 +00:00
rillig
a37bf773f6 make(1): clean up test output of opt-jobs-no-action 2020-12-09 08:20:56 +00:00
rillig
255e230425 make(1): remove noise from test output of opt-jobs-no-action 2020-12-09 08:18:35 +00:00
rillig
a98a651d79 make(1): split the -j -n test into separate targets
The manual page says that in -j mode when the shell does not have ErrCtl
(and none of the default shells has that), the command prefix '-'
"affects the entire job", but this seems to be wrong.  At least, there
is no change in the output from before, when all commands had been in
the same target.
2020-12-09 08:15:45 +00:00
rillig
c179784be7 make(1): add test for the -n option combined with RunFlags 2020-12-09 07:57:51 +00:00
rillig
332d2f1b45 make(1): refine test for combining -j1 and -n 2020-12-09 07:24:52 +00:00
rillig
de83a47b93 make(1): add more tests for combining -j1 and -n 2020-12-09 00:43:48 +00:00
rillig
32df21f05a make(1): add test for combining -j1 with -n 2020-12-09 00:25:00 +00:00
rillig
c7f2a250c3 make(1): in jobs mode, invert local variable noSpecials to run 2020-12-08 21:34:49 +00:00
rillig
8fe50308d3 make(1): negate RunFlags.silent to become RunFlags.echo
This reduces the number of negations in the code.
2020-12-08 20:17:18 +00:00
rillig
e539c72b67 make(1): move flags errOff into RunFlags.ignerr 2020-12-08 20:10:24 +00:00
rillig
d79cfe4364 make(1): move flag runAlways into RunFlags 2020-12-08 20:04:17 +00:00
rillig
14ae239081 make(1): move flag shutUp into struct RunFlags
Running a command is controlled by several flags.  Instead of passing
them around individually, it's easier to have them grouped.
2020-12-08 19:58:20 +00:00
rillig
0f9f7cf8c4 make(1): split JobPrintSpecials into manageable pieces 2020-12-08 00:50:04 +00:00
rillig
b6db76aec6 make(1): extract JobPrintSpecials from JobPrintCommand 2020-12-08 00:23:30 +00:00
rillig
ba0f4facab make(1): extract InitShellNameAndPath from Shell_Init
This gets rid of the ugly "else #endif".
2020-12-08 00:09:51 +00:00
rillig
2125e11bfd make(1): clean up debug logging 2020-12-07 23:59:59 +00:00
rillig
b75505322d make(1): replace signal handling macros with local functions 2020-12-07 23:53:09 +00:00
rillig
d96e3096f2 make(1): indent job.c with tabs instead of spaces 2020-12-07 23:48:04 +00:00
rillig
f411373c7b make(1): remove duplicate code for job output 2020-12-07 22:55:01 +00:00
rillig
affd50e454 make(1): replace macro MESSAGE with local function
The first parameter of the macro was always stdout, and there was no
apparent reason to pass anything else there.

Let the compiler decide whether to inline this or not, it's not
time-critical.
2020-12-07 22:47:03 +00:00
rillig
4d2ba079d3 make(1): remove duplicate code from bmake_strdup
Inlining is the job of the compiler, not of humans.
2020-12-07 22:37:18 +00:00
rillig
c8309d07f3 make(1): normalize output of test sh-dots for non-native mode 2020-12-07 22:27:56 +00:00
rillig
1e55774c0d make(1): add tests and tutorial for the ?= assignment operator 2020-12-07 21:35:43 +00:00
rillig
ee5b8583e3 make(1): rename Var_Export1 to ExportVar
Since Var_Export1 is neither exported by the module nor does it belong
to the Var type, the previous function name was misleading.  The 1 in
the function name was not as expressive as possible.  The new name
aligns nicely with UnexportVar, which is a very young name as well.
2020-12-07 01:50:19 +00:00
rillig
ab66f2c17b make(1): fix wrong exit status for multiple failed main targets 2020-12-07 01:35:33 +00:00
rillig
42387fd8d5 make(1): add test for wrong exit status 0 after failed targets with -k 2020-12-07 01:32:04 +00:00
rillig
01c0fcab45 make(1): actually fix the use-after-free bug and the double-free
The use-after-free bug had been there since 2020-11-22, the double-free
bug since a few minutes.
2020-12-07 01:27:08 +00:00
rillig
dc1759932a make(1): fix use-after-free in -DDEBUG_SRC mode (since 2020-11-22) 2020-12-07 01:24:41 +00:00
rillig
e6b596f6c6 make(1): merge local variables in Compat_Run 2020-12-07 01:10:03 +00:00
rillig
8ec6d47a7d make(1): clean up Compat_Run
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-07 01:07:13 +00:00
rillig
ea51e814f2 make(1): don't make .END if the main targets already failed
This only applies to -k mode.  By default, make exits earlier and skips
the .END node as well if an error occurs.
2020-12-07 01:04:06 +00:00
rillig
e48e1a2882 make(1): fix exit status in -k mode if a dependency fails
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-07 00:53:30 +00:00
rillig
4de25ee2cb make(1): refactor Compat_Run to show the error condition more clearly
This refactoring allows to gradually change the conditions for the
"Stop." error message, to demonstrate which cases are affected by each
tiny change.
2020-12-06 23:02:56 +00:00
rillig
2b76f94f3e make(1): refactor error handling in Compat_Run
This is in preparation for the upcoming bug fixes.
2020-12-06 22:49:40 +00:00
rillig
91dd52293d make(1): test all combinations of failed main and .END targets
Adding an individual test for each of the 16 combinations would have
been too much manual work, and it's not easy to come up with a good
naming scheme for all the tests, keeping them short and expressive at
the same time.
2020-12-06 22:36:58 +00:00
rillig
abd175cf7f make(1): add test for .END after failed main node 2020-12-06 21:22:04 +00:00
rillig
571df9215e make(1): document undefined behavior from 2014
Earlier versions of make didn't know the -v option to print the expanded
value of a variable.  To make the test runnable by older makes as well,
switch to -V instead, which has been available much longer.
2020-12-06 20:55:30 +00:00
rillig
8ceba29732 make(1): error out on null bytes in makefiles
Makefiles are text files, they must not contain null bytes.

The previous code in this area was rotten anyway.  It assumed that
buf_end could be NULL even if buf_ptr was a valid pointer, which is no
longer true, probably since a few years already.

Continuing parsing after a null byte does not make sense.  If there's a
null byte in a text file, that file is corrupted, and parsing it leads
to unintended effects easily.  Therefore the only sensible action is to
stop parsing immediately.

The check whether cf->readMore could be null was outdated as well, which
previously made the fatal error impossible to reach.  Because of the
missing unit tests, nobody noticed this though.

The "exit status 0" in opt-file.exp is worring but that's due to another
bug and will be fixed in a follow-up commit.
2020-12-06 20:33:44 +00:00
rillig
227529d0a8 make(1): rename IFile.nextbuf to readMore
The previous name sounded too much like a noun, which was too confusing.
See unit-tests/opt-file.mk for the history of this part of the code.
2020-12-06 20:09:01 +00:00
rillig
1516c90ccf make(1): document how make behaved for null bytes in the makefile 2020-12-06 20:07:25 +00:00
rillig
ee90815510 make(1): add test for makefile containing null bytes 2020-12-06 19:18:26 +00:00
rillig
4e133ccc5e make(1): test parsing a makefile that ends in a backslash 2020-12-06 19:00:48 +00:00
rillig
856f84743d make(1): fix undefined behavior in ParseEOF
Adding a number to a null pointer should have been caught by any
Undefined Behavior Sanitizer, but apparently neither GCC nor Clang do
this.
2020-12-06 18:37:04 +00:00
rillig
2069cc7bbf make(1): remove comment decoration 2020-12-06 18:13:17 +00:00
rillig
16ad1eafba make(1): move CleanEnv to UnexportVars
It clearly didn't belong in the GetVarnamesToUnexport part of the code.
2020-12-06 17:41:52 +00:00
rillig
b5432954a4 make(1): extract UnexportVars from Var_UnExport 2020-12-06 17:35:51 +00:00
rillig
73f3a22b54 make(1): fix comment in test for directive unexport-env 2020-12-06 17:29:27 +00:00
rillig
2b33648640 make(1): clean up GetVarnamesToUnexport 2020-12-06 17:27:10 +00:00
rillig
afef166f61 make(1): extract GetVarnamesToUnexport from Var_UnExport 2020-12-06 17:22:44 +00:00
rillig
d97dc758c9 make(1): replace pointer comparisons with enum
Keeping track of what it means if varname.str == str is not as
expressive as declaring what exactly to unexport.
2020-12-06 16:24:30 +00:00