bpo-45850: Implement deep-freeze on Windows (#29648)

Implement changes to build with deep-frozen modules on Windows.
Note that we now require Python 3.10 as the "bootstrap" or "host" Python.
This causes a modest startup speed (around 7%) on Windows.
This commit is contained in:
Guido van Rossum 2021-11-22 10:09:48 -08:00 committed by GitHub
parent 4d6c0c0cce
commit 1037ca5a8e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 500 additions and 24 deletions

View file

@ -11,7 +11,6 @@ import posixpath
import platform
import subprocess
import sys
import textwrap
import time
from update_file import updating_file_with_tmpfile, update_file_with_tmpfile
@ -55,6 +54,7 @@ FROZEN_FILE = os.path.join(ROOT_DIR, 'Python', 'frozen.c')
MAKEFILE = os.path.join(ROOT_DIR, 'Makefile.pre.in')
PCBUILD_PROJECT = os.path.join(ROOT_DIR, 'PCbuild', '_freeze_module.vcxproj')
PCBUILD_FILTERS = os.path.join(ROOT_DIR, 'PCbuild', '_freeze_module.vcxproj.filters')
PCBUILD_PYTHONCORE = os.path.join(ROOT_DIR, 'PCbuild', 'pythoncore.vcxproj')
OS_PATH = 'ntpath' if os.name == 'nt' else 'posixpath'
@ -717,20 +717,28 @@ def regen_makefile(modules):
def regen_pcbuild(modules):
projlines = []
filterlines = []
corelines = []
for src in _iter_sources(modules):
pyfile = relpath_for_windows_display(src.pyfile, ROOT_DIR)
header = relpath_for_windows_display(src.frozenfile, ROOT_DIR)
deepbase = "df." + src.id
deepoutfile = f"Python\\deepfreeze\\{deepbase}.c"
intfile = ntpath.splitext(ntpath.basename(header))[0] + '.g.h'
deepintfile = ntpath.splitext(ntpath.basename(header))[0] + '.g.c'
projlines.append(f' <None Include="..\\{pyfile}">')
projlines.append(f' <ModName>{src.frozenid}</ModName>')
projlines.append(f' <IntFile>$(IntDir){intfile}</IntFile>')
projlines.append(f' <OutFile>$(PySourcePath){header}</OutFile>')
projlines.append(f' <DeepIntFile>$(IntDir){deepintfile}</DeepIntFile>')
projlines.append(f' <DeepOutFile>$(PySourcePath){deepoutfile}</DeepOutFile>')
projlines.append(f' </None>')
filterlines.append(f' <None Include="..\\{pyfile}">')
filterlines.append(' <Filter>Python Files</Filter>')
filterlines.append(' </None>')
corelines.append(f' <ClCompile Include="..\\{deepoutfile}" />')
print(f'# Updating {os.path.relpath(PCBUILD_PROJECT)}')
with updating_file_with_tmpfile(PCBUILD_PROJECT) as (infile, outfile):
lines = infile.readlines()
@ -753,6 +761,17 @@ def regen_pcbuild(modules):
PCBUILD_FILTERS,
)
outfile.writelines(lines)
print(f'# Updating {os.path.relpath(PCBUILD_PYTHONCORE)}')
with updating_file_with_tmpfile(PCBUILD_PYTHONCORE) as (infile, outfile):
lines = infile.readlines()
lines = replace_block(
lines,
'<!-- BEGIN deepfreeze -->',
'<!-- END deepfreeze -->',
corelines,
PCBUILD_FILTERS,
)
outfile.writelines(lines)
#######################################