Skip to content

Commit 5bb8646

Browse files
committed
gh-108740: Fix "make regen-all" race condition
Fix a race condition in "make regen-all". The deepfreeze.c source and files generated by Argument Clinic are now generated or updated before generating "global objects". Previously, some identifiers may miss depending on the order in which these files were generated. * "make regen-global-objects": Make sure that deepfreeze.c is generated and up to date, and always run "make clinic". * "make clinic" no longer runs generate_global_objects.py script anymore. * "make regen-deepfreeze" now only updates deepfreeze.c, it doesn't build deepfreeze.o anymore. * Remove misleading messages in "make regen-global-objects" and "make clinic". They are outdated, these commands are now safe to use. * Document generates files in Doc/using/configure.rst
1 parent 594b000 commit 5bb8646

File tree

3 files changed

+36
-8
lines changed

3 files changed

+36
-8
lines changed

Doc/using/configure.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,29 @@ See also :pep:`7` "Style Guide for C Code" and :pep:`11` "CPython platform
6060
support".
6161

6262

63+
Generated files
64+
===============
65+
66+
To reduce build dependencies, Python source code contains multiple generated
67+
files. Commands to regenerate all generated files::
68+
69+
make regen-all
70+
make regen-stdlib-module-names
71+
make regen-limited-abi
72+
make regen-configure
73+
74+
The ``Makefile.pre.in`` documents generated files, their inputs, and tools used
75+
to regenerate them. Search for ``regen-*`` make targets.
76+
77+
The ``make regen-configure`` command runs `tiran/cpython_autoconf
78+
<https://github.com/tiran/cpython_autoconf>`_ container for reproducible build;
79+
see container ``entry.sh`` script. The container is optional, the following
80+
command can be run locally, the generated files depend on autoconf and aclocal
81+
versions::
82+
83+
autoreconf -ivf -Werror
84+
85+
6386
.. _configure-options:
6487

6588
Configure Options

Makefile.pre.in

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,7 @@ OBJECT_OBJS= \
490490
Objects/weakrefobject.o \
491491
@PERF_TRAMPOLINE_OBJ@
492492

493+
DEEPFREEZE_C = Python/deepfreeze/deepfreeze.c
493494
DEEPFREEZE_OBJS = Python/deepfreeze/deepfreeze.o
494495

495496
##########################################################################
@@ -777,7 +778,6 @@ coverage-report: regen-token regen-frozen
777778
.PHONY: clinic
778779
clinic: check-clean-src $(srcdir)/Modules/_blake2/blake2s_impl.c
779780
$(PYTHON_FOR_REGEN) $(srcdir)/Tools/clinic/clinic.py --make --exclude Lib/test/clinic.test.c --srcdir $(srcdir)
780-
$(PYTHON_FOR_REGEN) $(srcdir)/Tools/build/generate_global_objects.py
781781

782782
.PHONY: clinic-tests
783783
clinic-tests: check-clean-src $(srcdir)/Lib/test/clinic.test.c
@@ -1252,7 +1252,7 @@ regen-frozen: Tools/build/freeze_modules.py $(FROZEN_FILES_IN)
12521252
# Deepfreeze targets
12531253

12541254
.PHONY: regen-deepfreeze
1255-
regen-deepfreeze: $(DEEPFREEZE_OBJS)
1255+
regen-deepfreeze: $(DEEPFREEZE_C)
12561256

12571257
DEEPFREEZE_DEPS=$(srcdir)/Tools/build/deepfreeze.py Include/internal/pycore_global_strings.h $(FREEZE_MODULE_DEPS) $(FROZEN_FILES_OUT)
12581258

@@ -1284,8 +1284,6 @@ Python/deepfreeze/deepfreeze.c: $(DEEPFREEZE_DEPS)
12841284
Python/frozen_modules/frozen_only.h:frozen_only \
12851285
-o Python/deepfreeze/deepfreeze.c
12861286
# END: deepfreeze modules
1287-
@echo "Note: Deepfreeze may have added some global objects,"
1288-
@echo " so run 'make regen-global-objects' if necessary."
12891287

12901288
# We keep this renamed target around for folks with muscle memory.
12911289
.PHONY: regen-importlib
@@ -1295,10 +1293,11 @@ regen-importlib: regen-frozen
12951293
# Global objects
12961294

12971295
.PHONY: regen-global-objects
1298-
regen-global-objects: $(srcdir)/Tools/build/generate_global_objects.py
1296+
# Dependencies which can add and/or remove _Py_ID() identifiers:
1297+
# - deepfreeze.c
1298+
# - "make clinic"
1299+
regen-global-objects: $(srcdir)/Tools/build/generate_global_objects.py $(DEEPFREEZE_C) clinic
12991300
$(PYTHON_FOR_REGEN) $(srcdir)/Tools/build/generate_global_objects.py
1300-
@echo "Note: Global objects can be added or removed by other tools (e.g. deepfreeze), "
1301-
@echo " so be sure to re-run regen-global-objects after those tools."
13021301

13031302
############################################################################
13041303
# ABI
@@ -1321,8 +1320,9 @@ regen-limited-abi: all
13211320
# Regenerate all generated files
13221321

13231322
.PHONY: regen-all
1323+
# "regen-global-objects" runs "clinic".
13241324
regen-all: regen-cases regen-typeslots \
1325-
regen-token regen-ast regen-keyword regen-sre regen-frozen clinic \
1325+
regen-token regen-ast regen-keyword regen-sre regen-frozen \
13261326
regen-pegen-metaparser regen-pegen regen-test-frozenmain \
13271327
regen-test-levenshtein regen-global-objects
13281328
@echo
@@ -2594,6 +2594,7 @@ recheck:
25942594
autoconf:
25952595
(cd $(srcdir); autoreconf -ivf -Werror)
25962596

2597+
# See https://github.com/tiran/cpython_autoconf container
25972598
.PHONY: regen-configure
25982599
regen-configure:
25992600
@if command -v podman >/dev/null; then RUNTIME="podman"; else RUNTIME="docker"; fi; \
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Fix a race condition in ``make regen-all``. The ``deepfreeze.c`` source and
2+
files generated by Argument Clinic are now generated or updated before
3+
generating "global objects". Previously, some identifiers may miss depending
4+
on the order in which these files were generated. Patch by Victor Stinner.

0 commit comments

Comments
 (0)