From 00c8efe5501f4ce693fd45bef026f3cab6c1b923 Mon Sep 17 00:00:00 2001 From: rillig Date: Wed, 17 Aug 2022 20:10:29 +0000 Subject: [PATCH] make: fix exit status for '-q' (since 1994) --- usr.bin/make/compat.c | 6 +++--- usr.bin/make/make.c | 6 +++--- usr.bin/make/unit-tests/opt-query.exp | 4 ++-- usr.bin/make/unit-tests/opt-query.mk | 18 ++++++++---------- 4 files changed, 16 insertions(+), 18 deletions(-) diff --git a/usr.bin/make/compat.c b/usr.bin/make/compat.c index 6f12cc1ae6cf2..affbf09ec04df 100644 --- a/usr.bin/make/compat.c +++ b/usr.bin/make/compat.c @@ -1,4 +1,4 @@ -/* $NetBSD: compat.c,v 1.240 2022/05/07 17:49:47 rillig Exp $ */ +/* $NetBSD: compat.c,v 1.241 2022/08/17 20:10:29 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990 The Regents of the University of California. @@ -91,7 +91,7 @@ #include "pathnames.h" /* "@(#)compat.c 8.2 (Berkeley) 3/19/94" */ -MAKE_RCSID("$NetBSD: compat.c,v 1.240 2022/05/07 17:49:47 rillig Exp $"); +MAKE_RCSID("$NetBSD: compat.c,v 1.241 2022/08/17 20:10:29 rillig Exp $"); static GNode *curTarg = NULL; static pid_t compatChild; @@ -570,7 +570,7 @@ MakeUnmade(GNode *gn, GNode *pgn) * to tell him/her "yes". */ DEBUG0(MAKE, "out-of-date.\n"); - if (opts.query) + if (opts.query && gn != Targ_GetEndNode()) exit(1); /* diff --git a/usr.bin/make/make.c b/usr.bin/make/make.c index fa1e594a1b164..ed9152421021e 100644 --- a/usr.bin/make/make.c +++ b/usr.bin/make/make.c @@ -1,4 +1,4 @@ -/* $NetBSD: make.c,v 1.255 2022/05/07 17:49:47 rillig Exp $ */ +/* $NetBSD: make.c,v 1.256 2022/08/17 20:10:29 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -104,7 +104,7 @@ #include "job.h" /* "@(#)make.c 8.1 (Berkeley) 6/6/93" */ -MAKE_RCSID("$NetBSD: make.c,v 1.255 2022/05/07 17:49:47 rillig Exp $"); +MAKE_RCSID("$NetBSD: make.c,v 1.256 2022/08/17 20:10:29 rillig Exp $"); /* Sequence # to detect recursion. */ static unsigned int checked_seqno = 1; @@ -1077,7 +1077,7 @@ MakeStartJobs(void) if (GNode_IsOODate(gn)) { DEBUG0(MAKE, "out-of-date\n"); if (opts.query) - return true; + return strcmp(gn->name, ".MAIN") != 0; GNode_SetLocalVars(gn); Job_Make(gn); have_token = false; diff --git a/usr.bin/make/unit-tests/opt-query.exp b/usr.bin/make/unit-tests/opt-query.exp index f4c5b8ad50625..0ba62780d8440 100644 --- a/usr.bin/make/unit-tests/opt-query.exp +++ b/usr.bin/make/unit-tests/opt-query.exp @@ -7,7 +7,7 @@ opt-query-file.out-of-date in compat mode: query status 1 Making opt-query-file.up-to-date in compat mode: `opt-query-file.up-to-date' is up to date. -opt-query-file.up-to-date in compat mode: query status 1 +opt-query-file.up-to-date in compat mode: query status 0 Making phony in compat mode: phony in compat mode: query status 1 @@ -16,7 +16,7 @@ Making opt-query-file.out-of-date in jobs mode: opt-query-file.out-of-date in jobs mode: query status 1 Making opt-query-file.up-to-date in jobs mode: -opt-query-file.up-to-date in jobs mode: query status 1 +opt-query-file.up-to-date in jobs mode: query status 0 Making phony in jobs mode: phony in jobs mode: query status 1 diff --git a/usr.bin/make/unit-tests/opt-query.mk b/usr.bin/make/unit-tests/opt-query.mk index 082a0a5c9f79c..019f25b711802 100644 --- a/usr.bin/make/unit-tests/opt-query.mk +++ b/usr.bin/make/unit-tests/opt-query.mk @@ -1,4 +1,4 @@ -# $NetBSD: opt-query.mk,v 1.5 2022/08/17 20:05:41 rillig Exp $ +# $NetBSD: opt-query.mk,v 1.6 2022/08/17 20:10:29 rillig Exp $ # # Tests for the -q command line option. # @@ -24,6 +24,7 @@ all: .PHONY variants cleanup _!= touch -f opt-query-file.up-to-date variants: .PHONY + . for target in commands @echo 'Making ${target}': @${MAKE} -r -f ${MAKEFILE} -q ${mode:Mjobs:%=-j1} ${target} PART=commands \ @@ -31,6 +32,7 @@ variants: .PHONY || echo "${target}: query status $$?" @echo . endfor + . for mode in compat jobs . for target in opt-query-file.out-of-date opt-query-file.up-to-date phony @echo 'Making ${target} in ${mode} mode': @@ -41,18 +43,14 @@ variants: .PHONY . endfor . endfor +# Between 1994 and before 2022-08-17, the exit status for '-q' was always 1, +# the cause for that exit code varied over time though. +# # expect: opt-query-file.out-of-date in compat mode: query status 1 - -# FIXME: must be 0, not 1. -# expect: opt-query-file.up-to-date in compat mode: query status 1 - +# expect: opt-query-file.up-to-date in compat mode: query status 0 # expect: phony in compat mode: query status 1 - # expect: opt-query-file.out-of-date in jobs mode: query status 1 - -# FIXME: must be 0, not 1. -# expect: opt-query-file.up-to-date in jobs mode: query status 1 - +# expect: opt-query-file.up-to-date in jobs mode: query status 0 # expect: phony in jobs mode: query status 1 cleanup: .PHONY