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 ...).
This commit is contained in:
Paul Smith 2022-07-16 19:43:34 -04:00
parent 2fe96e4a41
commit 77881d2281
3 changed files with 42 additions and 23 deletions

View File

@ -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:

View File

@ -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;

View File

@ -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;