diff options
| author | Simon J. Gerraty <sjg@FreeBSD.org> | 2025-06-28 02:38:49 +0000 |
|---|---|---|
| committer | Simon J. Gerraty <sjg@FreeBSD.org> | 2025-06-28 02:38:49 +0000 |
| commit | 4f8f2bc2946615330eaa2cc1f6b37d97865fa58a (patch) | |
| tree | aa7729a97d1faeb358c9d981caadfad466f997a7 /parse.c | |
| parent | 284d1f7d496806b18558ab55e4654fd5e96d6a3e (diff) | |
Import bmake-20250618vendor/NetBSD/bmake/20250618
Intersting/relevant changes since bmake-20250414
ChangeLog since bmake-20250414
2025-06-18 Simon J Gerraty <sjg@beast.crufty.net>
* VERSION (_MAKE_VERSION): 20250618
Merge with NetBSD make, pick up
o parse.c: in a warning without location information,
print the stack trace
2025-06-15 Simon J Gerraty <sjg@beast.crufty.net>
* VERSION (_MAKE_VERSION): 20250615
Merge with NetBSD make, pick up
o add on-demand inter-process stack traces
o job.c,meta.c: do not discard empty lines in the output of a command
o job.c: add job prefix if necessary in non-default filtered mode
o parse.c,var.c: skip inter-process stack trace when
MAKE_STACK_TRACE=no
2025-06-12 Simon J Gerraty <sjg@beast.crufty.net>
* VERSION (_MAKE_VERSION): 20250612
Merge with NetBSD make, pick up
o use a common style for unexpected error messages
o parse.c: add program name to stack traces from sub-makes
add quotes to "in directory" line in stack traces
o var.c: check variable names for invalid characters when there
are no modifiers to apply. This detects and warns about gmake
syntax like: $(addprefix -I, $(LIST))
2025-06-09 Simon J Gerraty <sjg@beast.crufty.net>
* VERSION (_MAKE_VERSION): 20250606
Merge with NetBSD make, pick up
o main.c: fix bug in handling of output of children in jobs mode
2025-05-28 Simon J Gerraty <sjg@beast.crufty.net>
* VERSION (_MAKE_VERSION): 20250528
Merge with NetBSD make, pick up
o show contents of MAKEFLAGS in the stack trace.
o main.c: delay warning about bogus -J flag, if we end up in
compat mode before the call to InitMaxJobs, the warning isn't
necessary.
2025-05-25 Simon J Gerraty <sjg@beast.crufty.net>
* VERSION (_MAKE_VERSION): 20250525
Merge with NetBSD make, pick up
o main.c: set .CURDIR earlier so it can be reported in some errors.
2025-05-20 Simon J Gerraty <sjg@beast.crufty.net>
* VERSION (_MAKE_VERSION): 20250520
Merge with NetBSD make, pick up
o rename variables, remove now-redundant comments
o job.c: clean up building the shell commands in parallel mode
remove timeout for polling in parallel mode
o main.c: clean up error message for malformed internal -J option
2025-05-11 Simon J Gerraty <sjg@beast.crufty.net>
* VERSION (_MAKE_VERSION): 20250511
Merge with NetBSD make, pick up
o job.c: rename token pool variables to be more descriptive
move ContinueJobs further up, to eliminate a forward declaration
error out if writing to an internal pipe fails
clean up constant names and function names
use uniform debug log messages for the token pool
in the debug log, replace magic numbers with identifiers
o main.c: clean up error message for malformed internal -J option
o make.c: replace bitset in trace output with descriptive node
attributes
o targ.c: add end marker for -dg1, -dg2 and -dg3 debug log
o var.c: fix order of error messages in the ":?" modifier
2025-04-25 Simon J Gerraty <sjg@beast.crufty.net>
* VERSION (_MAKE_VERSION): 20250424
Merge with NetBSD make, pick up
o cleanup; replace unsigned int with just unsigned
Inline the TMPPAT macro, as it is only needed in a single place
o move struct Job from job.h to job.c
o job.c: group the code for handling the job token pool
avoid excessive values of -j
o make.c: fix grammar in debug log message
mk/ChangeLog since bmake-20250414
2025-05-28 Simon J Gerraty <sjg@beast.crufty.net>
* install-mk (MK_VERSION): 20250528
* add dirdeps2dplibs.mk
2025-05-18 Simon J Gerraty <sjg@beast.crufty.net>
* install-mk (MK_VERSION): 20250518
* meta.autodep.mk (META_FILES): re-work to fix filtering.
if OPTIMIZE_OBJECT_META_FILES==yes
provide a default META_FILE_OBJ_FILTER that selects a valid
.SUFFIX to match *o.meta, there's no guarantee that it will be as
simple as .o or .So etc.
We have to defer evaluation until the target script is run
for any of these filters to have any effect.
Use :S,${.OBJDIR}/,, rather than :T incase there are objects
in sub-dirs.
* lib.mk: leverage ${.SUFFIXES} when setting dependencies.
* add UPDATE_DEPENDFILE as a dependent option - follows
DIRDEPS_BUILD and use MK_UPDATE_DEPENDFILE as default for
UPDATE_DEPENDFILE when we think it should be yes.
This allows override with -DWITH[OUT]_UPDATE_DEPENDFILE
without overriding UPDATE_DEPENDFILE directly - which can lead to
trouble.
2025-05-16 Simon J Gerraty <sjg@beast.crufty.net>
* install-mk (MK_VERSION): 20250515
* meta2deps.py: resolve the target of a Move or Link first
and track the last path resolved, then if the src is a relative
path we can easily use that last path to resolve the src correctly.
* meta2deps.sh: for a Move or Link add the dir of target path to
the list used to resolve the src path.
Diffstat (limited to 'parse.c')
| -rw-r--r-- | parse.c | 90 |
1 files changed, 72 insertions, 18 deletions
@@ -1,4 +1,4 @@ -/* $NetBSD: parse.c,v 1.743 2025/04/13 09:34:43 rillig Exp $ */ +/* $NetBSD: parse.c,v 1.752 2025/06/16 18:20:00 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -110,7 +110,7 @@ #include "pathnames.h" /* "@(#)parse.c 8.3 (Berkeley) 3/19/94" */ -MAKE_RCSID("$NetBSD: parse.c,v 1.743 2025/04/13 09:34:43 rillig Exp $"); +MAKE_RCSID("$NetBSD: parse.c,v 1.752 2025/06/16 18:20:00 rillig Exp $"); /* Detects a multiple-inclusion guard in a makefile. */ typedef enum { @@ -130,7 +130,7 @@ typedef struct IncludedFile { unsigned forBodyReadLines; /* the number of physical lines that have * been read from the file above the body of * the .for loop */ - unsigned int condMinDepth; /* depth of nested 'if' directives, at the + unsigned condMinDepth; /* depth of nested 'if' directives, at the * beginning of the file */ bool depending; /* state of doing_depend on EOF */ @@ -342,7 +342,7 @@ CurFile(void) return GetInclude(includes.len - 1); } -unsigned int +unsigned CurFile_CondMinDepth(void) { return CurFile()->condMinDepth; @@ -372,7 +372,7 @@ LoadFile(const char *path, int fd) assert(buf.len < buf.cap); n = read(fd, buf.data + buf.len, buf.cap - buf.len); if (n < 0) { - Error("%s: read error: %s", path, strerror(errno)); + Error("%s: %s", path, strerror(errno)); exit(2); /* Not 1 so -q can distinguish error */ } if (n == 0) @@ -388,23 +388,43 @@ LoadFile(const char *path, int fd) return buf; /* may not be null-terminated */ } +const char * +GetParentStackTrace(void) +{ + static bool initialized; + static const char *parentStackTrace; + + if (!initialized) { + const char *env = getenv("MAKE_STACK_TRACE"); + parentStackTrace = env == NULL ? NULL + : env[0] == '\t' ? bmake_strdup(env) + : strcmp(env, "yes") == 0 ? bmake_strdup("") + : NULL; + initialized = true; + } + return parentStackTrace; +} + /* * Print the current chain of .include and .for directives. In Parse_Fatal * or other functions that already print the location, includingInnermost * would be redundant, but in other cases like Error or Fatal it needs to be * included. */ -void -PrintStackTrace(bool includingInnermost) +char * +GetStackTrace(bool includingInnermost) { + const char *parentStackTrace; + Buffer buffer, *buf = &buffer; const IncludedFile *entries; size_t i, n; + bool hasDetails; - bool hasDetails = EvalStack_PrintDetails(); - + Buf_Init(buf); + hasDetails = EvalStack_Details(buf); n = includes.len; if (n == 0) - return; + goto add_parent_stack_trace; entries = GetInclude(0); if (!includingInnermost && !(hasDetails && n > 1) @@ -424,16 +444,49 @@ PrintStackTrace(bool includingInnermost) if (entry->forLoop != NULL) { char *details = ForLoop_Details(entry->forLoop); - debug_printf("\tin .for loop from %s:%u with %s\n", - fname, entry->forHeadLineno, details); + Buf_AddStr(buf, "\tin .for loop from "); + Buf_AddStr(buf, fname); + Buf_AddStr(buf, ":"); + Buf_AddInt(buf, (int)entry->forHeadLineno); + Buf_AddStr(buf, " with "); + Buf_AddStr(buf, details); + Buf_AddStr(buf, "\n"); free(details); } else if (i + 1 < n && entries[i + 1].forLoop != NULL) { /* entry->lineno is not a useful line number */ - } else - debug_printf("\tin %s:%u\n", fname, entry->lineno); + } else { + Buf_AddStr(buf, "\tin "); + Buf_AddStr(buf, fname); + Buf_AddStr(buf, ":"); + Buf_AddInt(buf, (int)entry->lineno); + Buf_AddStr(buf, "\n"); + } + } + +add_parent_stack_trace: + parentStackTrace = GetParentStackTrace(); + if ((makelevel > 0 && (n > 0 || !includingInnermost)) + || parentStackTrace != NULL) { + Buf_AddStr(buf, "\tin "); + Buf_AddStr(buf, progname); + Buf_AddStr(buf, " in directory \""); + Buf_AddStr(buf, curdir); + Buf_AddStr(buf, "\"\n"); } - if (makelevel > 0) - debug_printf("\tin directory %s\n", curdir); + + if (parentStackTrace != NULL) + Buf_AddStr(buf, parentStackTrace); + + return Buf_DoneData(buf); +} + +void +PrintStackTrace(bool includingInnermost) +{ + char *stackTrace = GetStackTrace(includingInnermost); + fprintf(stderr, "%s", stackTrace); + fflush(stderr); + free(stackTrace); } /* Check if the current character is escaped on the current line. */ @@ -547,7 +600,8 @@ ParseVErrorInternal(FILE *f, bool useVars, const GNode *gn, parseErrors++; } - if (level == PARSE_FATAL || DEBUG(PARSE)) + if (level == PARSE_FATAL || DEBUG(PARSE) + || (gn == NULL && includes.len == 0 /* see PrintLocation */)) PrintStackTrace(false); } @@ -713,7 +767,7 @@ TryApplyDependencyOperator(GNode *gn, GNodeType op) cohort->centurion = gn; gn->unmade_cohorts++; snprintf(cohort->cohort_num, sizeof cohort->cohort_num, "#%d", - (unsigned int)gn->unmade_cohorts % 1000000); + (unsigned)gn->unmade_cohorts % 1000000); } else { gn->type |= op; /* preserve any previous flags */ } |
