diff --git a/Makefile.pre.in b/Makefile.pre.in index e6c6a6ba53a..8d335a7e139 100644 --- a/Makefile.pre.in +++ b/Makefile.pre.in @@ -1136,10 +1136,7 @@ regen-frozen: Tools/scripts/freeze_modules.py $(FROZEN_FILES_IN) # Deepfreeze targets .PHONY: regen-deepfreeze -regen-deepfreeze: - @# Possibly generate globals first, to make sure _bootstrap_python builds. - $(PYTHON_FOR_REGEN) $(srcdir)/Tools/scripts/generate_global_objects.py - $(MAKE) $(DEEPFREEZE_OBJS) +regen-deepfreeze: $(DEEPFREEZE_OBJS) DEEPFREEZE_DEPS=$(srcdir)/Tools/scripts/deepfreeze.py $(FREEZE_MODULE_DEPS) $(FROZEN_FILES_OUT) @@ -1180,13 +1177,25 @@ regen-importlib: regen-frozen ############################################################################ # Global objects -.PHONY: regen-global-objects -regen-global-objects: regen-deepfreeze - @# We already ran in once, before deepfreezing, to make sure - @# _bootstrap_python builds. Now we run it again to catch any - @# remaining globals, including those added by deepfreeze. +GLOBAL_OBJECTS_TARGETS = \ + $(srcdir)/Include/internal/pycore_global_objects.h \ + $(srcdir)/Include/internal/pycore_global_strings.h + +# The global objects will get regenerated as soon these files +# are required, including as a prerequisite for regen-deepfreeze. +$(GLOBAL_OBJECTS_TARGETS): generate-global-objects + +.PHONY: generate-global-objects +generate-global-objects: $(srcdir)/Tools/scripts/generate_global_objects.py $(PYTHON_FOR_REGEN) $(srcdir)/Tools/scripts/generate_global_objects.py +.PHONY: generate-global-objects-after-deepfreeze +generate-global-objects-after-deepfreeze: regen-deepfreeze $(srcdir)/Tools/scripts/generate_global_objects.py + $(PYTHON_FOR_REGEN) $(srcdir)/Tools/scripts/generate_global_objects.py + +.PHONY: regen-global-objects +regen-global-objects: regen-deepfreeze generate-global-objects-after-deepfreeze + ############################################################################ # ABI diff --git a/Tools/scripts/generate_global_objects.py b/Tools/scripts/generate_global_objects.py index f7653604e82..826f4c4c83a 100644 --- a/Tools/scripts/generate_global_objects.py +++ b/Tools/scripts/generate_global_objects.py @@ -115,7 +115,12 @@ def iter_global_strings(): id_regex = re.compile(r'\b_Py_ID\((\w+)\)') str_regex = re.compile(r'\b_Py_DECLARE_STR\((\w+), "(.*?)"\)') for filename in iter_files(): - with open(filename, encoding='utf-8') as infile: + try: + infile = open(filename, encoding='utf-8') + except FileNotFoundError: + # The file must have been a temporary file. + continue + with infile: for lno, line in enumerate(infile, 1): for m in id_regex.finditer(line): identifier, = m.groups()