Commit Graph

2487 Commits

Author SHA1 Message Date
rillig
0c7959ba7a make(1): reword variable invocation to variable expression
Variables are a passive thing.  They cannot be invoked, they can only be
evaluated.
2020-09-12 19:41:20 +00:00
rillig
806157ea4e make(1): extract ShortVarValue from Var_Parse 2020-09-12 19:33:02 +00:00
rillig
ff82a67733 make(1): extract ParseVarname from Var_Parse
This was an easy part since it affects only a few variables.  250 lines
for a single function is still quite a lot, so further refactorings will
follow.
2020-09-12 19:24:59 +00:00
rillig
4d7d4cbd25 make(1): rename local variable in Var_Subst 2020-09-12 19:15:20 +00:00
rillig
e9b14ba5d5 make(1): remove double negation in Var_Parse 2020-09-12 19:13:43 +00:00
rillig
3efb761560 make(1): clean up Var_Parse 2020-09-12 18:45:24 +00:00
rillig
ded615357f make(1): rename local variables in Var_Parse
The main property of the former "str" is not being a string but pointing
at the start of the expression to be parsed.

The main property of the former "tstr" is not being a string but being
the moving pointer, the current parsing position.  No idea what the "t"
in "tstr" stood for.
2020-09-12 18:39:37 +00:00
rillig
160db1bcad make(1): rename Var_ParsePP back to Var_Parse
The migration to the "parsing position" pointer has been done.
2020-09-12 18:19:50 +00:00
rillig
ca6cff446a make(1): migrate CondParser_String to Var_ParsePP 2020-09-12 18:04:45 +00:00
rillig
a24e6a839a make(1): use correct character literals in TryParseNumber 2020-09-12 18:02:43 +00:00
rillig
1b82cb8766 make(1): add test for Infinity and NaN
Neither is recognized by the make parser, which is good since the main
task of make is dependency resolution and text processing, not
calculating.
2020-09-12 18:01:51 +00:00
rillig
3c08467d34 make(1): add tests for comparison tokens without whitespace 2020-09-12 17:47:24 +00:00
rillig
1dfbf55e58 make(1): clean up code in CondParser_String
The two parts of the for loop were not related in any way, which made
the code more confusing than necessary.
2020-09-12 17:14:40 +00:00
rillig
d4d05b9c2a make(1): add typedef for signal handler
Without this typedef, both the declaration and the definition of
bmake_signal were as unreadable as the declaration in the signal(3)
manual page.
2020-09-12 16:46:24 +00:00
rillig
75e5493ba3 make(1): fix API of Targ_PrintNode
There was no need to export Targ_PrintNode at all.  All the callers need
is a high-level API for printing a single node or a list of nodes.  The
implementation detail that Targ_PrintNode was used as a callback to
Lst_ForEach should have never leaked into the API.
2020-09-12 16:38:19 +00:00
rillig
74f3fda8b2 make(1): remove unintended noinline from previous commit 2020-09-12 16:24:20 +00:00
rillig
81c4719295 make(1): fix trailing space in output of related node names (-dg2) 2020-09-12 16:22:32 +00:00
rillig
2d4cf7ec20 make(1): fix API for Targ_PrintCmd
The previous API was too low-level and not strictly typed.
2020-09-12 16:13:48 +00:00
rillig
46e01cf359 make(1): fix prototype of Suff_EndTransform 2020-09-12 15:21:25 +00:00
rillig
8c7f5b73b9 make(1): move PrintAddr to where it belongs 2020-09-12 15:15:51 +00:00
rillig
66b9293081 make(1): fix prototype of Compat_Make 2020-09-12 15:10:55 +00:00
rillig
467bf54d72 make(1): fix name and prototype of Compat_RunCommand
By convention, exported identifiers are written with underscore.

The prototype of an exported function must not use void * just because
it is used in Lst_ForEach.  This is an implementation detail and must
remain so.
2020-09-12 15:03:39 +00:00
rillig
de1804033e make(1): fix inconsistent code indentation 2020-09-12 14:41:00 +00:00
rillig
5d597631bc make(1): fix indentation in dir.c 2020-09-12 12:24:21 +00:00
rillig
fb925e321c make(1): rename local variable in Dir_FindFile
The name "cp" is not appropriate for a variable containing the basename
of a path.
2020-09-12 12:15:22 +00:00
rillig
f800db6729 make(1): add test for .PARSEFILE 2020-09-12 11:55:28 +00:00
rillig
3289a24517 make(1): add test for .PARSEDIR 2020-09-12 11:45:47 +00:00
rillig
88f0952b3a make(1): split ParseVErrorInternal into 2 functions 2020-09-12 11:21:15 +00:00
rillig
12edfb4410 make(1): inline local variable in Cond_Eval 2020-09-12 10:41:43 +00:00
rillig
dd9f912916 make(1): fix wording of parse error in conditionals
The word "should" is not appropriate for situations that eventually lead
to a parse error.
2020-09-12 10:38:52 +00:00
rillig
1941ac7d8e make(1): use proper return type for For_Accum 2020-09-12 10:14:16 +00:00
rillig
45fc46008a make(1): update the comment about .for loops to match the code 2020-09-12 10:12:09 +00:00
rillig
dbe7290c9c make(1): add tests for combining the :D and :U variable modifiers 2020-09-12 07:04:51 +00:00
rillig
1fcb18225c make(1): add wrappers around ctype.h functions
This avoids casting the argument to unsigned char, and to cast the
result of toupper/tolower back to char.
2020-09-11 17:32:36 +00:00
rillig
b30dd7c747 make(1): split EvalComparison into smaller functions 2020-09-11 16:37:48 +00:00
rillig
e9b0139227 make(1): clean up code for evaluating conditions 2020-09-11 16:23:47 +00:00
rillig
776a68ed0f make(1): extract EvalNotEmpty from CondParser_Comparison 2020-09-11 16:22:15 +00:00
rillig
146e020376 make(1): fix tests about nonexistent = and === operators 2020-09-11 15:33:28 +00:00
rillig
45ad91be45 make(1): add tests for the unknown = and === operators 2020-09-11 15:19:04 +00:00
rillig
84f74a93fc make(1): split CondParser_Comparison into 2 parts 2020-09-11 13:58:45 +00:00
rillig
38ac32b33e make(1): document CondParser_Comparison 2020-09-11 07:09:40 +00:00
rillig
30109ee17c make(1): fix comment in test for the || operator in conditions
Thanks to wiz for discovering this.
2020-09-11 06:51:38 +00:00
rillig
56350d0e74 make(1): add tests for really strange edge cases in conditions 2020-09-11 06:47:42 +00:00
rillig
b1c40cfb87 make(1): reorder parameters of condition parsing functions
First the subject, then the options, then the output parameters.
2020-09-11 06:08:10 +00:00
rillig
e3ff571cdb make(1): add missing space in source code 2020-09-11 05:37:40 +00:00
rillig
4f76601a57 make(1): add rationale for evaluating expression after parse error 2020-09-11 05:29:46 +00:00
rillig
32213c9dd0 make(1): fix line numbers from test result of the previous commit 2020-09-11 05:14:21 +00:00
rillig
7233424f15 make(1): add test for evaluation of condition after parse error 2020-09-11 05:12:08 +00:00
rillig
9df3b7b65d make(1): reduce code size in CondParser_Eval 2020-09-11 05:03:20 +00:00
rillig
7ed2c478c5 make(1): use consistent naming scheme for condition parsing functions 2020-09-11 04:57:15 +00:00
rillig
8714c6fe6e make(1): rename CondGetString to CondParser_String
This describes the function's effect more accurately.  The verb "get" is
not commonly associated to having side effects.
2020-09-11 04:40:26 +00:00
rillig
f9beff981e make(1): rename GNodeSuff.gn to gnp
It was confusing to have a field called "gn" that was not a pointer to a
GNode, but a double-pointer to GNode instead.
2020-09-11 04:36:12 +00:00
rillig
fc3e32ef07 make(1): replace *a->b with a->b[0]
This allows the code to be read strictly from left to right.  In most
places this style was already used.
2020-09-11 04:32:39 +00:00
rillig
aa1ee0301b make(1): replace *par->p with par->p[0]
It's a few characters more code than before but can be read strictly
from left to right, which was not possible before.
2020-09-11 04:22:22 +00:00
rillig
f031863371 make(1): rename CondParser.condExpr to p
The prefix "cond" was needed when this struct field was a global
variable.  The main name "expr" was not precise enough since this code is
about parsing a condition, not an expression.

During parsing, this variable does not contain the whole expression but
a pointer to the remaining part of the condition, therefore the name
"expr" had been confusing.
2020-09-11 04:18:44 +00:00
rillig
c69f7fe123 make(1): rename CondLexer to CondParser
The name CondLexer was wrong since this type is about parsing conditions
that can be arbitrarily nested.
2020-09-11 04:07:44 +00:00
rillig
6d5d05ff0f make(1): reduce code size in CondGetString
The pattern is now the usual "test the character, then increment the
pointer", throughout the whole function.
2020-09-10 23:37:54 +00:00
rillig
6ddbc03f29 make(1): skip redundant condExpr-- in CondGetString 2020-09-10 23:27:27 +00:00
rillig
2bf492c8b8 make(1): reduce code size for parsing the || or && operators
On x86_64, accessing [0] generates less code than [1].
2020-09-10 22:47:22 +00:00
rillig
949eb7fd83 make(1): add tests for the |, ||, ||| operators 2020-09-10 22:44:08 +00:00
rillig
89d5f8aeda make(1): add test for the &, && and &&& operators 2020-09-10 22:38:57 +00:00
rillig
1aa23ac7b9 make(1): add test for .SILENT 2020-09-10 21:40:50 +00:00
rillig
fb492da4a2 make(1): add test for .MAKEFLAGS 2020-09-10 21:22:07 +00:00
rillig
aa448ea91d make(1): clean up comments in cond.c 2020-09-08 18:51:23 +00:00
rillig
76c80899be make(1): add CondLexer_SkipWhitespace 2020-09-08 18:10:34 +00:00
rillig
9b7d994754 make(1): rename CondLexer.condPushBack to curr
This variable has some context information from the struct now,
therefore its name can be shorter.
2020-09-08 18:06:27 +00:00
rillig
be4d8db544 make(1): group the condition parsing state into a struct
Instead of having 3 global variables, the struct clearly communicates
that the 3 variables belong together. During debugging, it's easy to
just "p *lex" instead of remembering the names of the 3 former global
variables.

Converting the global variables into a local variable makes it
immediately clear that the functions in this file operate on this
struct.  Keeping the global variables in mind is more difficult.  Having
a local variable also gets rid of the 3 sv_* variables in
Cond_EvalExpression, which were also a sign that these "global
variables" were not that global at all.

This commit only contains the minimal code changes for converting the
variables into a local struct.  It was tempting to add functions like
CondLexer_SkipWhitespace, but this is better left for a follow-up
commit.
2020-09-08 17:55:23 +00:00
rillig
9f6b7470f7 make(1): in CondGetString, replace repeated Buf_Add with Buf_AddStr 2020-09-08 14:51:43 +00:00
rillig
d8bc78b637 make(1): add test for wildcards in dependency declarations 2020-09-08 05:33:05 +00:00
rillig
112c95a538 make(1): fix off-by-one error in SuffExpandChildren
In suff.c r1.144 from yesterday, in the line "cp += nested_p - cp", I
accidentally removed the "- 1".  Since these "- 1" lines lead to slow
execution, each branch now increments the pointer separately by the
actually needed amount.

Fixing this bug posed way more new questions than it answered, and it
revealed an inconsistency in the parser about how characters are to be
escaped, and missing details in the documentation of Var_Parse, as well
as a parse error that unexpectedly doesn't stop make from continuing.
2020-09-08 05:26:21 +00:00
rillig
3bb127c1bf make(1): document that nested braces work as expected now 2020-09-07 19:48:08 +00:00
rillig
db958a8ce2 make(1): extend and explain the test for comments 2020-09-07 19:17:36 +00:00
rillig
107d144dad make(1): explain why each test is run in a sub-make 2020-09-07 18:49:15 +00:00
rillig
1d8529b09b make(1): use consistent spelling for postprocessing 2020-09-07 18:43:59 +00:00
rillig
4144affb22 make(1): add test for the .WAIT dependency source 2020-09-07 18:40:32 +00:00
rillig
cf16582094 make(1): with -dp, print name of the function instead of its address
This makes the output a bit more reproducible.  There are still the file
descriptors, which may differ between different runs, but at least the
nextbuf function is printed using a symbolic name instead of a meaningless address.
Besides loadedfile_nextbuf, the only other function is ForIterate.
2020-09-07 18:37:09 +00:00
rillig
c7c417c4f1 make(1): migrate SuffExpandChildren to Var_ParsePP 2020-09-07 07:15:26 +00:00
rillig
11dcb9bdaf make(1): migrate to Var_ParsePP in Var_Parse and Var_Subst 2020-09-07 07:10:56 +00:00
rillig
11af043635 make(1): migrate ApplyModifiers to Var_ParsePP 2020-09-07 07:04:30 +00:00
rillig
193b2ca5f4 make(1): migrate Var_Parse to Var_ParsePP in ParseDoDependency 2020-09-07 06:58:02 +00:00
rillig
163aaa9b04 make(1): migrate Var_Parse to Var_ParsePP in archive handling 2020-09-07 06:51:05 +00:00
rillig
a41c30d038 make(1): remove unnecessary cp-- from Arch_ParseArchive 2020-09-07 06:44:53 +00:00
rillig
40b40038da make(1): save a strlen call in ForIterate 2020-09-07 06:28:22 +00:00
rillig
83915ab45f make(1): constify local variables in ForIterate 2020-09-07 06:27:29 +00:00
rillig
ae6eb8a7cc make(1): split local variable in ForIterate 2020-09-07 06:26:18 +00:00
rillig
953112797d make(1): remove redundant includes 2020-09-07 06:20:07 +00:00
rillig
28d4e7745c make(1): convert ForEscapes from #define to enum 2020-09-07 06:01:11 +00:00
rillig
ca751b452a make(1): add local variable for escapes to for_substitute
Just for debugging.  No change in code size.
2020-09-07 05:58:08 +00:00
rillig
4186926f7b make(1): clean up comments in job.c 2020-09-07 05:32:12 +00:00
rillig
3f25d2876e make(1): fix archive test when .CURDIR != .PARSEDIR 2020-09-07 05:16:32 +00:00
rillig
fa00c797c6 make(1): add const for Parse_IsVar 2020-09-06 19:34:36 +00:00
rillig
78cc09048b make(1): add const to For_Eval and For_Accum 2020-09-06 19:30:53 +00:00
rillig
2d9413362f make(1): clean up For_Eval
* Reduce scope of local variables.
* Remove unnecessary null character test before positive isspace call.
2020-09-06 19:28:49 +00:00
rillig
44d49322ad make(1): properly initialize For structure in For_Eval
Initializing a Buffer or a strlist_t with zero-valued bytes only works
by conincidence, but because it would be the correct way.  In the code
path "missing `in' in for", that zero-filled Buffer is freed using
Buf_Destroy, which could have invoked undefined behavior.
2020-09-06 19:24:12 +00:00
rillig
0244d862b4 make(1): improve documentation in For_Eval 2020-09-06 19:19:49 +00:00
rillig
47ba525800 make(1): fix type of For.short_var 2020-09-06 19:18:16 +00:00
rillig
d2ef6c55f3 make(1): add test for the -de option 2020-09-06 04:35:03 +00:00
rillig
000f3267b7 make(1): replay the changes from v1.283
I accidentally reverted them in v1.284.
2020-09-05 19:11:16 +00:00
rillig
f31746d78f make(1): clean up comments about parsing 2020-09-05 19:07:25 +00:00
rillig
c058562d66 make(1): fix comments about setting .PARSEDIR and .PARSEFILE 2020-09-05 18:41:59 +00:00
rillig
568c2fcd37 make(1): make GetActuallyIncludingFile faster
In deeply nested includes, starting the search from the inner end is
faster since it needs fewer comparisons.
2020-09-05 18:31:03 +00:00
rillig
3dd79b1f4a make(1): fix .INCLUDEDFROMDIR/.INCLUDEDFROMFILE 2020-09-05 18:18:05 +00:00
rillig
118ec9dfc5 make(1): add test for .INCLUDEDFILE combined with .for loops
The .for loops are implemented as a special kind of .include, therefore
they affect the .INCLUDEDFROM variable.
2020-09-05 18:13:47 +00:00
rillig
8981885e47 make(1): make test for .INCLUDEDFROMDIR simpler
The .info and .warning directives provide exactly the early expansion
that this test needs.  No more .for for getting a snapshot of a
variable.
2020-09-05 16:59:19 +00:00
rillig
9378c3ad8d make(1): add tests for some of the special sources 2020-09-05 15:57:12 +00:00
rillig
613d864f26 make(1): fix local variable type in ParseIsEscaped 2020-09-05 15:12:03 +00:00
rillig
6fa639d0d3 make(1): fix return type of ParseIsEscaped 2020-09-05 15:05:08 +00:00
rillig
bc484e3768 make(1): remove redundant prototype for ParseMark 2020-09-05 15:04:09 +00:00
rillig
41034fe6df make(1): remove redundant prototypes for local functions from parse.c 2020-09-05 14:58:07 +00:00
rillig
59980735fc make(1): remove initial size argument from Hash_InitTable
In all but one case this argument was set to auto-detect anyway.  The
one case where it was set was not worth keeping this complicated API.
2020-09-05 13:55:08 +00:00
rillig
09d79112a7 make(1): make Hash_Table independent from -funsigned-char
This only makes a difference for Hash_Table keys outside the ASCII
character set, and these are barely used in practice, if at all.

The effects of this change can only be seen in debug mode, when printing
the full contents of the variable namespaces.  In this output, the order
of the entries might change.

All other use cases stay the same as before.
2020-09-05 13:36:25 +00:00
rillig
42e06d6e82 make(1): add expected test result for hashing variable names 2020-09-05 13:34:19 +00:00
rillig
6544b03ea1 make(1): add test for intentional hash collision for variable names
Hash collisions may slow down make in certain special situations.  There
is no point though in maliciously triggering such a situation since
anyone who can inject values into makefiles can easily run shell
commands using the :!cmd! modifier or similar mechanisms.  Crafting
variable names just to slow down make is thus not an attack vector.
2020-09-05 12:59:07 +00:00
rillig
55c34e75ce make(1): remove trailing whitespace in -dg1 debug output 2020-09-05 06:46:12 +00:00
rillig
95fadeb4d8 make(1): move test for -dg1 from opt-debug-g1 to opt-debug-graph1 2020-09-05 06:36:40 +00:00
rillig
edc462c8ea make(1): fix test for the MAKEFILE variable
That test had assumed that it would always be run with CURDIR ==
PARSEDIR, which is not the case for ./build.sh.
2020-09-05 06:25:38 +00:00
rillig
5630da511e make(1): add tests for each debug option 2020-09-05 06:20:50 +00:00
rillig
919ee589c7 make(1): rename local functions for parsing conditions
The word "get" implies a cheap operation without side effects.  Parsing
instead has lots of side effects, even if it's only that the parsing
position is updated.
2020-09-04 21:08:44 +00:00
rillig
3e8f8a1a29 make(1): migrate get_mpt_arg to Var_ParsePP
This part is covered well by the unit tests.  When I forgot to decrement
the linePtr, several of them failed reliably.
2020-09-04 20:51:01 +00:00
rillig
09567ebca5 make(1): migrate Var_Parse in CondGetArg to Var_ParsePP 2020-09-04 20:32:34 +00:00
rillig
26222804bc make(1): add more explanation for undefined variable expressions 2020-09-04 20:28:15 +00:00
rillig
a1d05e1e9e make(1): re-enable the archive test
The test had failed in the releng build because it assumed it were run
with .CURDIR == .PARSEDIR.  This assumption is true when the tests are
run directly from usr.bin/make, but not when they are run from
tests/usr.bin/make.
2020-09-04 19:03:38 +00:00
rillig
9cc1256284 make(1): use a stack instead of a list for the nested include path
By using a Stack instead of a Lst, the available API is reduced to the
very few functions that are really needed for a stack.  This prevents
accidental misuse (such as confusing Lst_Append with Lst_Prepend) and
clearly communicates what the expected behavior is.

A stack also needs fewer calls to bmake_malloc than an equally-sized
list, and the memory is contiguous.  For the nested include path, all
this doesn't matter, but the type is so generic that it may be used in
other places as well.
2020-09-04 17:59:36 +00:00
rillig
612b32e506 make(1): unexport For_Iterate
By convention, exported functions have an underscore, and static
functions don't.
2020-09-04 17:35:00 +00:00
rillig
60c2e21286 make(1): add test for the special variable MAKEFILE 2020-09-04 17:05:39 +00:00
rillig
d4bba47099 make(1): fix expected file for archive test
This test is currently disabled, therefore it didn't fail immediately.
2020-09-04 17:03:17 +00:00
rillig
e8702174c8 make(1): add test for :hash returning ffffffff
In the previous brute force search, it seemed there was no string with
that hash code.  That was probably an oversight or a little programming
mistake.  Anyway, it's possible to get that hash value, so keep the
example.
2020-09-04 06:54:07 +00:00
rillig
cd269e3b78 make(1): extend tests for the :hash variable modifier
The previous test vectors didn't contain any hash with a leading zero.
This could have been a simple programming mistake by using %8x instead
of the intended %08x.  Using snprintf wouldn't have been possible anyway
since the hex digits are printed in little-endian order, but without
reversing the bits of each digit.  Kind of unusual, but doesn't affect
the distribution of the hashes.
2020-09-04 05:23:25 +00:00
rillig
a2fc9de97d make(1): add test for expansion of indirect variables in dependencies 2020-09-03 19:50:14 +00:00
rillig
ed3d9167a3 make: extend test for unresolved variables in dependencies
This is to ensure that the upcoming refactoring of Var_Parse in
SuffExpandChildren does not break anything.
2020-09-03 19:10:56 +00:00
rillig
4a7f0cb429 make(1): migrate ApplyModifier_Defined to Var_ParsePP 2020-09-03 18:53:46 +00:00
rillig
c183963589 make(1): add tests for the :D and :U modifiers
This prepares a refactoring for ApplyModifier_Defined.
2020-09-03 18:52:36 +00:00
rillig
0cc07a3c94 make(1): migrate Var_Parse API to parsing position
The ApplyModifier functions already use this pattern.  For simplicity
and consistency Var_Parse should do the same.  This saves a parameter to
be passed.

The migration takes place step by step, just like for the Lst functions
a few days ago.
2020-09-03 18:19:15 +00:00
rillig
ecb4f44224 make(1): document use of magic values in CondDoEmpty 2020-09-03 17:16:01 +00:00
rillig
4dd5292c3e make(1): add test for the empty function in conditionals 2020-09-03 17:13:42 +00:00
rillig
e3cda9a21a make(1): update documentation for Cond_EvalExpression and Cond_Eval 2020-09-03 16:14:58 +00:00
rillig
da17666427 make(1): make parameter of Cond_Eval and Cond_EvalExpression const 2020-09-03 16:02:02 +00:00
rillig
e010af6e23 make(1): document the value restrictions for Boolean variables
The previous lenient rule came from the sprite.h header that was not
specific to make.  To avoid confusion, only the expected values should
be stored in a Boolean variable.  To help find obvious violations and
inconsistencies, there are different possibilities for the Boolean type,
during development.

In C there is no way to actually enforce this restriction at runtime.
It would be possible in C++, but the code is not ready to be compiled
with a C++ compiler.
2020-09-02 23:42:58 +00:00
rillig
c62bab2173 make(1): improve grouping of the Lst functions
Lst_IsEmpty does not belong in the "create and destroy" group, but in
"query information without modifying anything".

The functions named LstNode_* all belong together.  They do not provide
much abstraction, but still they restrict the API and hide a few struct
fields that are only used internally by Lst_Open/Lst_Close and
Lst_ForEach.

Use consistent wording in the documentation of the functions (list,
node, datum).
2020-09-02 23:33:13 +00:00
rillig
cd07afa0d7 make(1): fix wrong comments in test for the .for loop
These comments were my original assumptions, which I wrote before
running the test and before looking at the implementation.
2020-09-02 22:58:59 +00:00
rillig
be8672544c make(1): fix documentation of Var_Subst
The "var" parameter does not exist anymore.
2020-09-02 06:25:48 +00:00
rillig
dd462d74ce make(1): clean up comments in var.c, make VarQuote const-correct 2020-09-02 06:19:11 +00:00
rillig
09d927125b make(1): remove redundancy from comments in make_malloc.c 2020-09-02 06:10:44 +00:00
rillig
337b196f85 make(1): fix typo in unit test for the .for loop 2020-09-02 05:36:58 +00:00
rillig
640eab791b make(1): add test for the .for directive
For a long time, I had assumed that the iteration variables of a .for
loop are just normal global variables.  This assumption was wrong but
didn't have any consequences.

The iteration variables of a .for loop can just be accessed like global
variables, therefore it is not obvious that they are implemented in a
completely different way.

There are some edge cases in conditions used inside .for loops, in which
the iteration variables cannot be used like normal variables.  An
example is brought up in https://gnats.netbsd.org/47888, which observes
that the defined() and empty() functions in conditions only work with
variables but ignore the iteration "variables", simply because these are
not variables but only expressions.
2020-09-02 05:33:57 +00:00
rillig
34a9f9ee4a make(1): fix cached_stat for files with st_mtime 0 2020-09-02 04:32:13 +00:00
rillig
13b5ed8e96 make(1): fix aliasing problem in cached_stat from the previous commit
When the struct stat was used for both calling the actual stat and for
returning the result, no copying was needed.  This also had the side
effect that for the first call of cached_stat, the returned struct stat
included all the fields properly filled in, and on later calls, these
fields were all zeroed out.

These two variables are separate now, thus the fields need to be copied
explicitly.  There are no existing unit tests for this, but ./build.sh
failed reliably.
2020-09-02 04:19:52 +00:00
rillig
0c93b3da8f make(1): reduce number of stat fields returned by cached_stat
Only st_mtime and st_mode are actually filled, the remaining fields had
been set to zero.  To prevent these from ever being accessed, a custom
struct make_stat replaces the previously used struct stat.

The fields in struct make_stat are intentionally named different from
the fields in struct stat because NetBSD and some other operating
systems define st_mtime as a macro, and that would not work in a field
declaration.
2020-09-02 04:08:54 +00:00
rillig
e2052aea2d make(1): use proper types in API of cached_stat and cached_lstat 2020-09-02 03:28:12 +00:00
rillig
2626dad6cf make(1): use Hash API from dir.c
When the Hash struct fields are renamed the next time, this should not
influence any code outside hash.h and hash.c.
2020-09-02 03:15:21 +00:00
rillig
5518d2b27c make(1): rename Hash_Table fields
Back in the 1980s it made sense to have the type information encoded in
the variable names.  At the time when make was imported into the NetBSD
tree (1993-03-21), the functions did indeed not have prototypes, they
only had return types.  The void type was already invented at that time.
Since the compiler could not verify the types of function parameters, it
made perfect sense to have each variable tell whether it was a pointer
or not.

Since ISO C90 this is no longer necessary since the compiler checks
this.  The variable names can now focus on the application level and
their high-level meaning, expressing the relationship to other
variables instead of encoding redundant type information.
2020-09-01 21:11:31 +00:00
rillig
b567ed9890 make(1): replace Hash_Table macros with inline functions 2020-09-01 21:00:15 +00:00
rillig
795de22c71 make(1): inline constant for hash table size
The name HTSIZE didn't provide any explanation for the value 191, and it
is obvious that this is a hash table size.  Therefore giving the
constant a name didn't explain anything or make it less magic.
2020-09-01 20:54:00 +00:00
rillig
90b52971fa make(1): improve documentation for enum.c and enum.h 2020-09-01 20:34:51 +00:00
rillig
93d390f91b make(1): improve variable names and data types in Dir_FindHereOrAbove 2020-09-01 20:17:18 +00:00
rillig
6f8bfeb0a6 make(1): add test for the -m option, the special .../ path 2020-09-01 20:14:34 +00:00
rillig
95110f95c2 make(1): add test for -m option with special argument .../ 2020-09-01 19:17:58 +00:00
rillig
39ed054cac make(1): make data types in Dir_HasWildcards more precise 2020-09-01 17:56:32 +00:00
rillig
93677eff47 make(1): mark LIBSUFF and RECHECK as independent build options 2020-09-01 17:40:34 +00:00
rillig
dc36bab27e make(1): clean up documentation in buf.h, and redundant include files 2020-09-01 17:38:26 +00:00
rillig
8d45a60e32 make(1): remove filemon object files on clean 2020-09-01 17:12:30 +00:00
rillig
7a2f02b40d make(1): move some of the :ts tests into a separate file
The successful cases can be easily tested in the .if conditions.  Around
these conditions, there is enough space for explaining the test cases
and their purpose.

The failure cases have been left in the file for now since they still
produce unwanted characters in the output.  These characters are not
produced when the parse error occurs in a conditional.
2020-08-31 19:58:21 +00:00
rillig
32c7ea9694 make(1): inline a local variable in VarUniq
Just to eliminate any remote possibility of aliasing and thereby
forgetting to update all involved variables.
2020-08-31 19:09:19 +00:00
rillig
411604f9db make(1): add more examples to the documentation of ParseModifierPart 2020-08-31 19:05:53 +00:00
rillig
a91afb0520 make(1): extend the documentation for the test variants 2020-08-31 18:57:41 +00:00
rillig
faae3ee83c make(1): fix the :u modifier, which was broken for almost a day
Big thanks go to sjg, who discovered the bug and did the main work to
track it down.

In the unit tests for the :u modifier from the previous commit, I had
forgotten to actually add the :u modifier at the end.  I added it now
and also added a few other tests.  It's better to have a few more tests
than too few.
2020-08-31 17:41:38 +00:00
rillig
c119b05bf3 make(1): add test for the currently broken :u variable modifier
The :u modifier had been broken in var.c 1.479 from 2020.08.30.19.56.02.
The code that implements the :u modifier was well-covered in the unit
tests, except for the single line that actually deals with adjacent
duplicate words.

The "refactoring" commit that replaced brk_string with Str_Words had not
taken into account that the number of words (in ac) had to be passed to
WordList_JoinFree.  Instead, the number of words was always preserved,
and the words at the end were therefore duplicated in the result.

The fix for this bug will be in the follow-up commit.
2020-08-31 17:32:13 +00:00
rillig
28423acec1 make(1): document the purpose of the test variants 2020-08-31 17:25:29 +00:00
rillig
93031f070d make(1): add test driver for different build options
This program's purpose is to reduce the build failures of the whole
build.sh just because one of the many possible configurations fails.
2020-08-31 16:51:17 +00:00
rillig
490b9ed0a1 make(1): fix compilation for -DNDEBUG and -O3
The -O3 option of GCC 5.5 is unsure about whether s and t are always
defined, since SuffParseTransform only defines them if it returns TRUE.

Therefore assert that it does.  When compiled with -NDEBUG, this would
result in an unused variable, therefore use it using the well-known
cast-to-void pattern.
2020-08-31 16:44:25 +00:00
rillig
38e9e4c9c6 make(1): improve documentation for Buffer fields 2020-08-31 16:42:10 +00:00
rillig
1b001ba380 make(1): fix compilation with GCC 8 2020-08-31 16:41:19 +00:00
sjg
95f6f1e60d Add test case for FLAGS dependent on .TARGET 2020-08-31 16:20:00 +00:00
rillig
90a952c9c5 make(1): fix copy-and-paste mistake for compiling with GCC10 2020-08-31 06:44:12 +00:00
rillig
e0ec26a690 make(1): parenthesize macro arguments
Just in case anyone wants to use them for copy-and-paste.

The invocations of these macros are left cautious since the
system-provided definition of these macros may have forgotten the
parentheses as well.
2020-08-31 06:21:07 +00:00
rillig
52ac672935 make(1): fix unbalanced Lst_Open/Lst_Close in SuffFindCmds
This bug had been there since the initial import of make, on 1993-03-21.
It just never broke the build because of the missing assertion.

https://mail-index.netbsd.org/tech-toolchain/2020/08/30/msg003847.html

The error message "cd: can't cd to include" that I got when I first
applied the fix was unrelated.  It was caused by an extra directory
"include" in src/tools/compat that didn't belong there.  With that
directory removed, running "./build.sh -j8 tools" succeeds as expected.
2020-08-31 05:56:02 +00:00
rillig
eddd7f4268 make(1): fix comment for Lst_Destroy 2020-08-30 21:20:06 +00:00
rillig
dcafa71348 make(1): remove unreachable code from CompatRunCommand
At the point where Str_Words is called, the string contains no
meta-characters.  This means that the parameter "expand" in Str_Words is
never looked at.  This in turn means that this parameter can be set to
FALSE, thereby making it impossible that Str_Words returns NULL.
2020-08-30 20:08:47 +00:00
rillig
5dd250059b make(1): replace brk_string with Str_Words
The API is much simpler, and there is less detail that is exposed by
default and fewer punctuation to type on the caller's side.  To see that
there is some memory to be freed, one would have to look into the
struct.  Having part of the return value as the actual return value and
the rest in output parameters was unnecessarily asymmetrical.
2020-08-30 19:56:02 +00:00
rillig
1465c374a8 make(1): add debug macros to suff.c
This reduces the visual space that the debugging statements need.
2020-08-30 18:26:41 +00:00
rillig
75c5a5daf7 make(1): extend test for .ifmake and .MAKEFLAGS 2020-08-30 14:25:45 +00:00
rillig
f8cb0fda82 make(1): rename GNode.iParents to implicitParents
The i alone was too ambiguous.  It could have meant ignore, implicit,
interactive, and probably many more.
2020-08-30 14:11:42 +00:00
rillig
2b7542e41b make(1): remove ineffective malloc_options variable
According to jemalloc(3), the variable must be called _malloc_options,
with a leading underscore, to have an effect.

Renaming the variable indeed enables the option.  There's not much point
having this variable around though, since it neither detects a trivial
double-free nor freeing an invalid pointer in the following code
snippet:

	char *asdf = bmake_malloc(10);
	fprintf(stderr, "%c\n", *asdf);
	free(asdf + 8);
	free(asdf);
	free(asdf);
	exit(1);

Instead, it just crashes with a segmentation fault.
2020-08-30 13:53:02 +00:00
rillig
eb0c83b502 make(1): rename Lst_Datum to LstNode_Datum 2020-08-30 11:15:05 +00:00
rillig
2d4a05ee59 make(1): rename Lst_Memeber to Lst_FindDatum
The new name nicely aligns with Lst_Find and Lst_FindFrom.
2020-08-30 11:12:05 +00:00
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
rillig
335ef99a86 make(1): fix assertion failure in suffix handling
Found by running ./build.sh, in the very early stage.
Fixed by restoring the previous behavior of returning NULL for invalid
arguments.
2020-08-28 06:37:21 +00:00
rillig
d5d52de25e make(1): clean up Dir_AddDir
Extract the null check for path to the top level.  This has the
side-effect of only incrementing dotLast.refCount if that entry is
actually used.

Reduce the indentation of the code by returning early from the simple
branches.
2020-08-28 04:59:17 +00:00
rillig
942d06c278 make(1): remove trailing 'S' from names of Lst functions
The migration from null-passing Lst functions to argument-checking Lst
functions is completed.

There were 2 surprises: The targets list may be NULL, and in Dir_AddDir,
the path may be NULL.  The latter case is especially surprising since
that function turns into an almost-nop in that case.  This is another
case where probably 2 independent functions have been squeezed into a
single function.  This may be improved in a follow-up commit.

All other lists were fine.  They were always defined and thus didn't
need much work.
2020-08-28 04:48:56 +00:00
rillig
4acfd85d5e make(1): migrate Lst_Find to Lst_FindS 2020-08-28 04:28:45 +00:00
rillig
acebd2797e make(1): remove unused reference to Lst_Last 2020-08-28 04:16:57 +00:00
rillig
4b307a6103 make(1): migrate Lst_First to Lst_FirstS 2020-08-28 04:14:31 +00:00
rillig
21328ac495 make(1): add test for the undocumented .NULL special dependency target 2020-08-28 04:05:35 +00:00
rillig
f0fdf22f6f make(1): add tests for the special .INCLUDES and .LIBS variables 2020-08-28 03:51:06 +00:00
rillig
3b8b408b28 make(1): print suffix flags in the standard way
This changes the output (it is now SUFF_NULL instead of just NULL), and
the order of the flags in the output is reversed.
2020-08-28 03:35:45 +00:00
rillig
274dc2d0aa make(1): disable the sync-mi convenience target 2020-08-28 02:45:51 +00:00
rillig
74fd7ff4cd make(1): migrate Lst_IsEmpty to Lst_IsEmptyS 2020-08-27 19:15:35 +00:00
rillig
5be8116c2e make(1): pass the command-line variables to the subdir make 2020-08-27 19:09:37 +00:00
rillig
2e8adea593 make(1): add test for the -dg1 option 2020-08-27 19:00:17 +00:00
rillig
8dde8e9642 make(1): migrate Lst_Last to Lst_LastS 2020-08-27 07:03:48 +00:00
rillig
b855b10134 make(1): migrate Lst_Succ to Lst_SuccS 2020-08-27 07:00:29 +00:00