Commit Graph

19354 Commits

Author SHA1 Message Date
jakllsch c0b7f470de fix inconsistent whitespace in units.lib 2022-02-15 13:44:47 +00:00
christos 32f083259b 1. restore the previous finish() logic to make:
script -e -c /usr/bin/true
	script -e -c /usr/bin/false
   exit with the proper exit code.
2. handle system return value correctly (nabijaczleweli)
3. factor out the conversion of wait status -> shell return code.
2022-02-13 19:40:14 +00:00
rillig a5ff839cac indent: consistently use nparen for indexing parser_state.paren
No binary change.
2022-02-13 12:48:12 +00:00
rillig 8944241faa indent: rename parser_state.p_l_follow and paren_level
The previous variable names were misleading.

Paren_level is not the current level of parentheses but the one from the
beginning of the current output line.  For better accuracy, rename it to
line_start_paren_level.

P_l_follow is not the level of parentheses that will be active at some
point in the future, as the previous name suggested.  Instead, it is the
level of parentheses right now.  For better accuracy, rename it to
nparen.  This nicely matches its main usage, which is as index to the
parser_state.paren array.

No binary change.
2022-02-13 12:43:26 +00:00
rillig bcceabb713 indent: replace bitmasking code with struct
The struct directly represents the properties of a pair of parentheses,
without forcing the human reader to decode any bitset.  This makes it
easier to find the remaining bugs in the heuristic for determining the
kind of parentheses.

No functional change outside debug mode.
2022-02-13 12:20:09 +00:00
rillig 553571d1de indent: change parser_state.cast_mask to 0-based indexing
Having 1-based indexing was completely unexpected, and it didn't match
the 0-based indexing of parser_state.paren_indents.

No functional change.
2022-02-13 12:09:19 +00:00
rillig 6800db9a1f script: declare dooutput as __dead
This fixes the Clang build, which failed with:

usr.bin/script/script.c:255:1: error:
    function 'dooutput' could be declared with attribute 'noreturn'
    [-Werror,-Wmissing-noreturn]
2022-02-12 23:03:52 +00:00
rillig 00e52ceab0 tests/make: clean up comments in test for indirect -k failures
See PR#49720.
2022-02-12 20:05:36 +00:00
rillig 74bde70120 indent: fix indentation of enum constants in typedef (since 2019-04-04)
The solution is not elegant since it adds a small state machine inside
the parser state, but at least these states only depend on the sequence
of token types and not on any other part of the parser state.

Reported in PR#55453.
2022-02-12 19:56:52 +00:00
rillig 4797e58d66 indent: extend debug logging for the parser state
The member names in struct parser_state are not trustworthy, for example
in_decl does not correspond to the intuitive definition of "inside a
declaration".  To cope with this uncertainty, output the full state of
the parser state to the debug log, not only the changes.  This helps to
track the inner state for small differences in the input, such as
between 'typedef enum { TA, TB } TT' and 'enum { EA, EB } ET'.

This hopefully helps in fixing PR#55453.

No functional change outside debug mode.
2022-02-12 15:50:14 +00:00
rillig d865043f3f tests/make: document the history of bugs in '-k' mode
Reported in PR#49720 in 2015, fixed independently in compat.c 1.199 from
2020-12-07.
2022-02-12 13:17:57 +00:00
rillig 084616387f make: fix echoing of command with '-' in silent target in jobs mode
Since job.c 1.83 from 2003-12-20, the command had been echoed even if
the target had the attribute '.SILENT'.

In sh-flags.exp, each removed 'echo' command is below a target name
matching the pattern 'opt-?j????-tgt-??s-cmd-?i?', which means that the
target was marked as silent, either through a global '.SILENT'
declaration or the command line option '-s' or the attribute '.SILENT'
on the target.

Reported by Alan Barrett in PR#45356.
2022-02-12 11:14:48 +00:00
rillig b048c4e49a tests/make: demonstrate bug for .SILENT in jobs mode (since 2003)
Reported 2011 in PR#45356.
2022-02-12 01:15:17 +00:00
rillig de563b6775 tests/make: reproduce filesystem lookup of .PHONY nodes
As described in PR toolchain/15164.
2022-02-11 23:44:18 +00:00
rillig 0c4d2fbc8c make: remove comment about environment variable with empty name
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-11 21:44:10 +00:00
rillig 58e6b25658 make: simplify control flow in CondParser_Comparison
No functional change.
2022-02-11 21:18:09 +00:00
christos c3c5452ebd PR/56254: RVP: Don't call non-async-signal-safe functions from signal handlers.
Establish a non-restart signal handler to avoid blocking in long I/Os.
2022-02-11 21:15:25 +00:00
rillig 875f1878c6 make: simplify control flow in ModifyWord_SysVSubst
No functional change.
2022-02-09 21:32:38 +00:00
rillig b64904b413 make: remove redundant conditions
A line starting with '======' is parsed as a variable assignment, with
an empty variable name and a value starting with '=====', making that
condition unreachable.

No functional change.
2022-02-09 21:28:57 +00:00
rillig aa87467a3a tests/make: remove redundant 'echo' from variable assignments
Before main.c 1.231 from 2014-09-09, a variable assignment using the
operator '!=' generated a warning "Couldn't read shell's output" if the
output of the command was empty.  The simplest way to suppress this
wrong warning was to add an empty 'echo' to the command.  This hack is
no longer needed.
2022-02-09 21:24:29 +00:00
rillig fcef55c3cb make: fix mistakes, spelling and typos in comments and manual page
No binary change for -DNDEBUG.
2022-02-09 21:09:24 +00:00
rillig 9102e2397a make: clean up variable names
No binary change.
2022-02-09 21:03:13 +00:00
rillig 189e0de59d make: prefix the warning about read-only .OBJDIR with a colon
For consistency with the other warnings.
2022-02-09 20:52:06 +00:00
rillig 05a9897bf8 tests/make: use more distinctive placeholder for TMPDIR 2022-02-09 18:54:19 +00:00
wiz 0e821de497 Fix typo in usage. 2022-02-09 07:51:45 +00:00
mrg aac8c56e2d allow the number of disks displayed in the default output
to be controlled.
2022-02-09 07:34:08 +00:00
sjg f153d1ed09 Use a variable to store command line to be filtered.
This avoids any nasty side effects from content of command line.

Reviewed by: rillig
2022-02-08 22:36:02 +00:00
rillig c5bbb4fe33 make: remove stray empty line
No functional change.
2022-02-07 23:24:26 +00:00
rillig 1c62825e82 tests/make: demonstrate combination of .USE with transformation rule
Reported in 2003 in PR toolchain/20993.  Linking a transformation rule
with .USE or .USEBEFORE node makes the transformation rule fail.
2022-02-07 22:43:50 +00:00
rillig f94e4c8a71 lint: drop compatibility with C90
Since tools/README 1.5 from 2022-02-03, the tools no longer need to be
compatible with C90, they may now use C99 features.  Lint had used
<stdbool.h> and snprintf already.

No functional change.
2022-02-07 21:57:47 +00:00
rillig a3b73aeb65 lint: reword message about bit-field in a union
There is nothing illegal about a bit-field in a union, it is allowed by
C90, C99 and C11.

Fixes PR toolchain/53219.
2022-02-07 02:44:49 +00:00
rillig 2de13c8b1e tests/make: document and try to reproduce the crash in Parse_IsVar
Fixed in parse.c 1.662 from today.  To actually crash make, the end of
the expanded dependency line must be at the end of a mapped region.
There is no guaranteed crash, as this depends on the memory allocator.
NetBSD's jemalloc allocates large contiguous regions, making it less
likely for an allocation to end up at the end of a mapped region.  The
memory allocators used by FreeBSD and OpenBSD are better at detecting
such bugs.
2022-02-05 10:41:15 +00:00
sjg d70be79c58 Ensure Parse_IsVar does not step off the end of input string. 2022-02-05 00:37:19 +00:00
rillig a28470e27b make: improve C90 support
Do not use inline functions, remove trailing comma in enum declaration,
do not use 'long long' for printing a timestamp.  This re-introduces the
Year 2038 Problem for pre-C99 compilers when printing the trace log, but
that is a seldom used feature.
2022-02-05 00:26:21 +00:00
rillig 739f5af983 tests/make: migrate test-variants.sh from shell to make
Using a makefile for defining the test variants allows running several
test variants individually, instead of using a single filter expression.

The test variants can be configured more fine-grained.  It is possible
to exclude a few test cases per variant, which is useful for no-regex, a
compile-time switch for excluding the variable modifier ':C'.

Fix the definitions for the C90 tests.  Previously they didn't override
the compiler option '-Wsystem-headers', thereby complaining about usage
of 'long long'.
2022-02-05 00:20:48 +00:00
rillig 27f729c6f0 make: use fixed type for comparing numbers using the modifier ':On'
When the modifier ':On' was added on 2021-07-30, there were concerns
that pre-C99 environments would not have the type 'long long', therefore
the type was made configurable, but parsing such numbers was hard-coded
to using strtoll.

To improve compatibility with C90 environments, use 'long' and 'strtol'
in these environments.  In C99 environments, use 'long long' and
'strtoll', to account for larger file sizes.

If the flexibility of choosing yet another type for these numbers should
ever arise, it can still be implemented.  Until then, reduce the number
of possible build configurations.
2022-02-04 23:43:10 +00:00
rillig 54add74bf1 make: use unsigned int for line numbers everywhere
Previously, some line numbers were stored as signed int while others
were stored as size_t.  Since line numbers are never negative, use an
unsigned type.  Since the maximum file size for makefiles is 1 GB (see
loadfile), unsigned int is large enough even on 64-bit platforms.

Using a single data types reduces the number of type conversions.  Using
unsigned int improves compatibility with C90 (printf %u instead of %zu),
which is needed by bmake, which is derived from usr.bin/make.

No functional change.
2022-02-04 23:22:19 +00:00
mrg e2b62dbb1e when picking which 2 disks to show in the 'vmstat' default output
and they haven't been specified on the command line, pick the two
devices that have had the largest read+write IO bytes count.
2022-02-01 09:18:07 +00:00
rillig 556f1b4b59 make: remove redundant declaration of HashIter_Init
Since hash.h 1.41 from 2021-12-07.

No binary change.
2022-01-31 22:58:26 +00:00
rillig 52d8b4720c make: make DEBUG0 simpler
All arguments to DEBUG0 are string literals, and none of them contains a
'%', which makes them safe to pass to printf directly.  Any accidental
'%' would be caught by the compiler.

No functional change.
2022-01-31 20:49:27 +00:00
christos 03fbb540b5 Make the GNode lineno unsigned to fix lint warning in var.c calling
PrintLocation()
2022-01-30 13:21:08 +00:00
sjg c6b66c0365 Tweak description of local variable assignments 2022-01-29 20:54:58 +00:00
rillig 2d30eb833a tests/make: clean up variants that are tested
Since main.c 1.373 from 2020-10-18, make does not use iovec anymore, so
remove that test variant.

Document the details of why generating the test coverage took so long on
NetBSD < 10.

Add another test variant with optimization for binary size (-Os), since
with that option, GCC 10 does not perform the same data flow analysis as
with -O2, in particular it gets confused about whether local variables
are correctly initialized across function calls.
2022-01-29 10:44:40 +00:00
rillig e55e22919c tests/make: sync comment in test for recursive variable 2022-01-29 10:21:26 +00:00
rillig a5fc9d51a1 make: for recursive variables in commands, print location
Print the approximate location based on the last command that has been
defined for the target.  It would be possible to get more detailed
location information by counting the number of commands of the target,
but that would get messy due to .USEBEFORE, .USE and .DEFAULT, and
still, this is an edge case, so don't waste too much code for it now.
Having this hint about the location is more helpful than just a plain
"Variable X is recursive" without any further details.
2022-01-29 10:19:49 +00:00
rillig 2856bc0c6e tests/make: demonstrate recursive variable in target 2022-01-29 10:09:37 +00:00
rillig a270f08cb3 make: print stack trace on fatal errors
The only fatal error that occurs while the makefiles are read in is the
one about recursive variables, which didn't give any hint about the
location before.

If a recursive variable is detected while evaluating the commands of a
target to be made, there is no location information, as before.
2022-01-29 09:38:26 +00:00
sjg 33d445c441 Document quirks of target local variable assignments 2022-01-29 07:42:10 +00:00
rillig 376b091f41 make: rename labels in CondParser_Leaf
No binary change.
2022-01-29 01:12:36 +00:00
rillig 5643b394fa make: inline functions that have a single call site
No functional change.
2022-01-29 01:07:31 +00:00
rillig 33b1fb5e4c tests/make: extend and isolate tests for target-local variables
Reusing the target var-scope-local.o for several tests made the test
more difficult to understand than necessary.  The test names '2' and '3'
didn't convey any meaning.

Instead, add more test targets that are named after what they test.  Add
tests for each of the 5 variable assignment operators, to demonstrate an
inconsistency between '+=' and '?='.

Add tests for the built-in target-local variables as well and explain
the general concepts, in particular the exact point where target-local
expressions are expanded.

The lines in the expected output file are not generated in the same
order as they appear in the makefile, so allow the 'expect' lines in
non-linear order, in check-expect.lua.
2022-01-29 00:52:53 +00:00
sjg 4a311e4fd9 numEntries can vary 2022-01-27 21:50:50 +00:00
rillig fc7f141b6a tests/make: add more edge cases for expansion of .for loop body 2022-01-27 20:15:14 +00:00
rillig 8a005f65eb tests/make: explain escaping in .for loops, add more test cases 2022-01-27 11:26:44 +00:00
rillig 212c705a96 make: clean up AddEscape for building the body of a .for loop
Adding 1 + len bytes but only incrementing the pointer by len bytes
looked suspicious, so use the same expression in both places.

No functional change.
2022-01-27 11:16:44 +00:00
rillig de42c1b82b make: merge duplicate code for finding an entry in a hash table
No functional change.
2022-01-27 11:00:07 +00:00
rillig 109ed975ee make: replace HashEntry_KeyEquals with strncmp
No functional change.
2022-01-27 10:45:36 +00:00
rillig 3618dda4ec tests/make: test hash code collisions of variable names
In HashEntry_KeyEquals, the line 'return false' was not covered by any
tests before.  Since it is an edge case that two variable names (or
other keys) have the same 32-bit hash code and still differ, better test
for that edge case explicitly since a bug in this place would be rare
and hard to find.
2022-01-27 10:42:02 +00:00
rillig f311b58f78 make: remove trailing whitespace, break lines
No binary change, except for assertion line numbers.
2022-01-27 10:34:55 +00:00
sjg f9f3e5b1c9 Unit test for local variables 2022-01-27 06:56:27 +00:00
sjg 30df8a48fa Allow local variable assignments in dependency lines
The variable is set in the context of the target.
This syntax has been supported by gmake for ~ever.
If necessary a makefile can set .MAKE.TARGET_LOCAL_VARIABLES=false
to disable this.

Expose GetBooleanExpr so parse.c can use it.
2022-01-27 06:02:59 +00:00
sjg cc52ff90df Do not allow /usr/obj to cause failure. 2022-01-27 02:24:46 +00:00
rillig 8764ef0945 make: generate coverage summary on 'make test-coverage' 2022-01-26 23:00:55 +00:00
rillig ba58882375 tests/make: test meta mode in jobs mode 2022-01-26 22:47:03 +00:00
rillig 43a11772f6 tests/make: remove unnecessary conditional processing for meta test
The .if/.else distracted from the main topic of the test and made it too
hard to see the main targets.
2022-01-26 22:19:25 +00:00
rillig 9c9a198116 make: clean up eat_dots for meta mode, part 2
At least on OpenBSD, "If the src and dst strings overlap, the behavior
is undefined" (since 2013-09-25), so rather use memmove instead.

Keep all other bugs for now, for example "/a/b//../" is reduced to
"/a/b/" instead of the correct "/a/", and for repeated "/././././" in
long paths, the performance is quadratic instead of linear.

Inline the two calls to eat_dots, turning the first into a two-liner.
2022-01-26 12:41:26 +00:00
rillig be6d53ad03 make: clean up eat_dots for meta mode
No binary change.
2022-01-26 12:16:03 +00:00
rillig 971eb6df76 tests/make: demonstrate that the 'static' in Var_Parse has an effect 2022-01-24 22:59:49 +00:00
rillig 5caaef8905 make: remove unsatisfiable condition in VarSubstExpr
At that point, emode can have only 2 values, none of which is
VARE_UNDEFERR.

No binary change since GCC had figured this out all the time, it just
didn't reveal this little secret.
2022-01-24 20:54:54 +00:00
rillig 88653ff45e make: when expanding nested variables, check simple things first
No functional change, just a little performance improvement for
expressions that are not evaluated anyway but only parsed.
2022-01-24 20:49:55 +00:00
andvar 492c086f0a s/begining/beginning/ in comments and messages. 2022-01-24 09:14:36 +00:00
rillig e14907aad9 make: merge nonints.h into make.h
No functional change.
2022-01-23 22:12:16 +00:00
rillig c63989d496 tests/make: add a few more tests 2022-01-23 21:48:59 +00:00
rillig acb5ef8d14 tests/make: add more tests for the modifier ':ts' 2022-01-23 18:59:18 +00:00
rillig 2569281c8c tests/make: run nested makes with -r to reduce side effects 2022-01-23 18:15:29 +00:00
rillig c556b4e908 tests/make: migrate modts to varmod-to-separator and explain 2022-01-23 18:00:53 +00:00
rillig 76f64f81d9 tests/make: rename var-class to var-scope
There is no such concept as a "variable class" in make, these tests
focus on the variable scope instead.
2022-01-23 16:25:53 +00:00
rillig 72c3edd3a3 tests/make: extend test suite, move old tests to 2020 scheme
The tests from envfirst.mk are now in opt-env.mk.
The tests from modword.mk are now in varmod-select-words.mk.
2022-01-23 16:09:38 +00:00
rillig e4b7864877 tests/make: add a few more tests, mainly for special targets 2022-01-22 21:50:41 +00:00
rillig 2aba30c909 make: add missing newline after "cannot continue" message
It was wrong of Parse_File to output an unfinished line and hope for
some other code to finish it.  As demonstrated in the test, PrintOnError
did not do that in the case of additional debug output.

To keep the overall behavior as close as possible to before, the other
callers of PrintOnError now have to pass the newline themselves. Passing
strings that start with newlines but don't end with them looked
suspicious anyway.
2022-01-22 18:59:23 +00:00
rillig c7d1780dbb tests/make: add a few more tests 2022-01-22 17:10:51 +00:00
rillig 3d8e7b4309 make: clean up comments 2022-01-22 16:24:45 +00:00
rillig 889dbcb036 tests/make: explore edge cases involving .ifmake 2022-01-22 16:23:56 +00:00
christos 8ff73d8547 Use /dev/tty for SIGINFO
Fix some size_t<->int
2022-01-22 14:08:19 +00:00
christos 40ec67d237 make siginfo handler print to /dev/tty. 2022-01-22 14:00:45 +00:00
christos 05daad6266 dooutput can return if finish() does not find a chile process. 2022-01-20 19:49:51 +00:00
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