Commit Graph

2102 Commits

Author SHA1 Message Date
rillig
31e761ac2c make(1): use loops instead of Lst_ForEach for propagating to cohorts
For one-liners, Lst_ForEach creates a lot of overhead, both at runtime
and for reading and understanding the code.

In this simple case where the structure of the traversed nodes is not
modified, a simple loop is enough.  This avoids a lot of conversions to
void * and thus prevents type mistakes.
2020-08-29 20:20:44 +00:00
rillig
f52782ac02 make(1): fix sh-dots test
The exact output depends on the shell.  Some shells prefix the error
message with their name, some don't.
2020-08-29 19:35:38 +00:00
rillig
fc496dc802 make(1): add test for the .ifmake directive 2020-08-29 19:07:32 +00:00
rillig
a02fdff94e make(1): add tests for .else and .for + .endif 2020-08-29 18:50:25 +00:00
rillig
d28d390c4c make(1): add tests for .SILENT, .BEGIN and .END 2020-08-29 17:34:21 +00:00
rillig
64e0a331dc make(1): fix build with -DUSE_EMALLOC 2020-08-29 16:47:45 +00:00
rillig
cad1a8f59c make(1): explain the shuffled messages in the test output 2020-08-29 16:13:27 +00:00
rillig
157f198ab9 make(1): add test for the special .IGNORE dependency source 2020-08-29 15:06:33 +00:00
rillig
6c6514f5e6 make(1): fix assertion failure for .SUFFIXES in archives
This occurred in the posix1.mk test, even though it is disabled in
unit-tests.  But in tests/usr.bin/make it still runs.  There, it should
have produced an "expected failure" but crashed instead.

The archive-suffix test is the stripped-down version of the posix1 test.
2020-08-29 14:47:26 +00:00
rillig
3c38adc32d make(1): trust that Var_Parse never returns NULL
That function is quite long, but all its return paths lead either to the
expanded variable expression, or to var_Error or varNoError.
2020-08-29 13:38:48 +00:00
rillig
82fdd8ef8a make(1): trust that Var_Subst never returns NULL
It really never does, and it doesn't even report errors.  It just
returns the content of the buffer, up to the first parse error.
2020-08-29 13:16:54 +00:00
rillig
5701760711 make(1): make getBoolean simpler
This function is so seldom used that there is no point having
complicated code for it.
2020-08-29 13:04:30 +00:00
rillig
123d5708b5 make(1): add comments for ModifyWord_Subst
Without any comments, the code is unnecessarily hard to follow.
2020-08-29 12:48:17 +00:00
rillig
0f5754839c make(1): clean up comments in dir.c 2020-08-29 12:39:32 +00:00
rillig
7571daa697 make(1): clean up documentation for CompatInterrupt and Compat_Run 2020-08-29 12:36:20 +00:00
rillig
b2375adf62 make(1): split ApplyModifier_To into paragraphs 2020-08-29 12:27:10 +00:00
rillig
1c4ffcb2c3 make(1): remove ReturnStatus, SUCCESS and FAILURE
These are used in so few places now that it is easier to use a simple
Boolean for them.
2020-08-29 12:20:17 +00:00
rillig
b48f40fbd4 make(1): clean up comments in suff.c, small refactorings
In SuffParseTransform, the parameter names have been renamed to make the
"side effects" comment redundant.

In Suff_AddSuffix and Suff_AddLib, the parameter has been made const.

In SuffRemoveSrc, the unused variable has been removed, and the return
type has been fixed.
2020-08-29 12:01:46 +00:00
rillig
23181bcce8 make(1): add bmake_strsedup for duplicating a substring 2020-08-29 11:24:54 +00:00
rillig
a030b41f9a make(1): merge duplicate code for bmake_strldup 2020-08-29 11:13:43 +00:00
rillig
1421342aa6 make(1): fix test opt-debug-g1
Including the directory cache made the test output fragile.
2020-08-29 10:52:47 +00:00
rillig
bb2ba6a0e5 make(1): rename LstNode functions to match their type 2020-08-29 10:41:12 +00:00
rillig
938bc75c66 make(1): clean up indentation, comments and variable scope in job.c 2020-08-29 10:35:03 +00:00
rillig
4ec235756f make(1): remove duplicate code for allocation a substring 2020-08-29 10:32:00 +00:00
rillig
f6a7d0bc31 make(1): rename Lst_FindB back to Lst_Find
The migration from "comparison function" to "match function" is done,
the "B" in the names is no longer needed.
2020-08-29 10:12:06 +00:00
rillig
db2e5ed453 make(1): migrate remaining Lst_Find to Lst_FindB
While here, rename SuffSuffIsSuffix to SuffSuffGetSuffix since a
function named "is" should return a boolean, not a string pointer.
2020-08-29 10:06:23 +00:00
rillig
d1c1d9370a make(1): start replacing Lst_Find with Lst_FindB
Lst_Find is called with a "comparison" function that returns the integer
0 if the desired node is found.  This leads to confusion since there are
so many different return value conventions for int, such as 0/1 for
mimicking false/true, -1/0 as in close(2), and the sign as in strcmp(3).
This API is much easier to understand if the "comparison" function is
not called a comparison function (since that is too close to strcmp),
but a "match" function that just returns a boolean.

In Lst_FindFromB, the node argument may be null.  This deviates from the
other Lst functions, which require Lst and LstNode to generally be
non-null.  In this case it is useful though to make the calling code
simpler.

In arch.c, this makes a lot of the previous documentation redundant.

In cond.c, the documentation is reduced a little bit since it had
already been cleaned up before.  It also removes the strange negation
from CondFindStrMatch.

In dir.c, the documentation collapses as well.

In main.c, separating the ReadMakefile function from the callbacks for
Lst_FindB allows the former to get back its natural function signature,
with proper types and no unused parameters.

To catch any accidental mistakes during the migration from Lst_Find to
Lst_FindB, the code can be compiled with -DUSE_DOUBLE_BOOLEAN, which
will complain about incompatible function pointer types.
2020-08-29 09:30:10 +00:00
rillig
793f3a81dd make(1): fix null pointer dereference when sys.mk is not found
This is quite hard to trigger in a real-life scenario since it requires
precise timing.

Instead, I created /tmp/sys.mk and ran "./make -m /tmp -f /dev/null" in
the debugger, after setting a breakpoint in this line:

ln = Lst_Find(sysMkPath, ReadMakefile, NULL);

Once this line was reached, I removed /tmp/sys.mk to make ReadMakefile
fail.  Just adding a few parse errors won't help since ReadMakefile only
fails if the file cannot be found.
2020-08-29 08:59:08 +00:00
rillig
15828a96ed make(1): add another Boolean variant to check during development 2020-08-29 08:09:07 +00:00
rillig
5783a5d404 make(1): allow for strict type checking for Boolean
Having Boolean aliased to int creates ambiguities since int is widely
used.  Allow to occasionally compile make with -DUSE_DOUBLE_BOOLEAN to
check that the type definitions still agree.
2020-08-29 07:52:55 +00:00
rillig
7c1ae9cea7 make(1): clean up code in make.c
Var_Subst never returns NULL.

In Main_ExportMAKEFLAGS, don't compare ints with booleans.

In MainParseArgs, use char for the current character.  First, that's
more precise and correct, and second, it makes debugging easier for
those who don't know the ASCII table by heart.
2020-08-29 07:13:17 +00:00
rillig
da6468d597 make(1): rename confusing function ReadAllMakefiles
The old name implied that the function would read multiple files, which
was not the case.

The comment above that function was highly confusing.  It's not that the
function returns a boolean, but rather 0 or non-zero, and 0 means that
Lst_Find should stop searching.

One of the next refactorings will be to make Lst_Find return the first
list node for which the function returns TRUE.  This will reduce the
confusion about the several functions called SomethingP in suff.c.  The
P suffix means to return TRUE or FALSE, not 0 or non-zero.
2020-08-29 07:05:12 +00:00
rillig
ae6246b519 make(1): remove redundant MAKEFLAGS from subdir make
The make flags are passed via the environment, not via the command line.
This is not as obvious and visible, but it works.
2020-08-28 20:57:54 +00:00
rillig
61206e6661 make(1): remove unused variable not_parallel
The variable malloc_options seems unused as well, but the manual page
for jemalloc(3) mentions it.
2020-08-28 20:23:20 +00:00
rillig
d418859d56 make(1): remove redundant comments from hash.c 2020-08-28 20:16:19 +00:00
rillig
2b65eef82d make(1): inline LstIsValid and LstNodeIsValid
A simple null pointer comparison is easier to understand than the fuzzy
word "valid".
2020-08-28 19:52:14 +00:00
rillig
851c5fa92a make(1): fix build errors for USER_CPPFLAGS=-DNDEBUG
The functions LstIsValid and LstNodeIsValid are only used in assertions.

Without the always-false assertion, Enum_ValueToString could have
returned undefined behavior.
2020-08-28 19:46:04 +00:00
rillig
dcdf071d13 make(1): rename SuffixCmpData to SuffSuffIsSuffixArgs
The new name makes the comment above that struct redundant.
2020-08-28 19:21:00 +00:00
rillig
328f88448d make(1): clean up targ.c
The main part is removing redundant or outdated information from
comments.  In a few places, the expression cond ? TRUE : FALSE has been
simplified.
2020-08-28 19:14:07 +00:00
rillig
d9d33f9cdc make(1): clean up arch.c
Remove redundant parts of the function comments.  Move the "side
effects" to the main section, since these effects are main effects, not
side effects.

Remove the redundant prototype for ArchFree.
2020-08-28 18:34:45 +00:00
rillig
2c88efad6f make(1): fix test for interrupted command execution
In the first version of this test, I had completely misunderstood the
whole topic.

To test the interrupt, the make process has to be interrupted, not the
shell.  This generates the correct message that the target is removed.

The filename for .PHONY targets is removed even though .PHONY targets
usually don't correspond to a file.  The message is only printed if
there actually is a corresponding file.  That's why this message does
not appear when interrupting "make clean".

Finally, since files get created and removed during a single run of
make, the file cache needs to be disabled.  This is done by prefixing
the filenames with "././", see Dir_FindFile.
2020-08-28 18:16:22 +00:00
rillig
c0a3672957 make(1): clean up suffix handling 2020-08-28 17:27:21 +00:00
rillig
24bce02441 make(1): add tests for :tl and :tu modifiers 2020-08-28 17:21:02 +00:00
rillig
5c2c546f89 make(1): fix manual page about the modifiers of the :C modifier 2020-08-28 17:15:04 +00:00
rillig
24bb4aab54 make(1): add test for interrupting a command 2020-08-28 15:40:53 +00:00
rillig
793156de9d make(1): add tests for the &&, || and ! operators 2020-08-28 14:48:37 +00:00
rillig
24afb09ffc make(1): add test for unquoted string literals 2020-08-28 14:07:51 +00:00
rillig
2556a5c35b make(1): add test for operator precedence in conditions 2020-08-28 13:50:48 +00:00
rillig
4566d0c791 make(1): extend test for the exists function in conditions 2020-08-28 12:59:36 +00:00
rillig
2c8df40906 make(1): fix the other assertion from Lst_FindFrom
When I migrated the Lst_FindFrom to the strict API variant, I forgot
that Lst_FindFrom requires both arguments (list and node) to be
non-null.  I had only checked that the list is non-null.

There are only very few calls to Lst_FindFrom, and they are all ok now.
2020-08-28 06:47:14 +00:00