Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/xlint Add -R (source filename remapping) for MKREPRO



details:   https://anonhg.NetBSD.org/src/rev/8c6c7802e107
branches:  trunk
changeset: 349815:8c6c7802e107
user:      christos <christos%NetBSD.org@localhost>
date:      Sat Dec 24 17:43:45 2016 +0000

description:
Add -R (source filename remapping) for MKREPRO

diffstat:

 usr.bin/xlint/lint1/externs1.h |   4 ++-
 usr.bin/xlint/lint1/main1.c    |  10 ++++++--
 usr.bin/xlint/lint1/mem1.c     |  47 +++++++++++++++++++++++++++++++++++++++--
 usr.bin/xlint/lint1/scan.l     |   7 +++--
 usr.bin/xlint/xlint/lint.1     |  11 ++++++++-
 usr.bin/xlint/xlint/xlint.c    |  14 ++++++++----
 6 files changed, 76 insertions(+), 17 deletions(-)

diffs (248 lines):

diff -r fe62071bdc4a -r 8c6c7802e107 usr.bin/xlint/lint1/externs1.h
--- a/usr.bin/xlint/lint1/externs1.h    Sat Dec 24 17:36:59 2016 +0000
+++ b/usr.bin/xlint/lint1/externs1.h    Sat Dec 24 17:43:45 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: externs1.h,v 1.32 2014/04/18 00:23:46 christos Exp $   */
+/*     $NetBSD: externs1.h,v 1.33 2016/12/24 17:43:45 christos Exp $   */
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -96,6 +96,8 @@
 extern const   char *fnalloc(const char *);
 extern const   char *fnnalloc(const char *, size_t);
 extern int     getfnid(const char *);
+extern void    fnaddreplsrcdir(char *);
+extern const char *fnxform(const char *, size_t);
 
 extern void    initmem(void);
 
diff -r fe62071bdc4a -r 8c6c7802e107 usr.bin/xlint/lint1/main1.c
--- a/usr.bin/xlint/lint1/main1.c       Sat Dec 24 17:36:59 2016 +0000
+++ b/usr.bin/xlint/lint1/main1.c       Sat Dec 24 17:43:45 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: main1.c,v 1.25 2014/04/18 21:53:44 christos Exp $      */
+/*     $NetBSD: main1.c,v 1.26 2016/12/24 17:43:45 christos Exp $      */
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: main1.c,v 1.25 2014/04/18 21:53:44 christos Exp $");
+__RCSID("$NetBSD: main1.c,v 1.26 2016/12/24 17:43:45 christos Exp $");
 #endif
 
 #include <sys/types.h>
@@ -176,7 +176,7 @@
        setprogname(argv[0]);
 
        ERR_ZERO(&msgset);
-       while ((c = getopt(argc, argv, "abcdeghmprstuvwyzFPSX:")) != -1) {
+       while ((c = getopt(argc, argv, "abcdeghmprstuvwyzFPR:SX:")) != -1) {
                switch (c) {
                case 'a':       aflag++;        break;
                case 'b':       bflag = 1;      break;
@@ -202,6 +202,10 @@
                        msglist();
                        return(0);
 
+               case 'R':       
+                       fnaddreplsrcdir(optarg);
+                       break;
+
                case 'X':
                        for (ptr = strtok(optarg, ","); ptr;
                            ptr = strtok(NULL, ",")) {
diff -r fe62071bdc4a -r 8c6c7802e107 usr.bin/xlint/lint1/mem1.c
--- a/usr.bin/xlint/lint1/mem1.c        Sat Dec 24 17:36:59 2016 +0000
+++ b/usr.bin/xlint/lint1/mem1.c        Sat Dec 24 17:43:45 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mem1.c,v 1.17 2014/04/18 00:21:14 christos Exp $       */
+/*     $NetBSD: mem1.c,v 1.18 2016/12/24 17:43:45 christos Exp $       */
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: mem1.c,v 1.17 2014/04/18 00:21:14 christos Exp $");
+__RCSID("$NetBSD: mem1.c,v 1.18 2016/12/24 17:43:45 christos Exp $");
 #endif
 
 #include <sys/types.h>
@@ -87,6 +87,47 @@
        return (s != NULL ? fnnalloc(s, strlen(s)) : NULL);
 }
 
+struct repl {
+       char *orig;
+       char *repl;
+       size_t len;
+       struct repl *next;
+};
+
+struct repl *replist;
+
+void
+fnaddreplsrcdir(char *arg)
+{
+       struct repl *r = xmalloc(sizeof(*r));
+       
+       r->orig = arg;
+       if ((r->repl = strchr(arg, '=')) == NULL) 
+               err(1, "Bad replacement directory spec `%s'", arg);
+       r->len = r->repl - r->orig;
+       *(r->repl)++ = '\0';
+       if (replist == NULL) {
+               r->next = NULL;
+       } else
+               r->next = replist;
+       replist = r;
+}
+
+const char *
+fnxform(const char *name, size_t len)
+{
+       static char buf[MAXPATHLEN];
+       struct repl *r;
+
+       for (r = replist; r; r = r->next)
+               if (r->len < len && memcmp(name, r->orig, r->len) == 0)
+                       break;
+       if (r == NULL)
+               return name;
+       snprintf(buf, sizeof(buf), "%s%s", r->repl, name + r->len);
+       return buf;
+}
+
 const char *
 fnnalloc(const char *s, size_t len)
 {
@@ -111,7 +152,7 @@
                outclr();
                outint(fn->fn_id);
                outchar('s');
-               outstrg(fn->fn_name);
+               outstrg(fnxform(fn->fn_name, fn->fn_len));
        }
        return (fn->fn_name);
 }
diff -r fe62071bdc4a -r 8c6c7802e107 usr.bin/xlint/lint1/scan.l
--- a/usr.bin/xlint/lint1/scan.l        Sat Dec 24 17:36:59 2016 +0000
+++ b/usr.bin/xlint/lint1/scan.l        Sat Dec 24 17:43:45 2016 +0000
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: scan.l,v 1.67 2016/11/05 01:09:30 christos Exp $ */
+/* $NetBSD: scan.l,v 1.68 2016/12/24 17:43:45 christos Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -35,7 +35,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: scan.l,v 1.67 2016/11/05 01:09:30 christos Exp $");
+__RCSID("$NetBSD: scan.l,v 1.68 2016/12/24 17:43:45 christos Exp $");
 #endif
 
 #include <stdlib.h>
@@ -1117,7 +1117,8 @@
                 */
                if (first) {
                        csrc_pos.p_file = curr_pos.p_file;
-                       outsrc(curr_pos.p_file);
+                       outsrc(fnxform(curr_pos.p_file,
+                           strlen(curr_pos.p_file)));
                        first = 0;
                }
        }
diff -r fe62071bdc4a -r 8c6c7802e107 usr.bin/xlint/xlint/lint.1
--- a/usr.bin/xlint/xlint/lint.1        Sat Dec 24 17:36:59 2016 +0000
+++ b/usr.bin/xlint/xlint/lint.1        Sat Dec 24 17:43:45 2016 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: lint.1,v 1.37 2013/04/19 18:51:14 christos Exp $
+.\" $NetBSD: lint.1,v 1.38 2016/12/24 17:43:45 christos Exp $
 .\"
 .\" Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
 .\" Copyright (c) 1994, 1995 Jochen Pohl
@@ -30,7 +30,7 @@
 .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd April 19, 2013
+.Dd December 24, 2016
 .Dt LINT 1
 .Os
 .Sh NAME
@@ -60,6 +60,7 @@
 .Op Fl D Ar name Ns Op =def
 .Op Fl d Ar directory
 .Op Fl I Ar directory
+.Op Fl R Ar old=new
 .Op Fl MD
 .Op Fl U Ar name
 .Op Fl X Ar id Ns Op ,id ...
@@ -347,6 +348,12 @@
 .It Fl r
 In case of redeclarations report the position of the
 previous declaration.
+.It Fl R Ar old=new
+Remap 
+.Ar old
+directory prefixes to
+.Ar new
+for reproducible builds.
 .It Fl S
 C9X mode.
 Currently not fully implemented.
diff -r fe62071bdc4a -r 8c6c7802e107 usr.bin/xlint/xlint/xlint.c
--- a/usr.bin/xlint/xlint/xlint.c       Sat Dec 24 17:36:59 2016 +0000
+++ b/usr.bin/xlint/xlint/xlint.c       Sat Dec 24 17:43:45 2016 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: xlint.c,v 1.45 2016/09/05 00:40:30 sevan Exp $ */
+/* $NetBSD: xlint.c,v 1.46 2016/12/24 17:43:45 christos 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.45 2016/09/05 00:40:30 sevan Exp $");
+__RCSID("$NetBSD: xlint.c,v 1.46 2016/12/24 17:43:45 christos Exp $");
 #endif
 
 #include <sys/param.h>
@@ -298,8 +298,8 @@
        (void)fprintf(stderr,
            "       %s [-abceghprvwzHFS] [|-s|-t] -Clibrary [-Dname[=def]]\n"
            " [-X <id>[,<id>]...\n", getprogname());
-       (void)fprintf(stderr, "\t[-Idirectory] [-Uname] [-Bpath] file"
-           " ...\n");
+       (void)fprintf(stderr, "\t[-Idirectory] [-Uname] [-Bpath] [-R old=new]"
+           " file ...\n");
        terminate(-1);
 }
 
@@ -368,7 +368,7 @@
        (void)signal(SIGINT, terminate);
        (void)signal(SIGQUIT, terminate);
        (void)signal(SIGTERM, terminate);
-       while ((c = getopt(argc, argv, "abcd:eghil:no:prstuvwxzB:C:D:FHI:L:M:PSU:VX:")) != -1) {
+       while ((c = getopt(argc, argv, "abcd:eghil:no:prstuvwxzB:C:D:FHI:L:M:PR:SU:VX:")) != -1) {
                switch (c) {
 
                case 'a':
@@ -423,6 +423,10 @@
                        appcstrg(&l1flags, "-P");
                        break;
 
+               case 'R':
+                       appcstrg(&l1flags, concat2("-R", optarg));
+                       break;
+
                case 's':
                        if (tflag)
                                usage();



Home | Main Index | Thread Index | Old Index