Module Name:    src
Committed By:   rillig
Date:           Tue Nov 24 19:33:13 UTC 2020

Modified Files:
        src/usr.bin/make: make.c make.h

Log Message:
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.


To generate a diff of this commit:
cvs rdiff -u -r1.210 -r1.211 src/usr.bin/make/make.c
cvs rdiff -u -r1.217 -r1.218 src/usr.bin/make/make.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/make/make.c
diff -u src/usr.bin/make/make.c:1.210 src/usr.bin/make/make.c:1.211
--- src/usr.bin/make/make.c:1.210	Sat Nov 21 10:51:26 2020
+++ src/usr.bin/make/make.c	Tue Nov 24 19:33:13 2020
@@ -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 @@ IsWaitingForOrder(GNode *gn)
     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 @@ Make_Update(GNode *cgn)
 	 * 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 @@ Make_DoAllVar(GNode *gn)
     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 @@ MakeBuildChild(void *v_cn, void *toBeMad
 	       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 @@ MakeStartJobs(void)
 	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 @@ MakeStartJobs(void)
 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 ",

Index: src/usr.bin/make/make.h
diff -u src/usr.bin/make/make.h:1.217 src/usr.bin/make/make.h:1.218
--- src/usr.bin/make/make.h:1.217	Tue Nov 24 18:17:45 2020
+++ src/usr.bin/make/make.h	Tue Nov 24 19:33:13 2020
@@ -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 @@ typedef enum GNodeMade {
     /* 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 @@ GNode_Path(const GNode *gn)
 }
 
 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;

Reply via email to