Commit Graph

16207 Commits

Author SHA1 Message Date
rillig 4cd1b0bee0 make(1): clean up code style in make.c and suff.c 2020-11-16 22:31:42 +00:00
rillig 50a84755c6 make(1): clean up code style in targ.c 2020-11-16 22:28:44 +00:00
rillig 66dadf45cc make(1): initialize and free GNode fields in declaration order
Initialization and destruction of the fields is independent from the
other fields.  Therefore use declaration order, which allows to quickly
see whether a field was forgotten.

While here, add comments that in cleanup mode, not all memory is freed.
The variables of a node and the suffix survive right now.
2020-11-16 22:27:03 +00:00
rillig a13421bf80 make(1): fix initialization order of modules (broken since today)
In CLEANUP mode, Var_Init depends on Targ_Init since the variable scopes
are implemented as GNodes.

By the way, since 1999-09-15 variables are no longer stored in lists but
in hash tables.
2020-11-16 22:08:20 +00:00
rillig 5f6b9ee03e make(1): rename variables in targ.c
The previous names didn't make it obvious that 'allTargets' and 'targets'
belong together.  Naming both 'allTargets' provides a stronger hint.
2020-11-16 21:59:08 +00:00
rillig 2084acadbb make(1): clean up and extend comments in targ.c 2020-11-16 21:53:10 +00:00
rillig 73f094ffae make(1): make some GNode functions const 2020-11-16 21:48:18 +00:00
rillig e99bba9c48 make(1): in CLEANUP mode, preallocate list of all GNodes
This makes the code simpler and more uniform.
2020-11-16 21:44:29 +00:00
rillig b478f4bee7 make(1): rename TargFreeGN to GNode_Free
This is the usual counterpart to a New function, like for Lst, HashTable,
Buffer.
2020-11-16 21:41:02 +00:00
rillig b360908cec make(1): rename Targ_NewGN to GNode_New
This function is a classical constructor function, and if it weren't for
CLEANUP mode, it would have no dependencies on anything else besides the
memory allocator.  Therefore it doesn't really matter which module
defines this function, and there is no need for the "Targ" to be part of
the function name.
2020-11-16 21:39:22 +00:00
rillig 45c6dd2a91 make(1): inline SUFF_DEBUG3 and SUFF_DEBUG4
Each of them was only used a single time, which was not worth an
additional macro.
2020-11-16 18:49:54 +00:00
rillig 46bda17f30 make(1): clean up coding style in suff.c 2020-11-16 18:47:03 +00:00
rillig c0556f26c6 make(1): improve local variable names in suff.c
The name 's' was used for both 'suff' and 'src', which was unnecessarily
confusing.
2020-11-16 18:45:44 +00:00
rillig a904d54e51 make(1): remove redundant braces and parentheses from suff.c 2020-11-16 18:41:41 +00:00
rillig 768707fd01 make(1): use boolean expressions in conditions 2020-11-16 18:38:49 +00:00
rillig c1fe01b2fe make(1): clean up comments in suff.c 2020-11-16 18:34:29 +00:00
rillig 71e1e47432 make(1): use postfix increment where possible 2020-11-16 18:28:27 +00:00
rillig 21564d7f02 make(1): mark Suff.ref as probably unused 2020-11-16 16:15:37 +00:00
rillig f40c84018a make(1): add test for self-referencing suffix rule
Just to ensure that make doesn't run into an endless loop.
2020-11-16 15:12:16 +00:00
rillig 39390ebfcd make(1): clean up coding style in compat, parse, suff 2020-11-15 22:31:03 +00:00
rillig cf24ed751a make(1): document why .BEGIN cannot be combined with .USE/.USEBEFORE 2020-11-15 22:28:08 +00:00
rillig 81f83ffc8f make(1): fix typo in test for variable with empty name 2020-11-15 20:50:46 +00:00
rillig 52dc87bd97 make(1): add loud target to the .SILENT test 2020-11-15 20:49:20 +00:00
rillig 8b9a4b8f91 make(1): add tests for the .BEGIN node 2020-11-15 20:47:01 +00:00
rillig 7c69bb8eca make(1): update and add comments in tests
As a result of the new comments, some line numbers have changed in the
output of the tests.  No other changes.
2020-11-15 20:20:58 +00:00
rillig 2655930386 make(1): add remarks to var.c and the test varmod-match 2020-11-15 18:33:41 +00:00
rillig 32363c2f23 make(1): rename ApplyModifiersState.v to var 2020-11-15 18:32:29 +00:00
rillig 6d2affbd76 make(1): add remarks to the tests about conditions 2020-11-15 14:58:14 +00:00
rillig 960c8aaeec make(1): add tests for the '!' operator in conditions 2020-11-15 14:14:24 +00:00
rillig e3d2e555ae make(1): clean up some tests
Fix some mistakes in comments.

Improve some comments to be easier understandable.

Inline variables that are irrelevant for the test at hand (RUN,
MAKE_CMD).

Remove references to functions and constants that have since been removed
or renamed.
2020-11-15 14:07:53 +00:00
rillig 6a13e2b2ff make(1): add test for operator precedence using truth tables 2020-11-15 14:04:26 +00:00
rillig 1c1f145671 make(1): clean up make.h, meta.c, parse.c, str.c
The main changes are in the comments, which have been shortened and
corrected.

Some local variables changed their names.

In ParseErrorInternal, the scope of va_start is now narrower.

In ParseDoDependency, the type of tOp has been fixed.

ParseGetLine doesn't take flags anymore but instead a parsing mode.
Previously, the flags had not been combined anyway.

At the beginning of Parse_File, fatals is already guaranteed to be 0, and
even if not, it would be wrong to just discard the fatal errors.
2020-11-15 12:02:44 +00:00
rillig c687019fa0 make(1): add tests for edge cases when parsing directives 2020-11-15 11:57:00 +00:00
rillig b98bad40ff make(1): clean up make.c stylistically 2020-11-15 10:11:26 +00:00
rillig bc1d97ac3e make(1): rename checked to checked_seqno
The new name is more precise and also matches the GNode field.
2020-11-15 09:57:05 +00:00
rillig b2fa0c70f6 make(1): clean up ParseBoolean 2020-11-15 09:54:16 +00:00
rillig d41df8af85 make(1): clean up getTmpdir
Reduce indentation, structure code into paragraphs.
2020-11-15 09:38:44 +00:00
rillig 5848054cb4 make(1): clean up PrintOnError
No functional change.
2020-11-15 09:33:50 +00:00
rillig 8bd114fc0d make(1): fix previous commit for parse_debug_options 2020-11-15 08:12:35 +00:00
rillig 37d0ea76db make(1): reduce code size of parse_debug_options
Each access to a global variable requires a relocation.  Skip these.
2020-11-15 08:10:15 +00:00
rillig d9555d3712 make(1): add test for passing MAKEFLAGS to sub-makes 2020-11-15 06:19:34 +00:00
sjg 0a563920ba Avoid reading unexpected makefiles 2020-11-15 06:06:19 +00:00
rillig 0095a8b653 make(1): fix test varmod-to-abs with USE_ABSOLUTE_TESTNAMES=yes
When running the tests with specifying absolute filenames, it doesn't
make sense to prefix the MAKEFILE with "./", which made the tests fail on
FreeBSD.
2020-11-15 05:48:17 +00:00
sjg 1d14792992 Avoid problem with /usr/obj 2020-11-15 05:43:56 +00:00
rillig aed55ce676 make(1): switch cache for realpath from GNode to HashTable
An unintended side effect from the GNode implementation was that the
variable modifier :tA and the other places where cached_realpath are
used could be affected by setting a variable in the global scope,
thereby "redirecting" absolute paths to completely unrelated but
existing paths.

Another unintended side effect was that filenames containing a dollar
sign would not be resolved correctly since the dollar sign would be
expanded as a variable expression by Var_Set.

While here, the debugging output for the realpath cache has been
adjusted to the standard behavior.  Previously, when a new entry was
added to the cache, this was logged for the module VAR, as a side effect
of calling Var_Set, but only if the preprocessor macro
DEBUG_REALPATH_CACHE was defined at compilation time.  When relative
paths were purged from the cache because the current directory changed
and logging for the DIR module was active, the log output went directly
to stderr instead of the usual opts.debug_file.  This deviation from the
standard behavior was probably not intended as well.

All logging concerning the realpath cache now goes into the standard
debug log file and is controlled by the -dd option, not -dv.
2020-11-14 23:03:08 +00:00
rillig f2f5e31ea3 make(1): add tests for the command line option -C 2020-11-14 22:39:14 +00:00
rillig b0c345bc98 make(1): document the -S option
This option has been available at least since 1993-03-21, and for the
same time it has been undocumented.
2020-11-14 22:19:13 +00:00
rillig fca591a0a1 make(1): document since when the -C option is available 2020-11-14 22:17:29 +00:00
rillig 6eea38db80 make(1): fix trailing whitespace in usage (since 2009-08-27) 2020-11-14 22:16:17 +00:00
rillig c79799252b make(1): don't modify progname in usage 2020-11-14 21:55:22 +00:00
rillig 64455685f0 make(1): replace a few HashTable_CreateEntry with HashTable_Set
Instead of HashTable_CreateEntry and HashEntry_Set, several places just
need the HashEntry for storing a value in it.  This makes the calling
code simpler to understand.

These parts of the code are already hard enough to understand since they
are about memory management and aliasing.  Having a too detailed API for
the HashTable only distracts from these topics.
2020-11-14 21:29:44 +00:00
rillig 5cb24dfe8b make(1): inline local variable in Dir_UpdateMTime
Now that the signature of cached_stats is cleaned up, the line is short
enough to contain the whole condition.
2020-11-14 19:36:31 +00:00
rillig 33ac710bcd make(1): remove redundant struct make_stat
In the cache for stat(2) and lstat(2), only one of the two timestamps
was ever used.  To prevent a result from stat(2) leaking into the cache
for lstat(2), there have been two completely separate caches all the
time.  Using different fields in the struct was therefore unnecessary.

By removing the redundant field, the internal struct in the cache is the
same as the external struct.  This makes one of them redundant, thus
struct make_stat has been renamed to cached_stat, which better describes
its purpose, and the internal struct cache_st has been removed.

Just as before, the cache prevents any direct access to its internal
data.  When passing it to the caller, it is copied.

Just as before, the field names of struct cached_stat cannot correspond
to those from struct stat, since the latter are often defined as macros.
Therefore they are prefixed with cst instead of st.

The redundancy had been added on 2020-06-05.
2020-11-14 19:24:24 +00:00
rillig cdffd09272 make(1): add test for undocumented path-to-abspath mapping for :tA 2020-11-14 18:47:21 +00:00
rillig ba42b366eb make(1): clean up Fatal
Use the shortest possible scope between va_start and the corresponding
va_end.
2020-11-14 18:36:27 +00:00
rillig 210964aa26 make(1): clean up InitDefSysIncPath
Flipping the arguments to strncmp puts the subject first in the
sentence. Inverting the condition makes the code flow easier to follow.
2020-11-14 18:14:34 +00:00
rillig dd1b372a68 make(1): use progname instead of hard-coded 'make' in warning
This only affects the warning that chdir to objdir failed.  In sub-makes
the progname includes the [n], allowing to narrow down the actual cause
of the problem.
2020-11-14 18:07:26 +00:00
rillig 919a9a1235 make(1): remove redundant parameter from str2Lst_Append 2020-11-14 17:39:59 +00:00
rillig 97f85a860c make(1): rename Main_SetVarObjdir to SetVarObjdir
Only exported functions should be prefixed with the module name.
2020-11-14 17:39:14 +00:00
rillig a9f48205a2 make(1): add tests for edge cases in parsing the command line 2020-11-14 17:33:51 +00:00
rillig c066253900 make(1): use different style of accessing characters in MainParseArgs
The * is preferred for iterators.  Since argv[i] is not an iterator but
a fixed string, argv[i][0] expresses the idea "read the first character"
more directly.
2020-11-14 17:29:41 +00:00
rillig be37b1861d make(1): clean up JobExec, JobStart, JobDoOutput
The comments about temporary files for shell output are no longer
relevant since the output is always handled via pipes.
2020-11-14 17:04:01 +00:00
rillig 7c1b340629 make(1): remove indentation in JobOutput 2020-11-14 16:44:04 +00:00
rillig ea2c6c3049 make(1): clean up comment above ParseDoDependencyTargetSpecial 2020-11-14 16:09:08 +00:00
rillig 0daf0385f1 make(1): rename DEFAULT to defaultNode
In C, uppercase names are typically used for constants, and this is not
a constant.
2020-11-14 15:58:01 +00:00
rillig 92adb5cab7 make(1): use stderr for error message about failed touch
Error messages belong on stderr, not stdout.  Since at least 1993,
stdout had been used for no good reason.  Plus, in all these years,
nobody ever tested this code path since otherwise the missing newline at
the end of the error message would have been obvious.

This is a good candidate for the "oldest bug in make" trophy.
2020-11-14 15:47:35 +00:00
rillig 0bd6f1df40 make(1): add test for the -t option in jobs mode 2020-11-14 15:35:20 +00:00
rillig 15e853479d make(1): fix debug output for GNode details 2020-11-14 15:03:37 +00:00
rillig 096012f043 make(1): use symbolic names in debug output of GNodes 2020-11-14 14:57:05 +00:00
rillig 777851f30d make(1): clean up Job_Touch
Several more outdated comments were removed.  To compensate for that,
several new comments mark places where errors are not properly
propagated.
2020-11-14 14:16:01 +00:00
rillig 5569c170e9 make(1): add test for touching a .MAKE target 2020-11-14 14:13:09 +00:00
rillig 9689f236cd make(1): add test for the command line option -t 2020-11-14 13:59:58 +00:00
rillig c3260e2a8a make(1): rename JobClose to JobClosePipes, remove confusing comments
The comments referred to w_status, which had been there in 1993, but not
anymore.  Several other details were outdated as well.
2020-11-14 13:45:34 +00:00
rillig 75ee36445d make(1): fix grammar: setup -> set up 2020-11-14 13:27:01 +00:00
rillig f7446908e0 make(1): test ignoring errors from shell commands in jobs mode 2020-11-14 13:17:47 +00:00
rillig 16e9b880fb make(1): replace macro DBPRINTF with JobPrintln
This macro had been bad in several ways.  Its name started with DB, an
unnecessary abbreviation for DEBUG.  Many places that used this macro
used it with the same format string, "%s\n".  This format string can
better be expressed in a function name, JobPrintln.

Only in a few places was the macro used with different format strings.
The one for "set -x" was even forced to arbitrarily separate the
argument from the format string in order to match the expected macro
parameters.

A better choice would have been to use the standard form "%s\n", "set
-x" from the beginning.  Anyway, that call is calling JobPrintln as well
now.

The remaining templates are user-specified, and if anyone should ever
define a completely custom shell with echo handling and error handling
enabled, they will easily crash make when the templates don't contain
exactly one %s conversion.  That's the responsibility of the user, and
it has always been.
2020-11-14 13:07:39 +00:00
rillig 53224557e0 make(1): rename JobState to JobStatus
The status is only part of the whole state of a job.
2020-11-14 12:38:06 +00:00
rillig 8b4bb015b0 make(1): remove redundant parameter from cached_stats
The hash table for the cached data depends only on the passed flags,
therefore the caller does not need to know about their existence.
2020-11-14 11:51:58 +00:00
rillig e20908b45e make(1): clean up cached_stats
No functional change.
2020-11-14 11:22:17 +00:00
sjg 89f902192c Remove RO_OBJDIR when done 2020-11-14 07:36:00 +00:00
rillig c4ab1f9b64 make(1): clarify what 'recently' means in the comments in dir.c 2020-11-14 06:15:11 +00:00
rillig c42680b1fe make(1): fix typo in comments
This typo may have been influenced by all the '$' in the code.
2020-11-14 06:10:28 +00:00
rillig c4b14f3d93 make(1): flatten Dir_InitCur 2020-11-14 06:08:24 +00:00
rillig 66c9f4a5a2 make(1): clean up preprocessor macros in InitVarMachine 2020-11-13 19:45:24 +00:00
rillig ecb0e97ca6 make(1): in lint mode, check for ".else <cond>" 2020-11-13 09:01:59 +00:00
rillig eb5fad2de4 make(1): add more tests for parsing .else with argument 2020-11-13 08:35:34 +00:00
rillig cb6ce05fd8 make(1): flatten #ifdef in InitVarMachineArch
Without proper indentation, that chain of nested #ifndef directives was
really hard to read.
2020-11-13 08:21:37 +00:00
rillig f8bb6cd7ea make(1): use bitset for IfState
Previously, the individual IfStates contained redundant information,
which was apparent in the documentation.  This led to expressions like
(state > ELSE_ACTIVE) that are hard to read since the reader has to look
up the order of the enum.

To avoid this, the state of an '.if' block is now encoded using a bitset,
encoding the properties of each state directly.  This replaces the
previous (state > ELSE_ACTIVE) with !(state & IFS_ACTIVE), which is
easier to understand.

No change in behavior.
2020-11-13 07:52:03 +00:00
rillig 7417acad48 make(1): replace large switch with if-else in Cond_EvalLine 2020-11-13 07:35:27 +00:00
rillig b4169b94fb make(1): move the comment about ".else <cond>" to the correct place 2020-11-13 06:19:27 +00:00
sjg f35602449c Use explicit MAKEOBJDIR to avoid tripping over /usr/obj 2020-11-12 23:53:17 +00:00
sjg aa03bcf7d6 Pass a writable flag to Main_SetObjdir to control writable check
For curdir and an explicit .OBJDIR target, we allow for
the directory to be read-only.
During InitObjdir we otherwise default to requiring objdir to be
writable - this can be controlled by env variable
MAKE_OBJDIR_CHECK_WRITABLE

Add unit-tests/objdir-writable

Reviewed by: christos rillig
2020-11-12 23:35:21 +00:00
rillig a3a0dc2a39 make(1): add test for missing check on .endif with arguments 2020-11-12 22:40:11 +00:00
rillig cbcbd89e47 make(1): improve readability of IfState documentation
The words "None" and "One" looked and sounded too similar.
2020-11-12 22:27:55 +00:00
rillig 2e199e776f make(1): avoid race condition in test opt-debug-jobs
Thanks sjg for finding this and suggesting the fix.
2020-11-12 21:54:52 +00:00
rillig 50e09e5492 make(1): rename local variable in Cond_EvalLine
A variable called line is not supposed to be a moving target, that's what
the name p is reserved for.
2020-11-12 20:16:20 +00:00
rillig 0a1e46e5f9 make(1): remove complicated code to find the definition for plain .if 2020-11-12 20:06:37 +00:00
rillig c27d210cef make(1): document IfState in more detail 2020-11-12 20:01:27 +00:00
rillig d0d92c5376 make(1): move test for missing space after .if to correct file 2020-11-12 19:46:36 +00:00
rillig 4890da5730 make(1): add test for missing space after .if directive 2020-11-12 19:45:24 +00:00