Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/config Sort files in ${ALLFILES} in the order of par...



details:   https://anonhg.NetBSD.org/src/rev/a64d77c0e017
branches:  trunk
changeset: 810571:a64d77c0e017
user:      uebayasi <uebayasi%NetBSD.org@localhost>
date:      Fri Sep 04 10:16:35 2015 +0000

description:
Sort files in ${ALLFILES} in the order of parsing of `files.*'.

config(1) reads the first `files.${MACHINE}' when it encounters `machine'.
Then it includes common `files.${MACHINE_SUBARCH}', `files.${MACHINE_ARCH}',
and MI `sys/conf/files' at last.  This change makes the first "file" in
`files.${MACHINE}' appear first in ${ALLFILES}.

diffstat:

 usr.bin/config/defs.h       |   7 ++++++-
 usr.bin/config/files.c      |  41 +++++++++++++++++++++++++++++++++++++++--
 usr.bin/config/mkmakefile.c |  18 +++++++++---------
 usr.bin/config/scan.l       |   9 +++++++--
 4 files changed, 61 insertions(+), 14 deletions(-)

diffs (249 lines):

diff -r 782de5b374c7 -r a64d77c0e017 usr.bin/config/defs.h
--- a/usr.bin/config/defs.h     Fri Sep 04 09:18:11 2015 +0000
+++ b/usr.bin/config/defs.h     Fri Sep 04 10:16:35 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: defs.h,v 1.92 2015/09/04 06:10:47 uebayasi Exp $       */
+/*     $NetBSD: defs.h,v 1.93 2015/09/04 10:16:35 uebayasi Exp $       */
 
 /*
  * Copyright (c) 1992, 1993
@@ -353,6 +353,7 @@
        struct nvlist *fi_optf; /* flattened version of above, if needed */
        const char *fi_mkrule;  /* special make rule, if any */
        struct attr *fi_attr;   /* owner attr */
+       int fi_order;           /* score of order in ${ALLFILES} */
        TAILQ_ENTRY(files) fi_anext;    /* next file in attr */
 };
 
@@ -362,6 +363,9 @@
 #define        FI_NEEDSFLAG    0x04    /* needs-flag */
 #define        FI_HIDDEN       0x08    /* obscured by other(s), base names overlap */
 
+extern size_t nselfiles;
+extern struct files **selfiles;
+
 /*
  * Condition expressions.
  */
@@ -613,6 +617,7 @@
 int    firstfile(const char *);
 void   package(const char *);
 int    include(const char *, int, int, int);
+extern int includedepth;
 
 /* sem.c, other than for yacc actions */
 void   initsem(void);
diff -r 782de5b374c7 -r a64d77c0e017 usr.bin/config/files.c
--- a/usr.bin/config/files.c    Fri Sep 04 09:18:11 2015 +0000
+++ b/usr.bin/config/files.c    Fri Sep 04 10:16:35 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: files.c,v 1.32 2015/09/04 06:01:40 uebayasi Exp $      */
+/*     $NetBSD: files.c,v 1.33 2015/09/04 10:16:35 uebayasi Exp $      */
 
 /*
  * Copyright (c) 1992, 1993
@@ -45,7 +45,7 @@
 #endif
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: files.c,v 1.32 2015/09/04 06:01:40 uebayasi Exp $");
+__RCSID("$NetBSD: files.c,v 1.33 2015/09/04 10:16:35 uebayasi Exp $");
 
 #include <sys/param.h>
 #include <errno.h>
@@ -57,6 +57,10 @@
 
 extern const char *yyfile;
 
+int nallfiles;
+size_t nselfiles;
+struct files **selfiles;
+
 /*
  * We check that each full path name is unique.  File base names
  * should generally also be unique, e.g., having both a net/xx.c and
@@ -181,6 +185,7 @@
        fi->fi_optf = NULL;
        fi->fi_mkrule = rule;
        fi->fi_attr = NULL;
+       fi->fi_order = (int)nallfiles + (includedepth << 16);
        switch (fi->fi_suffix) {
        case 'c':
                TAILQ_INSERT_TAIL(&allcfiles, fi, fi_snext);
@@ -202,6 +207,8 @@
                    "unknown suffix");
                break;
        }
+       CFGDBG(3, "file added `%s' at order score %d", fi->fi_path, fi->fi_order);
+       nallfiles++;
        return;
  bad:
        if (optx != NULL) {
@@ -263,6 +270,21 @@
        return (0);
 }
 
+static int
+cmpfiles(const void *a, const void *b)
+{
+       const struct files * const *fia = a, * const *fib = b;
+       int sa = (*fia)->fi_order;
+       int sb = (*fib)->fi_order;
+
+       if (sa < sb)
+               return -1;
+       else if (sa > sb)
+               return 1;
+       else
+               return 0;
+}
+
 /*
  * We have finished reading everything.  Tack the files down: calculate
  * selection and counts as needed.  Check that the object files built
@@ -277,6 +299,9 @@
        struct config *cf;
        char swapname[100];
 
+       /* Place these files at last. */
+       int onallfiles = nallfiles;
+       nallfiles = 1 << 30;
        addfile("devsw.c", NULL, 0, NULL);
        addfile("ioconf.c", NULL, 0, NULL);
 
@@ -285,6 +310,7 @@
                    cf->cf_name);
                addfile(intern(swapname), NULL, 0, NULL);
        }
+       nallfiles = onallfiles;
 
        err = 0;
        TAILQ_FOREACH(fi, &allfiles, fi_next) {
@@ -334,6 +360,7 @@
                        }
                }
                fi->fi_flags |= FI_SEL;
+               nselfiles++;
                CFGDBG(3, "file selected `%s'", fi->fi_path);
 
                /* Add other files to the default "netbsd" attribute. */
@@ -343,6 +370,16 @@
                CFGDBG(3, "file `%s' belongs to attr `%s'", fi->fi_path,
                    fi->fi_attr->a_name);
        }
+
+       /* Order files. */
+       selfiles = malloc(nselfiles * sizeof(fi));
+       int i = 0;
+       TAILQ_FOREACH(fi, &allfiles, fi_next) {
+               if ((fi->fi_flags & FI_SEL) == 0)
+                       continue;
+               selfiles[i++] = fi;
+       }
+       qsort(selfiles, nselfiles, (unsigned)sizeof(fi), cmpfiles);
        return (err);
 }
 
diff -r 782de5b374c7 -r a64d77c0e017 usr.bin/config/mkmakefile.c
--- a/usr.bin/config/mkmakefile.c       Fri Sep 04 09:18:11 2015 +0000
+++ b/usr.bin/config/mkmakefile.c       Fri Sep 04 10:16:35 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mkmakefile.c,v 1.67 2015/09/04 06:10:47 uebayasi Exp $ */
+/*     $NetBSD: mkmakefile.c,v 1.68 2015/09/04 10:16:35 uebayasi Exp $ */
 
 /*
  * Copyright (c) 1992, 1993
@@ -45,7 +45,7 @@
 #endif
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: mkmakefile.c,v 1.67 2015/09/04 06:10:47 uebayasi Exp $");
+__RCSID("$NetBSD: mkmakefile.c,v 1.68 2015/09/04 10:16:35 uebayasi Exp $");
 
 #include <sys/param.h>
 #include <ctype.h>
@@ -470,13 +470,13 @@
 {
        struct files *fi;
        static int called;
+       int i;
        int found = 0;
 
        if (called++ != 0)
                return;
-       TAILQ_FOREACH(fi, &allfiles, fi_next) {
-               if ((fi->fi_flags & FI_SEL) == 0)
-                       continue;
+       for (i = 0; i < (int)nselfiles; i++) {
+               fi = selfiles[i];
                if (found++ == 0)
                        fprintf(fp, "ALLFILES= \\\n");
                putc('\t', fp);
@@ -493,18 +493,18 @@
 emitrules(FILE *fp)
 {
        struct files *fi;
+       int i;
        int found = 0;
 
-       TAILQ_FOREACH(fi, &allfiles, fi_next) {
-               if ((fi->fi_flags & FI_SEL) == 0)
-                       continue;
+       for (i = 0; i < (int)nselfiles; i++) {
+               fi = selfiles[i];
                if (fi->fi_mkrule == NULL)
                        continue;
                fprintf(fp, "%s.o: ", fi->fi_base);
                emitfile(fp, fi);
                putc('\n', fp);
                fprintf(fp, "\t%s\n\n", fi->fi_mkrule);
-               found = 1;
+               found++;
        }
        if (found == 0)
                fprintf(fp, "#%%RULES\n");
diff -r 782de5b374c7 -r a64d77c0e017 usr.bin/config/scan.l
--- a/usr.bin/config/scan.l     Fri Sep 04 09:18:11 2015 +0000
+++ b/usr.bin/config/scan.l     Fri Sep 04 10:16:35 2015 +0000
@@ -1,5 +1,5 @@
 %{
-/*     $NetBSD: scan.l,v 1.24 2015/09/01 13:42:48 uebayasi Exp $       */
+/*     $NetBSD: scan.l,v 1.25 2015/09/04 10:16:35 uebayasi Exp $       */
 
 /*
  * Copyright (c) 1992, 1993
@@ -42,7 +42,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: scan.l,v 1.24 2015/09/01 13:42:48 uebayasi Exp $");
+__RCSID("$NetBSD: scan.l,v 1.25 2015/09/04 10:16:35 uebayasi Exp $");
 
 #include <sys/param.h>
 #include <errno.h>
@@ -476,6 +476,8 @@
        free(fname2);
 }
 
+int includedepth;
+
 /*
  * Open the named file for inclusion at the current point.  Returns 0 on
  * success (file opened and previous state pushed), nonzero on failure
@@ -537,6 +539,7 @@
        yyfile = intern(s);
        yyline = 1;
        free(s);
+       includedepth++;
        return (0);
 }
 
@@ -599,6 +602,8 @@
        interesting = in->in_interesting;
        free(in);
 
+       includedepth--;
+
        return (ateof);
 }
 



Home | Main Index | Thread Index | Old Index