Skip to content

Commit cdafddf

Browse files
committed
unix: fix race condition in PGO builds
This works around a bug in CPython's build system related to how the make targets are defined. It has been causing a relatively hight rate of intermittent failures in CI due to a race condition.
1 parent 8823499 commit cdafddf

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

cpython-unix/build-cpython.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,11 @@ if [ -n "${PYTHON_MEETS_MINIMUM_VERSION_3_11}" ]; then
245245
patch -p1 -i ${ROOT}/patch-pwd-remove-conditional.patch
246246
fi
247247

248+
# The optimization make targets are both phony and non-phony. This leads
249+
# to PGO targets getting reevaluated after a build when you use multiple
250+
# make invocations. e.g. `make install` like we do below. Fix that.
251+
patch -p1 -i ${ROOT}/patch-pgo-make-targets.patch
252+
248253
# We patched configure.ac above. Reflect those changes.
249254
autoconf
250255

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
diff --git a/Makefile.pre.in b/Makefile.pre.in
2+
index b356f6293e..e584dede51 100644
3+
--- a/Makefile.pre.in
4+
+++ b/Makefile.pre.in
5+
@@ -642,12 +642,16 @@ run_profile_task:
6+
build_all_merge_profile:
7+
$(LLVM_PROF_MERGER)
8+
9+
-# Compile Python binary with profile guided optimization.
10+
-# To force re-running of the profile task, remove the profile-run-stamp file.
11+
-profile-opt: profile-run-stamp
12+
+profile-rebuild-stamp: profile-run-stamp
13+
@echo "Rebuilding with profile guided optimizations:"
14+
-rm -f profile-clean-stamp
15+
$(MAKE) @DEF_MAKE_RULE@ CFLAGS_NODIST="$(CFLAGS_NODIST) $(PGO_PROF_USE_FLAG)" LDFLAGS_NODIST="$(LDFLAGS_NODIST)"
16+
+ touch $@
17+
+
18+
+# Compile Python binary with profile guided optimization.
19+
+# To force re-running of the profile task, remove the profile-run-stamp file.
20+
+.PHONY: profile-opt
21+
+profile-opt: profile-rebuild-stamp
22+
23+
# Compile and run with gcov
24+
.PHONY=coverage coverage-lcov coverage-report

0 commit comments

Comments
 (0)