Skip to content

Commit

Permalink
mamake: reduce backward compat stubs (re: 1aecc1b)
Browse files Browse the repository at this point in the history
Archaeological research on the Mamfiles in the ast-open-history
repo shows that the assignment-argument parsing code in the
'silent' and 'ignore' scripts was never used, because no
assignment-argument (e.g.: silent var=value somecommand) was ever
passed. So we don't need to try too hard to be backward compatible
with this.

src/cmd/INIT/mamake.c: run():
- Reduce the 'silent' stub to an empty alias. Any theoretical
  assignment-arguments will be true shell assignments (e.g.:
  'var=value somecommand') instead; the effect should be the same.
- Reduce the 'ignore' prefix to an 'env' command invocation plus
  ':' to ensure a zero exit status; 'env' will process any
  theoretical assignment-arguments. This is not safe for field
  splitting, but then again, this whole system never was.
- Since we're not using them any more, don't bother setting them
  at all in MAMAKE_STRICT mode.
  • Loading branch information
McDutchie committed Jan 28, 2024
1 parent fbf8f42 commit d9331f1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 17 deletions.
2 changes: 2 additions & 0 deletions src/cmd/INIT/README-mamake.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ ksh 93u+m made a few changes to `mamake` that make it easier to maintain Mamfile
* Indentation and word separators may use any whitespace (e.g. tabs), not only spaces.
* Unrecognized commands and rule attributes throw an error instead of being silently ignored.
* Fixed some crashing bugs and memory leaks.
* The `silent` and `ignore` command prefixes for shell actions are processed internally
for backward compatibility, unless the `MAMAKE_STRICT` variable is set.
* The `prev` command may now be used without a prior `make`...`done` to declare a simple
prerequisite, provided the `MAMAKE_STRICT` variable is set.
* The `notrace` attribute was added to disable xtrace for a rule's shell action.
Expand Down
24 changes: 7 additions & 17 deletions src/cmd/INIT/mamake.c
Original file line number Diff line number Diff line change
Expand Up @@ -1276,24 +1276,14 @@ run(Rule_t* r, char* s)
x = state.exec;
if (x)
{
/* stubs for backward compat */
if(!strict())
append(buf,
"alias silent=\n"
"ignore() { env \"$@\" || :; }\n"
);
/* find commands in the current working directory first */
append(buf,
/* stub for nmake's silent prefix (for backward compat) */
"silent()\n"
"(\n"
"while test \"$#\" -gt 0\n"
"do case $1 in\n"
"*=*) export \"$1\"; shift;;\n"
"*) break;;\n"
"esac\n"
"done\n"
"\"$@\"\n"
")\n"
/* stub for nmake's ignore prefix (for backward compat) */
"ignore()\n"
"{\n"
"silent \"$@\" || :\n" /* always return status 0 */
"}\n"
/* find commands in the current working directory first */
"case $PATH in\n"
".:*) ;;\n"
"*) PATH=.:$PATH;;\n"
Expand Down

0 comments on commit d9331f1

Please sign in to comment.