make: add missing newline after "cannot continue" message

It was wrong of Parse_File to output an unfinished line and hope for
some other code to finish it.  As demonstrated in the test, PrintOnError
did not do that in the case of additional debug output.

To keep the overall behavior as close as possible to before, the other
callers of PrintOnError now have to pass the newline themselves. Passing
strings that start with newlines but don't end with them looked
suspicious anyway.
This commit is contained in:
rillig 2022-01-22 18:59:23 +00:00
parent c7d1780dbb
commit 2aba30c909
6 changed files with 28 additions and 31 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: compat.c,v 1.237 2022/01/08 09:53:44 rillig Exp $ */
/* $NetBSD: compat.c,v 1.238 2022/01/22 18:59:23 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.237 2022/01/08 09:53:44 rillig Exp $");
MAKE_RCSID("$NetBSD: compat.c,v 1.238 2022/01/22 18:59:23 rillig Exp $");
static GNode *curTarg = NULL;
static pid_t compatChild;
@ -583,7 +583,7 @@ MakeUnmade(GNode *gn, GNode *pgn)
} else if (opts.keepgoing) {
pgn->flags.remake = false;
} else {
PrintOnError(gn, "\nStop.");
PrintOnError(gn, "\nStop.\n");
exit(1);
}
return true;
@ -671,7 +671,7 @@ MakeBeginNode(void)
Compat_Make(gn, gn);
if (GNode_IsError(gn)) {
PrintOnError(gn, "\nStop.");
PrintOnError(gn, "\nStop.\n");
exit(1);
}
}
@ -748,7 +748,7 @@ Compat_Run(GNodeList *targs)
Targ_PrintGraph(2);
else if (DEBUG(GRAPH3))
Targ_PrintGraph(3);
PrintOnError(errorNode, "\nStop.");
PrintOnError(errorNode, "\nStop.\n");
exit(1);
}
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: job.c,v 1.448 2022/01/08 09:53:44 rillig Exp $ */
/* $NetBSD: job.c,v 1.449 2022/01/22 18:59:23 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@ -142,7 +142,7 @@
#include "trace.h"
/* "@(#)job.c 8.2 (Berkeley) 3/19/94" */
MAKE_RCSID("$NetBSD: job.c,v 1.448 2022/01/08 09:53:44 rillig Exp $");
MAKE_RCSID("$NetBSD: job.c,v 1.449 2022/01/22 18:59:23 rillig Exp $");
/*
* A shell defines how the commands are run. All commands for a target are
@ -1108,7 +1108,7 @@ JobFinishDoneExitedError(Job *job, int *inout_status)
else {
if (deleteOnError)
JobDeleteTarget(job->node);
PrintOnError(job->node, NULL);
PrintOnError(job->node, "\n");
}
}
@ -1685,7 +1685,7 @@ JobStart(GNode *gn, bool special)
* also dead...
*/
if (!cmdsOK) {
PrintOnError(gn, NULL); /* provide some clue */
PrintOnError(gn, "\n"); /* provide some clue */
DieHorribly();
}
} else if (((gn->type & OP_MAKE) && !opts.noRecursiveExecute) ||
@ -1702,7 +1702,7 @@ JobStart(GNode *gn, bool special)
* also dead...
*/
if (!cmdsOK) {
PrintOnError(gn, NULL); /* provide some clue */
PrintOnError(gn, "\n"); /* provide some clue */
DieHorribly();
}
@ -1986,7 +1986,7 @@ JobRun(GNode *targ)
Compat_Make(targ, targ);
/* XXX: Replace with GNode_IsError(gn) */
if (targ->made == ERROR) {
PrintOnError(targ, "\n\nStop.");
PrintOnError(targ, "\n\nStop.\n");
exit(1);
}
#endif
@ -2951,7 +2951,7 @@ Job_RunTarget(const char *target, const char *fname)
JobRun(gn);
/* XXX: Replace with GNode_IsError(gn) */
if (gn->made == ERROR) {
PrintOnError(gn, "\n\nStop.");
PrintOnError(gn, "\n\nStop.\n");
exit(1);
}
return true;

View File

@ -1,4 +1,4 @@
/* $NetBSD: main.c,v 1.574 2022/01/22 16:24:45 rillig Exp $ */
/* $NetBSD: main.c,v 1.575 2022/01/22 18:59:23 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@ -111,7 +111,7 @@
#include "trace.h"
/* "@(#)main.c 8.3 (Berkeley) 3/19/94" */
MAKE_RCSID("$NetBSD: main.c,v 1.574 2022/01/22 16:24:45 rillig Exp $");
MAKE_RCSID("$NetBSD: main.c,v 1.575 2022/01/22 18:59:23 rillig Exp $");
#if defined(MAKE_NATIVE) && !defined(lint)
__COPYRIGHT("@(#) Copyright (c) 1988, 1989, 1990, 1993 "
"The Regents of the University of California. "
@ -1829,7 +1829,7 @@ Fatal(const char *fmt, ...)
(void)fprintf(stderr, "\n");
(void)fflush(stderr);
PrintOnError(NULL, NULL);
PrintOnError(NULL, "\n");
if (DEBUG(GRAPH2) || DEBUG(GRAPH3))
Targ_PrintGraph(2);
@ -1854,7 +1854,7 @@ Punt(const char *fmt, ...)
(void)fprintf(stderr, "\n");
(void)fflush(stderr);
PrintOnError(NULL, NULL);
PrintOnError(NULL, "\n");
DieHorribly();
}
@ -2045,9 +2045,7 @@ PrintOnError(GNode *gn, const char *msg)
if (errorNode != NULL)
return; /* we've been here! */
if (msg != NULL)
printf("%s", msg);
printf("\n%s: stopped in %s\n", progname, curdir);
printf("%s%s: stopped in %s\n", msg, progname, curdir);
/* we generally want to keep quiet if a sub-make died */
if (shouldDieQuietly(gn, -1))

View File

@ -1,4 +1,4 @@
/* $NetBSD: parse.c,v 1.654 2022/01/22 16:24:45 rillig Exp $ */
/* $NetBSD: parse.c,v 1.655 2022/01/22 18:59:23 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@ -106,7 +106,7 @@
#include "pathnames.h"
/* "@(#)parse.c 8.3 (Berkeley) 3/19/94" */
MAKE_RCSID("$NetBSD: parse.c,v 1.654 2022/01/22 16:24:45 rillig Exp $");
MAKE_RCSID("$NetBSD: parse.c,v 1.655 2022/01/22 18:59:23 rillig Exp $");
/*
* A file being read.
@ -548,7 +548,7 @@ HandleMessage(ParseErrorLevel level, const char *levelName, const char *umsg)
free(xmsg);
if (level == PARSE_FATAL) {
PrintOnError(NULL, NULL);
PrintOnError(NULL, "\n");
exit(1);
}
}
@ -2850,9 +2850,9 @@ Parse_File(const char *name, int fd)
if (parseErrors != 0) {
(void)fflush(stdout);
(void)fprintf(stderr,
"%s: Fatal errors encountered -- cannot continue",
"%s: Fatal errors encountered -- cannot continue\n",
progname);
PrintOnError(NULL, NULL);
PrintOnError(NULL, "");
exit(1);
}
}

View File

@ -1,6 +1,6 @@
make: "opt-debug-hash.mk" line 9: Missing argument for ".error"
make: Fatal errors encountered -- cannot continueHashTable targets: size=16 numEntries=0 maxchain=0
make: "opt-debug-hash.mk" line 11: Missing argument for ".error"
make: Fatal errors encountered -- cannot continue
HashTable targets: size=16 numEntries=0 maxchain=0
HashTable Global variables: size=16 numEntries=23 maxchain=3
make: stopped in unit-tests
exit status 1

View File

@ -1,4 +1,4 @@
# $NetBSD: opt-debug-hash.mk,v 1.2 2022/01/22 17:10:51 rillig Exp $
# $NetBSD: opt-debug-hash.mk,v 1.3 2022/01/22 18:59:24 rillig Exp $
#
# Tests for the -dh command line option, which adds debug logging for
# hash tables. Even more detailed logging is available by compiling
@ -6,7 +6,6 @@
.MAKEFLAGS: -dh
# Force a parse error, to demonstrate the newline character in the diagnostic
# that had been missing before parse.c 1.655 from 2022-01-22.
.error
# FIXME: There is a newline missing between 'continueHashTable'.
# expect: make: Fatal errors encountered -- cannot continueHashTable targets: size=16 numEntries=0 maxchain=0