Commit Graph

19368 Commits

Author SHA1 Message Date
rillig d910fbb739 make: fix filename in warning about duplicate script (since 2018-12-22) 2022-01-20 19:24:53 +00:00
rillig d2db2e8742 tests/make: refine test for wrong diagnostic line
To trigger the faulty code path, the file where the targets gets its
first command must be included via its relative path.  That was the case
when running 'cd usr.bin/make && make test' but not when running the
tests via ATF.
2022-01-20 19:16:25 +00:00
rillig 12889c829b tests/make: demonstrate wrong location in diagnostic (since 2018-12-22)
When a target has multiple places where commands are defined, the
diagnostics mixed up the filename in some cases.
2022-01-19 22:10:41 +00:00
andvar f923619fa4 fix typos in comments. 2022-01-17 20:38:49 +00:00
christos eaea20be3f If -e is specified exit with the exit status of the child process in
a shell-like format (nabijaczleweli)
2022-01-16 19:04:00 +00:00
sjg d9f6821145 Ensure make gets -r
Apart from ensuring no influence from /usr/share/mk
when bmake is built for the first time on a non-BSD
system, sys.mk will not be found
2022-01-16 18:16:06 +00:00
rillig 9d3954a537 make: condense code in Parse_IsVar
No functional change.
2022-01-16 09:41:28 +00:00
rillig 75f2782254 tests/make: document more edge cases for the assignment modifier ':sh' 2022-01-16 09:38:04 +00:00
rillig 990054f8df lint: warn about unreachable null statements
This warning flags the second semicolon of 'return;;' as being
unreachable.  It does not warn about these superfluous semicolons in
general though.

Seen in usr.bin/make/bmake_malloc.c.
2022-01-15 23:21:34 +00:00
rillig a20cbbf50a make: remove extra semicolon after statement
Lint will complain about this very soon.

No binary change.
2022-01-15 22:18:04 +00:00
rillig 86a2a4f6e7 tests/make: fix comment in test 2022-01-15 20:16:55 +00:00
rillig 9c1d64c23c make: replace Var_Value with Var_Exists where applicable
The latter function already existed in 1993, no idea why it was not
used.

No functional change.
2022-01-15 19:34:07 +00:00
rillig eb6499655d make: use islower for parsing directives
None of the directives has an uppercase letter, so there is no need to
test for it.

No functional change.
2022-01-15 19:13:08 +00:00
rillig 2ae09f1b0c make: remove unnecessary functions for expanding variable names
In meta mode, the affected variable patterns do not contain a '$'.

Outside of meta mode, Global_SetExpand was only called a single time, so
inline that call.

No functional change.
2022-01-15 19:05:23 +00:00
rillig bbf0adc973 make: merge duplicate code for expanding variable expressions
No functional change.
2022-01-15 18:34:41 +00:00
rillig 250e8719cd tests/make: ensure that the 'expect' comments in tests are correct
Based on tests/usr.bin/xlint/check-expect.lua.

For now, this extra check needs to be run manually.
2022-01-15 12:35:18 +00:00
rillig 0afc365659 make: remove trailing whitespace in meta.c 2022-01-15 09:08:57 +00:00
sjg fc98cca00e Add unit-test for .MAKE.META.CMP_FILTER 2022-01-14 19:31:44 +00:00
sjg 2b8714f27a meta_cmd_cmp: use bool for once
Just use Buf_Init() some mallocs will be inevitable.
2022-01-14 18:43:23 +00:00
rillig 31a82bbba6 make: inline EvalBare
No functional change.
2022-01-14 18:25:22 +00:00
sjg 3e72ec5137 meta.c: add .MAKE.META.CMP_FILTER
On rare occasions it is useful to be able to filter command lines
before comparison.
2022-01-13 04:51:50 +00:00
andvar c11ca9eaa9 fix few typos in comments. 2022-01-11 22:45:56 +00:00
rillig a572b8eaeb tests/make: clean up after test for option '-dF'
When the file for the debug log cannot be opened, make exits
immediately.  This doesn't give the test a chance to clean up the
temporary log file.

Instead of trying to treat a regular file as a directory and create a
file in it, assume that the directory /nonexistent-$uuid is actually
nonexistent.  This leads to the same kind of error message, independent
of strerror(3).
2022-01-11 19:47:34 +00:00
rillig b94b0e321f make: add debug logging for capturing the output of external commands
This applies to all 4 situations in which the output of an external
command is used for modifying a variable or an expression:

* the assignment operator '!='
* the assignment modifier '::!='
* the SUN shell modifier ':sh'
* the other shell modifier ':!cmd!'

Previously, only the shell modifier ':!cmd!' had debug logging.

Suggested by Christoph Badura.
2022-01-10 20:32:28 +00:00
rillig 5b01a92554 tests/make: add placeholders for .PARSEDIR and .INCLUDEDFROMDIR
When run via 'cd usr.bin/make/unit-tests && make test', the tests are in
the current directory.  When run via ATF, the tests are in
/usr/tests/usr.bin/make/unit-tests, while the current directory is a
temporary directory.  Allow both variants, plus others that may occur in
the bmake distribution.
2022-01-09 20:53:53 +00:00
rillig 7d0fa65d7d tests/make: ensure that '.ifn' is an unknown directive
Due to the way DetermineKindOfConditional works, it could have been that
'.ifn' is treated like the negation of the plain '.if'.
2022-01-09 20:21:44 +00:00
rillig dc362a8af1 make: add missing printflike annotations to parse.c
Clang is stricter than GCC in checking format string inconsistencies.
Reported by Tobias Nygren.
2022-01-09 19:57:14 +00:00
rillig fb272eaa4b make: extract low-level character operations into utility function
Suggested by nia.
https://mail-index.netbsd.org/source-changes-d/2022/01/09/msg013564.html

No functional change.
2022-01-09 18:59:27 +00:00
rillig d150208ab6 make: in Cmd_Exec, return error message instead of format string
This change leaves only literal format strings in parse.c.  It allows
for more detailed error messages than the current "non-zero status" or
"exited on a signal".

No functional change.
2022-01-09 18:49:28 +00:00
rillig 98b382b993 tests/make: demonstrate inconsistencies in Cmd_Exec callers
The assignment 'VAR != cmd' generates a warning, the others generate an
error message.  That error message is ignored for backwards
compatibility though.

The assignment via the expression ${VAR::!=cmd} only uses the output of
the command if there was no error, the other places use the output
nevertheless.
2022-01-09 18:22:31 +00:00
rillig cb36ae2edc make: shorten ApplyModifier_Assign
No functional change.
2022-01-09 16:56:08 +00:00
rillig 97eb68360f make: use consistent variable names for varargs
No binary change.
2022-01-09 15:48:30 +00:00
rillig ca04c22cac tests/make: test output channels for parse errors and other errors 2022-01-09 15:05:21 +00:00
rillig 5de02beb66 make: fix crash for newline in .for value in -dp mode (since yesterday) 2022-01-09 14:06:00 +00:00
rillig 477f723198 make: fix use-after-free in -dp mode (since yesterday)
In a .for loop that contains an unclosed .if directive,
Cond_restore_depth generates an error message.  If stack traces are
enabled using the option '-dp', the details of the .for loop are added
to the stack trace, but at that point, the ForLoop had already been
freed.  To reproduce:

make-2022.01.09.00.33.57 -r -f unit-tests/directive-for.mk -dp
2022-01-09 12:43:52 +00:00
rillig 69596ffca5 make: remove redundant lines from stack traces
These lines repeated the information from the .for loop line above them.
2022-01-09 11:43:58 +00:00
rillig e84f1fd909 make: in ApplyDependencySourceWait, align variable type with %u
No binary change.
2022-01-09 11:28:04 +00:00
mlelstv 8a61065f27 Let user gracefully abort recording with SIGINT. 2022-01-09 06:33:13 +00:00
rillig bfd564d160 make: remove redundant parameter from ForLoop_SubstVarLong
The buffer of a .for loop is always either empty or ends with '\n'.  A
variable name consists of arbitrary non-whitespace characters.
Therefore a variable name can never reach the end of the buffer.

No functional change.
2022-01-09 00:33:57 +00:00
rillig cbc7ee677b make: add details about .for loop variables to stack traces
The stack traces are enabled with the debug logging option '-dp'.
2022-01-08 23:52:26 +00:00
rillig cd63f07a11 make: fix stack traces in -dp mode (since 2021-01-26)
Previously, the stack traces omitted some lines that seemed to be
redundant.  As a result, the stack traces contained confusing line
numbers.
2022-01-08 23:41:43 +00:00
rillig 34152477d4 make: reduce confusing code in ParseForLoop
The previous version of the code gave the wrong impression that For_Eval
would modify CurFile.  That happens only later, in For_Run.

No functional change.
2022-01-08 22:42:27 +00:00
rillig 086c647c20 make: fix line number in debug log after returning from a file
The parser returns to the next line, not to the current line.
2022-01-08 22:24:20 +00:00
rillig 75d4a53089 tests/make: test line numbers in debug output for parsing files 2022-01-08 22:13:43 +00:00
rillig e72b1cbbbd make: return early from SkipIrrelevantBranches
No functional change.
2022-01-08 21:28:59 +00:00
rillig 577ef4e8d4 make: fix reported line numbers of continuation lines (since 2002)
Previously, multi-line directives like '.info' or '.error' reported the
line number of their last line instead of their first line, which is
more usual.  This also affected the debug log from '-dp'.
2022-01-08 20:21:34 +00:00
rillig 6da1a2e842 make: inline Buf_Clear
No functional change.
2022-01-08 17:25:19 +00:00
rillig 6403aeb99b make: rename is_shell_metachar, fix character conversion warning
No binary change.
2022-01-08 11:04:13 +00:00
rillig 33dd019cb6 tests/make: demonstrate edge case in parsing .for loops 2022-01-08 10:22:03 +00:00
rillig 94e9601469 make: constify UnescapeBackslash, fix typo in comment
No binary change.
2022-01-08 09:55:32 +00:00
rillig 93211f8ca3 make: remove redundant braces
No binary change, except for assertion line numbers.
2022-01-08 09:53:44 +00:00
rillig 5f7b57b18a make: clean up structure of For_Eval
Put related decisions on the same indentation level, remove unnecessary
negation, keep the code for the '.for' directive together.

No functional change.
2022-01-07 23:13:50 +00:00
rillig d4e6a81fff make: remove redundant condition in ParseRawLine
The input buffer is guaranteed to be terminated by '\n'.  This means
that after a '\\', there is no need to check for the end of that buffer.

While here, condense ReadLowLevelLine.

No functional change.
2022-01-07 22:08:09 +00:00
rillig 5e5304ee7e make: rename local variable in ParseRawLine
The previous variable name suggested that the variable would point to
the first '#' character of the line, instead it points to the whitespace
before the first '#'.

No functional change.
2022-01-07 21:57:26 +00:00
rillig a2a1ebf149 make: condense UnescapeBackslash
No functional change.
2022-01-07 21:40:56 +00:00
rillig b6944f8804 make: in loadfile, use simpler magic numbers
No functional change.
2022-01-07 21:04:50 +00:00
rillig 99e2f0ba08 make: have as few statements as possible between va_start and va_end
No functional change.
2022-01-07 21:00:49 +00:00
rillig bccb6308ed make: remove redundant function parameter in suffix handling
Now that mainNode is globally visible, there is no need to pass it
through function parameters.

No functional change.
2022-01-07 20:54:45 +00:00
rillig 68291d4356 make: merge duplicate variables for the main target
No functional change.
2022-01-07 20:50:35 +00:00
rillig 41d6d049a6 make: clean up comments, variable names, function names
The comment in ApplyDependencySourceOther repeated the code, its second
half didn't match any current code.

The comment above ParseDependencySourcesEmpty repeated the code.

No binary change, except for assertion line numbers.
2022-01-07 20:37:25 +00:00
rillig 897a695314 make: clean up handling of .for loops
Sort ForLoop members in natural reading order.

Remove redundant condition in ForLoop_ParseItems; at that point, the
number of variables is non-zero.

Rename Buf_AddEscaped since that function is not part of the Buffer API,
it is specific to .for loops.

No functional change.
2022-01-07 20:15:10 +00:00
rillig 9053a08fe0 make: eliminate file-scope variable forLevel
No functional change.
2022-01-07 20:09:58 +00:00
rillig d8d5dfa77e make: use simpler code for handling .for loops
Since the body of a .for loop is scanned from start to end, there is no
need to remember the length of a variable name.

Using memcmp for comparing the variable name was probably overkill since
the variable names are usually very short, so rather compare them byte
by byte.

No functional change.
2022-01-07 20:04:49 +00:00
rillig 596c2276c5 tests/make: fix documentation in cond-func.mk 2022-01-07 19:30:17 +00:00
rillig fa9a5efd89 make: rename and inline Targ_Precious
No functional change.
2022-01-07 19:24:27 +00:00
nia 71e4ddc293 Update Advent Sunday date to 2022 2022-01-07 16:51:25 +00:00
rillig 0a69dfa9c9 make: clean up comments and names in parse.c
No binary change except for assertion line numbers.
2022-01-07 14:03:55 +00:00
rillig 13ac08f1cf make: rename IFile and its fields to match their actual content
For lines that use backslash continuation, the human-readable line
number does not equal the number of raw lines that have been read from
the file.

The big comment in PrintStackTrace has become outdated, it still
referred to first_lineno.  Due to the bugs documented in
opt-debug-parse.mk, that function needs to be redone completely.

No functional change.
2022-01-07 13:56:09 +00:00
rillig d1d0ae7f4e make: merge calls to ApplyModifier_Time
This enables GCC 11 to inline ApplyModifier_Time, like all the other
modifiers.  Similar pattern as for ':M' and ':N', as well as for ':D'
and ':U'.

No functional change.
2022-01-07 12:44:57 +00:00
rillig f42040f836 make: merge duplicate code for modifiers 'gmtime' and 'localtime'
No functional change.
2022-01-07 12:37:27 +00:00
rillig 55ad9d7f7a make: clean up variable modifiers 'gmtime' and 'localtime'
Use consistent wording (zulu -> gmt), make VarStrftime parameter order
consistent with strftime, rename confusing 'time_t utc' to 't',
eliminate common subexpression in error message.

No functional change.
2022-01-07 12:33:25 +00:00
bad 83f02db3da mention ifmcstat(8) in SEE ALSO. 2022-01-07 10:17:39 +00:00
rillig 48b9dbe103 make: clean up ParseDependencySources
It is not necessary anymore to modify the passed-in line.  It had been
necessary when the parsing function was several hundred lines long, to
avoid gotos.

No functional change.
2022-01-07 09:49:43 +00:00
rillig 34864483f6 make: clean up local variables in ParseDependencyTargets
Having only a single moving pointer is less confusing than the previous
copying between tgt and cp.  For example, it did not make sense that the
target would start with '!'.

No functional change.
2022-01-07 09:35:11 +00:00
rillig 73878341fb make: remove redundant variable in ParseDependencyTargetWord
No functional change.
2022-01-07 09:28:35 +00:00
rillig d17c41c8f8 make: clean up function argument names and comments
No binary change except for assertion line numbers.
2022-01-07 09:19:43 +00:00
rillig c96a899199 make: remove redundant initializer in CondParser_ComparisonOrLeaf
No binary change.
2022-01-07 09:02:19 +00:00
rillig 42b43724f2 make: clean up nitpicks in parse.c
In PrintLocation, fname is not an iterator, so prefer fname[0] over
*fname.

List stdout and stderr in this order, for consistency with main.c.

No functional change.
2022-01-07 08:48:16 +00:00
rillig f1b783dc51 make: reduce negations in ParseVErrorInternal
No functional change.
2022-01-07 08:37:23 +00:00
rillig 399f66b1c1 make: rename local variable in bmake_malloc
The length of a string does not include the trailing '\0'.

No binary change.
2022-01-07 08:30:04 +00:00
rillig b4aaa18dd0 make: reduce code for initializing error handling in shell
No functional change.
2022-01-07 08:28:06 +00:00
rillig 03e107a990 make: fix null pointer when including empty file (since 2022-01-01)
Calling malloc(0) may return a null pointer, but callers of bmake_malloc
do not expect that.

Reported by Chris Pinnock, found by cross-compiling NetBSD on OpenBSD,
where tools/groff creates Makefile.dep files of size 0.
2022-01-07 08:20:00 +00:00
rillig e8daafff8a tests/make: demonstrate bugs in PrintStackTrace 2022-01-02 03:23:55 +00:00
rillig 4f74f4363c make: clean up nitpicks
In ParseWord, the expressions '*p' and 'ch' are the same.

In ParseDependencyTargetWord, clean up a wordy comment and join two
conditions.

In the test cond-token-number, clarify that make doesn't convert from
hex to decimal but only from hex to internal representation.

No functional change.
2022-01-02 02:57:39 +00:00
rillig 40b21b7214 make: clean up parsing of makefiles
Remove redundant comments.

Rename IFile.first_lineno to forBodyLineno since it only contains a
useful value in .for loops but not in .include files.  Also clarify that
this line number is the start of the loop body, since in PrintStackTrace
this line is used as a human-readable line number.  For a .for loop in
which the loop head spans multiple lines, this line number is wrong
anyway.

No functional change.
2022-01-02 02:39:55 +00:00
rillig 2854faca31 make: remove redundant IFile.fromForLoop
No functional change.
2022-01-02 02:16:12 +00:00
rillig f34697b908 make: clean up handling of .for loops and .include directives
No functional change.
2022-01-02 01:54:43 +00:00
rillig a8864c85ab tests/make: test edge cases in .for loops 2022-01-02 01:35:31 +00:00
rillig a031a6b834 make: in .for loops, pass the body to be filled as parameter
This is a preparation for cleaning up the code for loading and parsing
files, especially the part for including other files and for .for loops.

No functional change.
2022-01-02 00:12:47 +00:00
rillig 27ddd4f416 make: fix line number in error message about open conditionals 2022-01-02 00:07:20 +00:00
rillig 856d759998 make: remove unused parameter from Parse_PushInput
The parameter readMore was never NULL.

No functional change.
2022-01-01 21:50:29 +00:00
rillig d0fc36607a make: fix error message when reading more than 1 GB from stdin
Previously, the error message was:
	make: (null): file too large
Now it is:
	make: (stdin): file too large
2022-01-01 21:41:50 +00:00
rillig 2936433d4b make: clean up loadfile
Do not reserve extra space "just in case a makefile does not end in
'\n'" since that doesn't happen often.

The assertion for 'buf.len <= buf.cap' was redundant.

No functional change.
2022-01-01 21:19:37 +00:00
rillig 974a87afaf make: convert do-while into while in FindKeyword
GCC generates more efficient code; previously it wasn't aware that (end
- start) was always positive, thus allowing to omit the code for
dividing a negative number by 2.

No functional change.
2022-01-01 21:04:15 +00:00
rillig 82da1a6f2f make: reduce indentation in Main_SetObjdir
No functional change.
2022-01-01 19:53:40 +00:00
rillig 45f3b8b58c make: remove redundant comments from ParseDependencySourceSpecial 2022-01-01 19:44:05 +00:00
msaitoh 777518dc50 s/implemenation/implementation/ in comment. 2022-01-01 08:34:34 +00:00
rillig b67077487c make: sync API documentation of parse.c with latest changes 2021-12-31 01:34:45 +00:00
rillig cdfa6c832b make: prevent out-of-bounds pointer in AdjustVarassignOp
It's a rather theoretical case that 'name' would point at the very end
of the address space and the string there would be "V=", but in that
case, the expression 'name + 3' would wrap around.
2021-12-31 01:08:59 +00:00
rillig d0ff7e426a make: merge duplicate code in Parse_IsVar
No functional change.
2021-12-31 00:45:21 +00:00
rillig ea8a2fa797 make: eliminate type VarAssignParsed
No functional change.
2021-12-31 00:37:50 +00:00
rillig 76c752e5f5 make: unexport types VarAssignOp and VarAssign
These types are only needed in the parsing module.

No functional change.
2021-12-31 00:18:06 +00:00
rillig 82d845ef18 make: list VarAssignOp in the same order as in the manual page
No functional change.
2021-12-31 00:01:02 +00:00
rillig 024157d11c make: condense code in ApplyModifier_Assign
List the assignment operators in the same order as in the manual page.

No functional change.
2021-12-30 23:56:34 +00:00
rillig 8d39532123 tests/make: demonstrate edge case that evaluates an expression twice 2021-12-30 02:14:55 +00:00
rillig 34c3bf6d63 make: remove redundant code from CondParser_ComparisonOrLeaf
No functional change.
2021-12-30 01:34:26 +00:00
rillig 9d23feca8b make: split ParseWord into the actual ParseWord and ParseFuncArg
Combining two similar but fundamentally different parsing tasks in a
single function only increased the complexity, of the implementation as
well as the call sites.

The code makes it obvious now that a function argument is a bare word
surrounded by parentheses.

The special case of an empty word is only needed for the function
argument, it cannot occur in a bare word.  The code for that has been
moved to the caller.  Such an empty word not only occurs for 'defined()'
but also for 'defined(${:U})'.

No functional change.
2021-12-30 01:30:33 +00:00
rillig 60c0325e23 make: make ParseWord in condition parser simpler
Merge the two return values (bool, string) into a single return value.
As before, the caller cannot observe the difference between a parse
error and an empty word, both are handled in the same way.

In CondParser_ComparisonOrLeaf, the word cannot be empty since the
calling function CondParser_Token already handles all cases that could
lead to an empty word.

No functional change.
2021-12-30 01:06:43 +00:00
rillig 03e72f0a3a make: internally return false for irrelevant leaves in conditions
The result of irrelevant leaves is effectively ignored by CondParser_And
and CondParser_Or.  Use the 'doEval &&' pattern to make the code
consistent with CondParser_Comparison and CondParser_FuncCall.

No functional change.
2021-12-30 00:22:20 +00:00
rillig d5e7b1f687 make: in irrelevant function calls in conditions, return false
When a condition contains an irrelevant function call, it doesn't matter
whether the function call evaluates to true or to false, it will be
discarded anyway by either CondParser_And or CondParser_Or.

Returning false instead of true makes the code simpler, plus it is more
common to return false for irrelevant results.

No functional change.
2021-12-29 08:23:40 +00:00
rillig dfb79a6573 make: use simpler return type for ParseWord in conditions
No functional change.
2021-12-29 08:15:45 +00:00
rillig 56ec8664b8 make: replace table for function lookup in conditions with simple code
The code for looking up the function from the table forced the compiler
to use a specific memory layout.  Replacing the table with explicit code
provides the compiler more opportunities to optimize the code.  Another
side effect is that there are fewer pointer operations.

Previously, is_token checked that the character after the word does not
continue the word, this is now done separately since for the function
lookup, this check was unnecessary.  The newly added skip_string
provides a higher abstraction level, it is no longer necessary to pass
the string length as a separate, redundant parameter.

No functional change.
2021-12-29 07:40:52 +00:00
rillig c41220df56 make: clean up condition parser
No functional change.
2021-12-29 05:16:44 +00:00
rillig 661e0bd3a7 make: merge duplicate types CondEvalResult and CondResult
No binary change.
2021-12-29 05:05:21 +00:00
rillig 6035ea7532 make: merge duplicate enum constants for CondEvalResult and CondResult
No binary change.
2021-12-29 05:01:35 +00:00
rillig 3a10c88e96 make: remove redundant parameter for evaluating conditions
No functional change.
2021-12-29 04:50:56 +00:00
rillig bcf936b8fd make: merge types CondResult and CondEvalResult
No functional change.
2021-12-29 04:41:38 +00:00
rillig 5be4420992 lint: do not output "Lint pass2:"
A colon at the end of a line requires at least 1 follow-up line, but
xlint cannot know whether lint2 will find anything to complain about.
Having a colon followed by nothing creates unnecessary confusion.
2021-12-28 22:59:56 +00:00
rillig 15f2f5fb32 tests/make: test function names without following '(' 2021-12-28 22:13:56 +00:00
rillig 5b6709cb7c make: fix double-free in CLEANUP mode (since 2021.12.27.23.11.55)
When make is run without the '-f' option, it searches for the files
'makefile' and 'Makefile' in the current directory.  The function
ReadFirstDefaultMakefile allocated memory for these filenames, added the
filenames to opts.makefiles and then freed the memory.  From that
moment, opts.makefiles contained dangling pointers.

The function main_CleanUp cleans the list, but only if make is compiled
with -DCLEANUP.  Since main.c 1.557 from 2021.12.27.23.11.55, the
strings in opts.makefiles are freed as well, before that, only the list
nodes were freed.  Freeing the strings led to the double-free.

Fix this bug by using a separate list for these short-lived strings.  At
the point where ReadFirstDefaultMakefile is called, opts.makefiles is
not used anymore, therefore there are no side effects.

To reproduce, run 'make test-coverage', which compiles with -DCLEANUP.
The test opt-chdir failed with a segmentation fault in main_Cleanup.
This test may be the only one that doesn't use the option '-f'.
2021-12-28 21:56:13 +00:00
rillig 6b8cc654d4 make: rename and constify SkipExtraTargets
No binary change.
2021-12-28 19:43:42 +00:00
rillig 6523598688 make: clean up function names in parse.c, remove redundant comments
No functional change.
2021-12-28 19:41:01 +00:00
rillig 0332878aff make: extract the non-parsing part from ParseDependencyTargets
No functional change.
2021-12-28 19:13:40 +00:00
rillig 8eade2c2c0 make: clean up ParseDependency
No functional change.
2021-12-28 19:01:36 +00:00
rillig 0e9020d18e make: remove redundant variable in ParseDependencyTargets
The idea of that variable was to work on constant strings as far as
possible.  For now it just blew up the code unnecessarily.

No binary change.
2021-12-28 17:58:41 +00:00
rillig 77e13755e6 make: remove redundant parameter from ParseDependencyTargets
No functional change.
2021-12-28 17:45:56 +00:00
rillig 52b614be9e make: remove redundant parameters in dependency parsing functions
Before 2020, there had been a huge function for parsing a dependency
line, with lots of local variables that were reused for different
purposes.  When that function was split up into smaller functions, that
was done mechanically, without eliminating redundant variables.

No functional change.
2021-12-28 17:39:04 +00:00
rillig d7dc9abe90 make: remove redundant comments from ParseDependencyTargets
The large comment is already explained in the archive module.
2021-12-28 17:30:11 +00:00
rillig 91b79ddb5a make: reduce scope of the list of wildcard target names
The list is only used when a single target name is parsed, in case the
name contains wildcards.  There is no need to keep it any longer or
reuse it.

Clean up outdated and redundant comments.

No functional change.
2021-12-28 16:59:09 +00:00
rillig 338ef15d8a make: make ParseIsEscape simpler
No functional change.
2021-12-28 16:35:43 +00:00
rillig ca9b601382 make: rename functions for handling dependency lines
The prefix 'Parse' was ambiguous since it was both the module name and a
verb.  Rename those functions that don't actually parse anything.

No functional change.
2021-12-28 16:17:54 +00:00
rillig 04775b4d02 make: make debug logging for .ORDER more human-friendly
The interesting part of the .ORDER constraint is what is made before
what, so reveal this information in the debug log.

The debug output from the test looks a bit strange since it forces
'three' to be made before 'one', but that's because the test exercises
the edge case of introducing a circular dependency.
2021-12-28 16:11:00 +00:00
rillig e15ce18588 make: make debug logging a bit more human-friendly
The previous log format "ParseReadLine (%d): '%s'" focused on the
implementation, it was not immediately obvious to a casual reader that
the number in parentheses was the line number.  Additionally, having
both a colon and quotes in a log message is uncommon.  The quotes have
been added in parse.c 1.127 from 2007-01-01.

The new log format "Parsing line %d: %s" is meant to be easier readable
by humans.  The quotes are not needed since ParseReadLine always strips
trailing whitespace, leaving no room for ambiguities.  The other log
messages follow common punctuation rules, which makes the beginning of
the line equally unambiguous.  Before var.c 1.911 from 2021-04-05,
variable assignments were logged with the format "%s:%s = %s", without a
space after the colon.
2021-12-28 15:48:59 +00:00
rillig 4d796ef180 make: clean up variable names for parsing dependency lines
Rename 'spec' to 'special', for consistency with the previous commits.

Rename 'tOp' to 'targetAttr' since it is not an dependency operator like
':', it's an attribute like '.SILENT'.

No binary change, except for the line number of the assertion in line
1618.
2021-12-28 15:03:10 +00:00
rillig 48f5ae208e make: do not treat .USEBEFORE as candidate for the main target
A .USE target is not a candidate, so .USEBEFORE shouldn't either.

Since make.h 1.36 from 2001-07-03.  In that commit, OP_USEBEFORE should
have been added to OP_NOTARGET.
2021-12-28 14:22:51 +00:00
rillig 62a0c54367 make: extract OP_NOTARGET into separate function
No binary change, except for line numbers in assertions.
2021-12-28 14:06:42 +00:00
rillig aa6b5708e5 tests/make: use tabs instead of spaces for indentation 2021-12-28 10:47:00 +00:00
rillig e6db57e4b1 make: remove redundant local variable
The variable name 'end' suggested pointing to the end of the string, but
instead it pointed to the last possible starting position of the word to
be searched.  Remove this possible misunderstanding.

No functional change.
2021-12-28 01:27:37 +00:00
rillig c604dc9b17 make: clean up stylistically
No binary change.
2021-12-28 01:20:24 +00:00
rillig f329a60c1a make: constify cached_realpath
No binary change.
2021-12-28 01:11:36 +00:00
rillig 5467d03499 tests/make: clean up after test 'opt-debug-file' 2021-12-28 01:04:03 +00:00
rillig 1ed2b64416 tests/make: document inconsistencies between '!=' and '::!='
Found while trying to make the error messages from Cmd_Exec more
detailed.
2021-12-28 00:56:16 +00:00
rillig 0ce8241610 make: clean up Cmd_Exec
Renaming savederr to saved_errno makes the comment redundant.

Group the conditions for setting errfmt, retaining their relative order.

No functional change.
2021-12-27 23:44:06 +00:00
rillig ca80611ac0 make: reduce indentation of Cmd_Exec
No functional change.
2021-12-27 23:19:41 +00:00
rillig 48bc374a2e make: free the names of the makefiles in cleanup mode
Since parse.c 1.576 from 2021-12-13 the filenames from opts.makefiles no
longer end up in the GNodes, they are copied by Str_Intern.
2021-12-27 23:11:55 +00:00
rillig 0b37d6eba5 make: merge local variables holding the path to the object directory
This is a similar pattern as in the other situations where a string is
fed through Var_Subst.  In this case though, the unexpanded string may
need to be freed, therefore the FStr_Done that is not needed in the
other places.

No functional change.
2021-12-27 23:06:19 +00:00
rillig e4149aebc4 make: prevent out-of-bounds read for debug log file name
Even though the name of the debug log file currently only occurs in
strings of the form '-dFname' or '-dF+name', the code for replacing '%d'
with the PID accesses the passed string out of bounds.  That's not a
problem in practice but looks suspicious anyway.
2021-12-27 22:57:26 +00:00
rillig 069962538c make: remove usage message if the debug file cannot be opened
Since a non-writable file is not a syntax error, there is no point in
showing the usage in this situation.  Showing the usage may have been a
copy-and-paste mistake from a few lines below, when this option was
added back in main.c 1.133 from 2006-10-15.
2021-12-27 22:22:48 +00:00
rillig 0ad1c33dcd tests/make: cover a debug log file that cannot be opened 2021-12-27 22:04:20 +00:00
rillig 9756129355 make: narrow down the return type of ReadMakefile
No functional change.
2021-12-27 21:27:25 +00:00
rillig 80048f6c39 make: rename local variables to be simpler
No binary change.
2021-12-27 21:21:17 +00:00
rillig b1c34aa60f make: clean up 'explode'
Breaking out of the first 'for' loop was unnecessarily complicated.  The
call to strlen was not necessary since f already pointed at the end of
the string.

No functional change.
2021-12-27 20:59:59 +00:00
rillig 443ab0ca6f tests/make: test MAKEFLAGS in POSIX mode
This test covers the function 'explode' in main.c, the case in which the
flags are actually expanded.
2021-12-27 20:17:35 +00:00
rillig b77845afac make: replace __func__ with actual strings
Make is supposed to be C90-compatible, and __func__ is from C99.

No functional change.
2021-12-27 19:06:07 +00:00
rillig 4e16c2d814 make: clean up comments 2021-12-27 18:54:19 +00:00
rillig 2d7f7c37dc make: remove unnecessary words from command line options
Several years ago, the command line options were individual global
variables.  The global variable could therefore not be named 'silent'
since that would have conflicted with local variables of the same name.
After moving the global variable to the namespace 'struct CmdOpts',
there is no conflict anymore.

There doesn't seem to be any risk of naming collisions for the names
'touch' and 'query'.

No functional change.
2021-12-27 18:26:22 +00:00
rillig 2a65bef432 make: rename eunlink to unlink_file
The name eunlink suggested a relation with the similarly named functions
emalloc or esnprintf, but that was misleading.  Instead, unlink_file
works like unlink, except that it refuses to remove an empty directory.

No functional change.
2021-12-27 17:18:57 +00:00
christos f8e4e6f39e Add clang's optnone attribute. 2021-12-26 18:16:41 +00:00
rillig 2b9d699f00 mixerctl: add colon after 'Usage', add space after comma 2021-12-26 15:36:49 +00:00
rillig 70804612dd lint: don't try to trick mathematics by defining ZERO to a nonzero value
No binary change.
2021-12-25 13:51:42 +00:00
rillig e499719151 tests/make: explain the current behavior of the option '--version' 2021-12-23 11:05:58 +00:00
rillig c19c0be78a lint: remove redundant EOF tests in lexer
No functional change.
2021-12-22 15:47:42 +00:00
rillig ca061b3a21 lint: fix wrong error in strict bool mode in condition with comma
For the result of the comma operator, it doesn't matter whether the
comma itself comes from a system header or not.  Instead, it's the main
operator of the right operand.

Since 2021-11-16.
2021-12-22 15:36:37 +00:00
rillig 94d1e5f09d lint: clean up lex.c
Rename 'struct kwtab' to 'struct keyword' since a single keyword is not
a whole keyword table.

Sync comment for lex_name with reality: sbuf_t no longer contains the
hash value.

Remove redundant tests for EOF, as EOF is neither a space nor a digit
nor an xdigit.

No functional change.
2021-12-22 15:20:08 +00:00
rillig 2c1fba9316 lint: remove spaces around bit-field colon
As seen in /usr/share/misc/style.

No binary change.
2021-12-22 14:49:11 +00:00
rillig e84d1b21bb lint: rename C89 to C90 in variable names
No binary change.
2021-12-22 14:38:34 +00:00
rillig 675fdceed4 lint: clean up initialization
No functional change.
2021-12-22 14:35:23 +00:00
rillig 7a458352ec lint: use C90 instead of C89 when referring to the C standard 2021-12-22 14:25:35 +00:00
rillig 469bb78c7a lint: fix handling of initializations
The implementation from March 2021 added proper support for designators
but didn't model the brace levels correctly.  In particular, it could
not handle additional braces or omitted braces.  In such a case, lint
skipped the remaining initializers from the initialization.  Due to
this, type errors in the remaining initializers went unnoticed.  Another
effect was that arrays of unknown size were wrongly reported as having
size 0.

Both GCC and Clang recommend placing braces around each sub-type that is
initialized, such as a struct, union or array.  Postfix does not follow
these recommendations, therefore lint had to be disabled in
external/ibm-public/postfix/Makefile.inc.  This commit fixes the bugs
mentioned there.
2021-12-22 00:45:53 +00:00
rillig ef2849da0a lint: reword message 187 about too long string literal for initializer
The previous message was imprecise in that it didn't distinguish between
non-terminating and terminating null bytes.
2021-12-21 22:21:11 +00:00
rillig 6bf50d6b33 lint: treat incomplete union in the same way as incomplete struct
The newly added tests triggered the assertion in begin_designation since
for incomplete types the initialization is stopped before handling the
first brace.
2021-12-21 21:42:21 +00:00
rillig 9fccf86daf lint: rename debug_indent to debug_print_indent
The previous name could be mistaken to mean "increase the indentation of
the debug output".  Instead, the function prints the current indentation.

In externs1.h, the macro definition was a duplicate, the macros were
sorted differently than the functions a few lines above.

No binary change.
2021-12-21 21:04:08 +00:00
rillig 764d028677 lint: make function names a bit more concise
No binary change.
2021-12-21 16:50:11 +00:00
rillig 5862547a83 lint: sync comment with recent change of parameter name 2021-12-21 15:33:20 +00:00
roy 87df1469b9 Fix build of xlint/line1 with OBJDIR set. 2021-12-21 15:27:19 +00:00
rillig 688b335d12 lint: invert condition in build_name
No functional change.
2021-12-21 15:24:28 +00:00
rillig e35c0f08c3 lint: rename parameters in check_init_expr
An initialization has a left-hand and a right-hand side, reflect this in
the parameter names to avoid confusion.

No binary change.
2021-12-21 15:15:45 +00:00
rillig f960c40512 lint: add grammar rule for the beginning of a designation
This will be necessary to properly implement handling of initializers
and braced initializer-lists.

No functional change for now since the designation is already reset
after each expression and '}'.  To handle initializations properly, the
designation must not be reset after each expression, it must advance to
the next member instead.
2021-12-20 19:34:01 +00:00
rillig 957cb5a12b lint: in debug mode, output value of boolean expressions 2021-12-20 00:10:07 +00:00
rillig 9b86606652 lint: split local variable in initialization_end_brace_level
No functional change.
2021-12-19 23:50:27 +00:00
rillig dc21a504a1 lint: remove redundant braces
No binary change.
2021-12-19 10:42:36 +00:00
rillig 6a4d091e84 lint: reduce pointer usage when reading .ln lines
No binary change.
2021-12-19 10:29:06 +00:00
rillig 71b4f109dd lint: remove unused parameter in read_ln_line 2021-12-19 10:19:58 +00:00
rillig a973a9d425 lint: add typedef for types in initializations
No binary change except for line numbers in assertions.
2021-12-19 10:17:00 +00:00
rillig 47b442ca30 lint: document wrong data structures for modelling initializations
No functional change.
2021-12-18 13:23:09 +00:00
rillig 4c4276ca03 lint: move maximum seen subscript from brace level to initialization
There is no need to store this information at every brace level since in
any translation unit that survives a conforming C99 compiler, an array
of unknown size is only possible once per initialization, not once per
brace level.
2021-12-18 13:06:33 +00:00
rillig 5cfb5bfe3b lint: format grammar consistently
No binary change.
2021-12-18 11:37:00 +00:00
rillig ea3d926362 lint: use vector instead of list for designation in initialization
This change is a prerequisite for fixing the current bugs in handling
initializations.  Part of the fix will be designation_pop, which is
costly for a singly linked list.

As a side benefit, memory management becomes simpler and needs fewer
malloc calls.

No functional change.
2021-12-18 11:25:15 +00:00
rillig 1bff2bee23 lint: reduce code for beginning an initialization
No functional change.
2021-12-17 17:27:19 +00:00
rillig ec1cdc787e lint: inline sub-cases of brace_level_sub_type
Having the code in separate functions did not add to the clarity of the
code.  The additional information from the function names can be grasped
as easily from the case labels.

No functional change.
2021-12-17 17:21:48 +00:00
kre 9e155b2407 Remove an unnecessary test for NULL (the same thing is done in the
following lines) along with an incorrect return of nothing if it is
found (the following version correctly returns NULL).   Should unbreak build.
2021-12-17 15:29:44 +00:00
christos 882f1e27bb fix error messages, usage, add static, more checks for ioctl, KNF 2021-12-17 13:50:10 +00:00
christos 63b05cacd7 Provide a clipping function and use it to prevent setting values out of bounds.
(from RVP)
2021-12-17 13:42:06 +00:00
christos f3790781fe more protection from unset threads from RVP 2021-12-17 13:14:54 +00:00
rillig e0fcad7c02 lint: fix initialization with few braces from function
Seen in Postfix, smtp_proto.c.
2021-12-17 11:06:15 +00:00
rillig 9b48a2a756 lint: fix initialization of array with fewer braces
Seen in Postfix, cleanup_strerror.c.
2021-12-17 10:33:23 +00:00
rillig da62eac479 lint: work around lint bug in initialization with few braces
Needs a proper fix later, but for now, this workaround allows to run
lint on Postfix again.
2021-12-17 09:12:45 +00:00
rillig 7edbaf70d2 lint: rename is_string_array to is_character_array
The old name was too confusing.

No functional change.
2021-12-17 01:24:00 +00:00
rillig 53980716ca lint: in GCC mode, declare alloca and variants
The prototype declarations define the correct parameter types of these
functions so that they are no longer subject to the default argument
promotions (C11 6.5.2.2p6).

The GCC builtins are only recognized in GCC mode (-g).
2021-12-17 00:05:24 +00:00
rillig 3d9a4093f0 lint: narrow down parameter of build_name
Passing an arbitrary tokenizer symbol left too much freedom and
uncertainty to the caller, and 0 was a magic number in this context.

No functional change.
2021-12-16 23:46:21 +00:00