Skip to content

Commit de0202e

Browse files
[3.12] gh-108740: Fix "make regen-all" race condition (#108741) (#109019)
gh-108740: Fix "make regen-all" race condition (#108741) 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. * "make regen-deepfreeze" now only updates deepfreeze.c (C file). It doesn't build deepfreeze.o (object) anymore. * Remove misleading messages in "make regen-global-objects" and "make clinic". They are now outdated, these commands are now safe to use. * Document generates files in Doc/using/configure.rst. Co-authored-by: Erlend E. Aasland <[email protected]> (cherry picked from commit db1ee6a)
1 parent 55d7e8f commit de0202e

File tree

4 files changed

+38
-10
lines changed

4 files changed

+38
-10
lines changed

Doc/using/configure.rst

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

4545

46+
Generated files
47+
===============
48+
49+
To reduce build dependencies, Python source code contains multiple generated
50+
files. Commands to regenerate all generated files::
51+
52+
make regen-all
53+
make regen-stdlib-module-names
54+
make regen-limited-abi
55+
make regen-configure
56+
57+
The ``Makefile.pre.in`` file documents generated files, their inputs, and tools used
58+
to regenerate them. Search for ``regen-*`` make targets.
59+
60+
The ``make regen-configure`` command runs `tiran/cpython_autoconf
61+
<https://github.com/tiran/cpython_autoconf>`_ container for reproducible build;
62+
see container ``entry.sh`` script. The container is optional, the following
63+
command can be run locally, the generated files depend on autoconf and aclocal
64+
versions::
65+
66+
autoreconf -ivf -Werror
67+
68+
4669
.. _configure-options:
4770

4871
Configure Options

Makefile.pre.in

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,7 @@ OBJECT_OBJS= \
487487
Objects/weakrefobject.o \
488488
@PERF_TRAMPOLINE_OBJ@
489489

490+
DEEPFREEZE_C = Python/deepfreeze/deepfreeze.c
490491
DEEPFREEZE_OBJS = Python/deepfreeze/deepfreeze.o
491492

492493
##########################################################################
@@ -774,7 +775,6 @@ coverage-report: regen-token regen-frozen
774775
.PHONY: clinic
775776
clinic: check-clean-src $(srcdir)/Modules/_blake2/blake2s_impl.c
776777
$(PYTHON_FOR_REGEN) $(srcdir)/Tools/clinic/clinic.py --make --srcdir $(srcdir)
777-
$(PYTHON_FOR_REGEN) $(srcdir)/Tools/build/generate_global_objects.py
778778

779779
# Build the interpreter
780780
$(BUILDPYTHON): Programs/python.o $(LINK_PYTHON_DEPS)
@@ -1245,12 +1245,12 @@ regen-frozen: Tools/build/freeze_modules.py $(FROZEN_FILES_IN)
12451245
# Deepfreeze targets
12461246

12471247
.PHONY: regen-deepfreeze
1248-
regen-deepfreeze: $(DEEPFREEZE_OBJS)
1248+
regen-deepfreeze: $(DEEPFREEZE_C)
12491249

12501250
DEEPFREEZE_DEPS=$(srcdir)/Tools/build/deepfreeze.py $(FREEZE_MODULE_DEPS) $(FROZEN_FILES_OUT)
12511251

12521252
# BEGIN: deepfreeze modules
1253-
Python/deepfreeze/deepfreeze.c: $(DEEPFREEZE_DEPS)
1253+
$(DEEPFREEZE_C): $(DEEPFREEZE_DEPS)
12541254
$(PYTHON_FOR_FREEZE) $(srcdir)/Tools/build/deepfreeze.py \
12551255
Python/frozen_modules/importlib._bootstrap.h:importlib._bootstrap \
12561256
Python/frozen_modules/importlib._bootstrap_external.h:importlib._bootstrap_external \
@@ -1277,8 +1277,6 @@ Python/deepfreeze/deepfreeze.c: $(DEEPFREEZE_DEPS)
12771277
Python/frozen_modules/frozen_only.h:frozen_only \
12781278
-o Python/deepfreeze/deepfreeze.c
12791279
# END: deepfreeze modules
1280-
@echo "Note: Deepfreeze may have added some global objects,"
1281-
@echo " so run 'make regen-global-objects' if necessary."
12821280

12831281
# We keep this renamed target around for folks with muscle memory.
12841282
.PHONY: regen-importlib
@@ -1287,11 +1285,12 @@ regen-importlib: regen-frozen
12871285
############################################################################
12881286
# Global objects
12891287

1288+
# Dependencies which can add and/or remove _Py_ID() identifiers:
1289+
# - deepfreeze.c
1290+
# - "make clinic"
12901291
.PHONY: regen-global-objects
1291-
regen-global-objects: $(srcdir)/Tools/build/generate_global_objects.py
1292+
regen-global-objects: $(srcdir)/Tools/build/generate_global_objects.py $(DEEPFREEZE_C) clinic
12921293
$(PYTHON_FOR_REGEN) $(srcdir)/Tools/build/generate_global_objects.py
1293-
@echo "Note: Global objects can be added or removed by other tools (e.g. deepfreeze), "
1294-
@echo " so be sure to re-run regen-global-objects after those tools."
12951294

12961295
############################################################################
12971296
# ABI
@@ -1313,9 +1312,10 @@ regen-limited-abi: all
13131312
############################################################################
13141313
# Regenerate all generated files
13151314

1315+
# "clinic" is regenerated implicitly via "regen-global-objects".
13161316
.PHONY: regen-all
13171317
regen-all: regen-cases regen-opcode regen-opcode-targets regen-typeslots \
1318-
regen-token regen-ast regen-keyword regen-sre regen-frozen clinic \
1318+
regen-token regen-ast regen-keyword regen-sre regen-frozen \
13191319
regen-pegen-metaparser regen-pegen regen-test-frozenmain \
13201320
regen-test-levenshtein regen-global-objects
13211321
@echo
@@ -2586,6 +2586,7 @@ recheck:
25862586
autoconf:
25872587
(cd $(srcdir); autoreconf -ivf -Werror)
25882588

2589+
# See https://github.com/tiran/cpython_autoconf container
25892590
.PHONY: regen-configure
25902591
regen-configure:
25912592
@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.

Tools/build/freeze_modules.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,7 @@ def regen_makefile(modules):
585585
pyfiles = []
586586
frozenfiles = []
587587
rules = ['']
588-
deepfreezerules = ["Python/deepfreeze/deepfreeze.c: $(DEEPFREEZE_DEPS)",
588+
deepfreezerules = ["$(DEEPFREEZE_C): $(DEEPFREEZE_DEPS)",
589589
"\t$(PYTHON_FOR_FREEZE) $(srcdir)/Tools/build/deepfreeze.py \\"]
590590
for src in _iter_sources(modules):
591591
frozen_header = relpath_for_posix_display(src.frozenfile, ROOT_DIR)

0 commit comments

Comments
 (0)