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): fix debug output in out-of-date for co...



details:   https://anonhg.NetBSD.org/src/rev/2f12224d5253
branches:  trunk
changeset: 956831:2f12224d5253
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Nov 08 10:33:47 2020 +0000

description:
make(1): fix debug output in out-of-date for cohorts (since 2003-11-14)

Before, a wrong cause for being out-of-date was printed in the debug log,
for optional cohorts.  This was caused by having the same conditions
duplicated in the code, instead of putting them in a separate function.

Now the optional cohort is correctly identified as using the '::'
dependency operator.

diffstat:

 usr.bin/make/make.c                         |  53 ++++++++++++++--------------
 usr.bin/make/make.h                         |   5 +-
 usr.bin/make/unit-tests/depsrc-optional.exp |   4 +-
 usr.bin/make/unit-tests/depsrc-optional.mk  |  12 ++----
 4 files changed, 35 insertions(+), 39 deletions(-)

diffs (149 lines):

diff -r 8b669a8ceb3c -r 2f12224d5253 usr.bin/make/make.c
--- a/usr.bin/make/make.c       Sun Nov 08 10:17:55 2020 +0000
+++ b/usr.bin/make/make.c       Sun Nov 08 10:33:47 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: make.c,v 1.196 2020/11/08 10:17:55 rillig Exp $        */
+/*     $NetBSD: make.c,v 1.197 2020/11/08 10:33:47 rillig Exp $        */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -108,7 +108,7 @@
 #include "job.h"
 
 /*     "@(#)make.c     8.1 (Berkeley) 6/6/93"  */
-MAKE_RCSID("$NetBSD: make.c,v 1.196 2020/11/08 10:17:55 rillig Exp $");
+MAKE_RCSID("$NetBSD: make.c,v 1.197 2020/11/08 10:33:47 rillig Exp $");
 
 /* Sequence # to detect recursion. */
 static unsigned int checked = 1;
@@ -192,21 +192,31 @@
        gn->youngestChild = cgn;
 }
 
-/*
- * A node whose modification time is less than that of its
- * youngest child or that has no children (youngestChild == NULL) and
- * either doesn't exist (mtime == 0) and it isn't optional
- * or was the object of a * :: operator is out-of-date.
- * Why? Because that's the way Make does it.
- */
 static Boolean
-IsOlderThanYoungestChild(GNode *gn)
+IsOODateRegular(GNode *gn)
 {
-    return (gn->youngestChild != NULL &&
-           gn->mtime < gn->youngestChild->mtime) ||
-          (gn->youngestChild == NULL &&
-           ((gn->mtime == 0 && !(gn->type & OP_OPTIONAL))
-            || gn->type & OP_DOUBLEDEP));
+    /* These rules are inherited from the original Make. */
+
+    if (gn->youngestChild != NULL) {
+       if (gn->mtime < gn->youngestChild->mtime) {
+           DEBUG1(MAKE, "modified before source \"%s\"...",
+                  GNode_Path(gn->youngestChild));
+           return TRUE;
+       }
+       return FALSE;
+    }
+
+    if (gn->mtime == 0 && !(gn->type & OP_OPTIONAL)) {
+       DEBUG0(MAKE, "non-existent and no sources...");
+       return TRUE;
+    }
+
+    if (gn->type & OP_DOUBLEDEP) {
+       DEBUG0(MAKE, ":: operator and no sources...");
+       return TRUE;
+    }
+
+    return FALSE;
 }
 
 /* See if the node is out of date with respect to its sources.
@@ -292,18 +302,7 @@
            }
        }
        oodate = TRUE;
-    } else if (IsOlderThanYoungestChild(gn)) {
-       if (DEBUG(MAKE)) {
-           if (gn->youngestChild != NULL &&
-               gn->mtime < gn->youngestChild->mtime) {
-               debug_printf("modified before source \"%s\"...",
-                            GNode_Path(gn->youngestChild));
-           } else if (gn->mtime == 0) {
-               debug_printf("non-existent and no sources...");
-           } else {
-               debug_printf(":: operator and no sources...");
-           }
-       }
+    } else if (IsOODateRegular(gn)) {
        oodate = TRUE;
     } else {
        /*
diff -r 8b669a8ceb3c -r 2f12224d5253 usr.bin/make/make.h
--- a/usr.bin/make/make.h       Sun Nov 08 10:17:55 2020 +0000
+++ b/usr.bin/make/make.h       Sun Nov 08 10:33:47 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: make.h,v 1.200 2020/11/08 08:33:07 rillig Exp $        */
+/*     $NetBSD: make.h,v 1.201 2020/11/08 10:33:47 rillig Exp $        */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -199,7 +199,8 @@
     OP_FORCE           = 1 << 1,
     /* The dependency operator '::' behaves like ':', except that it allows
      * multiple dependency groups to be defined.  Each of these groups is
-     * executed on its own, independently from the others. */
+     * executed on its own, independently from the others.  Each individual
+     * dependency group is called a cohort. */
     OP_DOUBLEDEP       = 1 << 2,
 
     /* Matches the dependency operators ':', '!' and '::'. */
diff -r 8b669a8ceb3c -r 2f12224d5253 usr.bin/make/unit-tests/depsrc-optional.exp
--- a/usr.bin/make/unit-tests/depsrc-optional.exp       Sun Nov 08 10:17:55 2020 +0000
+++ b/usr.bin/make/unit-tests/depsrc-optional.exp       Sun Nov 08 10:33:47 2020 +0000
@@ -6,8 +6,8 @@
 Make_ExpandUse: examine optional
 Make_ExpandUse: examine optional-cohort
 Examining optional...non-existent...up-to-date.
-Examining optional-cohort...non-existent...non-existent and no sources...out-of-date.
-: This is not executed.
+Examining optional-cohort...non-existent...:: operator and no sources...out-of-date.
+: A leaf node using '::' is considered out-of-date.
  recheck(optional-cohort): update time from  0:00:00 Jan 01, 1970 to now
 Examining important...non-existent...modified before source "optional-cohort"...out-of-date.
 : important is made.
diff -r 8b669a8ceb3c -r 2f12224d5253 usr.bin/make/unit-tests/depsrc-optional.mk
--- a/usr.bin/make/unit-tests/depsrc-optional.mk        Sun Nov 08 10:17:55 2020 +0000
+++ b/usr.bin/make/unit-tests/depsrc-optional.mk        Sun Nov 08 10:33:47 2020 +0000
@@ -1,13 +1,10 @@
-# $NetBSD: depsrc-optional.mk,v 1.4 2020/11/08 10:17:55 rillig Exp $
+# $NetBSD: depsrc-optional.mk,v 1.5 2020/11/08 10:33:47 rillig Exp $
 #
 # Tests for the special source .OPTIONAL in dependency declarations,
 # which ignores the target if make cannot find out how to create it.
 #
 # TODO: Describe practical use cases for this feature.
 
-# TODO: Explain why the commands for "important" are not executed.
-# I had thought that only the "optional" commands were skipped.
-
 all: important
        : ${.TARGET} is made.
 
@@ -15,11 +12,10 @@
        : ${.TARGET} is made.
 
 optional: .OPTIONAL
-       : This is not executed.
+       : An optional leaf node is not executed.
 
-# XXX: "non-existent and no sources" is wrong, should be ":: operator and
-# no sources..." instead.
+# See IsOODateRegular.
 optional-cohort:: .OPTIONAL
-       : This is not executed.
+       : A leaf node using '::' is considered out-of-date.
 
 .MAKEFLAGS: -dm



Home | Main Index | Thread Index | Old Index