Remove use of sh -e when running in compat mode.
Its not posix compliant and serves very little purpose. With this change compat and jobs modes are consistent wrt how they treat each line of a script. Add support for the '+' command line prefix as required by posix. Lines prefixed with '+' are executed even when -n is given. [Actually posix says they should also be done for -q and -t] PR: Reviewed by: jmc
This commit is contained in:
parent
85b3ba5bf1
commit
4d3fc51f60
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: compat.c,v 1.53 2004/05/07 00:04:38 ross Exp $ */
|
||||
/* $NetBSD: compat.c,v 1.54 2004/05/07 08:12:15 sjg Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
|
||||
|
@ -70,14 +70,14 @@
|
|||
*/
|
||||
|
||||
#ifndef MAKE_NATIVE
|
||||
static char rcsid[] = "$NetBSD: compat.c,v 1.53 2004/05/07 00:04:38 ross Exp $";
|
||||
static char rcsid[] = "$NetBSD: compat.c,v 1.54 2004/05/07 08:12:15 sjg Exp $";
|
||||
#else
|
||||
#include <sys/cdefs.h>
|
||||
#ifndef lint
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)compat.c 8.2 (Berkeley) 3/19/94";
|
||||
#else
|
||||
__RCSID("$NetBSD: compat.c,v 1.53 2004/05/07 00:04:38 ross Exp $");
|
||||
__RCSID("$NetBSD: compat.c,v 1.54 2004/05/07 08:12:15 sjg Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
#endif
|
||||
|
@ -122,9 +122,24 @@ static char meta[256];
|
|||
static GNode *curTarg = NILGNODE;
|
||||
static GNode *ENDNode;
|
||||
static void CompatInterrupt(int);
|
||||
static int CompatRunCommand(ClientData, ClientData);
|
||||
static int CompatMake(ClientData, ClientData);
|
||||
|
||||
static void
|
||||
Compat_Init(void)
|
||||
{
|
||||
const char *cp;
|
||||
|
||||
Shell_Init(); /* setup default shell */
|
||||
|
||||
for (cp = "#=|^(){};&<>*?[]:$`\\\n"; *cp != '\0'; cp++) {
|
||||
meta[(unsigned char) *cp] = 1;
|
||||
}
|
||||
/*
|
||||
* The null character serves as a sentinel in the string.
|
||||
*/
|
||||
meta[0] = 1;
|
||||
}
|
||||
|
||||
/*-
|
||||
*-----------------------------------------------------------------------
|
||||
* CompatInterrupt --
|
||||
|
@ -187,12 +202,13 @@ CompatInterrupt(int signo)
|
|||
*
|
||||
*-----------------------------------------------------------------------
|
||||
*/
|
||||
static int
|
||||
int
|
||||
CompatRunCommand(ClientData cmdp, ClientData gnp)
|
||||
{
|
||||
char *cmdStart; /* Start of expanded command */
|
||||
char *cp, *bp;
|
||||
Boolean silent, /* Don't print command */
|
||||
doIt, /* Execute even if -n */
|
||||
errCheck; /* Check errors */
|
||||
int reason; /* Reason for child's death */
|
||||
int status; /* Description of child's death */
|
||||
|
@ -217,7 +233,8 @@ CompatRunCommand(ClientData cmdp, ClientData gnp)
|
|||
#endif
|
||||
silent = gn->type & OP_SILENT;
|
||||
errCheck = !(gn->type & OP_IGNORE);
|
||||
|
||||
doIt = FALSE;
|
||||
|
||||
cmdNode = Lst_Member (gn->commands, (ClientData)cmd);
|
||||
cmdStart = Var_Subst (NULL, cmd, gn, FALSE);
|
||||
|
||||
|
@ -245,11 +262,19 @@ CompatRunCommand(ClientData cmdp, ClientData gnp)
|
|||
return(0);
|
||||
}
|
||||
|
||||
while ((*cmd == '@') || (*cmd == '-')) {
|
||||
if (*cmd == '@') {
|
||||
while ((*cmd == '@') || (*cmd == '-') || (*cmd == '+')) {
|
||||
switch (*cmd) {
|
||||
case '@':
|
||||
silent = TRUE;
|
||||
} else {
|
||||
break;
|
||||
case '-':
|
||||
errCheck = FALSE;
|
||||
break;
|
||||
case '+':
|
||||
doIt = TRUE;
|
||||
if (!meta[0]) /* we came here from jobs */
|
||||
Compat_Init();
|
||||
break;
|
||||
}
|
||||
cmd++;
|
||||
}
|
||||
|
@ -279,16 +304,14 @@ CompatRunCommand(ClientData cmdp, ClientData gnp)
|
|||
* If we're not supposed to execute any commands, this is as far as
|
||||
* we go...
|
||||
*/
|
||||
if (NoExecute(gn)) {
|
||||
if (!doIt && NoExecute(gn)) {
|
||||
return (0);
|
||||
}
|
||||
|
||||
if (*cp != '\0') {
|
||||
/*
|
||||
* If *cp isn't the null character, we hit a "meta" character and
|
||||
* need to pass the command off to the shell. We give the shell the
|
||||
* -e flag as well as -c if it's supposed to exit when it hits an
|
||||
* error.
|
||||
* need to pass the command off to the shell.
|
||||
*/
|
||||
static const char *shargv[4];
|
||||
|
||||
|
@ -297,9 +320,9 @@ CompatRunCommand(ClientData cmdp, ClientData gnp)
|
|||
* The following work for any of the builtin shell specs.
|
||||
*/
|
||||
if (DEBUG(SHELL))
|
||||
shargv[1] = (errCheck ? "-exc" : "-xc");
|
||||
shargv[1] = "-xc";
|
||||
else
|
||||
shargv[1] = (errCheck ? "-ec" : "-c");
|
||||
shargv[1] = "-c";
|
||||
shargv[2] = cmd;
|
||||
shargv[3] = (char *)NULL;
|
||||
av = shargv;
|
||||
|
@ -596,11 +619,10 @@ cohorts:
|
|||
void
|
||||
Compat_Run(Lst targs)
|
||||
{
|
||||
const char *cp; /* Pointer to string of shell meta-characters */
|
||||
GNode *gn = NULL;/* Current root target */
|
||||
int errors; /* Number of targets not remade due to errors */
|
||||
|
||||
Shell_Init(); /* setup default shell */
|
||||
Compat_Init();
|
||||
|
||||
if (signal(SIGINT, SIG_IGN) != SIG_IGN) {
|
||||
signal(SIGINT, CompatInterrupt);
|
||||
|
@ -615,14 +637,6 @@ Compat_Run(Lst targs)
|
|||
signal(SIGQUIT, CompatInterrupt);
|
||||
}
|
||||
|
||||
for (cp = "#=|^(){};&<>*?[]:$`\\\n"; *cp != '\0'; cp++) {
|
||||
meta[(unsigned char) *cp] = 1;
|
||||
}
|
||||
/*
|
||||
* The null character serves as a sentinel in the string.
|
||||
*/
|
||||
meta[0] = 1;
|
||||
|
||||
ENDNode = Targ_FindNode(".END", TARG_CREATE);
|
||||
/*
|
||||
* If the user has defined a .BEGIN target, execute the commands attached
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: job.c,v 1.84 2004/05/07 00:04:38 ross Exp $ */
|
||||
/* $NetBSD: job.c,v 1.85 2004/05/07 08:12:15 sjg Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
|
||||
|
@ -70,14 +70,14 @@
|
|||
*/
|
||||
|
||||
#ifndef MAKE_NATIVE
|
||||
static char rcsid[] = "$NetBSD: job.c,v 1.84 2004/05/07 00:04:38 ross Exp $";
|
||||
static char rcsid[] = "$NetBSD: job.c,v 1.85 2004/05/07 08:12:15 sjg Exp $";
|
||||
#else
|
||||
#include <sys/cdefs.h>
|
||||
#ifndef lint
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)job.c 8.2 (Berkeley) 3/19/94";
|
||||
#else
|
||||
__RCSID("$NetBSD: job.c,v 1.84 2004/05/07 00:04:38 ross Exp $");
|
||||
__RCSID("$NetBSD: job.c,v 1.85 2004/05/07 08:12:15 sjg Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
#endif
|
||||
|
@ -704,11 +704,24 @@ JobPrintCommand(ClientData cmdp, ClientData jobp)
|
|||
/*
|
||||
* Check for leading @' and -'s to control echoing and error checking.
|
||||
*/
|
||||
while (*cmd == '@' || *cmd == '-') {
|
||||
if (*cmd == '@') {
|
||||
while (*cmd == '@' || *cmd == '-' || (*cmd == '+')) {
|
||||
switch (*cmd) {
|
||||
case '@':
|
||||
shutUp = TRUE;
|
||||
} else {
|
||||
break;
|
||||
case '-':
|
||||
errOff = TRUE;
|
||||
break;
|
||||
case '+':
|
||||
if (noSpecials) {
|
||||
/*
|
||||
* We're not actually executing anything...
|
||||
* but this one needs to be - use compat mode just for it.
|
||||
*/
|
||||
CompatRunCommand(cmdp, (ClientData)job->node);
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
cmd++;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
.\" $NetBSD: make.1,v 1.101 2004/02/05 23:51:46 wiz Exp $
|
||||
.\" $NetBSD: make.1,v 1.102 2004/05/07 08:12:16 sjg Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 1990, 1993
|
||||
.\" The Regents of the University of California. All rights reserved.
|
||||
|
@ -29,7 +29,7 @@
|
|||
.\"
|
||||
.\" from: @(#)make.1 8.4 (Berkeley) 3/19/94
|
||||
.\"
|
||||
.Dd February 6, 2004
|
||||
.Dd May 6, 2004
|
||||
.Dt MAKE 1
|
||||
.Os
|
||||
.Sh NAME
|
||||
|
@ -367,15 +367,23 @@ dependencies may be followed by a creation script, unless the
|
|||
.Ql Ic \&::
|
||||
operator is used.
|
||||
.Pp
|
||||
If the first or first two characters of the command line are
|
||||
.Ql Ic @
|
||||
and/or
|
||||
If the first characters of the command line are any combination of
|
||||
.Ql Ic @ ,
|
||||
.Ql Ic +
|
||||
or
|
||||
.Ql Ic \- ,
|
||||
the command is treated specially.
|
||||
A
|
||||
.Ql Ic @
|
||||
causes the command not to be echoed before it is executed.
|
||||
A
|
||||
.Ql Ic +
|
||||
causes the command to be executed even when
|
||||
.Fl n
|
||||
is given.
|
||||
This is similar to the effect of the .MAKE special source,
|
||||
except that the effect can be limited to a single line of a script.
|
||||
A
|
||||
.Ql Ic \-
|
||||
causes any non-zero exit status of the command line to be ignored.
|
||||
.Sh VARIABLE ASSIGNMENTS
|
||||
|
@ -1176,7 +1184,8 @@ operator is not an integral value, then
|
|||
string comparison is performed between the expanded
|
||||
variables.
|
||||
If no relational operator is given, it is assumed that the expanded
|
||||
variable is being compared against 0.
|
||||
variable is being compared against 0 or an empty string in the case
|
||||
of a string comparison.
|
||||
.Pp
|
||||
When
|
||||
.Nm
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: nonints.h,v 1.31 2004/05/07 00:04:40 ross Exp $ */
|
||||
/* $NetBSD: nonints.h,v 1.32 2004/05/07 08:12:16 sjg Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1988, 1989, 1990, 1993
|
||||
|
@ -90,6 +90,7 @@ void Arch_End(void);
|
|||
int Arch_IsLib(GNode *);
|
||||
|
||||
/* compat.c */
|
||||
int CompatRunCommand(ClientData cmdp, ClientData gnp);
|
||||
void Compat_Run(Lst);
|
||||
|
||||
/* cond.c */
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# $Id: Makefile,v 1.12 2004/04/08 00:59:01 sjg Exp $
|
||||
# $Id: Makefile,v 1.13 2004/05/07 08:12:16 sjg Exp $
|
||||
#
|
||||
# Unit tests for make(1)
|
||||
# The main targets are:
|
||||
|
@ -23,6 +23,7 @@ SUBFILES= \
|
|||
modmatch \
|
||||
modts \
|
||||
modword \
|
||||
posix \
|
||||
ternary \
|
||||
varcmd
|
||||
|
||||
|
@ -31,7 +32,7 @@ all: ${SUBFILES}
|
|||
# the tests are actually done with sub-makes.
|
||||
.PHONY: ${SUBFILES}
|
||||
${SUBFILES}:
|
||||
@${.MAKE} -k -f ${UNIT_TESTS}/$@
|
||||
-@${.MAKE} -k -f ${UNIT_TESTS}/$@
|
||||
|
||||
clean:
|
||||
rm -f *.out *.fail *.core
|
||||
|
@ -43,11 +44,15 @@ TEST_MAKE?= ${MAKE}
|
|||
# The driver.
|
||||
# We always pretend .MAKE was called 'make'
|
||||
# and strip ${.CURDIR}/ from the output
|
||||
# and replace anything after 'stopped in' with unit-tests
|
||||
# so the results can be compared.
|
||||
test:
|
||||
@echo "${TEST_MAKE} -f ${MAKEFILE} > ${.TARGET}.out 2>&1"
|
||||
@cd ${.OBJDIR} && ${TEST_MAKE} -f ${MAKEFILE} 2>&1 | \
|
||||
sed -e 's,^${TEST_MAKE:T}:,make:,' -e 's,${.CURDIR}/,,g' > ${.TARGET}.out || { \
|
||||
sed -e 's,^${TEST_MAKE:T}:,make:,' \
|
||||
-e '/stopped/s, /.*, unit-tests,' \
|
||||
-e 's,${.CURDIR}/,,g' \
|
||||
-e 's,${UNIT_TESTS}/,,g' > ${.TARGET}.out || { \
|
||||
tail ${.TARGET}.out; mv ${.TARGET}.out ${.TARGET}.fail; exit 1; }
|
||||
diff -u ${UNIT_TESTS}/${.TARGET}.exp ${.TARGET}.out
|
||||
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
# $Id: posix,v 1.1 2004/05/07 08:12:16 sjg Exp $
|
||||
|
||||
all: x plus subs err
|
||||
|
||||
x:
|
||||
@echo "Posix says we should execute the command as if run by system(3)"
|
||||
@echo "Expect 'Hello,' and 'World!'"
|
||||
@echo Hello,; false; echo "World!"
|
||||
|
||||
plus:
|
||||
@echo a command
|
||||
+@echo "a command prefixed by '+' executes even with -n"
|
||||
@echo another command
|
||||
|
||||
subs:
|
||||
@echo make -n
|
||||
@${.MAKE} -f ${MAKEFILE} -n plus
|
||||
@echo make -n -j1
|
||||
@${.MAKE} -f ${MAKEFILE} -n -j1 plus
|
||||
|
||||
err:
|
||||
@(echo Now we expect an error...; exit 1)
|
||||
@echo "Oops! you shouldn't see this!"
|
||||
|
|
@ -184,6 +184,28 @@ LIST:tw:C/ /,/g="one two three four five six"
|
|||
LIST:tw:C/ /,/1g="one two three four five six"
|
||||
LIST:tw:tW:C/ /,/="one,two three four five six"
|
||||
LIST:tW:tw:C/ /,/="one two three four five six"
|
||||
Posix says we should execute the command as if run by system(3)
|
||||
Expect 'Hello,' and 'World!'
|
||||
Hello,
|
||||
World!
|
||||
a command
|
||||
a command prefixed by '+' executes even with -n
|
||||
another command
|
||||
make -n
|
||||
echo a command
|
||||
echo "a command prefixed by '+' executes even with -n"
|
||||
a command prefixed by '+' executes even with -n
|
||||
echo another command
|
||||
make -n -j1
|
||||
{ echo a command
|
||||
} || exit $?
|
||||
echo "a command prefixed by '+' executes even with -n"
|
||||
a command prefixed by '+' executes even with -n
|
||||
{ echo another command
|
||||
} || exit $?
|
||||
Now we expect an error...
|
||||
*** Error code 1 (continuing)
|
||||
`all' not remade because of errors.
|
||||
The answer is unknown
|
||||
The answer is unknown
|
||||
The answer is empty
|
||||
|
|
Loading…
Reference in New Issue