Commit Graph

139 Commits

Author SHA1 Message Date
rillig
dcafa71348 make(1): remove unreachable code from CompatRunCommand
At the point where Str_Words is called, the string contains no
meta-characters.  This means that the parameter "expand" in Str_Words is
never looked at.  This in turn means that this parameter can be set to
FALSE, thereby making it impossible that Str_Words returns NULL.
2020-08-30 20:08:47 +00:00
rillig
5dd250059b make(1): replace brk_string with Str_Words
The API is much simpler, and there is less detail that is exposed by
default and fewer punctuation to type on the caller's side.  To see that
there is some memory to be freed, one would have to look into the
struct.  Having part of the return value as the actual return value and
the rest in output parameters was unnecessarily asymmetrical.
2020-08-30 19:56:02 +00:00
rillig
f8cb0fda82 make(1): rename GNode.iParents to implicitParents
The i alone was too ambiguous.  It could have meant ignore, implicit,
interactive, and probably many more.
2020-08-30 14:11:42 +00:00
rillig
2d4a05ee59 make(1): rename Lst_Memeber to Lst_FindDatum
The new name nicely aligns with Lst_Find and Lst_FindFrom.
2020-08-30 11:12:05 +00:00
rillig
6c6514f5e6 make(1): fix assertion failure for .SUFFIXES in archives
This occurred in the posix1.mk test, even though it is disabled in
unit-tests.  But in tests/usr.bin/make it still runs.  There, it should
have produced an "expected failure" but crashed instead.

The archive-suffix test is the stripped-down version of the posix1 test.
2020-08-29 14:47:26 +00:00
rillig
7571daa697 make(1): clean up documentation for CompatInterrupt and Compat_Run 2020-08-29 12:36:20 +00:00
rillig
15828a96ed make(1): add another Boolean variant to check during development 2020-08-29 08:09:07 +00:00
rillig
942d06c278 make(1): remove trailing 'S' from names of Lst functions
The migration from null-passing Lst functions to argument-checking Lst
functions is completed.

There were 2 surprises: The targets list may be NULL, and in Dir_AddDir,
the path may be NULL.  The latter case is especially surprising since
that function turns into an almost-nop in that case.  This is another
case where probably 2 independent functions have been squeezed into a
single function.  This may be improved in a follow-up commit.

All other lists were fine.  They were always defined and thus didn't
need much work.
2020-08-28 04:48:56 +00:00
rillig
74fd7ff4cd make(1): migrate Lst_IsEmpty to Lst_IsEmptyS 2020-08-27 19:15:35 +00:00
rillig
6c196ebe9c make(1): migrate Lst_ForEach to Lst_ForEachS
Most lists are always valid.  Only the "targets" variable may be null in
some cases, probably.
2020-08-27 06:53:57 +00:00
rillig
bb7e3dd932 make(1): make compat.c ready for WARNS=6 2020-08-23 19:00:19 +00:00
rillig
38885a7509 make(1): make brk_string return size_t for the number of words 2020-08-23 18:26:35 +00:00
rillig
a36e095453 make(1): handle special case of a list containing null pointers
GNode.commands is the only place in make where a list can contain null
pointers.  That's unexpected, and memory management in CompatRunCommand
looks suspicous enough to warrant extensive documentation.
2020-08-23 10:53:27 +00:00
rillig
a8b40c7d03 make(1): clean up headers
Remove redundant headers that are already included by "make.h".
Make <assert.h> available to all compilation units that use "make.h".
2020-08-22 21:42:38 +00:00
rillig
311f9720c3 make(1): replace segmentation fault with failed assertion
To reproduce: ./make -r -C unit-tests -f sh-dots.mk -j1

Without -j1, the test succeeds.
2020-08-22 19:53:22 +00:00
rillig
f724405abb make(1): require argument of Lst_Member to be non-null
Since the lists don't contain null pointers, it doesn't make sense to
search for a null pointer.  All calls but one already had obviously
non-null arguments.  The one remaining call using targ->suff has been
guarded for now.

The code for Lst_Member became much simpler than before.  Partly because
the old code had an extra condition for circular lists, which are not
used by make.
2020-08-22 15:43:32 +00:00
rillig
182c9e03db make(1): convert Lst_Enqueue and Lst_Dequeue to nonnull variants
Except for once instance in parse.c, the usage pattern for Lst_Dequeue
was to first test whether the list is empty.  This pattern allowed the
implementation of Lst_Dequeue to become simpler since the null check is
not needed anymore.

The calls to Lst_Enqueue never pass an invalid list or a null pointer,
therefore making them strict was trivial.
2020-08-22 14:39:12 +00:00
rillig
e997d2617b make(1): replace "(void)Lst_AtEnd" with stricter "Lst_AppendS"
This change ensures that there is actually something added to the list.
Lst_AtEnd had silently skipped the addition if the list was invalid
(null pointer), which was not intended in these cases.  The "(void)" is
assumed to mean "I know that this cannot fail", while it could also mean
"I don't care whether something actually happened".

Running "./build.sh -j6 tools" still succeeds after this change,
therefore chances are very low that this change breaks anything.  If
there is any change, it's an obvious assertion failure.  There is no
silent change in behavior though.
2020-08-22 11:35:00 +00:00
rillig
0bf8c3afa0 make(1): remove constant variable
The variable "local" had been TRUE for at least the last 28 years.

No change in binary size, as expected.
2020-08-22 10:07:29 +00:00
rillig
faf51c8c9a make(1): remove form feeds in the code 2020-08-22 08:01:34 +00:00
rillig
7b0da2fa03 make(1): make list library code stricter
Up to now, the list library didn't distinguish between programming
mistakes (violations of invariants, illegal parameter values) and
actually interesting situations like "element not found in list".

The current code contains many branches for conditions that are neither
exercised by the unit tests nor by real-world usage.  There is no point
in keeping this unnecessary code.

The list functions will be migrated from their lenient variants to the
stricter variants in small parts, each function getting the S suffix
when it is made strict, to avoid any confusion about how strict a
particular function is.  When all functions have been migrated, they
will be renamed back to their original names.

While here, the comments of the functions are cleaned up since they
mention irrelevant implementation details in the API comments, as well
as "side effects" that are really main effects.
2020-08-21 03:36:03 +00:00
rillig
bdd5655235 make(1): use consistent indentation in source code
Tabs for multiples of 8, then spaces.

The usage string has been kept as-is since the spaces there are
indentional and do influence the output.
2020-08-01 14:47:49 +00:00
rillig
ad6695e0a6 make(1): avoid calls to free(3) in the common case of a NULL pointer 2020-08-01 09:55:00 +00:00
rillig
ab2bfed61f make(1): let Var_Value return a const char *
The return value must not be modified anyway, so let the compiler check
this for free.
2020-08-01 09:25:36 +00:00
rillig
5ca4f23a1e make(1): remove dead code from Var_Subst
The first parameter from Var_Subst had been a literal NULL in all cases.
These have been fixed using this command:

sed -i 's|Var_Subst(NULL, |Var_Subst(|' *.c

The one remaining case was not found because the "NULL," was followed by
a line break instead of a space.

The removed code probably wouldn't have worked as expected anyway.
Expanding a single variable to a literal string would have led to
unexpected behavior for cases like ${VAR:M${pattern}}, in case pattern
would contain an unescaped ':' itself.
2020-07-28 16:42:22 +00:00
rillig
2b74fdb213 make(1): rename Varf_Flags to VarEvalFlags
In var.c there are lots of different flag types.  To make any accidental
mixture obvious, each flag group gets its own prefix.

The only flag group that is visible outside of var.c is concerned with
evaluating variables, therefore the "e", which replaces the former "f"
that probably just meant "flag".
2020-07-19 12:26:17 +00:00
rillig
820b5caede make(1): remove trailing whitespace 2020-07-03 08:13:23 +00:00
rillig
44d841d2c5 make(1): remove redundant parentheses around return values 2020-07-03 08:02:55 +00:00
rillig
91643e7541 make(1): remove useless parameter from Var_Set
The enum corresponding to this int parameter is only defined in var.c,
which makes it impractical for the outside to set this parameter to
anything but 0.

On x86_64, this reduces the size of the resulting executable by 5 kB.
2020-07-02 15:47:38 +00:00
riastradh
1378959eea Reimplement make(1) meta mode without filemon(4). 2020-01-19 19:42:32 +00:00
maxv
2a5d072bf2 Revert the filemon removal in bmake, as pointed out by maya we do care
about not introducing divergence with FreeBSD, and the cost of unused
is acceptable here.
2019-12-19 07:14:07 +00:00
maxv
e67f51b8f7 Retire filemon, discussed on tech-kern@. 2019-12-18 07:37:17 +00:00
sjg
a5cccb4af8 Make compat.c handle SIGINT etc more like job.c
If there is a running child, pass the signal on, and
wait for it to exit before we self-terminate.

Reviewed by: christos
2017-07-20 19:29:54 +00:00
dholland
9d33465685 Add a .DELETE_ON_ERROR: magic target that causes *failed* targets as
well as *interrupted* targets to be deleted. The name and behavior of
the variable matches gmake.

Also fix a glitch in newline output on error in compat mode that I
discovered while doing it.

Closes PR 51376.
2016-08-26 23:28:39 +00:00
sjg
ccfdc94797 Propagate errors from filemon.
If we encounter errors producing a .meta file,
we should not consider the target completed successfully.
2016-05-12 20:28:34 +00:00
christos
4d0b1055db Collapse the 3 boolean parameter to 1 flags parameter. No functional change. 2016-02-18 18:29:14 +00:00
christos
59ef53c17c remove free NULL checks (Tilman Sauerbeck) 2016-01-17 17:45:21 +00:00
christos
9487d441fb Preserve $$ in := assignments..
FOO=\$$CRAP
BAR:=${FOO}

all:
	echo ${FOO}
	echo ${BAR}
2016-01-09 00:55:17 +00:00
sjg
df0424202d Add Boolean wantit to Var_Parse and Var_Subst
wantit will be FALSE when we are just consuming to discard
in which case we skip "expensive" things like Cmd_Exec.

Reviewed by: christos
2015-10-11 04:51:24 +00:00
christos
0002ddbc7d make needshell customizable, so that xinstall can use it. 2015-06-19 14:32:04 +00:00
christos
3f6f33cbde create needshell so we don't scan the string multiple times. 2015-06-19 14:25:34 +00:00
mlelstv
75fd2a8412 Adjust metachar handling to previous behaviour:
- space and tab are no shell metachars, remove them from generic
  metachar function
- add space and tab as to-be-quoted characters for :Q modifier
- add = and : as characters that require command handling by the shell
2015-06-19 08:03:35 +00:00
christos
9beb5dadf3 Centralize the "is a meta char" test, instead of using two different arrays. 2015-06-17 17:43:23 +00:00
joerg
d92bea4fa3 Revert all make changes except the unit tests to the state of three
weeks ago. Individual changes can be reapplied after review.
2014-09-07 20:55:34 +00:00
christos
defa6c58f6 PR/46096: Jarmo Jaakkola: fix many problems with dependencies (PR 49086)
Quite extensive rewrite of the Suff module.  Some ripple effects into
Parse and Targ modules too.

Dependency searches in general were made to honor explicit rules so
implicit and explicit sources are no longer applied on targets that
do not invoke a transformation rule.

Archive member dependency search was rewritten.  Explicit rules now
work properly and $(.TARGET) is set correctly.  POSIX semantics for
lib(member.o) and .s1.a rules are supported.

.SUFFIXES list maintenance was rewritten so that scanning of existing
rules works when suffixes are added and that clearing the suffix list
removes single suffix rules too.  Transformation rule nodes are now
mixed with regular nodes so they are available as regular targets too
if needed (especially after the known suffixes are cleared).

The .NULL target was documented in the manual page, especially to
warn against using it when a single suffix rule would work.
A deprecation warning was also added to the manual and make also
warns the user if it encounters .NULL.

Search for suffix rules no longer allows the explicit dependencies
to override the selected transformation rule.  A check is made in
the search that the transformation that would be tried does not
already exist in the chain.  This prevents getting stuck in an infinite
loop under specific circumstances.  Local variables are now set
before node's children are expanded so dynamic sources work in
multi-stage transformations.  Make_HandleUse() no longer expands
the added children for transformation nodes, preventing triple
expansion and allowing the Suff module to properly postpone their
expansion until proper values are set for the local variables.

Directory prefix is no longer removed from $(.PREFIX) if the target
is found via directory search.

The last rule defined is now used instead of the first one (POSIX
requirement) in case a rule is defined multiple times.  Everything
defined in the first instance is undone, but things added "globally"
are honored.  To implement this, each node tracks attribute bits
which have been set by special targets (global) instead of special
sources (local).  They also track dependencies that were added by
a rule with commands (local) instead of rule with no commands (global).

New attribute, OP_FROM_SYS_MK is introduced.  It is set on all targets
found in system makefiles so that they are not eligible to become
the main target.  We cannot just set OP_NOTMAIN because it is one of
the attributes inherited from transformation and .USE rules and would
make any eligible target that uses a built-in inference rule ineligible.

The $(.IMPSRC) local variable now works like in gmake: it is set to
the first prerequisite for explicit rules.  For implicit rules it
is still the implied source.

The manual page is improved regarding the fixed features.  Test cases
for the fixed problems are added.

Other improvements in the Suff module include:
  - better debug messages for transformation rule search (length of
    the chain is now visualized by indentation)
  - Suff structures are created, destroyed and moved around by a set
    of maintenance functions so their reference counts are easier
    to track (this also gets rid of a lot of code duplication)
  - some unreasonably long functions were split into smaller ones
  - many local variables had their names changed to describe their
    purpose instead of their type
2014-08-23 15:05:40 +00:00
sjg
7a951eee59 Treat '~' as a meta char requiring a shell.
Patch from Steve McIntyre 93sam at debian.org

Reviewed by: christos
2014-01-03 00:02:01 +00:00
sjg
be3c37de45 Do not apply shellErrFlag unless errCheck is true. 2013-09-02 19:26:42 +00:00
sjg
db7ba27731 If commandShell hasErrCtl is true, set shellErrFlag for use by
CompatRunCommand() so that behavior in jobs and compat mode
remains consistent.
2013-07-05 22:14:56 +00:00
sjg
7a08ea2711 Remove Check_Cwd - it is no longer needed. 2013-01-25 02:01:10 +00:00
sjg
0afab3de7c Treat empty commands same as jobs mode 2012-10-07 19:17:31 +00:00