Skip to content

Commit

Permalink
Merge bmake-20240625
Browse files Browse the repository at this point in the history
Merge commit 'dbb5be7f07456d02ce444484c683b130439acb45'
  • Loading branch information
sgerraty authored and bsdjhb committed Oct 29, 2024
2 parents 3d13f6f + 8d5c8e2 commit 897b271
Show file tree
Hide file tree
Showing 71 changed files with 1,029 additions and 584 deletions.
49 changes: 49 additions & 0 deletions contrib/bmake/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,52 @@
2024-06-25 Simon J Gerraty <sjg@beast.crufty.net>

* VERSION (_MAKE_VERSION): 20240625
Merge with NetBSD make, pick up
o job.c: ensure shellPath is always duped, avoid upsetting free()

2024-06-16 Simon J Gerraty <sjg@beast.crufty.net>

* VERSION (_MAKE_VERSION): 20240616
Merge with NetBSD make, pick up
o clean up collection of context information for error messages
o in warnings, move the word "warning" to the front
o var.c: throw an error on attempt to override an internal
read-only variable

2024-06-10 Simon J Gerraty <sjg@beast.crufty.net>

* VERSION (_MAKE_VERSION): 20240610
Merge with NetBSD make, pick up
o for.c: remove redundant shortcut for building the .for loop body

2024-06-02 Simon J Gerraty <sjg@beast.crufty.net>

* VERSION (_MAKE_VERSION): 20240602
Merge with NetBSD make, pick up
o rename some VarEvalMode constants to better match debug names.
o var.c: avoid out-of-bounds read when parsing indirect modifiers.

2024-06-01 Simon J Gerraty <sjg@beast.crufty.net>

* VERSION (_MAKE_VERSION): 20240601
Merge with NetBSD make, pick up
o add .export-all rather than allow .export with no argument
which can happen accidentally.
o if lua is available, run check-expect.lua after unit-tests
o main.c: use snprintf rather than strncpy
fix memory leak when purging realpath cache.

2024-05-28 Simon J Gerraty <sjg@beast.crufty.net>

* VERSION (_MAKE_VERSION): 20240528
Merge with NetBSD make, pick up
o fix a number of memory leaks
o replace magic numbers with POSIX FILENO constants
o hash.c: remove dead code from HashTable_DeleteEntry
o main.c: when complaining about unusable .OBJDIR
call PrintOnError if MAKE_DEBUG_OBJDIR_CHECK_WRITABLE is true.
o parse.c: use fewer technical terms in debug message for dependency

2024-05-20 Simon J Gerraty <sjg@beast.crufty.net>

* VERSION (_MAKE_VERSION):
Expand Down
2 changes: 1 addition & 1 deletion contrib/bmake/VERSION
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# keep this compatible with sh and make
_MAKE_VERSION=20240520
_MAKE_VERSION=20240625
15 changes: 8 additions & 7 deletions contrib/bmake/arch.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* $NetBSD: arch.c,v 1.217 2024/04/27 20:41:32 rillig Exp $ */
/* $NetBSD: arch.c,v 1.219 2024/06/02 15:31:25 rillig Exp $ */

/*
* Copyright (c) 1988, 1989, 1990, 1993
Expand Down Expand Up @@ -147,7 +147,7 @@ struct ar_hdr {
#include "dir.h"

/* "@(#)arch.c 8.2 (Berkeley) 1/2/94" */
MAKE_RCSID("$NetBSD: arch.c,v 1.217 2024/04/27 20:41:32 rillig Exp $");
MAKE_RCSID("$NetBSD: arch.c,v 1.219 2024/06/02 15:31:25 rillig Exp $");

typedef struct List ArchList;
typedef struct ListNode ArchListNode;
Expand Down Expand Up @@ -204,7 +204,7 @@ ArchFree(Arch *a)
HashIter hi;

HashIter_Init(&hi, &a->members);
while (HashIter_Next(&hi) != NULL)
while (HashIter_Next(&hi))
free(hi.entry->value);

free(a->name);
Expand Down Expand Up @@ -257,7 +257,8 @@ Arch_ParseArchive(char **pp, GNodeList *gns, GNode *scope)
bool isError;

/* XXX: is expanded twice: once here and once below */
result = Var_Parse(&nested_p, scope, VARE_UNDEFERR);
result = Var_Parse(&nested_p, scope,
VARE_EVAL_DEFINED);
/* TODO: handle errors */
isError = result.str == var_Error;
FStr_Done(&result);
Expand All @@ -272,7 +273,7 @@ Arch_ParseArchive(char **pp, GNodeList *gns, GNode *scope)

spec[cp++ - spec] = '\0';
if (expandLib)
Var_Expand(&lib, scope, VARE_UNDEFERR);
Var_Expand(&lib, scope, VARE_EVAL_DEFINED);

for (;;) {
/*
Expand All @@ -296,7 +297,7 @@ Arch_ParseArchive(char **pp, GNodeList *gns, GNode *scope)
const char *nested_p = cp;

result = Var_Parse(&nested_p, scope,
VARE_UNDEFERR);
VARE_EVAL_DEFINED);
/* TODO: handle errors */
isError = result.str == var_Error;
FStr_Done(&result);
Expand Down Expand Up @@ -341,7 +342,7 @@ Arch_ParseArchive(char **pp, GNodeList *gns, GNode *scope)
char *p;
const char *unexpandedMem = mem.str;

Var_Expand(&mem, scope, VARE_UNDEFERR);
Var_Expand(&mem, scope, VARE_EVAL_DEFINED);

/*
* Now form an archive spec and recurse to deal with
Expand Down
33 changes: 22 additions & 11 deletions contrib/bmake/bmake.1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.\" $NetBSD: make.1,v 1.375 2024/03/10 02:53:37 sjg Exp $
.\" $NetBSD: make.1,v 1.377 2024/06/01 06:26:36 sjg Exp $
.\"
.\" Copyright (c) 1990, 1993
.\" The Regents of the University of California. All rights reserved.
Expand Down Expand Up @@ -29,7 +29,7 @@
.\"
.\" from: @(#)make.1 8.4 (Berkeley) 3/19/94
.\"
.Dd March 9, 2024
.Dd June 1, 2024
.Dt BMAKE 1
.Os
.Sh NAME
Expand Down Expand Up @@ -1143,9 +1143,19 @@ This mode can be used to detect undeclared dependencies between files.
Used to create files in a separate directory, see
.Va .OBJDIR .
.It Va MAKE_OBJDIR_CHECK_WRITABLE
Used to force a separate directory for the created files,
even if that directory is not writable, see
.Va .OBJDIR .
When true,
.Nm
will check that
.Va .OBJDIR
is writable, and issue a warning if not.
.It Va MAKE_DEBUG_OBJDIR_CHECK_WRITABLE
When true and
.Nm
is warning about an unwritable
.Va .OBJDIR ,
report the variables listed in
.Va MAKE_PRINT_VAR_ON_ERROR
to help debug.
.It Va MAKEOBJDIRPREFIX
Used to create files in a separate directory, see
.Va .OBJDIR .
Expand Down Expand Up @@ -1951,19 +1961,20 @@ The directives for exporting and unexporting variables are:
.Bl -tag -width Ds
.It Ic .export Ar variable No ...
Export the specified global variable.
If no variable list is provided, all globals are exported
except for internal variables (those that start with
.Ql \&. ) .
This is not affected by the
.Fl X
flag, so should be used with caution.
.Pp
For compatibility with other make programs,
.Cm export Ar variable\| Ns Cm \&= Ns Ar value
(without leading dot) is also accepted.
.Pp
Appending a variable name to
.Va .MAKE.EXPORTED
is equivalent to exporting a variable.
.It Ic .export-all
Export all globals except for internal variables (those that start with
.Ql \&. ) .
This is not affected by the
.Fl X
flag, so should be used with caution.
.It Ic .export-env Ar variable No ...
The same as
.Ql .export ,
Expand Down
26 changes: 17 additions & 9 deletions contrib/bmake/bmake.cat1
Original file line number Diff line number Diff line change
Expand Up @@ -756,8 +756,13 @@ VVAARRIIAABBLLEE AASSSSIIGGNNMMEENNTTSS
Used to create files in a separate directory, see _._O_B_J_D_I_R.

_M_A_K_E___O_B_J_D_I_R___C_H_E_C_K___W_R_I_T_A_B_L_E
Used to force a separate directory for the created files, even if
that directory is not writable, see _._O_B_J_D_I_R.
When true, bbmmaakkee will check that _._O_B_J_D_I_R is writable, and issue a

Check failure on line 759 in contrib/bmake/bmake.cat1

View workflow job for this annotation

GitHub Actions / Style Checker

Invalid UTF-8, patch and commit message should be encoded in UTF-8
warning if not.

_M_A_K_E___D_E_B_U_G___O_B_J_D_I_R___C_H_E_C_K___W_R_I_T_A_B_L_E

Check failure on line 762 in contrib/bmake/bmake.cat1

View workflow job for this annotation

GitHub Actions / Style Checker

Invalid UTF-8, patch and commit message should be encoded in UTF-8
When true and bbmmaakkee is warning about an unwritable _._O_B_J_D_I_R,

Check failure on line 763 in contrib/bmake/bmake.cat1

View workflow job for this annotation

GitHub Actions / Style Checker

Invalid UTF-8, patch and commit message should be encoded in UTF-8
report the variables listed in _M_A_K_E___P_R_I_N_T___V_A_R___O_N___E_R_R_O_R to help

Check failure on line 764 in contrib/bmake/bmake.cat1

View workflow job for this annotation

GitHub Actions / Style Checker

Invalid UTF-8, patch and commit message should be encoded in UTF-8
debug.

_M_A_K_E_O_B_J_D_I_R_P_R_E_F_I_X
Used to create files in a separate directory, see _._O_B_J_D_I_R.
Expand Down Expand Up @@ -1230,16 +1235,19 @@ DDIIRREECCTTIIVVEESS
The directives for exporting and unexporting variables are:

..eexxppoorrtt _v_a_r_i_a_b_l_e ...
Export the specified global variable. If no variable list is
provided, all globals are exported except for internal variables
(those that start with `.'). This is not affected by the --XX
flag, so should be used with caution. For compatibility with
other make programs, eexxppoorrtt _v_a_r_i_a_b_l_e==_v_a_l_u_e (without leading dot)
is also accepted.
Export the specified global variable.

For compatibility with other make programs, eexxppoorrtt _v_a_r_i_a_b_l_e==_v_a_l_u_e

Check failure on line 1240 in contrib/bmake/bmake.cat1

View workflow job for this annotation

GitHub Actions / Style Checker

Invalid UTF-8, patch and commit message should be encoded in UTF-8
(without leading dot) is also accepted.

Appending a variable name to _._M_A_K_E_._E_X_P_O_R_T_E_D is equivalent to
exporting a variable.

..eexxppoorrtt--aallll

Check failure on line 1246 in contrib/bmake/bmake.cat1

View workflow job for this annotation

GitHub Actions / Style Checker

Invalid UTF-8, patch and commit message should be encoded in UTF-8
Export all globals except for internal variables (those that
start with `.'). This is not affected by the --XX flag, so should

Check failure on line 1248 in contrib/bmake/bmake.cat1

View workflow job for this annotation

GitHub Actions / Style Checker

Invalid UTF-8, patch and commit message should be encoded in UTF-8
be used with caution.

..eexxppoorrtt--eennvv _v_a_r_i_a_b_l_e ...
The same as `.export', except that the variable is not appended
to _._M_A_K_E_._E_X_P_O_R_T_E_D. This allows exporting a value to the
Expand Down Expand Up @@ -1780,4 +1788,4 @@ BBUUGGSS
attempt to suppress a cascade of unnecessary errors, can result in a
seemingly unexplained `*** Error code 6'

FreeBSD 13.2-RELEASE-p10 March 9, 2024 FreeBSD 13.2-RELEASE-p10
FreeBSD 13.2-RELEASE-p11 June 1, 2024 FreeBSD 13.2-RELEASE-p11
57 changes: 31 additions & 26 deletions contrib/bmake/compat.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* $NetBSD: compat.c,v 1.255 2024/04/20 10:18:55 rillig Exp $ */
/* $NetBSD: compat.c,v 1.259 2024/06/15 20:02:45 rillig Exp $ */

/*
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
Expand Down Expand Up @@ -94,7 +94,7 @@
#include "pathnames.h"

/* "@(#)compat.c 8.2 (Berkeley) 3/19/94" */
MAKE_RCSID("$NetBSD: compat.c,v 1.255 2024/04/20 10:18:55 rillig Exp $");
MAKE_RCSID("$NetBSD: compat.c,v 1.259 2024/06/15 20:02:45 rillig Exp $");

static GNode *curTarg = NULL;
static pid_t compatChild;
Expand Down Expand Up @@ -203,6 +203,24 @@ UseShell(const char *cmd MAKE_ATTR_UNUSED)
#endif
}

static int
Compat_Spawn(const char **av)
{
int pid = vfork();
if (pid < 0)
Fatal("Could not fork");

if (pid == 0) {
#ifdef USE_META
if (useMeta)
meta_compat_child();
#endif
(void)execvp(av[0], (char *const *)UNCONST(av));
execDie("exec", av[0]);
}
return pid;

Check failure on line 221 in contrib/bmake/compat.c

View workflow job for this annotation

GitHub Actions / Style Checker

parentheses required on return
}

/*
* Execute the next command for a target. If the command returns an error,
* the node's made field is set to ERROR and creation stops.
Expand All @@ -225,21 +243,18 @@ Compat_RunCommand(const char *cmdp, GNode *gn, StringListNode *ln)
volatile bool errCheck; /* Check errors */
WAIT_T reason; /* Reason for child's death */
WAIT_T status; /* Description of child's death */
pid_t cpid; /* Child actually found */
pid_t retstat; /* Result of wait */
const char **volatile av; /* Argument vector for thing to exec */
const char **av; /* Arguments for the child process */
char **volatile mav; /* Copy of the argument vector for freeing */
bool useShell; /* True if command should be executed using a
* shell */
const char *volatile cmd = cmdp;
const char *cmd = cmdp;

silent = (gn->type & OP_SILENT) != OP_NONE;
errCheck = !(gn->type & OP_IGNORE);
doIt = false;

EvalStack_Push(gn->name, NULL, NULL);
cmdStart = Var_Subst(cmd, gn, VARE_WANTRES);
EvalStack_Pop();
cmdStart = Var_SubstInTarget(cmd, gn);
/* TODO: handle errors */

if (cmdStart[0] == '\0') {
Expand All @@ -264,11 +279,13 @@ Compat_RunCommand(const char *cmdp, GNode *gn, StringListNode *ln)
* usual '$$'.
*/
Lst_Append(&endNode->commands, cmdStart);
return true;
goto register_command;
}
}
if (strcmp(cmdStart, "...") == 0) {
gn->type |= OP_SAVE_CMDS;
register_command:
Parse_RegisterCommand(cmdStart);
return true;
}

Expand All @@ -288,7 +305,7 @@ Compat_RunCommand(const char *cmdp, GNode *gn, StringListNode *ln)
while (ch_isspace(*cmd))
cmd++;
if (cmd[0] == '\0')
return true;
goto register_command;

useShell = UseShell(cmd);

Expand All @@ -298,7 +315,7 @@ Compat_RunCommand(const char *cmdp, GNode *gn, StringListNode *ln)
}

if (!doIt && !GNode_ShouldExecute(gn))
return true;
goto register_command;

DEBUG1(JOB, "Execute: '%s'\n", cmd);

Expand Down Expand Up @@ -333,19 +350,7 @@ Compat_RunCommand(const char *cmdp, GNode *gn, StringListNode *ln)

Var_ReexportVars(gn);

compatChild = cpid = vfork();
if (cpid < 0)
Fatal("Could not fork");

if (cpid == 0) {
#ifdef USE_META
if (useMeta)
meta_compat_child();
#endif
(void)execvp(av[0], (char *const *)UNCONST(av));
execDie("exec", av[0]);
}

compatChild = Compat_Spawn(av);
free(mav);
free(bp);

Expand All @@ -355,11 +360,11 @@ Compat_RunCommand(const char *cmdp, GNode *gn, StringListNode *ln)

#ifdef USE_META
if (useMeta)
meta_compat_parent(cpid);
meta_compat_parent(compatChild);
#endif

/* The child is off and running. Now all we can do is wait... */
while ((retstat = wait(&reason)) != cpid) {
while ((retstat = wait(&reason)) != compatChild) {
if (retstat > 0)
JobReapChild(retstat, reason, false); /* not ours? */
if (retstat == -1 && errno != EINTR)
Expand Down
Loading

0 comments on commit 897b271

Please sign in to comment.