Commit Graph

2160 Commits

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