mirror of
https://github.com/python/cpython.git
synced 2025-07-19 01:05:26 +00:00
bpo-45873: Get rid of bootstrap_python (#29717)
Instead we use $(PYTHON_FOR_REGEN) .../deepfreeze.py with the frozen .h file as input, as we did for Windows in bpo-45850. We also get rid of the code that generates the .h files when make regen-frozen is run (i.e., .../make_frozen.py), and the MANIFEST file. Restore Python 3.8 and 3.9 as Windows host Python again Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
This commit is contained in:
parent
ae1965ccb4
commit
5be98e57b3
8 changed files with 240 additions and 412 deletions
|
@ -25,31 +25,6 @@ STDLIB_DIR = os.path.join(ROOT_DIR, 'Lib')
|
|||
# need to be updated.
|
||||
MODULES_DIR = os.path.join(ROOT_DIR, 'Python', 'frozen_modules')
|
||||
|
||||
if sys.platform != "win32":
|
||||
TOOL = os.path.join(ROOT_DIR, 'Programs', '_freeze_module')
|
||||
if not os.path.isfile(TOOL):
|
||||
# When building out of the source tree, get the tool from directory
|
||||
# of the Python executable
|
||||
TOOL = os.path.dirname(sys.executable)
|
||||
TOOL = os.path.join(TOOL, 'Programs', '_freeze_module')
|
||||
TOOL = os.path.abspath(TOOL)
|
||||
if not os.path.isfile(TOOL):
|
||||
sys.exit("ERROR: missing _freeze_module")
|
||||
else:
|
||||
def find_tool():
|
||||
archs = ['amd64', 'win32']
|
||||
if platform.machine() == "ARM64":
|
||||
archs.append('arm64')
|
||||
for arch in archs:
|
||||
for exe in ['_freeze_module.exe', '_freeze_module_d.exe']:
|
||||
tool = os.path.join(ROOT_DIR, 'PCbuild', arch, exe)
|
||||
if os.path.isfile(tool):
|
||||
return tool
|
||||
sys.exit("ERROR: missing _freeze_module.exe; you need to run PCbuild/build.bat")
|
||||
TOOL = find_tool()
|
||||
del find_tool
|
||||
|
||||
MANIFEST = os.path.join(MODULES_DIR, 'MANIFEST')
|
||||
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')
|
||||
|
@ -480,45 +455,6 @@ def replace_block(lines, start_marker, end_marker, replacements, file):
|
|||
return lines[:start_pos + 1] + replacements + lines[end_pos:]
|
||||
|
||||
|
||||
def regen_manifest(modules):
|
||||
header = 'module ispkg source frozen checksum'.split()
|
||||
widths = [5] * len(header)
|
||||
rows = []
|
||||
for mod in modules:
|
||||
info = mod.summarize()
|
||||
row = []
|
||||
for i, col in enumerate(header):
|
||||
value = info[col]
|
||||
if col == 'checksum':
|
||||
value = value[:12]
|
||||
elif col == 'ispkg':
|
||||
value = 'YES' if value else 'no'
|
||||
widths[i] = max(widths[i], len(value))
|
||||
row.append(value or '-')
|
||||
rows.append(row)
|
||||
|
||||
modlines = [
|
||||
'# The list of frozen modules with key information.',
|
||||
'# Note that the "check_generated_files" CI job will identify',
|
||||
'# when source files were changed but regen-frozen wasn\'t run.',
|
||||
'# This file is auto-generated by Tools/scripts/freeze_modules.py.',
|
||||
' '.join(c.center(w) for c, w in zip(header, widths)).rstrip(),
|
||||
' '.join('-' * w for w in widths),
|
||||
]
|
||||
for row in rows:
|
||||
for i, w in enumerate(widths):
|
||||
if header[i] == 'ispkg':
|
||||
row[i] = row[i].center(w)
|
||||
else:
|
||||
row[i] = row[i].ljust(w)
|
||||
modlines.append(' '.join(row).rstrip())
|
||||
|
||||
print(f'# Updating {os.path.relpath(MANIFEST)}')
|
||||
with open(MANIFEST, 'w', encoding="utf-8") as outfile:
|
||||
lines = (l + '\n' for l in modlines)
|
||||
outfile.writelines(lines)
|
||||
|
||||
|
||||
def regen_frozen(modules):
|
||||
headerlines = []
|
||||
parentdir = os.path.dirname(FROZEN_FILE)
|
||||
|
@ -648,11 +584,11 @@ def regen_makefile(modules):
|
|||
deepfreezefiles.append(f"\t\t{ofile} \\")
|
||||
|
||||
# Also add a deepfreeze rule.
|
||||
deepfreezerules.append(f'{cfile}: $(srcdir)/{_pyfile} $(DEEPFREEZE_DEPS)')
|
||||
deepfreezerules.append(f'\t@echo "Deepfreezing {cfile} from {_pyfile}"')
|
||||
deepfreezerules.append(f"\t@./$(BOOTSTRAP) \\")
|
||||
deepfreezerules.append(f"\t\t$(srcdir)/Tools/scripts/deepfreeze.py \\")
|
||||
deepfreezerules.append(f"\t\t$(srcdir)/{_pyfile} -m {src.frozenid} -o {cfile}")
|
||||
deepfreezerules.append(f'{cfile}: {header} $(DEEPFREEZE_DEPS)')
|
||||
deepfreezerules.append(
|
||||
f"\t$(PYTHON_FOR_REGEN) "
|
||||
f"$(srcdir)/Tools/scripts/deepfreeze.py "
|
||||
f"{header} -m {src.frozenid} -o {cfile}")
|
||||
deepfreezerules.append('')
|
||||
|
||||
for src in _iter_sources(modules):
|
||||
|
@ -663,7 +599,7 @@ def regen_makefile(modules):
|
|||
pyfiles.append(f'\t\t{pyfile} \\')
|
||||
|
||||
freeze = (f'Programs/_freeze_module {src.frozenid} '
|
||||
f'$(srcdir)/{pyfile} $(srcdir)/{header}')
|
||||
f'$(srcdir)/{pyfile} {header}')
|
||||
rules.extend([
|
||||
f'{header}: Programs/_freeze_module {pyfile}',
|
||||
f'\t{freeze}',
|
||||
|
@ -774,32 +710,6 @@ def regen_pcbuild(modules):
|
|||
outfile.writelines(lines)
|
||||
|
||||
|
||||
#######################################
|
||||
# freezing modules
|
||||
|
||||
def freeze_module(modname, pyfile=None, destdir=MODULES_DIR):
|
||||
"""Generate the frozen module .h file for the given module."""
|
||||
tmpsuffix = f'.{int(time.time())}'
|
||||
for modname, pyfile, ispkg in resolve_modules(modname, pyfile):
|
||||
frozenfile = resolve_frozen_file(modname, destdir)
|
||||
_freeze_module(modname, pyfile, frozenfile, tmpsuffix)
|
||||
|
||||
|
||||
def _freeze_module(frozenid, pyfile, frozenfile, tmpsuffix):
|
||||
tmpfile = f'{frozenfile}.{int(time.time())}'
|
||||
|
||||
argv = [TOOL, frozenid, pyfile, tmpfile]
|
||||
print('#', ' '.join(os.path.relpath(a) for a in argv), flush=True)
|
||||
try:
|
||||
subprocess.run(argv, check=True)
|
||||
except (FileNotFoundError, subprocess.CalledProcessError):
|
||||
if not os.path.exists(TOOL):
|
||||
sys.exit(f'ERROR: missing {TOOL}; you need to run "make regen-frozen"')
|
||||
raise # re-raise
|
||||
|
||||
update_file_with_tmpfile(frozenfile, tmpfile, create=True)
|
||||
|
||||
|
||||
#######################################
|
||||
# the script
|
||||
|
||||
|
@ -810,15 +720,7 @@ def main():
|
|||
# Regen build-related files.
|
||||
regen_makefile(modules)
|
||||
regen_pcbuild(modules)
|
||||
|
||||
# Freeze the target modules.
|
||||
tmpsuffix = f'.{int(time.time())}'
|
||||
for src in _iter_sources(modules):
|
||||
_freeze_module(src.frozenid, src.pyfile, src.frozenfile, tmpsuffix)
|
||||
|
||||
# Regen files dependent of frozen file details.
|
||||
regen_frozen(modules)
|
||||
regen_manifest(modules)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue