Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/make make: use shortcut functions Global_SetExpand a...



details:   https://anonhg.NetBSD.org/src/rev/b99d4eb321e0
branches:  trunk
changeset: 959168:b99d4eb321e0
user:      rillig <rillig%NetBSD.org@localhost>
date:      Wed Feb 03 08:00:36 2021 +0000

description:
make: use shortcut functions Global_SetExpand and Global_AppendExpand

There are many places where global variables are set or appended to.  To
reduce clutter and code size, encode the VAR_GLOBAL in the function
name.

The word Expand in the function names says that the variable name is
expanded.  In most of the cases, this is not necessary, but there are no
corresponding functions Global_Set or Global_Append yet.

Encoding the information whether the name is expanded or not in the
function name will make inconsistencies obvious in future manual code
reviews. Letting the compiler check this by using different types for
unexpanded and expanded variable names is probably not worth the effort.
There are still a few bugs to be fixed, such as in SetVar, which expands
the variable name twice in a row.

diffstat:

 usr.bin/make/dir.c     |   16 +++---
 usr.bin/make/job.c     |   10 ++--
 usr.bin/make/main.c    |  122 ++++++++++++++++++++++++------------------------
 usr.bin/make/meta.c    |   38 +++++++-------
 usr.bin/make/nonints.h |    4 +-
 usr.bin/make/parse.c   |   16 +++---
 usr.bin/make/suff.c    |    8 +-
 usr.bin/make/targ.c    |    6 +-
 usr.bin/make/util.c    |    6 +-
 usr.bin/make/var.c     |   22 ++++++--
 10 files changed, 131 insertions(+), 117 deletions(-)

diffs (truncated from 786 to 300 lines):

diff -r e0e5fd66cb83 -r b99d4eb321e0 usr.bin/make/dir.c
--- a/usr.bin/make/dir.c        Wed Feb 03 06:58:22 2021 +0000
+++ b/usr.bin/make/dir.c        Wed Feb 03 08:00:36 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: dir.c,v 1.265 2021/01/30 20:53:29 rillig Exp $ */
+/*     $NetBSD: dir.c,v 1.266 2021/02/03 08:00:36 rillig Exp $ */
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -138,7 +138,7 @@
 #include "job.h"
 
 /*     "@(#)dir.c      8.2 (Berkeley) 1/2/94"  */
-MAKE_RCSID("$NetBSD: dir.c,v 1.265 2021/01/30 20:53:29 rillig Exp $");
+MAKE_RCSID("$NetBSD: dir.c,v 1.266 2021/02/03 08:00:36 rillig Exp $");
 
 /*
  * A search path is a list of CachedDir structures. A CachedDir has in it the
@@ -555,15 +555,15 @@
                CachedDir *dir = ln->datum;
                if (dir == dotLast) {
                        seenDotLast = TRUE;
-                       Var_Append(".PATH", dotLast->name, VAR_GLOBAL);
+                       Global_AppendExpand(".PATH", dotLast->name);
                }
        }
 
        if (!seenDotLast) {
                if (dot != NULL)
-                       Var_Append(".PATH", dot->name, VAR_GLOBAL);
+                       Global_AppendExpand(".PATH", dot->name);
                if (cur != NULL)
-                       Var_Append(".PATH", cur->name, VAR_GLOBAL);
+                       Global_AppendExpand(".PATH", cur->name);
        }
 
        for (ln = dirSearchPath.dirs.first; ln != NULL; ln = ln->next) {
@@ -572,14 +572,14 @@
                        continue;
                if (dir == dot && seenDotLast)
                        continue;
-               Var_Append(".PATH", dir->name, VAR_GLOBAL);
+               Global_AppendExpand(".PATH", dir->name);
        }
 
        if (seenDotLast) {
                if (dot != NULL)
-                       Var_Append(".PATH", dot->name, VAR_GLOBAL);
+                       Global_AppendExpand(".PATH", dot->name);
                if (cur != NULL)
-                       Var_Append(".PATH", cur->name, VAR_GLOBAL);
+                       Global_AppendExpand(".PATH", cur->name);
        }
 }
 
diff -r e0e5fd66cb83 -r b99d4eb321e0 usr.bin/make/job.c
--- a/usr.bin/make/job.c        Wed Feb 03 06:58:22 2021 +0000
+++ b/usr.bin/make/job.c        Wed Feb 03 08:00:36 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: job.c,v 1.412 2021/02/01 21:09:25 rillig Exp $ */
+/*     $NetBSD: job.c,v 1.413 2021/02/03 08:00:36 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.412 2021/02/01 21:09:25 rillig Exp $");
+MAKE_RCSID("$NetBSD: job.c,v 1.413 2021/02/03 08:00:36 rillig Exp $");
 
 /*
  * A shell defines how the commands are run.  All commands for a target are
@@ -2177,7 +2177,7 @@
        if (targPrefix != NULL) {
                free(targPrefix);
        } else if (!Var_Exists(MAKE_JOB_PREFIX, VAR_GLOBAL)) {
-               Var_Set(MAKE_JOB_PREFIX, "---", VAR_GLOBAL);
+               Global_SetExpand(MAKE_JOB_PREFIX, "---");
        }
 
        (void)Var_Subst("${" MAKE_JOB_PREFIX "}",
@@ -2791,8 +2791,8 @@
        snprintf(jobarg, sizeof jobarg, "%d,%d",
            tokenWaitJob.inPipe, tokenWaitJob.outPipe);
 
-       Var_Append(MAKEFLAGS, "-J", VAR_GLOBAL);
-       Var_Append(MAKEFLAGS, jobarg, VAR_GLOBAL);
+       Global_AppendExpand(MAKEFLAGS, "-J");
+       Global_AppendExpand(MAKEFLAGS, jobarg);
 
        /*
         * Preload the job pipe with one token per job, save the one
diff -r e0e5fd66cb83 -r b99d4eb321e0 usr.bin/make/main.c
--- a/usr.bin/make/main.c       Wed Feb 03 06:58:22 2021 +0000
+++ b/usr.bin/make/main.c       Wed Feb 03 08:00:36 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: main.c,v 1.526 2021/02/01 21:04:10 rillig Exp $        */
+/*     $NetBSD: main.c,v 1.527 2021/02/03 08:00:36 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.526 2021/02/01 21:04:10 rillig Exp $");
+MAKE_RCSID("$NetBSD: main.c,v 1.527 2021/02/03 08:00:36 rillig Exp $");
 #if defined(MAKE_NATIVE) && !defined(lint)
 __COPYRIGHT("@(#) Copyright (c) 1988, 1989, 1990, 1993 "
            "The Regents of the University of California.  "
@@ -409,8 +409,8 @@
                jp_1 = -1;
                opts.compatMake = TRUE;
        } else {
-               Var_Append(MAKEFLAGS, "-J", VAR_GLOBAL);
-               Var_Append(MAKEFLAGS, argvalue, VAR_GLOBAL);
+               Global_AppendExpand(MAKEFLAGS, "-J");
+               Global_AppendExpand(MAKEFLAGS, argvalue);
        }
 }
 
@@ -427,9 +427,9 @@
                    progname);
                exit(2);        /* Not 1 so -q can distinguish error */
        }
-       Var_Append(MAKEFLAGS, "-j", VAR_GLOBAL);
-       Var_Append(MAKEFLAGS, argvalue, VAR_GLOBAL);
-       Var_Set(".MAKE.JOBS", argvalue, VAR_GLOBAL);
+       Global_AppendExpand(MAKEFLAGS, "-j");
+       Global_AppendExpand(MAKEFLAGS, argvalue);
+       Global_SetExpand(".MAKE.JOBS", argvalue);
        maxJobTokens = opts.maxJobs;
 }
 
@@ -446,8 +446,8 @@
        } else {
                (void)SearchPath_Add(sysIncPath, argvalue);
        }
-       Var_Append(MAKEFLAGS, "-m", VAR_GLOBAL);
-       Var_Append(MAKEFLAGS, argvalue, VAR_GLOBAL);
+       Global_AppendExpand(MAKEFLAGS, "-m");
+       Global_AppendExpand(MAKEFLAGS, argvalue);
 }
 
 static Boolean
@@ -458,22 +458,22 @@
                break;
        case 'B':
                opts.compatMake = TRUE;
-               Var_Append(MAKEFLAGS, "-B", VAR_GLOBAL);
-               Var_Set(MAKE_MODE, "compat", VAR_GLOBAL);
+               Global_AppendExpand(MAKEFLAGS, "-B");
+               Global_SetExpand(MAKE_MODE, "compat");
                break;
        case 'C':
                MainParseArgChdir(argvalue);
                break;
        case 'D':
                if (argvalue[0] == '\0') return FALSE;
-               Var_Set(argvalue, "1", VAR_GLOBAL);
-               Var_Append(MAKEFLAGS, "-D", VAR_GLOBAL);
-               Var_Append(MAKEFLAGS, argvalue, VAR_GLOBAL);
+               Global_SetExpand(argvalue, "1");
+               Global_AppendExpand(MAKEFLAGS, "-D");
+               Global_AppendExpand(MAKEFLAGS, argvalue);
                break;
        case 'I':
                Parse_AddIncludeDir(argvalue);
-               Var_Append(MAKEFLAGS, "-I", VAR_GLOBAL);
-               Var_Append(MAKEFLAGS, argvalue, VAR_GLOBAL);
+               Global_AppendExpand(MAKEFLAGS, "-I");
+               Global_AppendExpand(MAKEFLAGS, argvalue);
                break;
        case 'J':
                MainParseArgJobsInternal(argvalue);
@@ -481,24 +481,24 @@
        case 'N':
                opts.noExecute = TRUE;
                opts.noRecursiveExecute = TRUE;
-               Var_Append(MAKEFLAGS, "-N", VAR_GLOBAL);
+               Global_AppendExpand(MAKEFLAGS, "-N");
                break;
        case 'S':
                opts.keepgoing = FALSE;
-               Var_Append(MAKEFLAGS, "-S", VAR_GLOBAL);
+               Global_AppendExpand(MAKEFLAGS, "-S");
                break;
        case 'T':
                tracefile = bmake_strdup(argvalue);
-               Var_Append(MAKEFLAGS, "-T", VAR_GLOBAL);
-               Var_Append(MAKEFLAGS, argvalue, VAR_GLOBAL);
+               Global_AppendExpand(MAKEFLAGS, "-T");
+               Global_AppendExpand(MAKEFLAGS, argvalue);
                break;
        case 'V':
        case 'v':
                opts.printVars = c == 'v' ? PVM_EXPANDED : PVM_UNEXPANDED;
                Lst_Append(&opts.variables, bmake_strdup(argvalue));
                /* XXX: Why always -V? */
-               Var_Append(MAKEFLAGS, "-V", VAR_GLOBAL);
-               Var_Append(MAKEFLAGS, argvalue, VAR_GLOBAL);
+               Global_AppendExpand(MAKEFLAGS, "-V");
+               Global_AppendExpand(MAKEFLAGS, argvalue);
                break;
        case 'W':
                opts.parseWarnFatal = TRUE;
@@ -506,35 +506,35 @@
                break;
        case 'X':
                opts.varNoExportEnv = TRUE;
-               Var_Append(MAKEFLAGS, "-X", VAR_GLOBAL);
+               Global_AppendExpand(MAKEFLAGS, "-X");
                break;
        case 'd':
                /* If '-d-opts' don't pass to children */
                if (argvalue[0] == '-')
                        argvalue++;
                else {
-                       Var_Append(MAKEFLAGS, "-d", VAR_GLOBAL);
-                       Var_Append(MAKEFLAGS, argvalue, VAR_GLOBAL);
+                       Global_AppendExpand(MAKEFLAGS, "-d");
+                       Global_AppendExpand(MAKEFLAGS, argvalue);
                }
                MainParseArgDebug(argvalue);
                break;
        case 'e':
                opts.checkEnvFirst = TRUE;
-               Var_Append(MAKEFLAGS, "-e", VAR_GLOBAL);
+               Global_AppendExpand(MAKEFLAGS, "-e");
                break;
        case 'f':
                Lst_Append(&opts.makefiles, bmake_strdup(argvalue));
                break;
        case 'i':
                opts.ignoreErrors = TRUE;
-               Var_Append(MAKEFLAGS, "-i", VAR_GLOBAL);
+               Global_AppendExpand(MAKEFLAGS, "-i");
                break;
        case 'j':
                MainParseArgJobs(argvalue);
                break;
        case 'k':
                opts.keepgoing = TRUE;
-               Var_Append(MAKEFLAGS, "-k", VAR_GLOBAL);
+               Global_AppendExpand(MAKEFLAGS, "-k");
                break;
        case 'm':
                MainParseArgSysInc(argvalue);
@@ -542,28 +542,28 @@
                break;
        case 'n':
                opts.noExecute = TRUE;
-               Var_Append(MAKEFLAGS, "-n", VAR_GLOBAL);
+               Global_AppendExpand(MAKEFLAGS, "-n");
                break;
        case 'q':
                opts.queryFlag = TRUE;
                /* Kind of nonsensical, wot? */
-               Var_Append(MAKEFLAGS, "-q", VAR_GLOBAL);
+               Global_AppendExpand(MAKEFLAGS, "-q");
                break;
        case 'r':
                opts.noBuiltins = TRUE;
-               Var_Append(MAKEFLAGS, "-r", VAR_GLOBAL);
+               Global_AppendExpand(MAKEFLAGS, "-r");
                break;
        case 's':
                opts.beSilent = TRUE;
-               Var_Append(MAKEFLAGS, "-s", VAR_GLOBAL);
+               Global_AppendExpand(MAKEFLAGS, "-s");
                break;
        case 't':
                opts.touchFlag = TRUE;
-               Var_Append(MAKEFLAGS, "-t", VAR_GLOBAL);
+               Global_AppendExpand(MAKEFLAGS, "-t");
                break;
        case 'w':
                opts.enterFlag = TRUE;
-               Var_Append(MAKEFLAGS, "-w", VAR_GLOBAL);
+               Global_AppendExpand(MAKEFLAGS, "-w");
                break;
        default:
        case '?':
@@ -737,7 +737,7 @@
                            progname, path, strerror(errno));
                } else {
                        snprintf(objdir, sizeof objdir, "%s", path);
-                       Var_Set(".OBJDIR", objdir, VAR_GLOBAL);
+                       Global_SetExpand(".OBJDIR", objdir);
                        setenv("PWD", objdir, 1);
                        Dir_InitDot();
                        purge_relative_cached_realpaths();
@@ -957,13 +957,13 @@
        StringListNode *ln;
 
        if (Lst_IsEmpty(&opts.create)) {
-               Var_Set(".TARGETS", "", VAR_GLOBAL);
+               Global_SetExpand(".TARGETS", "");
                return;



Home | Main Index | Thread Index | Old Index