Module Name: src Committed By: rillig Date: Sun Nov 8 10:33:47 UTC 2020
Modified Files: src/usr.bin/make: make.c make.h src/usr.bin/make/unit-tests: depsrc-optional.exp depsrc-optional.mk Log Message: 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. To generate a diff of this commit: cvs rdiff -u -r1.196 -r1.197 src/usr.bin/make/make.c cvs rdiff -u -r1.200 -r1.201 src/usr.bin/make/make.h cvs rdiff -u -r1.3 -r1.4 src/usr.bin/make/unit-tests/depsrc-optional.exp cvs rdiff -u -r1.4 -r1.5 src/usr.bin/make/unit-tests/depsrc-optional.mk 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.196 src/usr.bin/make/make.c:1.197 --- src/usr.bin/make/make.c:1.196 Sun Nov 8 10:17:55 2020 +++ src/usr.bin/make/make.c Sun Nov 8 10:33:47 2020 @@ -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 @@ GNode_UpdateYoungestChild(GNode *gn, GNo 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 @@ GNode_IsOODate(GNode *gn) } } 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 { /* Index: src/usr.bin/make/make.h diff -u src/usr.bin/make/make.h:1.200 src/usr.bin/make/make.h:1.201 --- src/usr.bin/make/make.h:1.200 Sun Nov 8 08:33:07 2020 +++ src/usr.bin/make/make.h Sun Nov 8 10:33:47 2020 @@ -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 @@ typedef enum GNodeType { 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 '::'. */ Index: src/usr.bin/make/unit-tests/depsrc-optional.exp diff -u src/usr.bin/make/unit-tests/depsrc-optional.exp:1.3 src/usr.bin/make/unit-tests/depsrc-optional.exp:1.4 --- src/usr.bin/make/unit-tests/depsrc-optional.exp:1.3 Sun Nov 8 10:17:55 2020 +++ src/usr.bin/make/unit-tests/depsrc-optional.exp Sun Nov 8 10:33:47 2020 @@ -6,8 +6,8 @@ MakeAddChild: need to examine optional-c 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. Index: src/usr.bin/make/unit-tests/depsrc-optional.mk diff -u src/usr.bin/make/unit-tests/depsrc-optional.mk:1.4 src/usr.bin/make/unit-tests/depsrc-optional.mk:1.5 --- src/usr.bin/make/unit-tests/depsrc-optional.mk:1.4 Sun Nov 8 10:17:55 2020 +++ src/usr.bin/make/unit-tests/depsrc-optional.mk Sun Nov 8 10:33:47 2020 @@ -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 @@ important: optional optional-cohort : ${.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