From 77881d2281035e2ace1e30800ff3528e1ef1fd98 Mon Sep 17 00:00:00 2001 From: Paul Smith Date: Sat, 16 Jul 2022 19:43:34 -0400 Subject: [PATCH] Ensure that MAKEFLAGS is set when invoking $(shell ...) * src/main.c (main): Don't reset the jobserver if the number of slots has not changed. (define_makeflags): Add all normal flags even when ALL is not set. * tests/scripts/functions/shell: Test invoking make in $(shell ...). * tests/scripts/variables/MAKEFLAGS: Test the value of MAKEFLAGS in $(shell ...). --- src/main.c | 40 +++++++++++++------------------ tests/scripts/functions/shell | 15 ++++++++++++ tests/scripts/variables/MAKEFLAGS | 10 ++++++++ 3 files changed, 42 insertions(+), 23 deletions(-) diff --git a/src/main.c b/src/main.c index ef2d2c41..656eaec6 100644 --- a/src/main.c +++ b/src/main.c @@ -1088,7 +1088,7 @@ main (int argc, char **argv, char **envp) PATH_VAR (current_directory); unsigned int restarts = 0; unsigned int syncing = 0; - int argv_slots; + int argv_slots; /* The jobslot info we got from our parent process. */ #ifdef WINDOWS32 const char *unix_path = NULL; const char *windows32_path = NULL; @@ -2013,7 +2013,7 @@ main (int argc, char **argv, char **envp) if (arg_job_slots == INVALID_JOB_SLOTS || argv_slots != INVALID_JOB_SLOTS) arg_job_slots = old_arg_job_slots; - else if (jobserver_auth) + else if (jobserver_auth && arg_job_slots != old_arg_job_slots) { /* Makefile MAKEFLAGS set -j, but we already have a jobserver. Make us the master of a new jobserver group. */ @@ -3395,22 +3395,19 @@ define_makeflags (int all, int makefile) break; case positive_int: - if (all) + if ((cs->default_value != 0 + && (*(unsigned int *) cs->value_ptr + == *(unsigned int *) cs->default_value))) + break; + if (cs->noarg_value != 0 + && (*(unsigned int *) cs->value_ptr == + *(unsigned int *) cs->noarg_value)) + ADD_FLAG ("", 0); /* Optional value omitted; see below. */ + else { - if ((cs->default_value != 0 - && (*(unsigned int *) cs->value_ptr - == *(unsigned int *) cs->default_value))) - break; - if (cs->noarg_value != 0 - && (*(unsigned int *) cs->value_ptr == - *(unsigned int *) cs->noarg_value)) - ADD_FLAG ("", 0); /* Optional value omitted; see below. */ - else - { - char *buf = alloca (30); - sprintf (buf, "%u", *(unsigned int *) cs->value_ptr); - ADD_FLAG (buf, strlen (buf)); - } + char *buf = alloca (30); + sprintf (buf, "%u", *(unsigned int *) cs->value_ptr); + ADD_FLAG (buf, strlen (buf)); } break; @@ -3430,12 +3427,9 @@ define_makeflags (int all, int makefile) break; case string: - if (all) - { - p = *((char **)cs->value_ptr); - if (p) - ADD_FLAG (p, strlen (p)); - } + p = *((char **)cs->value_ptr); + if (p) + ADD_FLAG (p, strlen (p)); break; case filename: diff --git a/tests/scripts/functions/shell b/tests/scripts/functions/shell index 80425172..74387918 100644 --- a/tests/scripts/functions/shell +++ b/tests/scripts/functions/shell @@ -140,6 +140,21 @@ all: ; @echo '$(.SHELLSTATUS): $(out)' !, '', "127: $_\n"); } + + # If we're using pipes for jobserver, then we will close them and not + # allow them to be available to sub-makes invoked via $(shell ...) + run_make_test(q! +ifeq ($(ELT),) +default:; @$(MAKE) -f #MAKEFILE# ELT=1 +else ifeq ($(ELT),1) +OUTPUT := $(shell $(MAKE) -f #MAKEFILE# ELT=2) +$(info $(OUTPUT)) +default:;: $(ELT) +else +default:;: $(ELT) +endif +!, + '--no-print-directory -j2', "#MAKE#[2]: warning: jobserver unavailable: using -j1. Add '+' to parent make rule.\n: 2\n: 1"); } 1; diff --git a/tests/scripts/variables/MAKEFLAGS b/tests/scripts/variables/MAKEFLAGS index c8d32631..d5fa0d28 100644 --- a/tests/scripts/variables/MAKEFLAGS +++ b/tests/scripts/variables/MAKEFLAGS @@ -129,4 +129,14 @@ all:; $(info makeflags='$(MAKEFLAGS)') '-Onone -l2.5 -l2.5 -Onone -I/tmp -iknqrswd -i -n -s -k -I/tmp', "/makeflags='Bdiknqrsw -I/tmp -l2.5 -Onone --trace --warn-undefined-variables'/"); +# Verify MAKEFLAGS are all available to shell functions +$ENV{'MAKEFLAGS'} = 'ikB --no-print-directory --warn-undefined-variables'; +run_make_test(q! +MAKEFLAGS := iknqrsw -I/tmp -I/tmp -Onone -Onone -l2.5 -l2.5 --no-print-directory +XX := $(shell echo "$$MAKEFLAGS") +all:; $(info makeflags='$(XX)') +!, + '-Onone -l2.5 -l2.5 -Onone -I/tmp -iknqrs -i -n -s -k -I/tmp', + "makeflags='iknqrsw -I/tmp -I/tmp -Onone -Onone -l2.5 -l2.5 --no-print-directory'"); + 1;