Commit Graph

16854 Commits

Author SHA1 Message Date
rillig
a2efb39127 make(1): remove mmap for loading files, only allow files < 1 GiB
Using mmap is beneficial if the loaded data is read-only, or if it is
accessed in random order.  Neither of these applies here.  When loading
a file, make reads it strictly from top to bottom, once.  During
parsing, the loaded data is modified in-place to insert '\0' and '\n'
for terminating strings and lines.  Because of all of this, there is no
benefit in using mmap.

Reading the file using 2 calls to read(2) (one for the data, one for
checking for EOF) loads the data in a single pass, instead of producing
a page fault whenever the parser passes another page boundary.

Use a Buffer for loading the file data, to avoid calling bmake_realloc
directly.

Do not resize the loaded buffer at the end.  Each loaded file is
short-lived anyway, and only a few files are loaded at the same time, so
there is no point in optimizing this part for low memory usage.
2020-12-28 15:21:33 +00:00
rillig
355b925473 lint1: remove unused t_field 2020-12-28 12:56:33 +00:00
rillig
c631bd0242 lint1: remove trailing whitespace 2020-12-28 12:52:45 +00:00
htodd
5ed8424a90 Go into the resize directory to build/install the files since they're in the sets. 2020-12-28 03:48:41 +00:00
rillig
fc135022e2 make(1): replace global preserveUndefined with VARE_KEEP_UNDEF
Controlling the expansion of variable expressions using a global
variable and a VARE flag was inconsistent.

Converting the global variable into a flag had to prerequisites:

1.  The unintended duplicate variable assignment had to be fixed, as
done in parse.c 1.520 from 2020-12-27.  Without this fix, it would have
been necessary to add more flags to Var_Exists and Var_SetWithFlags, and
this would have become too complex.

2.  There had to be a unit test demonstrating that VARE_KEEP_DOLLAR only
applies to the top-level expression and is not passed to the
subexpressions, while VARE_KEEP_UNDEF applies to all subexpressions as
well.  This test is in var-op-expand.mk 1.10 from 2020-12-28, at least
for the ':@word@' modifier.  In ParseModifierPartSubst, VARE_KEEP_UNDEF
is not passed down either, in the same way.
2020-12-28 00:46:24 +00:00
rillig
f56290c2b3 make(1): extend test for modifier parts in ':=' assignments 2020-12-28 00:19:41 +00:00
rillig
6242d146aa make(1): add test for modifier parts in ':=' assignments 2020-12-27 23:25:33 +00:00
rillig
7c100c94f2 make(1): fix edge case in := with undefined in variable name
Previously, the assignment "VAR${UNDEF} := value" actually assigned to 2
variables.  See var-op-expand.mk for details.
2020-12-27 22:29:37 +00:00
rillig
2395673142 make(1): move test result of var-op-expand.mk from exp to mk
This makes it easier to run this test in older versions of make.  Empty
output means success.
2020-12-27 21:31:27 +00:00
reinoud
de9e35d4ce Make the new resize(1) manpage indistinguisable from the original 2020-12-27 21:25:02 +00:00
rillig
12e256c877 make(1): add more tests for ':=' assignments 2020-12-27 21:19:13 +00:00
reinoud
ef6e52b452 Import Xterm's resize(1) for querying (x)terminal sizes in base for headless
clients
2020-12-27 21:13:17 +00:00
rillig
3038064b5b make(1): add tests for variable assignments using the ':=' operator 2020-12-27 20:45:52 +00:00
rillig
996e51af2c make(1): skip variable expansion in ParseDependencyTargetWord
The goal of the code is just to skip over the variable expression, thus
there is no need to evaluate it.
2020-12-27 18:22:28 +00:00
rillig
514845e5f2 make(1): add test for ParseDependencyTargetWord 2020-12-27 18:20:26 +00:00
rillig
7eb297894b make(1): split test for indirect modifiers into paragraphs 2020-12-27 17:32:25 +00:00
rillig
970a54cb9f make(1): add tests for parsing indirect modifiers in nested expressions 2020-12-27 17:17:46 +00:00
rillig
9524640e66 make(1): remove dead code from ApplyModifiersIndirect
At that point, the expression can never be varUndefined.  At the
beginning of ParseVarnameLong, the expression is initialized to a simple
empty string, and that string is only ever converted to varUndefined at
the very end of Var_Parse.
2020-12-27 16:31:58 +00:00
rillig
565eefa2e5 make(1): remove outdated comment about string comparisons
Back in 1993, the variables in a context were stored in a linked list.
Searching such a list indeed required literally thousands of calls to
strcmp.  In make.h 1.22 from 1999-09-15, the linked list was replaced
with a hash table, requiring much fewer string comparisons.  Since then,
the rationale doesn't apply anymore.
2020-12-27 14:41:25 +00:00
rillig
8eecc3ec3e make(1): remove unnecessary VPR_ERR_SILENT 2020-12-27 14:02:12 +00:00
rillig
cd38937700 make(1): do not inspect output variables in ParseVarnameShort 2020-12-27 13:15:43 +00:00
rillig
39c946421d make(1): move error handling code out of UndefinedShortVarValue 2020-12-27 13:12:34 +00:00
rillig
bb4b461edd make(1): exit 2 on technical errors
This allows the -q option to distinguish errors from out-of-date
targets.  Granted, it's an edge case but it should be solved
consistently anyway.

The majority of cases in which make exits with exit status 1, even in -q
mode, is when there are parse errors.  These have been kept as-is for
now as they affect many of the unit tests.

The technical errors, on the other hand, occur so rarely that it's hard
to write reliable tests for them that fail consistently on all platforms
supported by make.
2020-12-27 11:47:04 +00:00
rillig
7c7dae763b make(1): split Var_Subst into easily understandable functions
Extracting the character-level details makes the essence of Var_Subst
visible in the code, which is to iterate over the given text, handling a
few types of tokens.
2020-12-27 11:03:00 +00:00
rillig
fab83987ed make(1): clean up VarParseResult constants
The many constants were invented because at that time I didn't quite
understand the actual outcomes of Var_Parse that need to be
distinguished.  There are only a few:

(1) Errors, whether they are parse errors, or evaluation errors or
    undefined variables.  The old constants VPR_PARSE_MSG and
    VPR_UNDEF_MSG are merged into VPR_ERR.

(2) Undefined expressions in a situation in which they are allowed.
    Previously the documentation for VPR_UNDEF_SILENT talked about
    undefined expressions in situations where they were not allowed.
    That case is fully covered by VPR_ERR instead.

(3) Errors that are silently ignored.  These are probably bugs.

(4) Everything went fine, the expression has a defined value.
2020-12-27 10:53:23 +00:00
rillig
e0ea9a9396 make(1): remove unnecessary VPR_UNKNOWN for error handling
There is no sensible way for a caller of Var_Parse to deal with an error
state of "maybe successful, maybe not", therefore remove the constant
for it.
2020-12-27 10:09:53 +00:00
rillig
6c648b37ce make(1): add error handling for .for loop items
Right now, Var_Subst always returns VPR_OK, even if there had been parse
errors or evaluation errors.  If that is no longer true, the errors will
be reported properly.
2020-12-27 10:04:32 +00:00
rillig
9be4bfa647 make(1): add test for missing error handling in .for loop 2020-12-27 09:58:35 +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
0134a24c0d make(1): add test for expansion errors in jobs mode
Since compat mode and jobs mode are implemented separately and vary in
lots of small details, each of them needs to be tested on its own.
2020-12-27 05:11:40 +00:00
rillig
ea8c5a40a4 make(1): align names of VarExportMode with the directives 2020-12-27 05:06:17 +00:00
sjg
a3aef1439d Use .MAKE.DEPENDFILE as makefiles set it 2020-12-26 03:54:48 +00:00
maya
70f2b24ae4 Update to 2021, hopefully less errors made in this year. 2020-12-25 09:02:41 +00:00
dholland
5a724c86b4 List calendar's known calendars explicitly, and only install those.
Prevents build failures caused by installing editor backups and other
such silliness.
2020-12-25 07:00:52 +00:00
rillig
50fdf93be0 make(1): fix a few lint warnings 2020-12-23 14:13:49 +00:00
rillig
f351ad51cc make(1): fix lint warnings for constant condition in DEBUG calls 2020-12-23 14:05:32 +00:00
rillig
ee045a8229 make(1): fix MAKE_RCSID for lint mode
Previously, running lint mode didn't define MAKE_RCSID at all, which
resulted in a syntax error.

While here, reduced the indentation and nesting of the preprocessor
directives.
2020-12-23 14:03:13 +00:00
rillig
dff2a68ecc make(1): rename CmdOpts.lint to strict
When running lint(1) on the code, it defines the preprocessor macro
"lint" to 1, which generated a syntax error in the declaration "Boolean
lint", as that became "Boolean 1".
2020-12-23 13:50:54 +00:00
rillig
b3b6e90160 make(1): remove trailing whitespace in manual page 2020-12-23 13:49:12 +00:00
rillig
060e7853a4 make(1): fix memory leak in Var_Undef (since 2020-12-22) 2020-12-23 13:11:27 +00:00
rillig
82632c2fd8 make(1): fix return type of macro DEBUG
This macro was supposed to return a boolean expression all the time, it
just hadn't been implemented this way.  This resulted in wrong output
for the test sh-flags, in compilation modes -DUSE_UCHAR_BOOLEAN and
-DUSE_CHAR_BOOLEAN, since in ParseCommandFlags, the expression
DEBUG(LOUD) didn't fit into a boolean.
2020-12-22 22:31:50 +00:00
rillig
a542a5a6b7 make(1): allow .undef to undefine multiple variables at once
Since make doesn't support variable names containing spaces, this edge
case is not enough reason to stop this feature.  Having multiple
variable names as arguments nicely aligns with other directives such as
.for and .export.
2020-12-22 20:10:21 +00:00
rillig
ad8b5377ca make(1): add test for undefined variable in dependency declaration 2020-12-22 19:38:44 +00:00
ginsbach
332df7ed8f nl(1): remove superfluous exit
Remove exit(3) call missed when errors were converted to errx(3).
2020-12-22 17:50:55 +00:00
rillig
bd691351f1 make(1): fix comment in test about null bytes in makefiles 2020-12-22 08:57:23 +00:00
rillig
e6d109f2d3 make(1): re-add improved assertion in ParseGetLine 2020-12-22 08:51:30 +00:00
rillig
9582eb4d33 make(1): remove assertion about lines ending with '\n'
It fails the NetBSD build.sh.
2020-12-22 08:31:13 +00:00
rillig
0c15097160 make(1): clean up after test opt-file 2020-12-22 08:23:12 +00:00
rillig
75fb9c6afb make(1): remove needless assignment to line_end in ParseGetLine 2020-12-22 08:10:39 +00:00
rillig
b46e8d7cf5 make(1): fix assertion failure for files without trailing newline
Previously, mmapped files didn't always have the final newline added.
Only those that ended at a page boundary did.

This confused ParseRawLine, which assumed (and since parse.c 1.510 from
moments ago also asserted) that every line ends with a newline, which
allows the code to assume that after a backslash, there is at least one
other character in the buffer, thereby preventing an out-of-bounds read.

This bug had been there at least since parse.c 1.170 from 2010-12-25
04:57:07, maybe even earlier, I didn't check.

Now line_end always points to the trailing newline, which allows
ParseGetLine to overwrite that character to end the string.
2020-12-22 08:05:08 +00:00
rillig
8a4190c0a5 make(1): fix commit number in tests for :gmtime and :localtime 2020-12-22 07:22:39 +00:00
rillig
9b03887383 make(1): prevent undefined behavior in loadfile_mmap
Reading a file without a trailing newline had resulted in an
out-of-bounds write, in the common case where the file is loaded via
mmap.
2020-12-22 06:48:33 +00:00
rillig
f2023805b3 make(1): remove excess newline from parse errors (since 2020-11-01)
For the modifiers :gmtime and :localtime, the excess newline had been
added in var.c 1.631 from 2020-10-31 21:40:20.

For the modifiers :range and :ts, the excess newline had been added in
var.c 1.635 from 2020-11-01 14:36:25.
2020-12-21 21:04:18 +00:00
rillig
ecb61f4a92 make(1): align tests for :localtime with those for :gmtime
These tests had been almost the same before, now they are as similar as
possible again.
2020-12-21 20:47:29 +00:00
rillig
23e24e814c make(1): move tests for :gmtime to parse time
It's easier to have both the expressions and the expected values in a
single file.  This also allows for flexible handling of multiple
acceptable outputs, in this case for 32-bit time_t.
2020-12-21 20:35:17 +00:00
sjg
2de15e97b5 Set default for .MAKE.OS once 2020-12-21 18:22:31 +00:00
rillig
8277081861 make(1): remove redundant parameters from ParseModifierPart 2020-12-21 02:38:57 +00:00
rillig
0743b63f41 make(1): fix garbled output for failed shell command (since 2020-12-20)
Passing a struct as printf argument for the %s conversion doesn't work.
On NetBSD-8.0-x86_64, the output looks normal, but on SunOS-5.9, the
output is garbled, containing bytes 0xFF and 0xFE.

This bug had been introduced in parse.c 1.507 from 2020-12-20 14:52:16.

Thanks to sjg for finding this bug so quickly.
2020-12-21 02:09:34 +00:00
rillig
fcd6900042 make(1): save a few memory allocations in variable expressions 2020-12-21 00:30:13 +00:00
rillig
e6694a528e make(1): switch memory handling from MFStr to FStr
This makes all intermediate strings constant.  For this simple
search-and-replace refactoring, all intermediate locations where the
"current value of the expression" was stored had to be of the type
MFStr.

Using FStr instead of MFStr allows to save a few memory allocations,
which will be done in the follow-up commits.
2020-12-21 00:20:58 +00:00
rillig
be2b5e4446 make(1): clean up memory management for expanding variable expressions
Previously, memory management had been split among several variables.
The general idea was very simple though.  The current value of the
expression needs to be kept in memory, and each modifier either keeps
that value or replaces it with its own newly allocated result, or
var_Error or varUndefined.

Using MFStr, it does not matter anymore that var_Error and varUndefined
are statically allocated since these are assigned using MFStr_InitRefer.

The complexity of the implementation is now closer to the actual
complexity.  Most probably the code can be simplified even more.
2020-12-21 00:11:29 +00:00
rillig
23688beebb make(1): add tests for :tW and :tw modifiers 2020-12-20 23:29:50 +00:00
rillig
b8f5741af7 make(1): use FStr for ApplyModifiersState.newVal
Memory management is still complicated in this area.  To clean this up,
the previous value of the expression needs to be converted to an MFStr
first, and later to an FStr.
2020-12-20 23:27:37 +00:00
rillig
26a72fc416 make(1): add tests for variable modifiers on trailing slashes 2020-12-20 22:57:40 +00:00
rillig
94f06ed7ea make(1): fix undefined behavior in meta_oodate
Do not increment a null pointer.

Do not assign to a variable twice in the same statement.  To be fair,
this may be safe because of the sequence point when the function is
called, but anyway, it looks too close to undefined behavior.
2020-12-20 22:36:40 +00:00
rillig
06ccd6ce96 make(1): reduce scope of cp in meta_oodate
That function is way too long (550 lines) and has too creative variable
names such as fname, fname1, fname2, fname3.
2020-12-20 22:12:36 +00:00
rillig
4b4d56707b make(1): fix declared variable type in printCMDs
No functional changes since StringListNode and GNodeListNode are both
typedefs of a simple generic ListNode.
2020-12-20 22:02:54 +00:00
rillig
5196cc55b0 make(1): omit linear search for command in Compat_RunCommand 2020-12-20 21:07:32 +00:00
rillig
7a800efcdb make(1): remove redundant assignment in ApplyModifier_SysV 2020-12-20 19:51:37 +00:00
rillig
00ba7da94c make(1): error out on unknown variable modifiers at parse time
Before, make printed an "error message" that did not include the word
error and thus was not easily identified as such.  This "error message"
also did not influence the exit status in the default mode but only in
-dL mode.  The error message also didn't include any line number
information and was thus rude.
2020-12-20 19:47:34 +00:00
rillig
d52e9b267b make(1): include line numbers in output of test varmod-edge.mk
Suppressing the line numbers does not provide much benefit, given that
the test file doesn't change often.
2020-12-20 19:37:23 +00:00
rillig
374368e991 make(1): move tests for indirect modifiers around
The next commit will error out on unknown modifiers and influence the
exit status.  The test modmisc.mk contains both parse time tests and run
time tests.  To prevent the latter from being run, the parse error is
moved to varmod-indirect.mk, which only contains parse time tests.
2020-12-20 19:29:06 +00:00
rillig
b1b3d2f62b make(1): remove wrong error message for indirect modifier in lint mode 2020-12-20 19:10:53 +00:00
rillig
4938cf88d2 make(1): document that indirect modifiers fall back to SysV modifiers 2020-12-20 19:02:28 +00:00
rillig
9c42de2852 make(1): remove redundant const declarations for parameters 2020-12-20 18:23:24 +00:00
rillig
ffd320932f make(1): extract ApplySingleModifier from ApplyModifiers 2020-12-20 18:13:50 +00:00
rillig
e2fd21af29 make(1): turn ApplyModifiersState.val into a local variable
This reduces the scope and makes it more obvious at which places this
variable can be changed and how the memory management is done.
2020-12-20 17:22:10 +00:00
rillig
0e4ce27167 make(1): use FStr for memory management in Var_SetWithFlags 2020-12-20 15:31:29 +00:00
rillig
fa8bd88f04 make(1): extract SetVar from Var_SetWithFlags
SetVar contains the part that is not concerned about memory management
and expansion of the variable name.
2020-12-20 15:26:40 +00:00
rillig
eb277e70f2 make(1): fix memory leak in Var_Delete (since yesterday)
The memory leak had been introduced in var.c 1.736 from 2020-12-19
20:47:24.
2020-12-20 15:04:29 +00:00
rillig
80fba7d531 make(1): clean up memory handling in VarAssign_EvalShell 2020-12-20 14:52:16 +00:00
rillig
0b4b42e295 make(1): clean up memory handling in Parse_DoVar 2020-12-20 14:48:35 +00:00
rillig
431ba0ec4b make(1): remove constant parameter from MakeMode 2020-12-20 14:39:46 +00:00
rillig
0307413016 make(1): change return type of Var_Value to FStr 2020-12-20 14:32:13 +00:00
rillig
0462095db2 make(1): use FStr in VarNew 2020-12-20 13:50:10 +00:00
rillig
03f1822098 make(1): eliminate libName_freeIt from Arch_ParseArchive 2020-12-20 13:46:27 +00:00
rillig
7b3d8cbe3a make(1): return FStr from Var_Parse
This reduces the number of variable declarations at the call sites.
2020-12-20 13:38:43 +00:00
rillig
49eb293fd6 make(1): clean up memory handling in CondParser_String 2020-12-20 13:03:48 +00:00
rillig
81b5e18281 make(1): export FStr and MFStr
These types are a replacement for the pattern "var + var_freeIt" that
enforces these two variables to be updated together.
2020-12-20 12:53:34 +00:00
rillig
37fbcac361 make(1): clean up memory handling in CondParser_String 2020-12-20 12:46:49 +00:00
rillig
8f72c319f5 make(1): document memory handling in ApplyModifiers 2020-12-20 11:38:51 +00:00
rillig
0af8f23f02 make(1): replace freeIt with FStr in EvalUndefined
Previously, the parameter out_freeIt was not guaranteed to be
initialized in every case, at least when looking only at EvalUndefined.
This contradicted the variable name.

Replace the two parameters with a single FStr to ensure that these
variables are always initialized together.
2020-12-20 10:59:21 +00:00
rillig
19824f4691 make(1): replace FStr_Assign with separate initialization functions
In GetVarnamesToUnexport, there is no need to free the local FStr since
the only place where it is assigned an allocated string is at the very
end.

Having separate functions for the two main use cases of a possibly
allocated string makes the calling code simpler.  This is a preparatory
commit for making the memory allocation in ApplyModifiers easier to
understand.
2020-12-20 00:57:29 +00:00
rillig
e0de850d21 make(1): extract string functions from ApplyModifier_To 2020-12-20 00:47:21 +00:00
rillig
ab975bef9f make(1): fix error message for .info/.warning/.error without argument
Previously, the error message was "Unknown directive", which was
obviously wrong.  The new error message is "Missing argument".
2020-12-19 22:33:11 +00:00
rillig
7772d52765 make(1): error out if .undef has not exactly 1 argument 2020-12-19 22:10:17 +00:00
rillig
715d1d3bec make(1): extract Var_DeleteVar from Var_Delete 2020-12-19 20:47:24 +00:00
rillig
f11ec78a23 make(1): add tests for undefining variables with exotic names 2020-12-19 20:35:39 +00:00
rillig
a4d0870803 make(1): extract Var_Undef from ParseDirective 2020-12-19 20:16:36 +00:00
rillig
863c2319ae make(1): rewrite tests for misspelled .elif directive
Put the simple tests at the top, demonstrating that there are already
some cases in which the misspelled directive is detected.  It's not
detected though if the surrounding conditional branch is skipped.
2020-12-19 19:49:01 +00:00
rillig
5df214d4aa make(1): extract ParseSkippedBranches from ParseReadLine 2020-12-19 17:54:29 +00:00
rillig
0cf31774e7 make(1): extract ParseForLoop from ParseReadLine 2020-12-19 17:49:11 +00:00
rillig
5ae56910c5 make(1): rename mode constants for ParseGetLine to be more expressive 2020-12-19 16:05:33 +00:00
rillig
8dfbff51e9 make(1): add test for null byte in .for loop body 2020-12-19 16:00:17 +00:00
rillig
5cd27da0e0 make(1): fix documentation of GetLineMode
ParseGetLine always returns a logical line, even for PARSE_RAW.
2020-12-19 15:29:28 +00:00
rillig
029d9ed461 make(1): improve comments for .for loops 2020-12-19 13:31:37 +00:00
rillig
ba24c12f6a make(1): reduce debugging details in Parse_SetInput
The address of readMoreArg is hardly useful when stepping through this
part of the code, therefore omit it.  Instead of mentioning the exact
function names of the data source, describe them in words, which helps
especially in the case of .for loops.
2020-12-19 13:30:00 +00:00
rillig
8b6f21ea9f make(1): rename ForIterate to ForReadMore 2020-12-19 13:20:17 +00:00
rillig
af7e852811 make(1): rename parameter line to lineno 2020-12-19 13:16:25 +00:00
rillig
4a31d445af make(1): document enum GetLineMode 2020-12-19 12:48:59 +00:00
rillig
959dba2f43 make(1): add test for backslash continuation lines in .for loops
This ensures that the line numbers for messages are the expected onces
in .for loops.

While experimenting with the backslash continuation lines, I noticed
that the reported line numbers for these are based on the number of
completely parsed physical lines, which nicely cancels out the + 1 that
has to be added for producing human-readable 1-based line numbers.  It
would be more correct to report the parse errors on the first affected
line.
2020-12-19 12:40:00 +00:00
rillig
c1c7380a9a make(1): fix line numbers in .for loops (since 2007-01-01) 2020-12-19 12:24:46 +00:00
rillig
e8319c8295 make(1): demonstrate wrong line numbers in .for loops, since 2007-01-01 2020-12-19 12:14:59 +00:00
rillig
44219d1a0a make(1): merge parameter of ParseRawLine into return value 2020-12-19 10:57:17 +00:00
rillig
89c1ddf072 make(1): clean up variable names in ParseGetLine and ParseRawLine 2020-12-19 10:49:36 +00:00
rillig
5ca350977a make(1): fix variable names in UnescapeBackslash
The previous variable names had been chosen at a time when compilers
didn't merge variables into the same registers.  Luckily, these times
are gone, and it's no longer necessary to use a variable for 2 or more
completely unrelated purposes.
2020-12-19 10:18:46 +00:00
rillig
ecc876b838 make(1): clean up ParseRawLine 2020-12-19 00:27:34 +00:00
rillig
0c5e588e71 make(1): extract ParseRawLine from ParseGetLine 2020-12-19 00:20:57 +00:00
rillig
e7a3ec57b0 make(1): clean up another local variable in ParseGetLine 2020-12-19 00:02:34 +00:00
rillig
7b504ab648 make(1): clean up UnescapeBackslash 2020-12-18 23:18:08 +00:00
rillig
419f399f4b make(1): remove unused parameter from UnescapeBackslash 2020-12-18 23:13:45 +00:00
rillig
effc4eb938 make(1): split ParseGetLine into separate functions 2020-12-18 19:02:37 +00:00
rillig
94e08101d9 make(1): separate ParseGetLine into paragraphs 2020-12-18 18:23:29 +00:00
rillig
b2ae71012b make(1): support using C99 bool for Boolean 2020-12-18 18:17:45 +00:00
rillig
6e84975ccd make(1): spell nonexistent consistently 2020-12-18 15:47:34 +00:00
rillig
d80c99b6f3 make(1): use symbolic time for 0 in Make_Recheck
This makes the test depsrc-optional independent from the current time
zone.
2020-12-18 14:46:44 +00:00
rillig
6e3f82b272 make(1): constify Targ_FmtTime 2020-12-18 14:36:46 +00:00
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