Skip to content

Commit d1f2ef5

Browse files
pythongh-108740: Fix "make regen-all" race condition (python#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 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. Backport notes: * Omit Doc/using/configure.rst changes. * no need to change "make clinic", it didn't run generate_global_objects.py script before. Co-authored-by: Erlend E. Aasland <[email protected]> (cherry picked from commit db1ee6a)
1 parent d631b82 commit d1f2ef5

File tree

3 files changed

+16
-9
lines changed

3 files changed

+16
-9
lines changed

Makefile.pre.in

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

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

492493
##########################################################################
@@ -1152,12 +1153,12 @@ regen-frozen: Tools/scripts/freeze_modules.py $(FROZEN_FILES_IN)
11521153
# Deepfreeze targets
11531154

11541155
.PHONY: regen-deepfreeze
1155-
regen-deepfreeze: $(DEEPFREEZE_OBJS)
1156+
regen-deepfreeze: $(DEEPFREEZE_C)
11561157

11571158
DEEPFREEZE_DEPS=$(srcdir)/Tools/scripts/deepfreeze.py $(FREEZE_MODULE_DEPS) $(FROZEN_FILES_OUT)
11581159

11591160
# BEGIN: deepfreeze modules
1160-
Python/deepfreeze/deepfreeze.c: $(DEEPFREEZE_DEPS)
1161+
$(DEEPFREEZE_C): $(DEEPFREEZE_DEPS)
11611162
$(PYTHON_FOR_FREEZE) $(srcdir)/Tools/scripts/deepfreeze.py \
11621163
Python/frozen_modules/importlib._bootstrap.h:importlib._bootstrap \
11631164
Python/frozen_modules/importlib._bootstrap_external.h:importlib._bootstrap_external \
@@ -1184,8 +1185,6 @@ Python/deepfreeze/deepfreeze.c: $(DEEPFREEZE_DEPS)
11841185
Python/frozen_modules/frozen_only.h:frozen_only \
11851186
-o Python/deepfreeze/deepfreeze.c
11861187
# END: deepfreeze modules
1187-
@echo "Note: Deepfreeze may have added some global objects,"
1188-
@echo " so run 'make regen-global-objects' if necessary."
11891188

11901189
# We keep this renamed target around for folks with muscle memory.
11911190
.PHONY: regen-importlib
@@ -1194,11 +1193,12 @@ regen-importlib: regen-frozen
11941193
############################################################################
11951194
# Global objects
11961195

1196+
# Dependencies which can add and/or remove _Py_ID() identifiers:
1197+
# - deepfreeze.c
1198+
# - "make clinic"
11971199
.PHONY: regen-global-objects
1198-
regen-global-objects: $(srcdir)/Tools/scripts/generate_global_objects.py
1200+
regen-global-objects: $(srcdir)/Tools/scripts/generate_global_objects.py $(DEEPFREEZE_C) clinic
11991201
$(PYTHON_FOR_REGEN) $(srcdir)/Tools/scripts/generate_global_objects.py
1200-
@echo "Note: Global objects can be added or removed by other tools (e.g. deepfreeze), "
1201-
@echo " so be sure to re-run regen-global-objects after those tools."
12021202

12031203
############################################################################
12041204
# ABI
@@ -1217,8 +1217,10 @@ regen-limited-abi: all
12171217
############################################################################
12181218
# Regenerate all generated files
12191219

1220+
# "clinic" is regenerated implicitly via "regen-global-objects".
1221+
.PHONY: regen-all
12201222
regen-all: regen-opcode regen-opcode-targets regen-typeslots \
1221-
regen-token regen-ast regen-keyword regen-sre regen-frozen clinic \
1223+
regen-token regen-ast regen-keyword regen-sre regen-frozen \
12221224
regen-pegen-metaparser regen-pegen regen-test-frozenmain \
12231225
regen-global-objects
12241226
@echo
@@ -2389,6 +2391,7 @@ recheck:
23892391
autoconf:
23902392
(cd $(srcdir); autoreconf -ivf -Werror)
23912393

2394+
# See https://github.com/tiran/cpython_autoconf container
23922395
.PHONY: regen-configure
23932396
regen-configure:
23942397
@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/scripts/freeze_modules.py

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

0 commit comments

Comments
 (0)