Commit Graph

2462 Commits

Author SHA1 Message Date
rillig
23b5e3ef8a make(1): fix indentation in Job_ParseShell 2020-09-27 19:06:47 +00:00
rillig
228b243e5a make(1): add test cases for the :range variable modifier 2020-09-27 18:11:31 +00:00
rillig
c5520b1066 make(1): fix punctuation and add paragraphs in config.h comments 2020-09-27 17:17:01 +00:00
rillig
304dea8c2e make(1): in the Buffer functions, rename bp to buf
It's not necessary to emphasize on the pointerness of the variable since
that's obvious from the context.
2020-09-27 16:59:02 +00:00
rillig
a7bebbf776 make(1): rename Buf_Size to Buf_Len
The new name better matches the field name Buffer.len as well as the
variables around the calls to this function.
2020-09-27 16:52:22 +00:00
rillig
886c644e5d make(1): prefer positive array index in Buf_AddByte
Ideally the condition for allocating more memory would have been
(old_len + 2 > bp->cap) since that's the actually intended wording.  But
GCC 5 neglected to generate good code for that on x86_64, so be it.
2020-09-27 16:38:32 +00:00
rillig
a549307932 make(1): rename Buffer fields
It was confusing to have a function Buf_Size that returns buf->count
even though there is also buf->size.
2020-09-27 16:21:06 +00:00
rillig
f139c2a2ab make(1): replace direct access to Buffer fields with inline function
This way, renaming the fields of the buffer is restricted to only buf.h
and buf.c.
2020-09-27 16:10:07 +00:00
rillig
60d7c828b9 make(1): inline Lst_ForEachUntil in Make_ExpandUse
The tricky detail here is that the current node from the iteration is
removed if it is no longer needed.

The Lst_FindDatum that has been removed was both inefficient and
misleading since it could never return null, yet there was a null check
for it.  The callback API from Lst_ForEachUntil would have required to
define a custom struct for passing this parameter to the callback
function, in addition to the parent node.

Inlining the whole Lst_ForEach and passing the list node as a parameter
is much more obvious.
2020-09-27 13:27:50 +00:00
rillig
234523181b make(1): run tests with jemalloc debugging enabled
This protects against very simple memory allocation bugs such as
migrating Lst_ForEachUntil to Lst_ForEach without remembering that
Lst_ForEachUntil can handle the situation where the current list node is
removed from the list, but Lst_ForEach cannot.  This happens in
Make_ExpandUse, for example.
2020-09-27 13:18:30 +00:00
rillig
bd99e52e66 make(1): inline Lst_ForEachUntil when parsing dependency lines
This avoids a few operations on void pointers.
2020-09-27 12:42:09 +00:00
rillig
fbb9ffc12c make(1): remove redundant null checks for the active targets
Before August 2020, the Lst library passed null pointers through.  This
was a confusing design pattern that has been removed since.  Now the Lst
functions fail fast on null pointers.

The 'targets' list is one of the few places where there is indeed an
optional list that may sometimes be null.  Back then, there was not
enough inline documentation to understand when the targets list was null
and when it wasn't.

Now that the documentation is there, the redundant and thereby
misleading null checks are no longer useful.
2020-09-27 12:26:23 +00:00
rillig
8cbf8c1227 make(1): inline PrintNode
Having a separate function had only been necessary for Lst_ForEachUntil.
2020-09-27 12:10:51 +00:00
rillig
8a70bc7074 make(1): inline Lst_ForEachUntil in ParseDoDependency 2020-09-27 12:05:04 +00:00
rillig
8f714173e8 make(1): inline Lst_ForEachUntil in Targ_PrintNodes
Printing a node does not modify the structure of the node, therefore the
additional housekeeping of Lst_ForEachUntil is not needed here.

Inlining the callback function also removes a lot of pointer stuff that
is more difficult to read than necessary.
2020-09-27 11:53:03 +00:00
rillig
405c56c525 make(1): inline Lst_ForEachUntil in Compat_Make
This avoids the extra local function and a few conversions to void
pointers, to gain additional type safety.

The code in Compat_RunCommand does not modify gn->commands structurally,
therefore it does not need the extra complexity of Lst_ForEachUntil.  It
does have access to a list node to exactly this list.  This list node is
only used to set the command to NULL after processing it, not for
removing the node from the list.
2020-09-27 11:43:46 +00:00
rillig
f393c9dcac make(1): rename local variable in MakeNodes
By convention, list nodes are named ln to distinguish them from GNodes,
which are called gn.
2020-09-27 11:39:02 +00:00
rillig
bdbb6e0ce2 make(1): make parameter of Compat_RunCommand const 2020-09-27 11:37:19 +00:00
rillig
1430a31b22 make(1): clean up comments in job.c and make.c 2020-09-27 11:14:03 +00:00
rillig
4ae53a3e65 make(1): fix CRLF line endings in unit tests 2020-09-27 09:53:41 +00:00
mrg
fd2e38eaf1 fix usr.bin/make build (which uses more warnings):
remove static only prototype TargPrintOnlySrc().
PrintOnlySources() does not return a value, make it void.
2020-09-27 01:07:12 +00:00
rillig
d449168a6a make(1): revert migration from Lst_ForEachUntil to Lst_ForEach
There is a crucial difference between these functions, in that
Lst_ForEachUntil can cope with a few concurrent modifications while
iterating over the list.  This is something that Lst_ForEach doesn't do.

This difference led to a crash very early in NetBSD's build.sh.
2020-09-26 17:39:45 +00:00
rillig
073f669ad5 make(1): inline and remove LstNode_Prev and LstNode_Next
These functions made the code larger than necessary.  The prev and next
fields are published intentionally since navigating in a doubly-linked
list is simple to do and there is no need to wrap this in a layer of
function calls, not even syntactically.  (On the execution level, the
function calls had been inlined anyway.)
2020-09-26 17:15:20 +00:00
rillig
5a9725dde8 make(1): inline Lst_ForEach in Targ_PrintGraph 2020-09-26 17:02:11 +00:00
rillig
d8a580cdaf make(1): replace a few Lst_ForEachUntil with simpler Lst_ForEach 2020-09-26 16:55:58 +00:00
rillig
ab003311ea make(1): inline Lst_ForEachUntil in Compat_Make 2020-09-26 16:41:42 +00:00
rillig
1d9026bdfa make(1): clean up obsolete comments about TARG constants 2020-09-26 16:27:27 +00:00
rillig
bc119df081 make(1): remove useless comment from TargFreeGN
GNode.fname is a const char *, therefore it cannot be freed anyway.
2020-09-26 16:21:17 +00:00
rillig
791df18439 make(1): inline Targ_FindNodeImpl
The 3 callers of this function passed different flags, and these flags
led to code paths that almost did not overlap.

It's a bit strange that GCC 5 didn't get that, and even marking the
function as inline did not produce much smaller code, even though the
conditions inside that function were obviously constant.  Clang 9 did a
better job here.

But even for human readers, inlining the function and then throwing away
the dead code leads to much easier code.

This pattern of squeezing completely different code into a single
function has already occurred in a different part of make, though I
don't remember where exactly.
2020-09-26 16:18:44 +00:00
rillig
cf5349557c make(1): clean up API for finding and creating GNodes
The previous API had complicated rules for the cases in which the single
function returned NULL or what it did.  The flags for that function were
confusing since passing TARG_NOHASH would create a new node even though
TARG_CREATE was not included in that bit mask.

Splitting the function into 3 separate functions avoids this confusion.
It also reveals several places where the complicated API led to
unreachable code.  Such code has been removed.
2020-09-26 16:00:12 +00:00
rillig
e58755b1f7 make(1): add test for '::' dependency operator with .ALLTARGETS 2020-09-26 15:41:53 +00:00
rillig
fa7e96862b make(1): replace Hash_FindEntry with Hash_FindValue in Targ_FindNode 2020-09-26 14:59:21 +00:00
rillig
5e8e948275 make(1): add Hash_FindValue, for direct access to hash table data 2020-09-26 14:48:31 +00:00
rillig
47974f53da make(1): replace a few Lst_ForEachUntil with simpler Lst_ForEach 2020-09-26 00:03:29 +00:00
rillig
6513361416 make(1): fix grammar and style in test dep-colon-bug-cross-file 2020-09-25 23:42:43 +00:00
rillig
6686652d07 make(1): remove redundant variable inLine from parse.c
This variable has served at least 27 years bringing unnecessary
redundancy to the code.  It was already redundant at 1993-03-21, when
the code was imported to NetBSD.
2020-09-25 23:39:51 +00:00
rillig
f500f93435 make(1): rename ParseFinishLine to FinishDependencyGroup
Even after 27 or more years, it's not too late to fix bad function
names.  This one for example does not finish a line but a dependency
group.
2020-09-25 23:35:25 +00:00
rillig
37aa92d20a make(1): fix missing check for duplicate commands in Parse_File 2020-09-25 23:30:16 +00:00
rillig
6c4e4cfc20 make(1): add test for harmless bug in Parse_File
When there is a dependency group at the end of a top-level makefile,
this dependency group is not finished properly.  This allows to add
further commands to the targets of this dependency group, which was not
intended.
2020-09-25 23:24:49 +00:00
rillig
68badaed50 make(1): fix undefined behavior for .MAKEFLAGS: -f file
Since at least 1993-03-21, adding other makefiles in a .MAKEFILES
dependency has invoked undefined behavior because the command line
arguments were copied directly into the global makefiles variable,
without a proper strdup.  Shortly after that, the word list created by
Str_Words (formerly brk_string) was freed.

This applies to both the -f and the -v and -V options.  Luckily it is an
edge case to use these options in .MAKEFLAGS at all.

The -T option had already been fixed at 2000-12-30, but not the other
options.
2020-09-25 23:18:59 +00:00
rillig
0ba7433aaf make(1): inline Lst_ForEachUntil in ParseLine_ShellCommand 2020-09-25 21:13:44 +00:00
rillig
31142950da make(1): extract ParseLine_ShellCommand from Parse_File
Parsing a single shell command from a line does not belong in
Parse_File, its proper place is in Parse_Line.  Having the whole
detailed code inline in Parse_File is even more confusing.
2020-09-25 20:57:22 +00:00
rillig
ba0ed6616b make(1): rename variables cp2 to be more expressive 2020-09-25 20:48:23 +00:00
rillig
922e04669b make(1): add test for make() function in conditions 2020-09-25 20:11:06 +00:00
rillig
abab61aa26 make(1): declare strings for suff.c constant 2020-09-25 19:50:04 +00:00
rillig
628f6ff857 make(1): extract parsing of the -dF option into separate function 2020-09-25 19:40:23 +00:00
rillig
489634a883 make(1): extract InitVarTarget from main 2020-09-25 19:24:56 +00:00
rillig
3d82cec1cd make(1): in FindSuffByName, return the suffix instead of a list node
None of the callers was interested in the list node.
2020-09-25 18:58:12 +00:00
rillig
b4b854cf1c make(1): add test for deleting the suffixes during parsing 2020-09-25 18:18:25 +00:00
rillig
ee4bd6beb7 make(1): migrate suff.c from Lst_ForEachUntil to Lst_ForEach 2020-09-25 17:55:19 +00:00