Skip to content

Commit

Permalink
build: mamake: some more necessary TLC, fixing minor issues
Browse files Browse the repository at this point in the history
This commit fixes three minor bugs in mamake:

1. The 'bind' command did not correctly propagate errors in its
   dependencies (e.g. a failure to link) to the current rule,
   causing a problem with the -k (keep going) option.

2. When an error occurred in a recursive mamake invovation, the
   nonzero exit status was not propagated back to the parent
   invocation and the failed build could exit with a zero status
   if the -k option was given.

3. When building in parallel and a rule's action had an error, the
   error message may have the wrong line number. (re: ced499a)

It also does some refactoring and various tweaks, and fixes more
potential dependency bugs. Main changes below (more minor or
self-evident tweaks omitted).

src/cmd/INIT/mamake.c:
- Change newof() macro expansions to standard calloc/malloc/realloc
  calls, which are a lot easier to read. Delete newof().
- Use time_t for time variables. This will keep mamake working past
  2038 on machines where 'unsigned long' is only 32 bits.
- Fix bug 3 as follows. The reap() function now delays the
  unsetting of a rule's PID until after potentially calling
  error_making(). The rule pointer is passed to report() via
  error_making() and report() checks if the rule's PID is set, in
  wich case the rule's endline is shown instead of the current
  input line.
- Add check_shellaction() which checks the results of a shell
  action and throws errors if needed. This replaces duplicate logic
  in run() and reap(), which both now just call that function.
- Report "target not generated" instead of "missing prerequisite"
  when a shell action exits with status 0 (success) but its target
  file is not found. This is done by having check_shellaction()
  pass a special code -1 to error_making().
- Add clearout_bg() which clears out the current rule's list of
  background jobs, waiting for them to finish (letting reap() throw
  errors) and propagating their timestamps for depencencies and and
  RULE_error flags for -k. This is now used both by the 'done'
  command and before invoking a virtual rule's shell action (which
  is never run in parallel).
- make(): case KEY('b','i','n','d'):
  - Correctly make sure that the indicated library (if built in the
    same Mamfile) has finished linking, and propagate its timestamp
    and error flag. This fixes bug 1.
  - Include header dependencies in the context of the current rule,
    not in the unnamed dummy rule. This should fix potential
    depedency bugs on the first use of 'bind' for a library.
- make(): case KEY('m','a','k','e'):
  - Eliminate loop that, before making the current rule, reaps any
    background jobs that have finished and cuts them out of the
    list. This worked fine, but is redundant. It is sufficient to
    call clearout_bg() at 'done' (see above).
- main(): When doing recurse() and bailing out, return with the
  highest remembered exit status. This fixes bug 2.

src/cmd/INIT/mamprobe.sh:
- Change remaining nmake-style variable expansions $(...) to new
  %mamake {...} expansions, not ${...}. (re: f5d5318)

bin/package:
- Filter '#reason:' lines from mamake -e out of the results; this
  is just noise for this purpose (whereas the trace headers are
  useful to know which target a compiler error message belongs to).
  • Loading branch information
McDutchie committed Aug 7, 2024
1 parent 82aa45e commit 2c98350
Show file tree
Hide file tree
Showing 4 changed files with 268 additions and 225 deletions.
6 changes: 3 additions & 3 deletions bin/package
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ command=${0##*/}
case $(getopts '[-][123:xyz]' opt --xyz 2>/dev/null; echo 0$opt) in
0123) USAGE=$'
[-?
@(#)$Id: '$command$' (ksh 93u+m) 2024-08-03 $
@(#)$Id: '$command$' (ksh 93u+m) 2024-08-07 $
]
[-author?Glenn Fowler <[email protected]>]
[-author?Contributors to https://github.com/ksh93/ksh]
Expand Down Expand Up @@ -564,7 +564,7 @@ SEE ALSO
pkgadd(1), pkgmk(1), rpm(1), sh(1), tar(1), optget(3)

IMPLEMENTATION
version package (ksh 93u+m) 2024-08-03
version package (ksh 93u+m) 2024-08-07
author Glenn Fowler <[email protected]>
author Contributors to https://github.com/ksh93/ksh
copyright (c) 1994-2012 AT&T Intellectual Property
Expand Down Expand Up @@ -3275,7 +3275,7 @@ results)eval "set -- $target"
case $filter in
errors) $exeg grep -E '^pax:|\*\*\*' $j
;;
*) $exec grep -E -iv '^($||[\+\[]|cc[^-:]|kill |make.*(file system time|has been replaced)|so|[0123456789]+ error|uncrate |[0123456789]+ block|ar: creat|iffe: test: |conf: (check|generate|read|probe|test)|[abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_][abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789]*=|gsf@research|ar:.*warning|cpio:|ld:.*(duplicate symbol|to obtain more information)|[0123456789]*$|(checking|creating|touch) [/abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789])| obsolete predefined symbol | is (almost always misused|dangerous|deprecated|not implemented)| trigraph| assigned to | cast .* different size| integer overflow .*<<| optimization may be attained | passed as |::__builtin|^creating.*\.a$|warning.*not optimized|exceeds size thresh|ld:.*preempts|is unchanged|with value >=|(-l|lib)\*|/(ast|sys)/(dir|limits|param|stropts)\.h.*redefined|usage|base registers|`\.\.\.` obsolete'"$i" $j |
*) $exec grep -E -iv '^(# reason:|$||[\+\[]|cc[^-:]|kill |make.*(file system time|has been replaced)|so|[0123456789]+ error|uncrate |[0123456789]+ block|ar: creat|iffe: test: |conf: (check|generate|read|probe|test)|[abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_][abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789]*=|gsf@research|ar:.*warning|cpio:|ld:.*(duplicate symbol|to obtain more information)|[0123456789]*$|(checking|creating|touch) [/abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789])| obsolete predefined symbol | is (almost always misused|dangerous|deprecated|not implemented)| trigraph| assigned to | cast .* different size| integer overflow .*<<| optimization may be attained | passed as |::__builtin|^creating.*\.a$|warning.*not optimized|exceeds size thresh|ld:.*preempts|is unchanged|with value >=|(-l|lib)\*|/(ast|sys)/(dir|limits|param|stropts)\.h.*redefined|usage|base registers|`\.\.\.` obsolete'"$i" $j |
$exec grep :
;;
esac
Expand Down
3 changes: 2 additions & 1 deletion src/cmd/INIT/README-mamake.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,10 @@ The *x* and *y* values may result from nested variable references.
The last `?` is optional.

In `%{`*variable*`-`*x*`}`, the value of *variable* is substituted
if it is defined and non-empty, otherwise the value of *x* is substituted.
if it is defined and non-empty, otherwise *x* is substituted.
In `%{`*variable*`+`*x*`}`, *x* is substituted if the value of
*variable* is defined and non-empty, otherwise the reference is removed.
In both cases, *x* may be empty.
Note that, unlike in `sh`(1), no distinction is made between an undefined
variable and a defined variable with an empty value.

Expand Down
Loading

0 comments on commit 2c98350

Please sign in to comment.