Commit Graph

16207 Commits

Author SHA1 Message Date
rillig 2815a97239 make(1): add test demonstrating how ':=' and ':@var@' interact 2020-11-08 18:05:32 +00:00
rillig f4123b6995 make(1): rename VARE_ASSIGN to VARE_KEEP_DOLLAR
The other flags in VarEvalFlags already describe their effects, not the
place where they are used.  It's more important to know the effect.

Only a single unit test had to be adjusted.  This probably means that
there are too few tests where the special effects of VARE_KEEP_DOLLAR
come into play.  It could also mean that the effects are so simple and
obvious that they don't need any debug log, but that's not the case.
2020-11-08 16:58:33 +00:00
rillig fc3bb0099a make(1): add test for expanding variable expressions 2020-11-08 16:44:47 +00:00
rillig d7477a0f5e make(1): fix documentation of preserveUndefined
Since it is a global variable and not a VarEvalFlags, it affects nested
subexpressions as well, and there is no way to escape it.
2020-11-08 15:18:09 +00:00
rillig 2861b54efc make(1): use strict typing in conditions of the form !var 2020-11-08 15:07:37 +00:00
rillig b3c236d26d make(1): reformat main.c more closely to share/misc/style 2020-11-08 14:50:24 +00:00
rillig cee278d89c make(1): remove redundant comment from main_ReadFiles
The code has become so simple that it made the comment redundant.
2020-11-08 14:19:15 +00:00
rillig 85e932d1f1 make(1): fix bug description of using := with undefined variable
In 1993, the variable names could not refer to other variables yet.
This has been made possible on 2000-05-11, when the "cool magic" was
added that allows assigning to VAR.${param}.
2020-11-08 14:00:52 +00:00
rillig 8052cdbc6b make(1): add test for edge case in resolving undefined variables 2020-11-08 13:46:15 +00:00
rillig 26fef79e1f make(1): rename init_machine to InitVarMachine
For consistency with the other Init functions.
2020-11-08 13:10:30 +00:00
rillig 7ae46b86bc make(1): move usage further to the top
This avoids a forward declaration.
2020-11-08 13:05:03 +00:00
rillig 888a07aa5f make(1): move documentation from main to the phase functions 2020-11-08 12:50:57 +00:00
rillig 076e0ee51e make(1): split main into manageable pieces
The purpose of a main function is to give a high-level overview about the
whole program.  270 lines of code with lots of tricky details did not serve this
purpose.  Split the code into functions corresponding to the phases.
2020-11-08 12:40:04 +00:00
rillig 2e67a6de2c make(1): indent main consistently 2020-11-08 12:21:27 +00:00
rillig baadd47933 make(1): inline ReadMakefileSucceeded into ReadFirstDefaultMakefile
This gets rid of a few void pointers and an unused function parameter.
2020-11-08 12:14:14 +00:00
rillig 07df1af962 make(1): inline Lst_ForEachUntil in ReadBuiltinRules
The list of expanded filenames for sys.mk is freed in the end, but not
the filenames themselves, as these are still needed.
2020-11-08 12:02:16 +00:00
rillig 536f0554b2 make(1): document inefficient cache lookup in DirMatchFiles 2020-11-08 11:57:49 +00:00
rillig b95bacc113 make(1): clean up Make_ExpandUse
The targets need to be copied to the 'examine' queue, not because the
targets list would be modified but because the queue is modified and the
targets list should not be affected by that.
2020-11-08 11:37:46 +00:00
rillig 7af06cd4db make(1): fix type of have_token in MakeStartJobs 2020-11-08 11:28:44 +00:00
rillig 0501efc058 make(1): inline MakeCheckOrder into IsWaitingForOrder
This gets rid of a few void pointers and an unnecessary and unused
function parameter.

The variable name "bn" may have meant "before", but that was not
obvious.  The new name "ogn" nicely matches the ".ORDER" in the debug
message.
2020-11-08 11:25:26 +00:00
rillig c8d73d927d make(1): inline MakeAddChild into ExamineLater
This gets rid of a few void pointers and unspecific variable names like
"l" for the list that should have rather been called "examine" all the
time.

Add quotes around placeholders in debug messages.  Especially for targets
like "all" the message had been syntactically misleading.
2020-11-08 11:05:58 +00:00
rillig 3f36fd563f make(1): inline MakeFindChild into PretendAllChildrenAreMade
This gets rid of a few void pointers and some function calls.  The
documentation of MakeFindChild essentially repeated what the code does,
and the redundant parts of it have been removed.
2020-11-08 10:50:50 +00:00
rillig 9eaa257adc make(1): extract PretendAllChildrenAreMade from Make_ExpandUse 2020-11-08 10:40:07 +00:00
rillig 44232204f9 make(1): fix debug output in out-of-date for cohorts (since 2003-11-14)
Before, a wrong cause for being out-of-date was printed in the debug log,
for optional cohorts.  This was caused by having the same conditions
duplicated in the code, instead of putting them in a separate function.

Now the optional cohort is correctly identified as using the '::'
dependency operator.
2020-11-08 10:33:47 +00:00
rillig 39669e10c8 make(1): add test for wrong debug message in GNode_IsOODate 2020-11-08 10:17:55 +00:00
rillig ea6b852749 make(1): extract condition from GNode_IsOODate into separate function 2020-11-08 09:48:52 +00:00
rillig 04f1ad0734 make(1): change return type of Dir_MTime to void
Only some callers actually needed the updated time, and because of the
many branches, it was difficult to see that the return value was indeed
gn->mtime all the time.
2020-11-08 09:34:55 +00:00
rillig 4b8c84d3fa make(1): change return type of Arch_MTime to void
This makes it easier to prove that Dir_MTime always returns gn->mtime,
without looking at the implementation of Arch_UpdateMTime.
2020-11-08 09:15:19 +00:00
rillig 76d1f7676d make(1): change return type of Arch_MemberMTime to void
This makes it easier to prove that Dir_MTime always returns gn->mtime,
without looking at the implementation of Arch_UpdateMemberMTime.
2020-11-08 09:06:22 +00:00
rillig 6917f97a8e make(1): clean up comments in Make_Recheck 2020-11-08 08:55:25 +00:00
rillig 5b07d35705 make(1): use common indentation style for else 2020-11-08 08:53:22 +00:00
rillig 45bb09a29c make(1): rename Make_OODate to GNode_IsOODate
It doesn't matter which of the make modules is in charge of determining
whether a node is out-of-date.  Therefore, remove the module name from
the function name.
2020-11-08 08:33:07 +00:00
rillig 299497c050 make(1): rename Make_TimeStamp to GNode_UpdateYoungestChild 2020-11-08 08:26:22 +00:00
rillig 174d00f8b3 make(1): split ReadMakefiles into separate functions
This keeps the indentation of the code small.

It also reduces the possible confusion about the two similar branches in
that function that differ in a small but important detail:
ReadAllMakefiles reads all the makefiles while ReadFirstDefaultMakefile
stops after the first existing makefile.
2020-11-08 02:56:43 +00:00
rillig 5a6e58dfc8 make(1): inline strncmp in Parse_IsVar
The usual compilers don't do this themselves.
2020-11-08 02:37:22 +00:00
rillig a0f3504519 make(1): add more tests for parsing .MAKEFLAGS lines 2020-11-08 02:31:24 +00:00
rillig 6c69d12662 make(1): fix unrealistic memory leak in Main_ParseArgLine
It's unlikely that anyone ever defines an environment variable named
".MAKE" and then runs make with the -e option, which would make the
environment variable stronger than the built-in global variable.
2020-11-08 02:05:34 +00:00
rillig d74b4b5e20 make(1): add remarks for missing command line options in MAKEFLAGS 2020-11-08 01:56:54 +00:00
rillig bd0c3126dd make(1): parse the internal option -J strictly 2020-11-08 01:52:24 +00:00
rillig 835c7b313d make(1): merge duplicate code in is_relpath 2020-11-08 01:43:58 +00:00
rillig 055b133f13 make(1): clean up overview comment in main.c 2020-11-08 01:40:01 +00:00
rillig acaf4036bf make(1): fix type mismatch between int and PrintVarsMode 2020-11-08 01:39:24 +00:00
rillig 7e6f874d42 make(1): rename list node to ln
That's the name that is used for list nodes outside lst.c, and there is
no reason to use a different name in the implementation of lists.  Sure,
the "l" of the name "ln" is redundant, but it's still shorter than
"node", and the latter sounds too similar to GNode.
2020-11-08 01:29:26 +00:00
rillig 69e1c55258 make(1): remove unused JOB_IGNDOTS
It had been used in 1993 at least, don't know when it was finally
removed.
2020-11-08 01:16:04 +00:00
rillig b36ccac2b5 make(1): format source code in JobStart and JobDoOutput 2020-11-08 01:07:00 +00:00
rillig 4a407abe71 make(1): fix indentation in JobExec 2020-11-08 01:00:25 +00:00
rillig 824fa93621 make(1): clean up debug output for running jobs
There is no remote anymore, therefore mentioning locally is redundant.
It was a bad idea anyway to build format strings that work with parts of
words.
2020-11-08 00:54:06 +00:00
rillig 27c298f96a make(1): rename Src.children to numChildren
There are several other types that have a field named 'children' that is
a list.  To avoid confusion, rename this one to differentiate them.
2020-11-08 00:28:52 +00:00
rillig fe0085a927 make(1): clean up local variable names in suffix handling
The file suff.c defines both Src and Suff, which makes the variable name
s ambiguous.

The word 'target' is ambiguous as well since it could mean a GNode or the
target suffix of a transformation.  Therefore, make the variable names
longer but more precise.

The comment about the nil return and the beanhead had been outdated
already in 1993.  There is no nil return anywhere nearby.  The longer
variable names make the rest of the comment redundant.
2020-11-08 00:26:06 +00:00
rillig bbcaee938d make(1): replace strstr in ParseMaybeSubMake with optimized code
This code is called for each command that is parsed.  Calling strstr with
4 strings that all start with the same character is unnecessary work.
Therefore, replace strstr with manually optimized code.  Neither GCC
5.5.0 nor GCC 10 inlines strncmp like this, otherwise I would have used
that.

Change in behavior: previously, a${MAKE}b would not be considered to be a
sub-make command, which is probably correct but does not occur in
practice.  The check for non-alphanumeric characters around the found
string was probably meant only for the plain word "make".
2020-11-07 23:41:38 +00:00
rillig 2d229f3114 make(1): add test for OP_SUBMAKE 2020-11-07 23:25:06 +00:00
rillig 66f93f928a make(1): clean up spacing in fallback implementation of vsnprintf 2020-11-07 22:29:58 +00:00
rillig 0ebf6fb1c8 make(1): fix type mismatch between int and VarExportFlags 2020-11-07 22:28:24 +00:00
rillig 86d5a02152 make(1): remove redundant empty lines from parse.c 2020-11-07 22:26:42 +00:00
rillig 867d085450 make(1): clean up parse.c
The generated code stays exactly the same.  The only changes will be the
line numbers of assertions.  To preserve them, the removed lines have
been filled up with comments and will be removed in the follow-up commit.
2020-11-07 22:25:19 +00:00
rillig b510c1df87 make(1): remove trailing whitespace 2020-11-07 21:40:08 +00:00
rillig b4794003d3 make(1): fix type mismatch between int and VarSetFlags 2020-11-07 21:31:07 +00:00
rillig f52baef877 make(1): fix inconsistent indentation after #ifdef
Combining #ifdef with regular if-then-else calls for trouble.
2020-11-07 21:26:43 +00:00
rillig 430e6af1a9 make(1): fix type of Job.suspended 2020-11-07 21:24:33 +00:00
rillig 4b7522eb2f make(1): clean up Make_OODate and Make_Run 2020-11-07 21:22:37 +00:00
rillig 6bcbf8f8c5 make(1): clean up Buf_AddEscaped in .for loops
All this dance of determining the needed escape characters before
iterating, saving them upfront, evaluating them later using complicated
boolean expressions was not necessary at all.  All that is needed is a
simple NeedsEscapes, called at just the right time.
2020-11-07 21:04:43 +00:00
rillig 82e2acd33b make(1): use proper enum constant instead of 0 for CachedStatsFlags 2020-11-07 20:45:21 +00:00
rillig 4189145590 make(1): clean up CondParser_Comparison 2020-11-07 20:39:56 +00:00
rillig 9dfbe25229 make(1): reword condition in CondParser_String
The parentheses were confusing for human readers.

The compiler doesn't really care about the wording of the condition, GCC
5 on amd64 generates non-obvious but nice code anyway, replacing the
logical or with a logical and.
2020-11-07 20:35:04 +00:00
rillig 3f0565e482 make(1): fix type mismatch between Boolean and Token
Even though the C boolean and Token are encoded the same, the code should
still distinguish them, for the benefit of human readers.
2020-11-07 20:14:15 +00:00
rillig 2a070b743a make(1): fix type mismatch in If_Eval
No practical consequences since TOK_FALSE == 0 and TOK_TRUE == 1.
2020-11-07 20:11:32 +00:00
rillig 337a59929f make(1): clean up JobStart
Initialize the fields in declaration order.
Initialize Job.flags in a single assignment.
2020-11-07 20:03:56 +00:00
rillig 595e4d4033 make(1): add test for job command flags 2020-11-07 20:01:17 +00:00
rillig 9666e9b4ec make(1): add test for parse error in function defined() 2020-11-07 14:40:51 +00:00
rillig a26b3f9daa make(1): add test for parse error in condition using empty() 2020-11-07 14:37:30 +00:00
rillig b06323cade make(1): clean up Compat_Make 2020-11-07 14:32:12 +00:00
rillig 78a74ade12 make(1): clean up Compat_RunCommand 2020-11-07 14:27:16 +00:00
rillig f2a42695ee make(1): replace switch with if-else chain in Compat_RunCommand 2020-11-07 14:18:25 +00:00
rillig 84d259f4c7 make(1): make API of Buf_Init simpler
In most cases, the caller doesn't want to specify the exact number of
preallocated bytes.
2020-11-07 14:11:58 +00:00
rillig addc005f94 make(1): clean up Arch_LibOODate 2020-11-07 14:04:49 +00:00
rillig 8e125d92d8 make(1): fix indentation in JobPrintCommand 2020-11-07 13:53:12 +00:00
rillig 21f2256abd make(1): document duplicate code in arch.c 2020-11-07 13:43:39 +00:00
rillig 57f23c721b make(1): fix function names in archive debug output 2020-11-07 13:39:41 +00:00
rillig 1c3d769b00 make(1): fix out-of-bounds pointer in ArchStatMember (since 1993-03-21) 2020-11-07 13:34:46 +00:00
rillig 1f17fbd4ea make(1): reduce indentation in ArchStatMember 2020-11-07 13:29:38 +00:00
rillig 9a8256f3d1 make(1): replace hashed with cached in comments
The hash table is just an implementation detail, not worth to be
mentioned in comments.
2020-11-07 13:24:06 +00:00
rillig 8842c564a7 make(1): fix access to undefined memory (since 1994-03-18)
This bug was added in arch.c 1.6, "Do extended-name archives".
2020-11-07 13:21:57 +00:00
rillig d6b80bab62 make(1): clean up ArchStatMember
Whether an archive entry is hashed or not is completely irrelevant.  The
interesting thing is whether it ends up in a cache.
2020-11-07 13:17:04 +00:00
rillig 0ae82920a2 make(1): document the relation between VARE_ASSIGN and preserveUndefined 2020-11-07 13:13:19 +00:00
rillig a7c9be28ec make(1): properly handle errors for malformed archive target names
Error messages don't belong on stdout.
2020-11-07 13:09:13 +00:00
rillig 68c0f9fa5d make(1): rename local variable in Arch_ParseArchive 2020-11-07 13:03:58 +00:00
rillig 7946dd8753 make(1): rename parameter of ArchSVR4Entry
It cannot be made a const string, so rather document it clearly that the
string is modified.
2020-11-07 12:58:55 +00:00
rillig 39248585d5 make(1): remove unused macro definitions from arch.c
These definitions have originally been added in arch.c 1.27 on
1998-05-21.  Even back then they had been unused, at least they had not
been used directly.  Since macros are expanded at their use site, there
could have been an indirect use, but that is not the case anymore.
2020-11-07 12:54:44 +00:00
rillig 76f4da4086 make(1): fix archive handling
It's no wonder that nobody is using the archive handling of make.  The
archives created by GNU binutils cannot be processed using make since the
format of the archive names has changed.  GNU binutils appends a slash to
the member names.  Support that format from now on.

Add more debugging output in ArchFindMember.  Since nobody uses this part
of make, it doesn't hurt that the debug output is now very verbose.

In Arch_Touch and Arch_TouchLib, move the snprintf to where it belongs.
There's no point modifying a local variable just to throw it away
afterwards.
2020-11-07 12:47:16 +00:00
rillig 01ba44dc94 make(1): extract ArchiveMember_HasName from ArchFindMember
Comparing a string to a space-padded string is complicated enough to be
extracted to a separate function.

The behavior changes a little bit.  Before, when searching for an archive
member with a short name (one that is space-padded in the archive), that
member was not searched using the AR_EFMT1 archive format.  This doesn't
matter in practice though since no regular archive member has a name
starting with "#1/".
2020-11-07 12:34:49 +00:00
rillig 4cda1b336f make(1): clean up comments in arch.c 2020-11-07 11:36:49 +00:00
rillig 3a6dda4ef7 make(1): add pp_skip_hspace to skip horizontal whitespace during parsing 2020-11-07 10:44:53 +00:00
rillig 2387420d4d make(1): document InitDefSysIncPath 2020-11-07 10:25:28 +00:00
rillig 0f06ab6304 make(1): omit redundant bitwise or in Compat_Make 2020-11-07 10:23:20 +00:00
rillig a0c9252554 make(1): clean up code stylistically
* Replace character literal 0 with '\0'.
* Replace pointer literal 0 with NULL.
* Remove redundant parentheses.
* Parentheses in multi-line conditions are not redundant at the
  beginning of a line.
* Replace a few !ptr with ptr == NULL.
* Replace a few ptr with ptr != NULL.
* Replace (expr & mask) == 0 with !(expr & mask).
* Remove redundant braces for blocks in cases where the generated code
  stays the same.  (Assertions further down in the code would get
  different line numbers.)
* Rename parameters in CondParser_String to reflect the data flow.
* Replace #ifdef notdef with #if 0.

The generated code stays exactly the same, at least with GCC 5.5.0 on
NetBSD 8.0 amd64 using the default configuration.
2020-11-07 10:16:18 +00:00
rillig a9ae1df50a make(1): fix references to Var_SetWithFlags in tests 2020-11-07 00:07:02 +00:00
rillig ec28553452 make(1): rename Var_Set_with_flags to Var_SetWithFlags
Now that the function is exported from the var module, it should stick
to the naming conventions for public functions.
2020-11-07 00:06:13 +00:00
rillig ec691613fa make(1): rename VarSet_Flags to VarSetFlags
Most other types don't have an underscore as well.
2020-11-07 00:02:54 +00:00
rillig 94119fc036 make(1): rename Arch_MemMTime to Arch_MemberMTime
The abbreviation Mem was ambiguous, it could have meant memory as well.
2020-11-06 23:59:21 +00:00
rillig b3350f600e make(1): rename getBoolean and s2Boolean 2020-11-06 23:11:11 +00:00
rillig c6fda0697c make(1): fix comment of Error 2020-11-06 23:05:20 +00:00
rillig a5d8e822d9 make(1): clean up Cmd_Exec stylistically 2020-11-06 23:04:20 +00:00
rillig c699fce5aa make(1): merge duplicate code for skipping horizontal whitespace 2020-11-06 22:39:10 +00:00
rillig 13f3350e29 make(1): move name of inline functions to the beginning of the line 2020-11-06 22:37:07 +00:00
rillig b790432830 make(1): rename dieQuietly to shouldDieQuietly
It was too confusing to have a function named die that doesn't actually
die.  Plus, the return type int didn't give any clue about what the
function actually returns.
2020-11-06 21:20:31 +00:00
rillig 0a495e5a5e make(1): document DEBUG_LINT 2020-11-06 21:12:19 +00:00
rillig 345b90d029 make(1): sort and renumber debug flags 2020-11-06 21:09:06 +00:00
rillig aed622d743 make(1): fix typo from previous commit 2020-11-06 21:01:43 +00:00
rillig cb04a499e0 make(1): fix wrong condition in mkTempFile (since 2020-10-31)
The wrong negation had been added in main.c 1.414 from 2020-10-31.
Found by GCC 10, which complained about a potential null pointer
dereference in line 2188.
2020-11-06 20:59:52 +00:00
rillig 238b0c9726 make(1): fix tests directive-ifmake and varcmd with custom boolean
When make is compiled with -DUSE_UCHAR_BOOLEAN, these tests failed.
Merge duplicate code and don't depend on the actual value of TRUE when
evaluating conditions.
2020-11-06 20:50:48 +00:00
rillig 5909008f0e make(1): fix indentation in test directive-ifmake 2020-11-06 20:29:35 +00:00
rillig 0413618a39 make(1): document progname 2020-11-06 20:24:08 +00:00
rillig ccc3382b36 make(1): clean up comments in make.h 2020-11-06 20:20:00 +00:00
rillig 65f155a6c5 make(1): rename local variable in Var_Parse 2020-11-06 00:29:50 +00:00
rillig fa220160d4 make(1): format source code of a few functions in var.c 2020-11-06 00:05:18 +00:00
rillig 6bbc9e2d08 make(1): update and clean up documentation of Var_Parse 2020-11-05 23:52:08 +00:00
rillig 53688f4e09 make(1): fix parameter name in ApplyModifiersIndirect and ApplyModifiers
The variable must be properly initialized before these functions are
called.
2020-11-05 23:24:47 +00:00
rillig b935945dfd make(1): clean up ParseVarnameLong
A parameter named pp is usually used as the parsing position, which is
updated upon successful return.  Not so in ParseVarnameLong, where it
was updated in the unsuccessful branch only.

To avoid confusion, rename it to out_FALSE_pp, which is a longer name
but expresses more clearly what actually happens.
2020-11-05 21:16:20 +00:00
rillig a3933499cd make(1): extract EvalUndefined from ParseVarnameLong 2020-11-05 20:50:13 +00:00
rillig 75f08f317a make(1): extract FindLocalLegacyVar from Var_Parse 2020-11-05 18:43:55 +00:00
rillig abe541fa3b make(1): replace '(' and ')' with neutral '\0' in Var_Parse
The only possible values for extramodifiers are "H:" and "T:", therefore
parsing is independent of startc and endc.  Use '\0' instead of '(' and
')' to remove any possible confusion about how '{' and '}' would be
handled.
2020-11-05 18:26:59 +00:00
rillig 00dcc1c28e make(1): clean up documentation for Var_Subst 2020-11-05 18:20:23 +00:00
rillig f1a0c4ee9e make(1): add test for legacy local variables @F, @D 2020-11-05 18:08:39 +00:00
rillig 143a32671d make(1): remove redundant parentheses from sizeof operator
The parentheses are only needed if the argument is a type, not an
expression.
2020-11-05 17:27:16 +00:00
rillig 509b998a12 make(1): remove wrong comment from Var_Subst
The error handling in variable expressions is inconsistent.  Some errors
are detected, most aren't.  In particular, the error message for
undefined variables is _not_ issued on undefined variables but instead
on parse errors.
2020-11-05 15:04:51 +00:00
rillig 5e4ca438e2 make(1): add remark for exit status 0 despite error 2020-11-05 00:41:04 +00:00
rillig b06b754327 make(1): extend documentation for GNodeType constants 2020-11-05 00:40:31 +00:00
rillig 92f8abe62c make(1): group GNode fields by topic, document ParseErrorLevel 2020-11-04 13:40:20 +00:00
rillig edc344ff8e make(1): align comments on a few commonly used variables 2020-11-04 13:31:58 +00:00
rillig 986c524c55 make(1): move declaration of parseIncPath from main.c to make.h 2020-11-04 13:29:42 +00:00
rillig f374fbd233 make(1): remove mistyped extern variable
Robust programs don't have extern variable declarations in .c files, as
that risks incomatible definitions that are not detected by the compiler
and invoke undefined behavior.  Make make a little more robust.
2020-11-04 13:27:00 +00:00
rillig 4114898887 make(1): rename MAKEFILE_PREFERENCE for consistency
The names of the other special variables are all prefixed with MAKE_.
2020-11-04 13:22:15 +00:00
rillig fffa505f7c make(1): remove unused names DTARGET, FPREFIX, etc. 2020-11-04 13:04:56 +00:00
rillig 523c5384c3 make(1): fix indentation in parse.c 2020-11-04 06:09:55 +00:00
rillig 6704cd8729 make(1): fix typo and reasoning in test varparse-undef-partial.mk 2020-11-04 05:10:01 +00:00
rillig 203505b9fe make(1): negate discardUndefined to preserveUndefined 2020-11-04 04:49:32 +00:00
rillig dd4859fa30 make(1): fix line numbers in test output of cmdline-undefined.mk 2020-11-04 04:47:56 +00:00
rillig 5e72f6e7d2 make(1): add test for undefined variables in command line arguments
The variable discardUndefined has an implicit negation in its name,
which makes it hard to understand.  Plus, most of the time it is true.
It's better to have a flag that is false most of the time and has a
positive name.

On the first attempt of inverting that variable, I stumbled upon
MainParseArgs, which initially leaves discardUndefined == FALSE, and
after handling the dashed options, sets it to TRUE.  This would make a
difference when more command line arguments would be added later via the
.MAKEFLAGS special target.

Upon further inspection, the only place where discardUndefined is used
is in VarAssign_EvalSubst in parse.c, and that place is not reachable
from any of the dashed options.  Therefore, discardUndefined could
already be set at the very beginning of MainParseArgs or even when
initializing the global variable itself, without any observable
difference.

Not even the ::= variable modifier could do anything about this since it
is not reachable from the dashed command line options as well, and in
addition, it expands its right-hand side in any case, always discarding
undefined variables.  Oh, these little inconsistencies everywhere.
2020-11-04 04:24:57 +00:00
rillig 7023b446cd make(1): rename oldVars to discardUndefined
While here, moved all the documentation about this variable into a
single place.
2020-11-04 03:37:51 +00:00
rillig a3c3bec228 make(1): add missing enum tag for GNodeMade 2020-11-04 03:13:46 +00:00
rillig b6a037a9ff make(1): document that "old-style" variables are older than 1993 2020-11-04 02:57:42 +00:00
rillig a83e30d15b make(1): remove redundant condition from ApplyModifiersIndirect
Whenever varUndefined is returned from another function, that is only
done if eflags does not contain VARE_UNDEFERR.  Therefore, testing for
that flag is unnecessary.
2020-11-04 02:53:18 +00:00
rillig 8d109d6d28 make(1): replace emptyString with allocated empty string
Special-casing this variable only made the code more complicated.
Furthermore, it is not related to error handling in any way and
therefore distracted the reader from this topic.
2020-11-04 02:26:21 +00:00
chs 951bbd420a Restrict to root any command option that prints kernel addresses. 2020-11-04 01:37:55 +00:00
christos 476a50b768 Handle dummy timestamp better and check for I/O errors. From khorben@ 2020-11-03 22:21:43 +00:00
rillig ee9222c118 make(1): clean up unit tests 2020-11-03 18:42:33 +00:00
rillig cc87f8b86e make(1): in tests, replace "dollar character" with "dollar sign" 2020-11-03 18:21:36 +00:00
rillig dd404992ad make(1): add all printable ASCII characters to the varmod-subst test
I must have missed some of them when I originally wrote the test.  Not
sure how that happened.  While here, use the official Unicode names.
2020-11-03 18:18:31 +00:00
rillig 71ebef30e6 make(1): document the interesting part of the test forsubst.mk 2020-11-03 17:59:27 +00:00
rillig 1f77b83ee6 make(1): clean up tests error.mk and escape.mk 2020-11-03 17:38:45 +00:00
rillig 4351c3a136 make(1): in test forloop.mk, replace shell execution with .info
It's easier to read in the code, and the output has line information to
better relate the output to the code.
2020-11-03 17:37:57 +00:00
rillig f7a7da5460 make(1): move tests from directives.mk to separate tests 2020-11-03 17:17:31 +00:00
rillig 0d60dc067d make(1): document test for parsing of variable assignments 2020-11-02 22:59:48 +00:00
rillig 3ef5b1ede1 make(1): fix undefined behavior in Parse_IsVar
Even though the pointer was out-of-bounds, a crash was unlikely in
practice, since typical C compilers don't check the pointers for invalid
values after each modification.  The memory it pointed to was not
accessed though.
2020-11-02 22:50:55 +00:00
rillig 662cb994c0 make(1): fix line numbers in test output of varname.mk 2020-11-02 22:46:52 +00:00
rillig 3f600bbee8 make(1): document undefined behavior in Parse_IsVar
Sigh.  If only C could be compiled in strict mode that detects these
out-of-bounds memory accesses.
2020-11-02 22:44:29 +00:00
rillig 4b61bc4789 make(1): fix test for parsing obscure variable names
I had forgotten the :U modifier.  Without that modifier, there's no
chance that the variable names would come out correctly.
2020-11-02 22:29:48 +00:00
rillig 18305c7a81 make(1): add tests for parsing ob obscure variable names 2020-11-02 22:16:24 +00:00
rillig 12e48a64c0 make(1): remove obsolete POSTPROC.varname from unit tests
It was not needed anymore since 2020-10-18.
2020-11-02 21:53:28 +00:00
rillig 0b15b1d9eb make(1): fix error handling on parse errors in variable expressions
This change doesn't change any of the unit tests since the error
handling code is not yet complete, see the many "handle errors" in the
code.  Nevertheless, the "out_FALSE_res = VPR_PARSE_MSG" was wrong since
the error message was only printed in lint mode, not in default mode.
2020-11-02 21:34:40 +00:00
rillig b4bc4f4041 make(1): improve local variable name in ParseVarname 2020-11-02 21:24:23 +00:00
rillig a948288bbf make(1): document that skipping a modifier on parse errors is risky 2020-11-02 21:15:00 +00:00
rillig 07a98669b2 make(1): clean up CompatDeleteTarget and CompatInterrupt 2020-11-02 20:50:24 +00:00
rillig d0a7e917ea make(1): error out on unclosed expressions after the colon 2020-11-02 20:48:36 +00:00
rillig 2d4a31316a make(1): add test for parse errors in commands in lint mode (-dL)
The difference to non-lint mode is that the exit status is now 2 instead
of 0.
2020-11-02 20:43:27 +00:00
rillig a167407e80 make(1): remove debugging code from sync-mi 2020-11-02 20:40:10 +00:00
rillig 70eb58e5c3 make(1): add test for unclosed variable after a colon 2020-11-02 20:37:50 +00:00
rillig 1d4c05cdbb make(1): add test for parse errors in shell commands, compat mode 2020-11-02 20:20:42 +00:00
rillig a758ae2cb7 make(1): handle errors when sync-mi fails because of a syntax error 2020-11-02 20:19:33 +00:00
rillig 77e23359af make(1): remove word "Ptr" from variable names
Whether or not a variable is a pointer is obvious from the context.
Since the introduction of function prototypes in C90, this information
is checked by the compiler and no longer needs to be encoded in the
variable names.
2020-11-02 19:07:09 +00:00
rillig 3dadee6b02 make(1): use freeIt pattern in Arch_ParseArchive
This makes the memory management more obvious than before, where the
status of the variable libName depended on subLibName.
2020-11-02 18:24:42 +00:00
rillig a2844a43b6 make(1): fix wording of a comment in var.c
The "why again" could be easily misunderstood, it was ambiguous.
2020-11-02 18:15:12 +00:00
rillig 6ef9687775 make(1): add a comment where to fix the STOP/STORE test from varmod.mk 2020-11-02 17:55:26 +00:00
rillig d63a8b84ac make(1): add test for the :P modifier, which does not fall back 2020-11-02 17:30:22 +00:00
rillig d6d469076d make(1): format code in ApplyModifiersIndirect and ApplyModifiers 2020-11-02 17:00:33 +00:00
rillig 85f3dc47f0 make(1): merge variables p and nested_p in ApplyModifiersIndirect
When the code was still in ApplyModifiers, the variable nested_p was
necessary to distinguish the parsing position in the nested modifier
from the parsing position of the main expression.
2020-11-02 16:55:18 +00:00
rillig 27fc6febc6 make(1): rename rval to mods in ApplyModifiersIndirect 2020-11-02 16:48:49 +00:00
rillig 2698af257a make(1): inline and rename variables in ApplyModifiersIndirect 2020-11-02 16:38:47 +00:00
uwe dedde0dc29 Use \*q to refer to ascii quote to save fontlock from confusion. 2020-11-02 07:03:48 +00:00
rillig 3f4c8dcae8 make(1): extract ApplyModifiersIndirect from ApplyModifiers 2020-11-01 23:17:40 +00:00
rillig cc537f1f99 make(1): rename local variable in ApplyModifiers 2020-11-01 22:48:41 +00:00
rillig 6710cb8258 make(1): add another test case for the SysV modifier
The "special case" in ApplyModifier_SysV looks redundant since in
SysVMatch, the empty word does not match anything.
2020-11-01 22:28:52 +00:00
christos 0076513c11 Replace col with the FreeBSD version that adds wide char support 2020-11-01 22:27:15 +00:00
rillig d5a2f60bf8 make(1): rename local variables in ApplyModifier_SysV 2020-11-01 22:12:54 +00:00
rillig 24be86456b make(1): add tests for parsing the SysV variable modifier 2020-11-01 22:10:57 +00:00
rillig 036a109997 make(1): reduce number of nested parentheses in ApplyModifier_Assign 2020-11-01 21:28:42 +00:00
kim ac0b9611e2 Bump date (for "-not") 2020-11-01 21:11:49 +00:00
rillig b418af7851 make(1): fix manual page regarding numerical comparisons
Make uses double, not int, for comparing things.
2020-11-01 20:24:45 +00:00
rillig ad6e88dcd8 make(1): add more tests for the variable modifier :M
Despite its popularity and usefulness, the variable modifier :M is
implemented so weirdly that it's not surprising people get confused
about make's parsing and escaping rules.
2020-11-01 19:49:28 +00:00
rillig 623cfc02b8 make(1): add test for surprising parsing result of the :M modifier 2020-11-01 19:25:23 +00:00
rillig e24143bc70 make(1): move test flags to test varmod-match-escape.mk 2020-11-01 19:02:22 +00:00
rillig aebcc64d87 make(1): revert unintended change from previous commit 2020-11-01 18:48:13 +00:00
rillig b6c94d2092 make(1): fix indentation of source code 2020-11-01 18:45:49 +00:00
rillig 0735b81a78 make(1): rename JobMatchShell to FindShellByName
The word 'match' was too unspecific.
2020-11-01 17:58:17 +00:00
rillig 40014b1e5a make(1): negate NoExecute to GNode_ShouldExecute 2020-11-01 17:47:26 +00:00
rillig 0056a7c168 make(1): reduce amount of work in test job-output-long-lines.mk
The effect that some of the separator lines start at the end of another
line is still visible.
2020-11-01 17:29:13 +00:00
rillig 1cfab1491d make(1): extract EscapeShellDblQuot from JobPrintCommand 2020-11-01 17:07:03 +00:00
rillig d4af0258b7 make(1): extract ParseRunOptions from JobPrintCommand 2020-11-01 16:57:02 +00:00
wiz 878fe969c6 Properly quote '\;' in example. 2020-11-01 16:47:29 +00:00
kim c3c5cb3347 Document the -not operator 2020-11-01 16:34:02 +00:00
rillig 480f175d0a make(1): treat malformed :range, :ts and :[...] as errors
Before, integer overflow in the :[1..2] modifier had not been detected,
and the actual behavior varied between ILP64 and LP64I32 machines.

Before, the :ts modifier accepted character literals like \012345 and
\x1F600, which don't fit in a single character and were thus truncated.

Before, the :range modifier issued an "Unknown modifier" error message
for :range=x, which was not quite correct.  The error message in this
case is now "Invalid number".
2020-11-01 14:36:25 +00:00
rillig a1853aaad8 make(1): add tests for the variable modifiers :[words] and :range 2020-11-01 13:55:31 +00:00
rillig 9e39890f47 make(1): add tests for parsing errors in the :ts variable modifier 2020-11-01 13:28:50 +00:00
rillig dca12caf9b make(1): add more tests for the variable modifier :range, edge cases 2020-11-01 13:10:22 +00:00
rillig 9b24a7eb93 make(1): clean up comments in ApplyModifier_Words 2020-11-01 12:34:45 +00:00
rillig 13ce664461 make(1): add test for out-of-bounds separator in variable modifier :ts 2020-11-01 11:50:11 +00:00
rillig 4d77f4ef94 make(1): demonstrate parsing bugs in test moderrs.mk
When a malformed variable expression is parsed, the remaining part of
the expression is passed unmodified to the output.  This is unexpected
and wrong.
2020-11-01 10:56:08 +00:00
rillig e415fa14ba make(1): renumber the tests in moderrs.mk, remove duplicates 2020-11-01 10:53:58 +00:00
rillig 87f799f9fd make(1): make test names in moderrs.mk more descriptive 2020-11-01 10:52:09 +00:00
rillig 598a8d140a make(1): precisely describe the expected output in the test moderrs.mk
By making "want:" the same length as "make:", the remaining text in
these lines can be compared easily.
2020-11-01 10:50:22 +00:00
rillig 897c76e5e1 make(1): separate sections of moderrs.mk with empty lines 2020-11-01 10:46:34 +00:00
rillig 79ecbf9746 make(1): add section headings to the test moderrs.mk 2020-11-01 10:12:38 +00:00
mrg 947dbbbacf add support for '-not': GNU and thus worldly scripts compatibility. 2020-11-01 05:38:29 +00:00
rillig d9cc6ff4db make(1): in lint mode, exit with error status on errors
Calling Parse_Error during parsing has always led to a nonzero exit
status.  Calling Parse_Error later, when expanding the shell commands,
has had no effect on the exit status.  Neither had calling Error.

To make make a reliable tool, it has to report errors as they occur.
Enable this strict behavior in lint mode for now.  Lint mode has to be
enabled explicitly, preserving the default behavior.
2020-11-01 00:24:57 +00:00
rillig 8e37eea5e0 make(1): clean up StrContainsWord 2020-10-31 23:44:42 +00:00
rillig 3172a2f718 make(1): fix out-of-bounds pointer in ParseTrackInput 2020-10-31 23:39:01 +00:00
rillig 33a4a1ca23 make(1): rename parameter of Var_Value 2020-10-31 23:23:22 +00:00
rillig d5ef4ec39d make(1): improve local variable name in ParseTrackInput
By the way, the Address Sanitizer that ran over this code on 2015-11-26
didn't find the other out-of-bounds bug.  Most probably the Address
Sanitizer only detected obvious bugs in the actual test data, and there
was no test case in which .MAKE.MAKEFILES was shorter than the newly
added makefile.
2020-10-31 23:10:06 +00:00
rillig 31dbea1d44 make(1): fix off-by-one bug in ParseTrackInput (since 2015-11-26) 2020-10-31 23:01:23 +00:00
rillig 97ce2a0641 make(1): add test for off-by-one bug in ParseTrackInput 2020-10-31 22:55:35 +00:00
rillig 625b0ad57d make(1): document possible undefined behavior in trace.c with .CURDIR 2020-10-31 22:05:56 +00:00
rillig da69a0e26b make(1): document local variable in parse.c more precisely 2020-10-31 21:52:56 +00:00
rillig 819ecf5275 make(1): make parsing of the :gmtime and :localtime modifiers stricter
These variable modifiers accept an optional timestamp in seconds, to
select which date to print.  This feature is only used very rarely.  The
NetBSD build doesn't use it at all, and the FreeBSD build mainly uses
the plain modifiers :gmtime and :localtime, but not their optional
argument :gmtime=1500000000.

Therefore, this change is not going to affect many builds.  Those that
are indeed affected had been wrong all the time anyway.

At parse time, these errors stop the build, as intended.  After that,
when the actual shell commands of the targets are expanded and run,
these errors don't stop anything, the build just continues as if nothing
had happened.  This is a general problem with Var_Parse, see the many
"handle errors" markers in the code.  Another problem is that on parse
errors, parsing continues and spits out spurious strings of the form
"mtime" and "ocaltime".  This as well is a general problem with error
handling in make.

ok sjg
2020-10-31 21:40:20 +00:00
rillig 8ac215b8e4 make(1): add test for debug log for expansion of curly braces 2020-10-31 21:30:03 +00:00
rillig 48500bfeb0 make(1): mark the output in test dir.mk with a prefix
This is needed to distinguish it from the debug log, which will be added
in the next commit.
2020-10-31 21:12:36 +00:00
sjg 5b5c22709e Main_SetObjdir is first called for curdir which may be readonly
Skip access check if path is curdir.
This ensures that all proper initialization is done at least once.

If path is not curdir it should be writable to be useful.

Reviewed by: rillig
2020-10-31 21:09:22 +00:00
rillig d4b0b9ea9e make(1): add more tests for the variable modifier :localtime 2020-10-31 20:30:06 +00:00
rillig a6a1909faa make(1): add test for :gmtime with space before the number of seconds 2020-10-31 19:55:26 +00:00
rillig 102185fb1d make(1): add tests for error handling in the :gmtime variable modifier 2020-10-31 19:48:23 +00:00
rillig 70f61825b1 make(1): format #include directives consistently 2020-10-31 18:41:07 +00:00
rillig b58481850f make(1): remove unused code from needshell
Since usr.bin/xinstall no longer uses this code, there is no need to
keep the second parameter.
2020-10-31 18:20:00 +00:00
rillig be7ddd2cbe make(1): rename ismeta to is_shell_metachar
The old name was too broad.
2020-10-31 18:17:08 +00:00
rillig 3b9a5011ac make(1): remove debug logging for the :Q variable modifier
The same information is already logged in LogAfterApply.
2020-10-31 18:14:59 +00:00
rillig 3296a96508 make(1): fix local variable names in ParseModifierPart 2020-10-31 18:05:16 +00:00
rillig 090539ffb6 make(1): remove dead code for filename expansion using curly braces
Any string containing curly braces is already handled in the very first
if statement.
2020-10-31 17:39:20 +00:00
rillig 64e1789ba6 make(1): revert requiring a writable objdir
The change in main.c 1.413 broke the NetBSD build.sh if it uses a
read-only source tree, as in the daily builds.

Original commit:
https://mail-index.netbsd.org/source-changes/2020/10/31/msg123560.html

Build log:
make warning: /home/source/ab/HEAD/src: Permission denied.
[1]   Segmentation fault      "${make}" -m ${T...
2020-10-31 16:13:00 +00:00
rillig 818c0eaf62 make(1): rewrite VarIsDynamic to VarnameIsDynamic
The condition for the context is the same for both short and long names,
therefore move that condition to the only caller.

Clean up the comment and move its parts to the appropriate places.  The
"with the dollar sign escaped" part had been wrong already in 1993, and
it didn't get better over time.
2020-10-31 15:23:52 +00:00
rillig 16db8f2ffd make(1): rename local variable freePtr in Var_Parse 2020-10-31 14:55:33 +00:00
rillig 564c7162e3 make(1): use consistent parameter order in varname parsing functions 2020-10-31 14:47:32 +00:00
rillig d43fb1d27c make(1): extract ParseVarnameLong from Var_Parse 2020-10-31 14:40:34 +00:00
rillig 5d25954065 make(1): extract ParseVarnameShort from Var_Parse
With its more than 200 lines, the latter has too much code to be read
easily.
2020-10-31 14:12:01 +00:00
rillig 030fdca903 make(1): add test for recursion detection with short variable names 2020-10-31 13:45:00 +00:00
rillig 48e5e1cf2f make(1): fix function names in test for variable debugging 2020-10-31 13:15:10 +00:00
rillig 7f78983052 make(1): fix type of ParseModifierPart parameter delim 2020-10-31 12:59:28 +00:00
rillig 8a82b186a7 make(1): extract IsEscapedModifierPart from ParseModifierPart 2020-10-31 12:57:39 +00:00
rillig d581710cf9 make(1): clean up ModifyWords
Reorder the parameters to match the documentation comment, and the
remaining parameters in chronological order.  Remove the unused
parameter ctxt.  The callbacks that need it pass it in their
modifyWordArgs instead.
2020-10-31 12:45:42 +00:00
rillig 08137c1148 make(1): add test for combining the :@ and :? variable modifiers 2020-10-31 12:34:03 +00:00
rillig 6c314bb2d6 make(1): remove redundant condition for regmatch_t.rm_eo being -1
If rm_so is -1, rm_eo is guaranteed to be -1 as well.
2020-10-31 12:22:43 +00:00
rillig 0de1ffc13b make(1): add tests for edge cases in the :C variable modifier 2020-10-31 12:20:36 +00:00
rillig ff78291f2d make(1): make memory allocation simpler in meta_create and meta_oodate
Since there is only a single variable left that needs to be freed at the
end (and probably never actually needs to be freed since nobody defines
an environment variable named .OBJDIR), there is no need to loop over
these variables.
2020-10-31 12:04:24 +00:00