Skip to content

Commit

Permalink
Update to bmake 20240625
Browse files Browse the repository at this point in the history
Relevant changes:
* VERSION (_MAKE_VERSION): 20240625
Merge with NetBSD make, pick up

* 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

* VERSION (_MAKE_VERSION): 20240610
Merge with NetBSD make, pick up
o for.c: remove redundant shortcut for building the .for loop body
  • Loading branch information
VexedUXR committed Jul 12, 2024
1 parent e831a99 commit 950e96b
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 71 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ LDADD+= user32.lib tre.lib
LDFLAGS+= /libpath:tre

# Version
CFLAGS+= /D MAKE_VERSION=\"20240602\"
CFLAGS+= /D MAKE_VERSION=\"20240625\"

TARGET?= ${VSCMD_ARG_TGT_ARCH:U${PROCESSOR_ARCHITECTURE}:tl:S,x64,amd64,1:S,x86,i386,1}
CFLAGS+= /D MACHINE=\"${TARGET}\"
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@

# bmake for Windows

## NOTE:
This project is no longer being maintained.

## Installing
bmake is now on chocolatey:
https://community.chocolatey.org/packages/bmake
Expand Down Expand Up @@ -51,4 +54,4 @@ The binary itself is functional and can be used as expected.
Some of the mk files have been ported, though some functionality is missing,
most notabaly: there is no `install` target and no support for manpages.

Up to date with bmake `20240602`
Up to date with bmake `20240625`
4 changes: 1 addition & 3 deletions compat.c
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,7 @@ Compat_RunCommand(const char *cmdp, GNode *gn, StringListNode *ln)
errCheck = !(gn->type & OP_IGNORE);
doIt = false;

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

if (cmdStart[0] == '\0') {
Expand Down
24 changes: 1 addition & 23 deletions for.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* $NetBSD: for.c,v 1.181 2024/06/02 15:31:25 rillig Exp $ */
/* $NetBSD: for.c,v 1.182 2024/06/07 18:57:30 rillig Exp $ */

/*
* Copyright (c) 1992, The Regents of the University of California.
Expand Down Expand Up @@ -329,23 +329,6 @@ ExprLen(const char *s, const char *e)
return 0;
}

/*
* The .for loop substitutes the items as ${:U<value>...}, which means
* that characters that break this syntax must be backslash-escaped.
*/
static bool
NeedsEscapes(Substring value, char endc)
{
const char *p;

for (p = value.start; p != value.end; p++) {
if (*p == ':' || *p == '$' || *p == '\\' || *p == endc ||
*p == '\n')
return true;
}
return false;
}

/*
* While expanding the body of a .for loop, write the item as a ${:U...}
* expression, escaping characters as needed. The result is later unescaped
Expand All @@ -357,11 +340,6 @@ AddEscaped(Buffer *cmds, Substring item, char endc)
const char *p;
char ch;

if (!NeedsEscapes(item, endc)) {
Buf_AddRange(cmds, item.start, item.end);
return;
}

for (p = item.start; p != item.end;) {
ch = *p;
if (ch == '$') {
Expand Down
6 changes: 3 additions & 3 deletions hash.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* $NetBSD: hash.c,v 1.77 2024/05/31 07:11:12 rillig Exp $ */
/* $NetBSD: hash.c,v 1.78 2024/06/05 22:06:53 rillig Exp $ */

/*
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
Expand Down Expand Up @@ -296,8 +296,8 @@ HashTable_DeleteEntry(HashTable *t, HashEntry *he)
}

/*
* Return the next entry in the hash table, or NULL if the end of the table
* is reached.
* Place the next entry from the hash table in hi->entry, or return false if
* the end of the table is reached.
*/
bool
HashIter_Next(HashIter *hi)
Expand Down
10 changes: 3 additions & 7 deletions job.c
Original file line number Diff line number Diff line change
Expand Up @@ -610,9 +610,7 @@ JobWriteCommand(Job *job, ShellWriter *wr, StringListNode *ln, const char *ucmd)

run = GNode_ShouldExecute(job->node);

EvalStack_Push(job->node->name, NULL, NULL);
xcmd = Var_Subst(ucmd, job->node, VARE_EVAL);
EvalStack_Pop();
xcmd = Var_SubstInTarget(ucmd, job->node);
/* TODO: handle errors */
xcmdStart = xcmd;

Expand Down Expand Up @@ -721,9 +719,7 @@ JobSaveCommands(Job *job)
* variables such as .TARGET, .IMPSRC. It is not intended to
* expand the other variables as well; see deptgt-end.mk.
*/
EvalStack_Push(job->node->name, NULL, NULL);
expanded_cmd = Var_Subst(cmd, job->node, VARE_EVAL);
EvalStack_Pop();
expanded_cmd = Var_SubstInTarget(cmd, job->node);
/* TODO: handle errors */
Lst_Append(&Targ_GetEndNode()->commands, expanded_cmd);
Parse_RegisterCommand(expanded_cmd);
Expand Down Expand Up @@ -1512,7 +1508,7 @@ InitShellNameAndPath(void)
shellName = shell->name;

#ifdef DEFSHELL_CUSTOM
if (isAbs(shellName[0])) {
if (isAbs(shellName)) {
shellPath = shellName;
shellName = str_basename(shellPath);
return;
Expand Down
5 changes: 2 additions & 3 deletions make.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* $NetBSD: make.h,v 1.325 2023/09/10 11:52:29 rillig Exp $ */
/* $NetBSD: make.h,v 1.339 2024/06/15 20:02:45 rillig Exp $ */

/*
* Copyright (c) 1988, 1989, 1990, 1993
Expand Down Expand Up @@ -982,6 +982,7 @@ FStr MAKE_ATTR_USE Var_Value(GNode *, const char *);
const char * MAKE_ATTR_USE GNode_ValueDirect(GNode *, const char *);
FStr Var_Parse(const char **, GNode *, VarEvalMode);
char *Var_Subst(const char *, GNode *, VarEvalMode);
char *Var_SubstInTarget(const char *, GNode *);
void Var_Expand(FStr *, GNode *, VarEvalMode);
void Var_Stats(void);
void Var_Dump(GNode *);
Expand All @@ -996,8 +997,6 @@ void Global_Append(const char *, const char *);
void Global_Delete(const char *);
void Global_Set_ReadOnly(const char *, const char *);

void EvalStack_Push(const char *, const char *, const char *);
void EvalStack_Pop(void);
const char *EvalStack_Details(void);

/* util.c */
Expand Down
4 changes: 2 additions & 2 deletions parse.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* $NetBSD: parse.c,v 1.730 2024/06/02 15:31:26 rillig Exp $ */
/* $NetBSD: parse.c,v 1.731 2024/06/15 19:43:56 rillig Exp $ */

/*
* Copyright (c) 1988, 1989, 1990, 1993
Expand Down Expand Up @@ -521,9 +521,9 @@ ParseVErrorInternal(FILE *f, bool useVars, const GNode *gn,
(void)fprintf(f, "%s: ", progname);

PrintLocation(f, useVars, gn);
fprintf(f, "%s", EvalStack_Details());
if (level == PARSE_WARNING)
(void)fprintf(f, "warning: ");
fprintf(f, "%s", EvalStack_Details());
(void)vfprintf(f, fmt, ap);
(void)fprintf(f, "\n");
(void)fflush(f);
Expand Down
85 changes: 57 additions & 28 deletions var.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* $NetBSD: var.c,v 1.1119 2024/06/02 15:31:26 rillig Exp $ */
/* $NetBSD: var.c,v 1.1121 2024/06/15 22:06:30 rillig Exp $ */

/*
* Copyright (c) 1988, 1989, 1990, 1993
Expand Down Expand Up @@ -191,6 +191,12 @@ typedef struct Var {
*/
bool readOnly:1;

/*
* The variable is read-only and immune to the .NOREADONLY special
* target. Any attempt to modify it results in an error.
*/
bool readOnlyLoud:1;

/*
* The variable is currently being accessed by Var_Parse or Var_Subst.
* This temporary marker is used to avoid endless recursion.
Expand Down Expand Up @@ -253,10 +259,15 @@ typedef struct SepBuf {
char sep;
} SepBuf;

typedef enum {
VSK_TARGET,
VSK_VARNAME,
VSK_EXPR
} EvalStackElementKind;

typedef struct {
const char *target;
const char *varname;
const char *expr;
EvalStackElementKind kind;
const char *str;
} EvalStackElement;

typedef struct {
Expand Down Expand Up @@ -331,21 +342,20 @@ static const char VarEvalMode_Name[][32] = {

static EvalStack evalStack;

void
EvalStack_Push(const char *target, const char *expr, const char *varname)
static void
EvalStack_Push(EvalStackElementKind kind, const char *str)
{
if (evalStack.len >= evalStack.cap) {
evalStack.cap = 16 + 2 * evalStack.cap;
evalStack.elems = bmake_realloc(evalStack.elems,
evalStack.cap * sizeof(*evalStack.elems));
}
evalStack.elems[evalStack.len].target = target;
evalStack.elems[evalStack.len].expr = expr;
evalStack.elems[evalStack.len].varname = varname;
evalStack.elems[evalStack.len].kind = kind;
evalStack.elems[evalStack.len].str = str;
evalStack.len++;
}

void
static void
EvalStack_Pop(void)
{
assert(evalStack.len > 0);
Expand All @@ -362,21 +372,12 @@ EvalStack_Details(void)
buf->len = 0;
for (i = 0; i < evalStack.len; i++) {
EvalStackElement *elem = evalStack.elems + i;
if (elem->target != NULL) {
Buf_AddStr(buf, "in target \"");
Buf_AddStr(buf, elem->target);
Buf_AddStr(buf, "\": ");
}
if (elem->expr != NULL) {
Buf_AddStr(buf, "while evaluating \"");
Buf_AddStr(buf, elem->expr);
Buf_AddStr(buf, "\": ");
}
if (elem->varname != NULL) {
Buf_AddStr(buf, "while evaluating variable \"");
Buf_AddStr(buf, elem->varname);
Buf_AddStr(buf, "\": ");
}
Buf_AddStr(buf,
elem->kind == VSK_TARGET ? "in target \"" :
elem->kind == VSK_EXPR ? "while evaluating \"" :
"while evaluating variable \"");
Buf_AddStr(buf, elem->str);
Buf_AddStr(buf, "\": ");
}
return buf->len > 0 ? buf->data : "";
}
Expand All @@ -394,6 +395,7 @@ VarNew(FStr name, const char *value,
var->shortLived = shortLived;
var->fromEnvironment = fromEnvironment;
var->readOnly = readOnly;
var->readOnlyLoud = false;
var->inUse = false;
var->exported = false;
var->reexport = false;
Expand Down Expand Up @@ -553,6 +555,12 @@ Var_Delete(GNode *scope, const char *varname)
}

v = he->value;
if (v->readOnlyLoud) {
Parse_Error(PARSE_FATAL,
"Cannot delete \"%s\" as it is read-only",
v->name.str);
return;
}
if (v->readOnly) {
DEBUG2(VAR, "%s: ignoring delete '%s' as it is read-only\n",
scope->name, varname);
Expand Down Expand Up @@ -1024,6 +1032,12 @@ Var_SetWithFlags(GNode *scope, const char *name, const char *val,
}
v = VarAddS(name, val, scope, flags);
} else {
if (v->readOnlyLoud) {
Parse_Error(PARSE_FATAL,
"Cannot overwrite \"%s\" as it is read-only",
v->name.str);
return;
}
if (v->readOnly && !(flags & VAR_SET_READONLY)) {
DEBUG3(VAR,
"%s: ignoring '%s = %s' as it is read-only\n",
Expand Down Expand Up @@ -1116,7 +1130,8 @@ Global_Delete(const char *name)
void
Global_Set_ReadOnly(const char *name, const char *value)
{
Var_SetWithFlags(SCOPE_GLOBAL, name, value, VAR_SET_READONLY);
Var_SetWithFlags(SCOPE_GLOBAL, name, value, VAR_SET_NONE);
VarFind(name, SCOPE_GLOBAL, false)->readOnlyLoud = true;
}

/*
Expand All @@ -1134,6 +1149,10 @@ Var_Append(GNode *scope, const char *name, const char *val)

if (v == NULL) {
Var_SetWithFlags(scope, name, val, VAR_SET_NONE);
} else if (v->readOnlyLoud) {
Parse_Error(PARSE_FATAL,
"Cannot append to \"%s\" as it is read-only", name);
return;
} else if (v->readOnly) {
DEBUG3(VAR, "%s: ignoring '%s += %s' as it is read-only\n",
scope->name, name, val);
Expand Down Expand Up @@ -4580,9 +4599,9 @@ Var_Parse(const char **pp, GNode *scope, VarEvalMode emode)
expr.value = FStr_InitRefer(v->val.data);

if (expr.name[0] != '\0')
EvalStack_Push(NULL, NULL, expr.name);
EvalStack_Push(VSK_VARNAME, expr.name);
else
EvalStack_Push(NULL, start, NULL);
EvalStack_Push(VSK_EXPR, start);

/*
* Before applying any modifiers, expand any nested expressions from
Expand Down Expand Up @@ -4760,6 +4779,16 @@ Var_Subst(const char *str, GNode *scope, VarEvalMode emode)
return Buf_DoneData(&res);
}

char *
Var_SubstInTarget(const char *str, GNode *scope)
{
char *res;
EvalStack_Push(VSK_TARGET, scope->name);
res = Var_Subst(str, scope, VARE_EVAL);
EvalStack_Pop();
return res;
}

void
Var_Expand(FStr *str, GNode *scope, VarEvalMode emode)
{
Expand Down

0 comments on commit 950e96b

Please sign in to comment.