make(1): omit linear search for command in Compat_RunCommand
This commit is contained in:
parent
7a800efcdb
commit
5196cc55b0
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: compat.c,v 1.215 2020/12/13 19:33:53 rillig Exp $ */
|
||||
/* $NetBSD: compat.c,v 1.216 2020/12/20 21:07:32 rillig Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
|
||||
@ -96,7 +96,7 @@
|
||||
#include "pathnames.h"
|
||||
|
||||
/* "@(#)compat.c 8.2 (Berkeley) 3/19/94" */
|
||||
MAKE_RCSID("$NetBSD: compat.c,v 1.215 2020/12/13 19:33:53 rillig Exp $");
|
||||
MAKE_RCSID("$NetBSD: compat.c,v 1.216 2020/12/20 21:07:32 rillig Exp $");
|
||||
|
||||
static GNode *curTarg = NULL;
|
||||
static pid_t compatChild;
|
||||
@ -211,13 +211,14 @@ UseShell(const char *cmd MAKE_ATTR_UNUSED)
|
||||
*
|
||||
* Input:
|
||||
* cmdp Command to execute
|
||||
* gnp Node from which the command came
|
||||
* gn Node from which the command came
|
||||
* ln List node that contains the command
|
||||
*
|
||||
* Results:
|
||||
* 0 if the command succeeded, 1 if an error occurred.
|
||||
*/
|
||||
int
|
||||
Compat_RunCommand(const char *cmdp, GNode *gn)
|
||||
Compat_RunCommand(const char *cmdp, GNode *gn, StringListNode *ln)
|
||||
{
|
||||
char *cmdStart; /* Start of expanded command */
|
||||
char *bp;
|
||||
@ -228,7 +229,6 @@ Compat_RunCommand(const char *cmdp, GNode *gn)
|
||||
int status; /* Description of child's death */
|
||||
pid_t cpid; /* Child actually found */
|
||||
pid_t retstat; /* Result of wait */
|
||||
StringListNode *cmdNode; /* Node where current command is located */
|
||||
const char **volatile av; /* Argument vector for thing to exec */
|
||||
char **volatile mav; /* Copy of the argument vector for freeing */
|
||||
Boolean useShell; /* TRUE if command should be executed
|
||||
@ -239,12 +239,6 @@ Compat_RunCommand(const char *cmdp, GNode *gn)
|
||||
errCheck = !(gn->type & OP_IGNORE);
|
||||
doIt = FALSE;
|
||||
|
||||
/* Luckily the commands don't end up in a string pool, otherwise
|
||||
* this comparison could match too early, in a dependency using "..."
|
||||
* for delayed commands, run in parallel mode, using the same shell
|
||||
* command line more than once; see JobPrintCommand.
|
||||
* TODO: write a unit-test to protect against this potential bug. */
|
||||
cmdNode = Lst_FindDatum(&gn->commands, cmd);
|
||||
(void)Var_Subst(cmd, gn, VARE_WANTRES, &cmdStart);
|
||||
/* TODO: handle errors */
|
||||
|
||||
@ -253,7 +247,7 @@ Compat_RunCommand(const char *cmdp, GNode *gn)
|
||||
return 0;
|
||||
}
|
||||
cmd = cmdStart;
|
||||
LstNode_Set(cmdNode, cmdStart);
|
||||
LstNode_Set(ln, cmdStart);
|
||||
|
||||
if (gn->type & OP_SAVE_CMDS) {
|
||||
GNode *endNode = Targ_GetEndNode();
|
||||
@ -379,7 +373,7 @@ Compat_RunCommand(const char *cmdp, GNode *gn)
|
||||
|
||||
/* XXX: Memory management looks suspicious here. */
|
||||
/* XXX: Setting a list item to NULL is unexpected. */
|
||||
LstNode_SetNull(cmdNode);
|
||||
LstNode_SetNull(ln);
|
||||
|
||||
#ifdef USE_META
|
||||
if (useMeta) {
|
||||
@ -467,7 +461,7 @@ RunCommands(GNode *gn)
|
||||
|
||||
for (ln = gn->commands.first; ln != NULL; ln = ln->next) {
|
||||
const char *cmd = ln->datum;
|
||||
if (Compat_RunCommand(cmd, gn) != 0)
|
||||
if (Compat_RunCommand(cmd, gn, ln) != 0)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: job.c,v 1.388 2020/12/15 21:19:47 rillig Exp $ */
|
||||
/* $NetBSD: job.c,v 1.389 2020/12/20 21:07:32 rillig Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
|
||||
@ -143,7 +143,7 @@
|
||||
#include "trace.h"
|
||||
|
||||
/* "@(#)job.c 8.2 (Berkeley) 3/19/94" */
|
||||
MAKE_RCSID("$NetBSD: job.c,v 1.388 2020/12/15 21:19:47 rillig Exp $");
|
||||
MAKE_RCSID("$NetBSD: job.c,v 1.389 2020/12/20 21:07:32 rillig Exp $");
|
||||
|
||||
/*
|
||||
* A shell defines how the commands are run. All commands for a target are
|
||||
@ -890,7 +890,7 @@ JobPrintSpecials(Job *job, ShellWriter *wr, const char *escCmd, Boolean run,
|
||||
* after all other targets have been made.
|
||||
*/
|
||||
static void
|
||||
JobPrintCommand(Job *job, ShellWriter *wr, const char *ucmd)
|
||||
JobPrintCommand(Job *job, ShellWriter *wr, StringListNode *ln, const char *ucmd)
|
||||
{
|
||||
Boolean run;
|
||||
|
||||
@ -917,7 +917,7 @@ JobPrintCommand(Job *job, ShellWriter *wr, const char *ucmd)
|
||||
* We're not actually executing anything...
|
||||
* but this one needs to be - use compat mode just for it.
|
||||
*/
|
||||
Compat_RunCommand(ucmd, job->node);
|
||||
Compat_RunCommand(ucmd, job->node, ln);
|
||||
free(xcmdStart);
|
||||
return;
|
||||
}
|
||||
@ -1005,7 +1005,7 @@ JobPrintCommands(Job *job)
|
||||
break;
|
||||
}
|
||||
|
||||
JobPrintCommand(job, &wr, ln->datum);
|
||||
JobPrintCommand(job, &wr, ln, ln->datum);
|
||||
seen = TRUE;
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: nonints.h,v 1.179 2020/12/20 14:39:46 rillig Exp $ */
|
||||
/* $NetBSD: nonints.h,v 1.180 2020/12/20 21:07:32 rillig Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1988, 1989, 1990, 1993
|
||||
@ -86,7 +86,7 @@ Boolean Arch_LibOODate(GNode *);
|
||||
Boolean Arch_IsLib(GNode *);
|
||||
|
||||
/* compat.c */
|
||||
int Compat_RunCommand(const char *, GNode *);
|
||||
int Compat_RunCommand(const char *, GNode *, StringListNode *);
|
||||
void Compat_Run(GNodeList *);
|
||||
void Compat_Make(GNode *, GNode *);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user