Skip to content

Commit 41551ee

Browse files
authored
bpo-45020: Fix build out of source tree (GH-28410)
* Makefile.pre.in: Add $(srcdir) when needed, remove it when it was used by mistake. * freeze_modules.py tool uses ./Programs/_freeze_module if the executable doesn't exist in the source tree.
1 parent c5a677d commit 41551ee

File tree

2 files changed

+23
-17
lines changed

2 files changed

+23
-17
lines changed

Makefile.pre.in

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -728,7 +728,7 @@ regen-test-frozenmain: $(BUILDPYTHON)
728728
# Regenerate Programs/test_frozenmain.h
729729
# from Programs/test_frozenmain.py
730730
# using Programs/freeze_test_frozenmain.py
731-
$(RUNSHARED) ./$(BUILDPYTHON) Programs/freeze_test_frozenmain.py Programs/test_frozenmain.h
731+
$(RUNSHARED) ./$(BUILDPYTHON) $(srcdir)/Programs/freeze_test_frozenmain.py Programs/test_frozenmain.h
732732

733733
Programs/_testembed: Programs/_testembed.o $(LIBRARY_DEPS)
734734
$(LINKCC) $(PY_CORE_LDFLAGS) $(LINKFORSHARED) -o $@ Programs/_testembed.o $(BLDLIBRARY) $(LIBS) $(MODLIBS) $(SYSLIBS)
@@ -751,40 +751,40 @@ regen-frozen: Tools/scripts/freeze_modules.py $(FROZEN_FILES)
751751
# BEGIN: freezing modules
752752

753753
Python/frozen_modules/importlib__bootstrap.h: Programs/_freeze_module Lib/importlib/_bootstrap.py
754-
$(srcdir)/Programs/_freeze_module importlib._bootstrap $(srcdir)/Lib/importlib/_bootstrap.py $(srcdir)/Python/frozen_modules/importlib__bootstrap.h
754+
Programs/_freeze_module importlib._bootstrap $(srcdir)/Lib/importlib/_bootstrap.py $(srcdir)/Python/frozen_modules/importlib__bootstrap.h
755755

756756
Python/frozen_modules/importlib__bootstrap_external.h: Programs/_freeze_module Lib/importlib/_bootstrap_external.py
757-
$(srcdir)/Programs/_freeze_module importlib._bootstrap_external $(srcdir)/Lib/importlib/_bootstrap_external.py $(srcdir)/Python/frozen_modules/importlib__bootstrap_external.h
757+
Programs/_freeze_module importlib._bootstrap_external $(srcdir)/Lib/importlib/_bootstrap_external.py $(srcdir)/Python/frozen_modules/importlib__bootstrap_external.h
758758

759759
Python/frozen_modules/zipimport.h: Programs/_freeze_module Lib/zipimport.py
760-
$(srcdir)/Programs/_freeze_module zipimport $(srcdir)/Lib/zipimport.py $(srcdir)/Python/frozen_modules/zipimport.h
760+
Programs/_freeze_module zipimport $(srcdir)/Lib/zipimport.py $(srcdir)/Python/frozen_modules/zipimport.h
761761

762762
Python/frozen_modules/abc.h: Programs/_freeze_module Lib/abc.py
763-
$(srcdir)/Programs/_freeze_module abc $(srcdir)/Lib/abc.py $(srcdir)/Python/frozen_modules/abc.h
763+
Programs/_freeze_module abc $(srcdir)/Lib/abc.py $(srcdir)/Python/frozen_modules/abc.h
764764

765765
Python/frozen_modules/io.h: Programs/_freeze_module Lib/io.py
766-
$(srcdir)/Programs/_freeze_module io $(srcdir)/Lib/io.py $(srcdir)/Python/frozen_modules/io.h
766+
Programs/_freeze_module io $(srcdir)/Lib/io.py $(srcdir)/Python/frozen_modules/io.h
767767

768768
Python/frozen_modules/_collections_abc.h: Programs/_freeze_module Lib/_collections_abc.py
769-
$(srcdir)/Programs/_freeze_module _collections_abc $(srcdir)/Lib/_collections_abc.py $(srcdir)/Python/frozen_modules/_collections_abc.h
769+
Programs/_freeze_module _collections_abc $(srcdir)/Lib/_collections_abc.py $(srcdir)/Python/frozen_modules/_collections_abc.h
770770

771771
Python/frozen_modules/_sitebuiltins.h: Programs/_freeze_module Lib/_sitebuiltins.py
772-
$(srcdir)/Programs/_freeze_module _sitebuiltins $(srcdir)/Lib/_sitebuiltins.py $(srcdir)/Python/frozen_modules/_sitebuiltins.h
772+
Programs/_freeze_module _sitebuiltins $(srcdir)/Lib/_sitebuiltins.py $(srcdir)/Python/frozen_modules/_sitebuiltins.h
773773

774774
Python/frozen_modules/genericpath.h: Programs/_freeze_module Lib/genericpath.py
775-
$(srcdir)/Programs/_freeze_module genericpath $(srcdir)/Lib/genericpath.py $(srcdir)/Python/frozen_modules/genericpath.h
775+
Programs/_freeze_module genericpath $(srcdir)/Lib/genericpath.py $(srcdir)/Python/frozen_modules/genericpath.h
776776

777777
Python/frozen_modules/ntpath.h: Programs/_freeze_module Lib/ntpath.py
778-
$(srcdir)/Programs/_freeze_module ntpath $(srcdir)/Lib/ntpath.py $(srcdir)/Python/frozen_modules/ntpath.h
778+
Programs/_freeze_module ntpath $(srcdir)/Lib/ntpath.py $(srcdir)/Python/frozen_modules/ntpath.h
779779

780780
Python/frozen_modules/posixpath.h: Programs/_freeze_module Lib/posixpath.py
781-
$(srcdir)/Programs/_freeze_module posixpath $(srcdir)/Lib/posixpath.py $(srcdir)/Python/frozen_modules/posixpath.h
781+
Programs/_freeze_module posixpath $(srcdir)/Lib/posixpath.py $(srcdir)/Python/frozen_modules/posixpath.h
782782

783783
Python/frozen_modules/stat.h: Programs/_freeze_module Lib/stat.py
784-
$(srcdir)/Programs/_freeze_module stat $(srcdir)/Lib/stat.py $(srcdir)/Python/frozen_modules/stat.h
784+
Programs/_freeze_module stat $(srcdir)/Lib/stat.py $(srcdir)/Python/frozen_modules/stat.h
785785

786786
Python/frozen_modules/__hello__.h: Programs/_freeze_module Lib/__hello__.py
787-
$(srcdir)/Programs/_freeze_module __hello__ $(srcdir)/Lib/__hello__.py $(srcdir)/Python/frozen_modules/__hello__.h
787+
Programs/_freeze_module __hello__ $(srcdir)/Lib/__hello__.py $(srcdir)/Python/frozen_modules/__hello__.h
788788

789789
# END: freezing modules
790790

Tools/scripts/freeze_modules.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@
1515
from update_file import updating_file_with_tmpfile
1616

1717

18-
SCRIPTS_DIR = os.path.abspath(os.path.dirname(__file__))
19-
TOOLS_DIR = os.path.dirname(SCRIPTS_DIR)
20-
ROOT_DIR = os.path.dirname(TOOLS_DIR)
18+
ROOT_DIR = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
19+
ROOT_DIR = os.path.abspath(ROOT_DIR)
2120

2221
STDLIB_DIR = os.path.join(ROOT_DIR, 'Lib')
2322
# If MODULES_DIR is changed then the .gitattributes and .gitignore files
@@ -26,6 +25,13 @@
2625

2726
if sys.platform != "win32":
2827
TOOL = os.path.join(ROOT_DIR, 'Programs', '_freeze_module')
28+
if not os.path.isfile(TOOL):
29+
# When building out of the source tree, get the tool from the current
30+
# directory
31+
TOOL = os.path.join('Programs', '_freeze_module')
32+
TOOL = os.path.abspath(TOOL)
33+
if not os.path.isfile(TOOL):
34+
sys.exit("ERROR: missing _freeze_module")
2935
else:
3036
def find_tool():
3137
for arch in ['amd64', 'win32']:
@@ -547,7 +553,7 @@ def regen_makefile(modules):
547553
# instead of going through an intermediate file like we used to.
548554
rules.append(f'{header}: Programs/_freeze_module {pyfile}')
549555
rules.append(
550-
(f'\t$(srcdir)/Programs/_freeze_module {src.frozenid} '
556+
(f'\tPrograms/_freeze_module {src.frozenid} '
551557
f'$(srcdir)/{pyfile} $(srcdir)/{header}'))
552558
rules.append('')
553559

0 commit comments

Comments
 (0)