From 8eaa206feccc913d172027a613d34a50210f4511 Mon Sep 17 00:00:00 2001 From: Riccardo Ghetta Date: Mon, 30 Oct 2023 17:14:26 +0100 Subject: gh-109515: When generating deep frozen modules on Windows, use a list file instead of arguments (GH-109516) --- PCbuild/_freeze_module.vcxproj | 64 +++++++++++++++++++++++++----------------- Tools/build/deepfreeze.py | 16 +++++++++-- Tools/build/freeze_modules.py | 28 ++++++++++++++++-- 3 files changed, 78 insertions(+), 30 deletions(-) diff --git a/PCbuild/_freeze_module.vcxproj b/PCbuild/_freeze_module.vcxproj index 5ca1058..cfcb6cb 100644 --- a/PCbuild/_freeze_module.vcxproj +++ b/PCbuild/_freeze_module.vcxproj @@ -395,6 +395,33 @@ $(PySourcePath)Python\frozen_modules\getpath.h + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -426,32 +453,19 @@ AfterTargets="_RebuildFrozen" DependsOnTargets="FindPythonForBuild" Condition="$(Configuration) != 'PGUpdate'"> + + + +$(IntDir)\deepfreeze_mappings.txt + + + + - + diff --git a/Tools/build/deepfreeze.py b/Tools/build/deepfreeze.py index fed7cf3..218c64e 100644 --- a/Tools/build/deepfreeze.py +++ b/Tools/build/deepfreeze.py @@ -488,7 +488,10 @@ def generate(args: list[str], output: TextIO) -> None: parser = argparse.ArgumentParser() parser.add_argument("-o", "--output", help="Defaults to deepfreeze.c", default="deepfreeze.c") parser.add_argument("-v", "--verbose", action="store_true", help="Print diagnostics") -parser.add_argument('args', nargs="+", help="Input file and module name (required) in file:modname format") +group = parser.add_mutually_exclusive_group(required=True) +group.add_argument("-f", "--file", help="read rule lines from a file") +group.add_argument('args', nargs="*", default=(), + help="Input file and module name (required) in file:modname format") @contextlib.contextmanager def report_time(label: str): @@ -506,9 +509,18 @@ def main() -> None: args = parser.parse_args() verbose = args.verbose output = args.output + + if args.file: + if verbose: + print(f"Reading targets from {args.file}") + with open(args.file, "rt", encoding="utf-8-sig") as fin: + rules = [x.strip() for x in fin] + else: + rules = args.args + with open(output, "w", encoding="utf-8") as file: with report_time("generate"): - generate(args.args, file) + generate(rules, file) if verbose: print(f"Wrote {os.path.getsize(output)} bytes to {output}") diff --git a/Tools/build/freeze_modules.py b/Tools/build/freeze_modules.py index a07f4d9..c5a3971 100644 --- a/Tools/build/freeze_modules.py +++ b/Tools/build/freeze_modules.py @@ -21,6 +21,7 @@ STDLIB_DIR = os.path.join(ROOT_DIR, 'Lib') # .gitattributes and .gitignore files needs to be updated. FROZEN_MODULES_DIR = os.path.join(ROOT_DIR, 'Python', 'frozen_modules') DEEPFROZEN_MODULES_DIR = os.path.join(ROOT_DIR, 'Python', 'deepfreeze') +DEEPFREEZE_MAPPING_FNAME = 'deepfreeze_mappings.txt' FROZEN_FILE = os.path.join(ROOT_DIR, 'Python', 'frozen.c') MAKEFILE = os.path.join(ROOT_DIR, 'Makefile.pre.in') @@ -645,7 +646,9 @@ def regen_pcbuild(modules): projlines = [] filterlines = [] corelines = [] - deepfreezerules = ['\t'] + deepfreezemappings = [] for src in _iter_sources(modules): pyfile = relpath_for_windows_display(src.pyfile, ROOT_DIR) header = relpath_for_windows_display(src.frozenfile, ROOT_DIR) @@ -659,8 +662,7 @@ def regen_pcbuild(modules): filterlines.append(f' ') filterlines.append(' Python Files') filterlines.append(' ') - deepfreezerules.append(f'\t\t "$(PySourcePath){header}:{src.frozenid}" ^') - deepfreezerules.append('\t\t "-o" "$(PySourcePath)Python\\deepfreeze\\deepfreeze.c"\'/>' ) + deepfreezemappings.append(f' \n') corelines.append(f' ') @@ -679,6 +681,26 @@ def regen_pcbuild(modules): lines = infile.readlines() lines = replace_block( lines, + '', + '', + deepfreezemappings, + PCBUILD_PROJECT, + ) + outfile.writelines(lines) + with updating_file_with_tmpfile(PCBUILD_PROJECT) as (infile, outfile): + lines = infile.readlines() + lines = replace_block( + lines, + '', + '', + [deepfreezemappingsfile, ], + PCBUILD_PROJECT, + ) + outfile.writelines(lines) + with updating_file_with_tmpfile(PCBUILD_PROJECT) as (infile, outfile): + lines = infile.readlines() + lines = replace_block( + lines, '', '', deepfreezerules, -- cgit v0.12