Skip to content

Commit 6c5f893

Browse files
committed
build: further refine build.ninja rules
In commit b0fcc6f ("build: rebuild build.ninja using "meson setup --reconfigure"", 2023-05-19) I changed the build.ninja rule in the Makefile to use "meson setup" so that the Makefile would pick up a changed path to the meson binary. However, there was a reason why build.ninja was rebuilt using $(NINJA) itself. Namely, ninja has its own cache of file modification times, and if it does not know about the modification that was done outside its control, it will *also* try to regenerate build.ninja. This can be simply by running "make" on a fresh tree immediately after "configure"; that will trigger an unnecessary meson run. So, apply a refinement to the rule in order to cover both cases: - track the meson binary that was used (and that is embedded in build.ninja's reconfigure rules); to do this, write build.ninja.stamp right after executing meson successfully - if it changed, force usage of "$(MESON) setup --reconfigure" to update the path in the reconfigure rule - if it didn't change, use "$(NINJA) build.ninja" just like before commit b0fcc6f. Reported-by: Mark Cave-Ayland <[email protected]> Tested-by: Mark Cave-Ayland <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 79dbd91 commit 6c5f893

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

Makefile

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,16 +83,17 @@ config-host.mak: $(SRC_PATH)/configure $(SRC_PATH)/scripts/meson-buildoptions.sh
8383
@if test -f meson-private/coredata.dat; then \
8484
./config.status --skip-meson; \
8585
else \
86-
./config.status && touch build.ninja.stamp; \
86+
./config.status; \
8787
fi
8888

8989
# 2. meson.stamp exists if meson has run at least once (so ninja reconfigure
9090
# works), but otherwise never needs to be updated
91+
9192
meson-private/coredata.dat: meson.stamp
9293
meson.stamp: config-host.mak
9394
@touch meson.stamp
9495

95-
# 3. ensure generated build files are up-to-date
96+
# 3. ensure meson-generated build files are up-to-date
9697

9798
ifneq ($(NINJA),)
9899
Makefile.ninja: build.ninja
@@ -106,11 +107,19 @@ Makefile.ninja: build.ninja
106107
endif
107108

108109
ifneq ($(MESON),)
109-
# A separate rule is needed for Makefile dependencies to avoid -n
110+
# The path to meson always points to pyvenv/bin/meson, but the absolute
111+
# paths could change. In that case, force a regeneration of build.ninja.
112+
# Note that this invocation of $(NINJA), just like when Make rebuilds
113+
# Makefiles, does not include -n.
110114
build.ninja: build.ninja.stamp
111115
$(build-files):
112116
build.ninja.stamp: meson.stamp $(build-files)
113-
$(MESON) setup --reconfigure $(SRC_PATH) && touch $@
117+
@if test "$$(cat build.ninja.stamp)" = "$(MESON)" && test -n "$(NINJA)"; then \
118+
$(NINJA) build.ninja; \
119+
else \
120+
echo "$(MESON) setup --reconfigure $(SRC_PATH)"; \
121+
$(MESON) setup --reconfigure $(SRC_PATH); \
122+
fi && echo "$(MESON)" > $@
114123

115124
Makefile.mtest: build.ninja scripts/mtest2make.py
116125
$(MESON) introspect --targets --tests --benchmarks | $(PYTHON) scripts/mtest2make.py > $@

configure

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1895,6 +1895,7 @@ if test "$skip_meson" = no; then
18951895
if test "$?" -ne 0 ; then
18961896
error_exit "meson setup failed"
18971897
fi
1898+
echo "$meson" > build.ninja.stamp
18981899
else
18991900
if test -f meson-private/cmd_line.txt; then
19001901
# Adjust old command line options that were removed

0 commit comments

Comments
 (0)