Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/xlint/xlint lint: on request, keep the preprocessor ...



details:   https://anonhg.NetBSD.org/src/rev/44cbe147c371
branches:  trunk
changeset: 1021017:44cbe147c371
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun May 02 21:05:42 2021 +0000

description:
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.

diffstat:

 usr.bin/xlint/xlint/lint.1  |   7 ++++++-
 usr.bin/xlint/xlint/xlint.c |  13 +++++++++----
 2 files changed, 15 insertions(+), 5 deletions(-)

diffs (55 lines):

diff -r 0d330c304c42 -r 44cbe147c371 usr.bin/xlint/xlint/lint.1
--- a/usr.bin/xlint/xlint/lint.1        Sun May 02 20:53:13 2021 +0000
+++ b/usr.bin/xlint/xlint/lint.1        Sun May 02 21:05:42 2021 +0000
@@ -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 @@
 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.
diff -r 0d330c304c42 -r 44cbe147c371 usr.bin/xlint/xlint/xlint.c
--- a/usr.bin/xlint/xlint/xlint.c       Sun May 02 20:53:13 2021 +0000
+++ b/usr.bin/xlint/xlint/xlint.c       Sun May 02 21:05:42 2021 +0000
@@ -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 @@
 
        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++)



Home | Main Index | Thread Index | Old Index