Skip to content

Commit

Permalink
make: fix exit status for '-q' (since 1994)
Browse files Browse the repository at this point in the history
  • Loading branch information
rillig committed Aug 17, 2022
1 parent 58b87ee commit 00c8efe
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 18 deletions.
6 changes: 3 additions & 3 deletions usr.bin/make/compat.c
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);

/*
Expand Down
6 changes: 3 additions & 3 deletions usr.bin/make/make.c
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions usr.bin/make/unit-tests/opt-query.exp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
18 changes: 8 additions & 10 deletions usr.bin/make/unit-tests/opt-query.mk
Original file line number Diff line number Diff line change
@@ -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.
#
Expand All @@ -24,13 +24,15 @@ 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 \
&& echo "${target}: query status $$?" \
|| 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':
Expand All @@ -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
Expand Down

0 comments on commit 00c8efe

Please sign in to comment.