summaryrefslogtreecommitdiff
path: root/usr.bin/make/var.c
AgeCommit message (Collapse)Author
2023-06-23make: clean up variable and function namesrillig
No functional change.
2023-06-23make: warn about malformed patterns in ':M', ':N' and '.if make(...)'rillig
These patterns shouldn't occur in practice, as their results are tricky to predict. Generate a warning for now, and maybe an error later. Reviewed by sjg@.
2023-06-22make: merge common code for handling the ':M' and ':N' modifiersrillig
No functional change.
2023-06-16make: do not allow delete of readOnly variable.sjg
Sometimes we mark a variable readOnly to guard against .undef
2023-06-01make: shorten function names, clean up commentsrillig
No functional change.
2023-05-10Make :mtime operate on each word in variable value.sjg
Reviewed by: rillig
2023-05-09make: improve error message for failed stat in ':mtime'rillig
2023-05-09make: :mtime=error throw error on stat(2) failuresjg
Sometimes we want fatal error if stat fails on the presumed pathname.
2023-05-09make: add :mtime to provide mtime of filesjg
The value of the variable is passed to stat(2) and st_mtime is new value. An optional arg can be used if stat(2) fails, otherwise the current time is used. See varmod-mtime.mk for usage examples.
2023-05-09make: allow ':gmtime' and ':localtime' with dynamic argumentrillig
This allows ${%Y:L:gmtime=${mtime}} instead of the indirect ${%Y:L:${:Ugmtime=${mtime}}}. The direct form also prevents any ':' from the nested expression to be interpreted as a separator, which doesn't matter for the ':gmtime' and ':localtime' modifiers but will prove useful for other modifiers that follow the same pattern.
2023-03-28make: declare all common symbols in headers, unexport othersrillig
No functional change.
2023-03-09make: fix memory leak when parsing ':from=to' modifiersrillig
Since var.c 1.925 from 2021-04-12.
2023-02-18make: fix parsing of unevaluated subexpressions with unbalanced '{}'rillig
Since var.c 1.323 from 2020-07-26, modifiers containing unbalanced braces or parentheses were parsed differently, depending on whether they were relevant or not. For example, the expression '${VAR:...}' is enclosed with braces. When this expression has a modifier ':S,},}},g' that would double each '}' in that expression, the parser got confused: If the expression was relevant, the modifier was parsed as usual, taking into account that the 3 '}' in the modifier are ordinary characters. If the expression was irrelevant, the parser only counted the '{' and the '}', without taking into account that a '}' might be escaped by a '\' or be an ordinary character. Parsing therefore stopped at the first '}', assuming it would finish the expression '${VAR:S,}'. This parsing mode of only counting balanced '{' and '}' makes sense for the modifier ':@var@...@', which expands each word of the expression using the template from the '...'. These templates tend to be simple enough that counting the '{' and '}' suffices.
2023-02-15make: inline macros for variable namesrillig
The variable name '.MAKEOVERRIDES' was already used in the non-macro form. No binary change.
2023-02-15make: inline macro for variable name ".MAKE.EXPORTED"rillig
The variable name is distinctive enough to be searched directly in the code instead of having a named constant for it. No binary change.
2023-02-14make: remove redundant type VarParseResultrillig
No functional change.
2023-02-14make: clean up calls to Var_Substrillig
None of the calls to Var_Subst used the return value, and the return value was always VPR_OK. No functional change.
2023-02-14make: reduce complexity of evaluating expressionsrillig
No functional change.
2023-02-13make: extract the decision of using a specific log formatrillig
No functional change.
2023-02-09make: ApplyModifier_Remember always use SCOPE_GLOBALsjg
Conditionals evaluate vars with SCOPE_CMDLINE, if :_ is used within a conditional expression and is thus set in SCOPE_CMDLINE, it breaks any use of :_ in SCOPE_GLOBAL. The simplest solution is for :_ to always use SCOPE_GLOBAL Reviewed by: rillig
2023-01-26make: some variables should be read-onlysjg
Make variables like .newline and .MAKE.{GID,PID,PPID,UID} read-only. Reviewed by: rillig
2023-01-24make: log adjustments of var.readOnlysjg
2023-01-23make: .[NO]READONLY for control of read-only variablessjg
Reviewed by: rillig
2022-12-05make: inline LazyBuf_AddBytesBetweenrillig
No binary change.
2022-10-01make: constify, fix comment indentationrillig
No functional change.
2022-10-01make: merge duplicate coderillig
No functional change.
2022-09-27make: set WARNS to 6, from the default 5rillig
No binary change on x86_64.
2022-08-24make: prevent future out-of-bounds errors when parsing expressionsrillig
A modifier in an expression ends not only at the next ':' or at the closing '}' or ')', but also at the end of the string. Previously, testing for the end of the string had been done separately, which was error-prone since 2006-05-11, when indirect modifiers were introduced. Since then, it was possible that the string terminator '\0' was accidentally skipped in cases where the loop condition only tested for the ending character. When parsing indirect modifiers, the ending character is indeed '\0', but when parsing direct modifiers, it is '}' or ')'. A welcome side effect is that in the case of unclosed expressions such as '${VAR:Modifier', the amount of error messages is reduced from 2 or 3 to only 1. The removed error messages were wrong and thus confusing anyway.
2022-08-24make: fix out-of-bounds read when parsing the ':M' modifierrillig
Since at least 2009-01-17, probably already since 2006-02-18, when modifiers were allowed to be nested expressions.
2022-08-24make: fix out-of-bounds read when parsing the ':D' modifierrillig
Since 2000-04-29, when the ':D' and ':U' modifiers were added.
2022-08-23make: revert parsing of modifier parts (since 2022-08-08)rillig
The modifier ':@var@body@' parses the body in parse-only mode and later uses Var_Subst on it, in which each literal '$' must be written as '$$'. Trying to parse the loop body using Var_Parse treated the text '$${var:-0}' as a single '$' followed by the expression '${var:-0}', wrongly complaining about the 'Unknown modifier "-0"'. Found by sjg.
2022-08-08make: fix parsing of modifiers containing unbalanced subexpressionsrillig
2022-08-05make: when parsing ':D' or ':U', only copy text if necessaryrillig
When parsing the expression ${:D any ${uninterpreted} text}, parsing of the ':D' modifier only needs to skip to the next delimiter, there is no need to keep record of the text that has been skipped. In this particular example, there had been an unnecessary memory allocation since the nested expression was not copied to the result buffer. Due to that, the resulting buffer contained " any text", which was not a substring of the text passed to the parser, thereby forcing the memory allocation. No functional change.
2022-08-05make: extract parsing of ':D' and ':U' modifiers into separate functionrillig
No functional change.
2022-06-14make: document parsing of short variable names, such as $irillig
No binary change.
2022-06-14make: reduce indentation in ParseVarnameShortrillig
No functional change.
2022-06-14make: simplify return type of IsShortVarnameValidrillig
No functional change.
2022-06-12make: reorganize Parse_Errorrillig
Determining the location where the error occurred is now done by ParseVErrorInternal. This frees the remaining code from keeping the filename and the line number together. It also makes Parse_Error short enough that it might be worth providing a separate function for each of the 3 log levels. No functional change.
2022-05-14make: clean up comments in Var_Parserillig
2022-05-09make: remove obsolete commentrillig
All instances of VarFind that could be replaced with VarFindSubstring have been replaced.
2022-03-27make: fix spacing, and a typo in a testrillig
2022-03-26make: avoid trailing whitespace in debug log for variablesrillig
Since trailing whitespace is invisible, describe the variable value in words to make it visible.
2022-03-26make: add space after colon in debug logging for variablesrillig
These log messages are intended for human interpretation, so don't make them unnecessarily hard to read.
2022-03-26make: prefer 'long long' over 'long' on 32-bit C99 platformsrillig
When sorting the words of an expression numerically using the modifier ':On' (added on 2021-07-30), use 64-bit numbers even on 32-bit platforms. A typical use case is comparing file sizes. When tracing the execution of jobs, fix an integer overflow after 2038. 32-bit platforms that use a pre-C99 compiler still have this problem. No change to the test suite since most tests simply skip any potential differences between 32-bit platforms and 64-bit platforms (see varmod-order-numeric.mk) or already account for both variants (see varmod-localtime.mk).
2022-03-26make: clean up commentsrillig
2022-03-26make: fix crash on .undef of an environment variable (since 2020-10-06)rillig
2022-03-03make: simplify ParseModifier_Matchrillig
No functional change.
2022-02-11make: remove comment about environment variable with empty namerillig
At least on NetBSD, make cannot be fooled with an environment variable having an empty name. When running '/usr/bin/env =undefined make', the argument is parsed as a variable assignment, but putenv(3) refuses to process an empty variable name. Calling execve(2) directly got a step further, the kernel didn't filter '=undefined' from the environment variables. But getenv(3) always returns NULL when querying the environment variable with the empty name. On other operating systems, things may be different. Trying to set an environment variable with an empty name may cause errors in env(1), putenv(3), execve(2), getenv(3) or other places, so don't add an automatic test for now.
2022-02-09make: simplify control flow in ModifyWord_SysVSubstrillig
No functional change.
2022-02-09make: clean up variable namesrillig
No binary change.