Module Name:    src
Committed By:   rillig
Date:           Sun May  2 21:05:42 UTC 2021

Modified Files:
        src/usr.bin/xlint/xlint: lint.1 xlint.c

Log Message:
lint: on request, keep the preprocessor output

Previously, the simplest way of getting the preprocessed translation
unit was to run lint with the additional flag -V, which outputs the
command line of the C preprocessor, among other things.  That command
line does not include the proper quoting though, so it cannot be used
verbatim as a shell command if the command line contains spaces such as
in -Du64="unsigned long long".

In the common situation where lint is run via a Makefile, the option -V
had to be added in the Makefile itself since there is no make variable
for additional user-settable lint flags.  This is not straight-forward
enough.

Adding another command line option for this purpose would reduce the
remaining namespace for options.  Most of the 52 letters are already
used up.

To make this situation as simple as possible, preserve the output of the
C preprocessor depending on an environment variable.


To generate a diff of this commit:
cvs rdiff -u -r1.43 -r1.44 src/usr.bin/xlint/xlint/lint.1
cvs rdiff -u -r1.62 -r1.63 src/usr.bin/xlint/xlint/xlint.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/xlint/xlint/lint.1
diff -u src/usr.bin/xlint/xlint/lint.1:1.43 src/usr.bin/xlint/xlint/lint.1:1.44
--- src/usr.bin/xlint/xlint/lint.1:1.43	Wed Apr 14 20:06:40 2021
+++ src/usr.bin/xlint/xlint/lint.1	Sun May  2 21:05:42 2021
@@ -1,4 +1,4 @@
-.\" $NetBSD: lint.1,v 1.43 2021/04/14 20:06:40 rillig Exp $
+.\" $NetBSD: lint.1,v 1.44 2021/05/02 21:05:42 rillig Exp $
 .\"
 .\" Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
 .\" Copyright (c) 1994, 1995 Jochen Pohl
@@ -579,6 +579,11 @@ option must exist.
 If this environment variable is undefined, then the default path
 .Pa /usr/libdata/lint
 will be used to search for the libraries.
+.It Ev LINT_KEEP_CPPOUT_ON_ERROR
+If
+.Nm
+exits unsuccessfully, do no delete the output from the C preprocessor,
+allowing for manual inspection.
 .It Ev TMPDIR
 Usually the path for temporary files can be redefined by setting
 this environment variable.

Index: src/usr.bin/xlint/xlint/xlint.c
diff -u src/usr.bin/xlint/xlint/xlint.c:1.62 src/usr.bin/xlint/xlint/xlint.c:1.63
--- src/usr.bin/xlint/xlint/xlint.c:1.62	Sun Apr 18 22:51:25 2021
+++ src/usr.bin/xlint/xlint/xlint.c	Sun May  2 21:05:42 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: xlint.c,v 1.62 2021/04/18 22:51:25 rillig Exp $ */
+/* $NetBSD: xlint.c,v 1.63 2021/05/02 21:05:42 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -38,7 +38,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: xlint.c,v 1.62 2021/04/18 22:51:25 rillig Exp $");
+__RCSID("$NetBSD: xlint.c,v 1.63 2021/05/02 21:05:42 rillig Exp $");
 #endif
 
 #include <sys/param.h>
@@ -260,8 +260,13 @@ terminate(int signo)
 
 	if (cppoutfd != -1)
 		(void)close(cppoutfd);
-	if (cppout != NULL)
-		(void)remove(cppout);
+	if (cppout != NULL) {
+		if (signo != 0 && getenv("LINT_KEEP_CPPOUT_ON_ERROR") != NULL)
+			printf("lint: preprocessor output kept in %s\n",
+			    cppout);
+		else
+			(void)remove(cppout);
+	}
 
 	if (p1out != NULL) {
 		for (i = 0; p1out[i] != NULL; i++)

Reply via email to