Commit Graph

2246 Commits

Author SHA1 Message Date
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