Obey order of multiple print/no-print directory options

Previously if --no-print-directory was seen anywhere even once
(environment, command line, etc.) it would always take precedence
over any --print-directory option.  Change this so that the last
seen option (which will be the command line, if present there) takes
precedence.

* NEWS: Mark this change in behavior.
* src/makeint.h (print_directory): A new variable to control printing.
* src/output.c (output_dump): Use the new variable.
(output_start): Ditto.
* src/main.c: Add a new variable print_directory.  Use -1 for
print_directory_flag so we know of the option was seen or not.  Add a
new default_print_directory_flag set to -1 to keep options from being
added.
(switches): Use flag_off for --no-print-directory, rather than a
separate inhibit_print_directory_flag.
(main): If print_directory_flag was set by the user, use that for
print_directory.  If not, compute the print_directory value based on
-s, -C, and sub-makes as before.
* tests/scripts/variables/GNUMAKEFLAGS: -w is not added automatically
* tests/scripts/options/print-directory: Add tests for overriding
print-directory options.
This commit is contained in:
Paul Smith
2020-03-30 14:07:10 -04:00
parent 660a2eafe5
commit 8e024a2532
6 changed files with 70 additions and 28 deletions

View File

@@ -2,15 +2,25 @@
$description = "Test the -w option to GNU make.";
my $enter = "#MAKE#: Entering directory '#PWD#'";
my $leave = "#MAKE#: Leaving directory '#PWD#'";
# Simple test without -w
run_make_test(q!
all: ; @echo hi
!,
"", "hi\n");
my $ans = "$enter\nhi\n$leave\n";
# Simple test with -w
run_make_test(undef, "-w",
"#MAKE#: Entering directory '#PWD#'\nhi\n#MAKE#: Leaving directory '#PWD#'\n");
run_make_test(undef, "-w", $ans);
# Simple test with overriding -w
run_make_test(undef, "-w --no-print-directory", "hi\n");
# Simple test with overriding --no-print-directory
run_make_test(undef, "--no-print-directory --print-directory", $ans);
# Test makefile rebuild to ensure no enter/leave
run_make_test(q!
@@ -21,13 +31,40 @@ foo: ; touch foo
"", "touch foo\n");
unlink('foo');
$ans = "$enter\ntouch foo\n$leave\n";
# Test makefile rebuild with -w
run_make_test(q!
include foo
all: ;@:
foo: ; touch foo
!,
"-w", "#MAKE#: Entering directory '#PWD#'\ntouch foo\n#MAKE#: Leaving directory '#PWD#'\n");
run_make_test(undef, "-w", $ans);
unlink('foo');
# Test makefile rebuild with -w overridden
run_make_test(undef, "-w --no-print-directory", "touch foo\n");
unlink('foo');
# Test makefile rebuild with --no-print-directory overridden
run_make_test(undef, "--no-print-directory --print-directory", $ans);
unlink('foo');
my $enter1 = "#MAKE#[1]: Entering directory '#PWD#'";
my $leave1 = "#MAKE#[1]: Leaving directory '#PWD#'";
$ans = "$enter1\nhi\n$leave1\n";
# Test makefile recursion with default enter/leave
run_make_test(q!
all: ;@$(MAKE) -f #MAKEFILE# recurse
recurse: ; @echo hi
!,
"", $ans);
# Disable enter/leave
run_make_test(undef, "--no-print-directory", "hi\n");
# Re-enable enter/leave
$ans = "$enter\n$ans$leave\n";
run_make_test(undef, "--no-print-directory -w", $ans);
# Override enter/leave
run_make_test(undef, "-w --no-print-directory", "hi\n");
1;

View File

@@ -35,7 +35,7 @@ all: ; @echo $@; echo MAKEFLAGS = $$MAKEFLAGS; echo GNUMAKEFLAGS = $$GNUMAKEFLAG
-include x.mk
x.mk: ; @echo $@; echo MAKEFLAGS = $$MAKEFLAGS; echo GNUMAKEFLAGS = $$GNUMAKEFLAGS; echo > $@
!,
"", "x.mk\nMAKEFLAGS = -Itst/bad\nGNUMAKEFLAGS =\nrecurse\nMAKEFLAGS = -Itst/bad\nGNUMAKEFLAGS =\n#MAKE#[1]: Entering directory '#PWD#'\nall\nMAKEFLAGS = w -Itst/bad\nGNUMAKEFLAGS =\n#MAKE#[1]: Leaving directory '#PWD#'\n");
"", "x.mk\nMAKEFLAGS = -Itst/bad\nGNUMAKEFLAGS =\nrecurse\nMAKEFLAGS = -Itst/bad\nGNUMAKEFLAGS =\n#MAKE#[1]: Entering directory '#PWD#'\nall\nMAKEFLAGS = -Itst/bad\nGNUMAKEFLAGS =\n#MAKE#[1]: Leaving directory '#PWD#'\n");
unlink('x.mk');