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(1): add high-level API for GNode.made



details:   https://anonhg.NetBSD.org/src/rev/4b65af508328
branches:  trunk
changeset: 946353:4b65af508328
user:      rillig <rillig%NetBSD.org@localhost>
date:      Tue Nov 24 19:33:13 2020 +0000

description:
make(1): add high-level API for GNode.made

Having an enum whose constants must be ordered in a certain way may be
unexpected to casual readers.  Hide this implementation detail in
separate functions.

diffstat:

 usr.bin/make/make.c |  15 ++++++++-------
 usr.bin/make/make.h |  23 ++++++++++++++++++++++-
 2 files changed, 30 insertions(+), 8 deletions(-)

diffs (120 lines):

diff -r 62215dc9a47c -r 4b65af508328 usr.bin/make/make.c
--- a/usr.bin/make/make.c       Tue Nov 24 19:04:42 2020 +0000
+++ b/usr.bin/make/make.c       Tue Nov 24 19:33:13 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: make.c,v 1.210 2020/11/21 10:51:26 rillig Exp $        */
+/*     $NetBSD: make.c,v 1.211 2020/11/24 19:33:13 rillig Exp $        */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -102,7 +102,7 @@
 #include "job.h"
 
 /*     "@(#)make.c     8.1 (Berkeley) 6/6/93"  */
-MAKE_RCSID("$NetBSD: make.c,v 1.210 2020/11/21 10:51:26 rillig Exp $");
+MAKE_RCSID("$NetBSD: make.c,v 1.211 2020/11/24 19:33:13 rillig Exp $");
 
 /* Sequence # to detect recursion. */
 static unsigned int checked_seqno = 1;
@@ -566,7 +566,7 @@
     for (ln = gn->order_pred->first; ln != NULL; ln = ln->next) {
        GNode *ogn = ln->datum;
 
-       if (ogn->made >= MADE || !(ogn->flags & REMAKE))
+       if (GNode_IsDone(ogn) || !(ogn->flags & REMAKE))
            continue;
 
        DEBUG2(MAKE, "IsWaitingForOrder: Waiting for .ORDER node \"%s%s\"\n",
@@ -679,7 +679,7 @@
         * A parent must wait for the completion of all instances
         * of a `::' dependency.
         */
-       if (centurion->unmade_cohorts != 0 || centurion->made < MADE) {
+       if (centurion->unmade_cohorts != 0 || !GNode_IsDone(centurion)) {
            DEBUG2(MAKE, "- centurion made %d, %d unmade cohorts\n",
                   centurion->made, centurion->unmade_cohorts);
            continue;
@@ -842,6 +842,7 @@
     gn->flags |= DONE_ALLSRC;
 }
 
+/* XXX: Replace void pointers in parameters with proper types. */
 static int
 MakeBuildChild(void *v_cn, void *toBeMade_next)
 {
@@ -852,7 +853,7 @@
               cn->name, cn->cohort_num);
        GNode_FprintDetails(opts.debug_file, "", cn, "\n");
     }
-    if (cn->made > DEFERRED)
+    if (GNode_IsReady(cn))
        return 0;
 
     /* If this node is on the RHS of a .ORDER, check LHSs. */
@@ -919,6 +920,7 @@
        DEBUG2(MAKE, "Examining %s%s...\n", gn->name, gn->cohort_num);
 
        if (gn->made != REQUESTED) {
+           /* XXX: Replace %d with string representation; see made_name. */
            DEBUG1(MAKE, "state %d\n", gn->made);
 
            make_abort(gn, __LINE__);
@@ -978,8 +980,7 @@
 static void
 MakePrintStatusOrderNode(GNode *ogn, GNode *gn)
 {
-    if (!(ogn->flags & REMAKE) || ogn->made > REQUESTED)
-       /* not waiting for this one */
+    if (!GNode_IsWaitingFor(ogn))
        return;
 
     printf("    `%s%s' has .ORDER dependency against %s%s ",
diff -r 62215dc9a47c -r 4b65af508328 usr.bin/make/make.h
--- a/usr.bin/make/make.h       Tue Nov 24 19:04:42 2020 +0000
+++ b/usr.bin/make/make.h       Tue Nov 24 19:33:13 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: make.h,v 1.217 2020/11/24 18:17:45 rillig Exp $        */
+/*     $NetBSD: make.h,v 1.218 2020/11/24 19:33:13 rillig Exp $        */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -197,11 +197,14 @@
     /* The node has been examined but is not yet ready since its
      * dependencies have to be made first. */
     DEFERRED,
+
     /* The node is on the toBeMade list. */
     REQUESTED,
+
     /* The node is already being made.
      * Trying to build a node in this state indicates a cycle in the graph. */
     BEINGMADE,
+
     /* Was out-of-date and has been made. */
     MADE,
     /* Was already up-to-date, does not need to be made. */
@@ -702,6 +705,24 @@
 }
 
 MAKE_INLINE Boolean
+GNode_IsWaitingFor(const GNode *gn)
+{
+       return (gn->flags & REMAKE) && gn->made <= REQUESTED;
+}
+
+MAKE_INLINE Boolean
+GNode_IsReady(const GNode *gn)
+{
+       return gn->made > DEFERRED;
+}
+
+MAKE_INLINE Boolean
+GNode_IsDone(const GNode *gn)
+{
+       return gn->made >= MADE;
+}
+
+MAKE_INLINE Boolean
 GNode_IsError(const GNode *gn)
 {
        return gn->made == ERROR || gn->made == ABORTED;



Home | Main Index | Thread Index | Old Index