From ef3ef6fa43d5cca072eed2a66064e818de583be7 Mon Sep 17 00:00:00 2001
From: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
Date: Thu, 20 Jan 2022 22:08:39 +0530
Subject: bpo-46429: Merge all deepfrozen files into one (GH-30572)
---
Makefile.pre.in | 145 ++++++---------------
.../Build/2022-01-19-04-36-15.bpo-46429.y0OtVL.rst | 1 +
PCbuild/_freeze_module.vcxproj | 89 +++++--------
PCbuild/pythoncore.vcxproj | 24 +---
Tools/scripts/deepfreeze.py | 59 ++++-----
Tools/scripts/freeze_modules.py | 45 +++----
6 files changed, 120 insertions(+), 243 deletions(-)
create mode 100644 Misc/NEWS.d/next/Build/2022-01-19-04-36-15.bpo-46429.y0OtVL.rst
diff --git a/Makefile.pre.in b/Makefile.pre.in
index 0b4d9a5..3ea019b 100644
--- a/Makefile.pre.in
+++ b/Makefile.pre.in
@@ -484,32 +484,7 @@ OBJECT_OBJS= \
Objects/unionobject.o \
Objects/weakrefobject.o
-# DEEPFREEZE_OBJS is auto-generated by Tools/scripts/freeze_modules.py.
-DEEPFREEZE_OBJS = \
- Python/deepfreeze/importlib._bootstrap.o \
- Python/deepfreeze/importlib._bootstrap_external.o \
- Python/deepfreeze/zipimport.o \
- Python/deepfreeze/abc.o \
- Python/deepfreeze/codecs.o \
- Python/deepfreeze/io.o \
- Python/deepfreeze/_collections_abc.o \
- Python/deepfreeze/_sitebuiltins.o \
- Python/deepfreeze/genericpath.o \
- Python/deepfreeze/ntpath.o \
- Python/deepfreeze/posixpath.o \
- Python/deepfreeze/os.o \
- Python/deepfreeze/site.o \
- Python/deepfreeze/stat.o \
- Python/deepfreeze/importlib.util.o \
- Python/deepfreeze/importlib.machinery.o \
- Python/deepfreeze/runpy.o \
- Python/deepfreeze/__hello__.o \
- Python/deepfreeze/__phello__.o \
- Python/deepfreeze/__phello__.ham.o \
- Python/deepfreeze/__phello__.ham.eggs.o \
- Python/deepfreeze/__phello__.spam.o \
- Python/deepfreeze/frozen_only.o
-# End DEEPFREEZE_OBJS
+DEEPFREEZE_OBJS = Python/deepfreeze/deepfreeze.o
##########################################################################
# objects that get linked into the Python library
@@ -984,86 +959,6 @@ _bootstrap_python: $(LIBRARY_OBJS_OMIT_FROZEN) Programs/_bootstrap_python.o Modu
$(LINKCC) $(PY_LDFLAGS_NOLTO) -o $@ $(LIBRARY_OBJS_OMIT_FROZEN) \
Programs/_bootstrap_python.o Modules/getpath.o $(LIBS) $(MODLIBS) $(SYSLIBS)
-############################################################################
-# Deepfreeze targets
-
-.PHONY: regen-deepfreeze
-regen-deepfreeze: $(DEEPFREEZE_OBJS)
-
-DEEPFREEZE_DEPS=$(srcdir)/Tools/scripts/deepfreeze.py $(FREEZE_MODULE_DEPS)
-
-# BEGIN: deepfreeze modules
-
-Python/deepfreeze/importlib._bootstrap.c: Python/frozen_modules/importlib._bootstrap.h $(DEEPFREEZE_DEPS)
- $(PYTHON_FOR_FREEZE) $(srcdir)/Tools/scripts/deepfreeze.py Python/frozen_modules/importlib._bootstrap.h -m importlib._bootstrap -o Python/deepfreeze/importlib._bootstrap.c
-
-Python/deepfreeze/importlib._bootstrap_external.c: Python/frozen_modules/importlib._bootstrap_external.h $(DEEPFREEZE_DEPS)
- $(PYTHON_FOR_FREEZE) $(srcdir)/Tools/scripts/deepfreeze.py Python/frozen_modules/importlib._bootstrap_external.h -m importlib._bootstrap_external -o Python/deepfreeze/importlib._bootstrap_external.c
-
-Python/deepfreeze/zipimport.c: Python/frozen_modules/zipimport.h $(DEEPFREEZE_DEPS)
- $(PYTHON_FOR_FREEZE) $(srcdir)/Tools/scripts/deepfreeze.py Python/frozen_modules/zipimport.h -m zipimport -o Python/deepfreeze/zipimport.c
-
-Python/deepfreeze/abc.c: Python/frozen_modules/abc.h $(DEEPFREEZE_DEPS)
- $(PYTHON_FOR_FREEZE) $(srcdir)/Tools/scripts/deepfreeze.py Python/frozen_modules/abc.h -m abc -o Python/deepfreeze/abc.c
-
-Python/deepfreeze/codecs.c: Python/frozen_modules/codecs.h $(DEEPFREEZE_DEPS)
- $(PYTHON_FOR_FREEZE) $(srcdir)/Tools/scripts/deepfreeze.py Python/frozen_modules/codecs.h -m codecs -o Python/deepfreeze/codecs.c
-
-Python/deepfreeze/io.c: Python/frozen_modules/io.h $(DEEPFREEZE_DEPS)
- $(PYTHON_FOR_FREEZE) $(srcdir)/Tools/scripts/deepfreeze.py Python/frozen_modules/io.h -m io -o Python/deepfreeze/io.c
-
-Python/deepfreeze/_collections_abc.c: Python/frozen_modules/_collections_abc.h $(DEEPFREEZE_DEPS)
- $(PYTHON_FOR_FREEZE) $(srcdir)/Tools/scripts/deepfreeze.py Python/frozen_modules/_collections_abc.h -m _collections_abc -o Python/deepfreeze/_collections_abc.c
-
-Python/deepfreeze/_sitebuiltins.c: Python/frozen_modules/_sitebuiltins.h $(DEEPFREEZE_DEPS)
- $(PYTHON_FOR_FREEZE) $(srcdir)/Tools/scripts/deepfreeze.py Python/frozen_modules/_sitebuiltins.h -m _sitebuiltins -o Python/deepfreeze/_sitebuiltins.c
-
-Python/deepfreeze/genericpath.c: Python/frozen_modules/genericpath.h $(DEEPFREEZE_DEPS)
- $(PYTHON_FOR_FREEZE) $(srcdir)/Tools/scripts/deepfreeze.py Python/frozen_modules/genericpath.h -m genericpath -o Python/deepfreeze/genericpath.c
-
-Python/deepfreeze/ntpath.c: Python/frozen_modules/ntpath.h $(DEEPFREEZE_DEPS)
- $(PYTHON_FOR_FREEZE) $(srcdir)/Tools/scripts/deepfreeze.py Python/frozen_modules/ntpath.h -m ntpath -o Python/deepfreeze/ntpath.c
-
-Python/deepfreeze/posixpath.c: Python/frozen_modules/posixpath.h $(DEEPFREEZE_DEPS)
- $(PYTHON_FOR_FREEZE) $(srcdir)/Tools/scripts/deepfreeze.py Python/frozen_modules/posixpath.h -m posixpath -o Python/deepfreeze/posixpath.c
-
-Python/deepfreeze/os.c: Python/frozen_modules/os.h $(DEEPFREEZE_DEPS)
- $(PYTHON_FOR_FREEZE) $(srcdir)/Tools/scripts/deepfreeze.py Python/frozen_modules/os.h -m os -o Python/deepfreeze/os.c
-
-Python/deepfreeze/site.c: Python/frozen_modules/site.h $(DEEPFREEZE_DEPS)
- $(PYTHON_FOR_FREEZE) $(srcdir)/Tools/scripts/deepfreeze.py Python/frozen_modules/site.h -m site -o Python/deepfreeze/site.c
-
-Python/deepfreeze/stat.c: Python/frozen_modules/stat.h $(DEEPFREEZE_DEPS)
- $(PYTHON_FOR_FREEZE) $(srcdir)/Tools/scripts/deepfreeze.py Python/frozen_modules/stat.h -m stat -o Python/deepfreeze/stat.c
-
-Python/deepfreeze/importlib.util.c: Python/frozen_modules/importlib.util.h $(DEEPFREEZE_DEPS)
- $(PYTHON_FOR_FREEZE) $(srcdir)/Tools/scripts/deepfreeze.py Python/frozen_modules/importlib.util.h -m importlib.util -o Python/deepfreeze/importlib.util.c
-
-Python/deepfreeze/importlib.machinery.c: Python/frozen_modules/importlib.machinery.h $(DEEPFREEZE_DEPS)
- $(PYTHON_FOR_FREEZE) $(srcdir)/Tools/scripts/deepfreeze.py Python/frozen_modules/importlib.machinery.h -m importlib.machinery -o Python/deepfreeze/importlib.machinery.c
-
-Python/deepfreeze/runpy.c: Python/frozen_modules/runpy.h $(DEEPFREEZE_DEPS)
- $(PYTHON_FOR_FREEZE) $(srcdir)/Tools/scripts/deepfreeze.py Python/frozen_modules/runpy.h -m runpy -o Python/deepfreeze/runpy.c
-
-Python/deepfreeze/__hello__.c: Python/frozen_modules/__hello__.h $(DEEPFREEZE_DEPS)
- $(PYTHON_FOR_FREEZE) $(srcdir)/Tools/scripts/deepfreeze.py Python/frozen_modules/__hello__.h -m __hello__ -o Python/deepfreeze/__hello__.c
-
-Python/deepfreeze/__phello__.c: Python/frozen_modules/__phello__.h $(DEEPFREEZE_DEPS)
- $(PYTHON_FOR_FREEZE) $(srcdir)/Tools/scripts/deepfreeze.py Python/frozen_modules/__phello__.h -m __phello__ -o Python/deepfreeze/__phello__.c
-
-Python/deepfreeze/__phello__.ham.c: Python/frozen_modules/__phello__.ham.h $(DEEPFREEZE_DEPS)
- $(PYTHON_FOR_FREEZE) $(srcdir)/Tools/scripts/deepfreeze.py Python/frozen_modules/__phello__.ham.h -m __phello__.ham -o Python/deepfreeze/__phello__.ham.c
-
-Python/deepfreeze/__phello__.ham.eggs.c: Python/frozen_modules/__phello__.ham.eggs.h $(DEEPFREEZE_DEPS)
- $(PYTHON_FOR_FREEZE) $(srcdir)/Tools/scripts/deepfreeze.py Python/frozen_modules/__phello__.ham.eggs.h -m __phello__.ham.eggs -o Python/deepfreeze/__phello__.ham.eggs.c
-
-Python/deepfreeze/__phello__.spam.c: Python/frozen_modules/__phello__.spam.h $(DEEPFREEZE_DEPS)
- $(PYTHON_FOR_FREEZE) $(srcdir)/Tools/scripts/deepfreeze.py Python/frozen_modules/__phello__.spam.h -m __phello__.spam -o Python/deepfreeze/__phello__.spam.c
-
-Python/deepfreeze/frozen_only.c: Python/frozen_modules/frozen_only.h $(DEEPFREEZE_DEPS)
- $(PYTHON_FOR_FREEZE) $(srcdir)/Tools/scripts/deepfreeze.py Python/frozen_modules/frozen_only.h -m frozen_only -o Python/deepfreeze/frozen_only.c
-
-# END: deepfreeze modules
############################################################################
# frozen modules (including importlib)
@@ -1235,6 +1130,44 @@ regen-frozen: Tools/scripts/freeze_modules.py $(FROZEN_FILES_IN)
$(PYTHON_FOR_REGEN) $(srcdir)/Tools/scripts/freeze_modules.py
@echo "The Makefile was updated, you may need to re-run make."
+############################################################################
+# Deepfreeze targets
+
+.PHONY: regen-deepfreeze
+regen-deepfreeze: $(DEEPFREEZE_OBJS)
+
+DEEPFREEZE_DEPS=$(srcdir)/Tools/scripts/deepfreeze.py $(FREEZE_MODULE_DEPS) $(FROZEN_FILES_OUT)
+
+# BEGIN: deepfreeze modules
+Python/deepfreeze/deepfreeze.c: $(DEEPFREEZE_DEPS)
+ $(PYTHON_FOR_FREEZE) $(srcdir)/Tools/scripts/deepfreeze.py \
+ Python/frozen_modules/importlib._bootstrap.h:importlib._bootstrap \
+ Python/frozen_modules/importlib._bootstrap_external.h:importlib._bootstrap_external \
+ Python/frozen_modules/zipimport.h:zipimport \
+ Python/frozen_modules/abc.h:abc \
+ Python/frozen_modules/codecs.h:codecs \
+ Python/frozen_modules/io.h:io \
+ Python/frozen_modules/_collections_abc.h:_collections_abc \
+ Python/frozen_modules/_sitebuiltins.h:_sitebuiltins \
+ Python/frozen_modules/genericpath.h:genericpath \
+ Python/frozen_modules/ntpath.h:ntpath \
+ Python/frozen_modules/posixpath.h:posixpath \
+ Python/frozen_modules/os.h:os \
+ Python/frozen_modules/site.h:site \
+ Python/frozen_modules/stat.h:stat \
+ Python/frozen_modules/importlib.util.h:importlib.util \
+ Python/frozen_modules/importlib.machinery.h:importlib.machinery \
+ Python/frozen_modules/runpy.h:runpy \
+ Python/frozen_modules/__hello__.h:__hello__ \
+ Python/frozen_modules/__phello__.h:__phello__ \
+ Python/frozen_modules/__phello__.ham.h:__phello__.ham \
+ Python/frozen_modules/__phello__.ham.eggs.h:__phello__.ham.eggs \
+ Python/frozen_modules/__phello__.spam.h:__phello__.spam \
+ Python/frozen_modules/frozen_only.h:frozen_only \
+ -o Python/deepfreeze/deepfreeze.c
+
+# END: deepfreeze modules
+
# We keep this renamed target around for folks with muscle memory.
.PHONY: regen-importlib
regen-importlib: regen-frozen
diff --git a/Misc/NEWS.d/next/Build/2022-01-19-04-36-15.bpo-46429.y0OtVL.rst b/Misc/NEWS.d/next/Build/2022-01-19-04-36-15.bpo-46429.y0OtVL.rst
new file mode 100644
index 0000000..c983d96
--- /dev/null
+++ b/Misc/NEWS.d/next/Build/2022-01-19-04-36-15.bpo-46429.y0OtVL.rst
@@ -0,0 +1 @@
+Merge all deep-frozen files into one for space savings. Patch by Kumar Aditya.
\ No newline at end of file
diff --git a/PCbuild/_freeze_module.vcxproj b/PCbuild/_freeze_module.vcxproj
index 59519ca..0a74f58 100644
--- a/PCbuild/_freeze_module.vcxproj
+++ b/PCbuild/_freeze_module.vcxproj
@@ -241,162 +241,116 @@
importlib._bootstrap
$(IntDir)importlib._bootstrap.g.h
$(PySourcePath)Python\frozen_modules\importlib._bootstrap.h
- $(IntDir)importlib._bootstrap.g.c
- $(PySourcePath)Python\deepfreeze\df.importlib._bootstrap.c
importlib._bootstrap_external
$(IntDir)importlib._bootstrap_external.g.h
$(PySourcePath)Python\frozen_modules\importlib._bootstrap_external.h
- $(IntDir)importlib._bootstrap_external.g.c
- $(PySourcePath)Python\deepfreeze\df.importlib._bootstrap_external.c
zipimport
$(IntDir)zipimport.g.h
$(PySourcePath)Python\frozen_modules\zipimport.h
- $(IntDir)zipimport.g.c
- $(PySourcePath)Python\deepfreeze\df.zipimport.c
abc
$(IntDir)abc.g.h
$(PySourcePath)Python\frozen_modules\abc.h
- $(IntDir)abc.g.c
- $(PySourcePath)Python\deepfreeze\df.abc.c
codecs
$(IntDir)codecs.g.h
$(PySourcePath)Python\frozen_modules\codecs.h
- $(IntDir)codecs.g.c
- $(PySourcePath)Python\deepfreeze\df.codecs.c
io
$(IntDir)io.g.h
$(PySourcePath)Python\frozen_modules\io.h
- $(IntDir)io.g.c
- $(PySourcePath)Python\deepfreeze\df.io.c
_collections_abc
$(IntDir)_collections_abc.g.h
$(PySourcePath)Python\frozen_modules\_collections_abc.h
- $(IntDir)_collections_abc.g.c
- $(PySourcePath)Python\deepfreeze\df._collections_abc.c
_sitebuiltins
$(IntDir)_sitebuiltins.g.h
$(PySourcePath)Python\frozen_modules\_sitebuiltins.h
- $(IntDir)_sitebuiltins.g.c
- $(PySourcePath)Python\deepfreeze\df._sitebuiltins.c
genericpath
$(IntDir)genericpath.g.h
$(PySourcePath)Python\frozen_modules\genericpath.h
- $(IntDir)genericpath.g.c
- $(PySourcePath)Python\deepfreeze\df.genericpath.c
ntpath
$(IntDir)ntpath.g.h
$(PySourcePath)Python\frozen_modules\ntpath.h
- $(IntDir)ntpath.g.c
- $(PySourcePath)Python\deepfreeze\df.ntpath.c
posixpath
$(IntDir)posixpath.g.h
$(PySourcePath)Python\frozen_modules\posixpath.h
- $(IntDir)posixpath.g.c
- $(PySourcePath)Python\deepfreeze\df.posixpath.c
os
$(IntDir)os.g.h
$(PySourcePath)Python\frozen_modules\os.h
- $(IntDir)os.g.c
- $(PySourcePath)Python\deepfreeze\df.os.c
site
$(IntDir)site.g.h
$(PySourcePath)Python\frozen_modules\site.h
- $(IntDir)site.g.c
- $(PySourcePath)Python\deepfreeze\df.site.c
stat
$(IntDir)stat.g.h
$(PySourcePath)Python\frozen_modules\stat.h
- $(IntDir)stat.g.c
- $(PySourcePath)Python\deepfreeze\df.stat.c
importlib.util
$(IntDir)importlib.util.g.h
$(PySourcePath)Python\frozen_modules\importlib.util.h
- $(IntDir)importlib.util.g.c
- $(PySourcePath)Python\deepfreeze\df.importlib.util.c
importlib.machinery
$(IntDir)importlib.machinery.g.h
$(PySourcePath)Python\frozen_modules\importlib.machinery.h
- $(IntDir)importlib.machinery.g.c
- $(PySourcePath)Python\deepfreeze\df.importlib.machinery.c
runpy
$(IntDir)runpy.g.h
$(PySourcePath)Python\frozen_modules\runpy.h
- $(IntDir)runpy.g.c
- $(PySourcePath)Python\deepfreeze\df.runpy.c
__hello__
$(IntDir)__hello__.g.h
$(PySourcePath)Python\frozen_modules\__hello__.h
- $(IntDir)__hello__.g.c
- $(PySourcePath)Python\deepfreeze\df.__hello__.c
__phello__
$(IntDir)__phello__.g.h
$(PySourcePath)Python\frozen_modules\__phello__.h
- $(IntDir)__phello__.g.c
- $(PySourcePath)Python\deepfreeze\df.__phello__.c
__phello__.ham
$(IntDir)__phello__.ham.g.h
$(PySourcePath)Python\frozen_modules\__phello__.ham.h
- $(IntDir)__phello__.ham.g.c
- $(PySourcePath)Python\deepfreeze\df.__phello__.ham.c
__phello__.ham.eggs
$(IntDir)__phello__.ham.eggs.g.h
$(PySourcePath)Python\frozen_modules\__phello__.ham.eggs.h
- $(IntDir)__phello__.ham.eggs.g.c
- $(PySourcePath)Python\deepfreeze\df.__phello__.ham.eggs.c
__phello__.spam
$(IntDir)__phello__.spam.g.h
$(PySourcePath)Python\frozen_modules\__phello__.spam.h
- $(IntDir)__phello__.spam.g.c
- $(PySourcePath)Python\deepfreeze\df.__phello__.spam.c
frozen_only
$(IntDir)frozen_only.g.h
$(PySourcePath)Python\frozen_modules\frozen_only.h
- $(IntDir)frozen_only.g.c
- $(PySourcePath)Python\deepfreeze\df.frozen_only.c
@@ -424,11 +378,11 @@
Condition="'@(_UpdatedGetPath)' != ''" Importance="high" />
-
+
-
+ Condition="!Exists(%(None.OutFile)) or (Exists(%(None.IntFile)) and '$([System.IO.File]::ReadAllText(%(None.OutFile)).Replace(`
`, `
`))' != '$([System.IO.File]::ReadAllText(%(None.IntFile)).Replace(`
`, `
`))')">
@@ -439,16 +393,33 @@
AfterTargets="_RebuildFrozen"
DependsOnTargets="FindPythonForBuild"
Condition="$(Configuration) != 'PGUpdate'">
-
-
-
-
-
-
-
+
+
+
diff --git a/PCbuild/pythoncore.vcxproj b/PCbuild/pythoncore.vcxproj
index 12eac8e..fd1ab83 100644
--- a/PCbuild/pythoncore.vcxproj
+++ b/PCbuild/pythoncore.vcxproj
@@ -528,29 +528,7 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
diff --git a/Tools/scripts/deepfreeze.py b/Tools/scripts/deepfreeze.py
index 49638b8..a7546a8 100644
--- a/Tools/scripts/deepfreeze.py
+++ b/Tools/scripts/deepfreeze.py
@@ -10,10 +10,9 @@ import collections
import contextlib
import os
import re
-import sys
import time
import types
-from typing import Dict, FrozenSet, Tuple, TextIO
+from typing import Dict, FrozenSet, TextIO, Tuple
import umarshal
@@ -104,10 +103,10 @@ def removesuffix(base: str, suffix: str) -> str:
class Printer:
- def __init__(self, file: TextIO):
+ def __init__(self, file: TextIO) -> None:
self.level = 0
self.file = file
- self.cache: Dict[Tuple[type, object], str] = {}
+ self.cache: Dict[tuple[type, object, str], str] = {}
self.hits, self.misses = 0, 0
self.patchups: list[str] = []
self.write('#include "Python.h"')
@@ -349,6 +348,15 @@ class Printer:
self.write("// TODO: The above tuple should be a frozenset")
return ret
+ def generate_file(self, module: str, code: object)-> None:
+ module = module.replace(".", "_")
+ self.generate(f"{module}_toplevel", code)
+ with self.block(f"static void {module}_do_patchups(void)"):
+ for p in self.patchups:
+ self.write(p)
+ self.patchups.clear()
+ self.write(EPILOGUE.replace("%%NAME%%", module))
+
def generate(self, name: str, obj: object) -> str:
# Use repr() in the key to distinguish -0.0 from +0.0
key = (type(obj), obj, repr(obj))
@@ -357,7 +365,7 @@ class Printer:
# print(f"Cache hit {key!r:.40}: {self.cache[key]!r:.40}")
return self.cache[key]
self.misses += 1
- if isinstance(obj, types.CodeType) or isinstance(obj, umarshal.Code):
+ if isinstance(obj, (types.CodeType, umarshal.Code)) :
val = self.generate_code(name, obj)
elif isinstance(obj, tuple):
val = self.generate_tuple(name, obj)
@@ -393,8 +401,8 @@ EPILOGUE = """
PyObject *
_Py_get_%%NAME%%_toplevel(void)
{
- do_patchups();
- return (PyObject *) &toplevel;
+ %%NAME%%_do_patchups();
+ return (PyObject *) &%%NAME%%_toplevel;
}
"""
@@ -419,29 +427,25 @@ def decode_frozen_data(source: str) -> types.CodeType:
return umarshal.loads(data)
-def generate(source: str, filename: str, modname: str, file: TextIO) -> None:
- if is_frozen_header(source):
- code = decode_frozen_data(source)
- else:
- code = compile(source, filename, "exec")
- printer = Printer(file)
- printer.generate("toplevel", code)
- printer.write("")
- with printer.block("static void do_patchups(void)"):
- for p in printer.patchups:
- printer.write(p)
- here = os.path.dirname(__file__)
- printer.write(EPILOGUE.replace("%%NAME%%", modname.replace(".", "_")))
+def generate(args: list[str], output: TextIO) -> None:
+ printer = Printer(output)
+ for arg in args:
+ file, modname = arg.rsplit(':', 1)
+ with open(file, "r", encoding="utf8") as fd:
+ source = fd.read()
+ if is_frozen_header(source):
+ code = decode_frozen_data(source)
+ else:
+ code = compile(fd.read(), f"", "exec")
+ printer.generate_file(modname, code)
if verbose:
print(f"Cache hits: {printer.hits}, misses: {printer.misses}")
parser = argparse.ArgumentParser()
-parser.add_argument("-m", "--module", help="Defaults to basename(file)")
-parser.add_argument("-o", "--output", help="Defaults to MODULE.c")
+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("file", help="Input file (required)")
-
+parser.add_argument('args', nargs="+", help="Input file and module name (required) in file:modname format")
@contextlib.contextmanager
def report_time(label: str):
@@ -458,13 +462,10 @@ def main() -> None:
global verbose
args = parser.parse_args()
verbose = args.verbose
- with open(args.file, encoding="utf-8") as f:
- source = f.read()
- modname = args.module or removesuffix(os.path.basename(args.file), ".py")
- output = args.output or modname + ".c"
+ output = args.output
with open(output, "w", encoding="utf-8") as file:
with report_time("generate"):
- generate(source, f"", modname, file)
+ generate(args.args, file)
if verbose:
print(f"Wrote {os.path.getsize(output)} bytes to {output}")
diff --git a/Tools/scripts/freeze_modules.py b/Tools/scripts/freeze_modules.py
index cbe8bf1..6d10758 100644
--- a/Tools/scripts/freeze_modules.py
+++ b/Tools/scripts/freeze_modules.py
@@ -575,16 +575,12 @@ def regen_frozen(modules):
def regen_makefile(modules):
pyfiles = []
frozenfiles = []
- deepfreezefiles = []
rules = ['']
- deepfreezerules = ['']
+ deepfreezerules = ["Python/deepfreeze/deepfreeze.c: $(DEEPFREEZE_DEPS)",
+ "\t$(PYTHON_FOR_FREEZE) $(srcdir)/Tools/scripts/deepfreeze.py \\"]
for src in _iter_sources(modules):
frozen_header = relpath_for_posix_display(src.frozenfile, ROOT_DIR)
- deepfreeze_header = relpath_for_posix_display(src.deepfreezefile, ROOT_DIR)
frozenfiles.append(f'\t\t{frozen_header} \\')
- cfile = deepfreeze_header[:-2] + ".c"
- ofile = deepfreeze_header[:-2] + ".o"
- deepfreezefiles.append(f"\t\t{ofile} \\")
pyfile = relpath_for_posix_display(src.pyfile, ROOT_DIR)
pyfiles.append(f'\t\t{pyfile} \\')
@@ -603,15 +599,11 @@ def regen_makefile(modules):
f'\t{freeze}',
'',
])
- deepfreezerules.append(f'{cfile}: {frozen_header} $(DEEPFREEZE_DEPS)')
- deepfreezerules.append(
- f"\t$(PYTHON_FOR_FREEZE) "
- f"$(srcdir)/Tools/scripts/deepfreeze.py "
- f"{frozen_header} -m {src.frozenid} -o {cfile}")
- deepfreezerules.append('')
+ deepfreezerules.append(f"\t{frozen_header}:{src.frozenid} \\")
+ deepfreezerules.append('\t-o Python/deepfreeze/deepfreeze.c')
+ deepfreezerules.append('')
pyfiles[-1] = pyfiles[-1].rstrip(" \\")
frozenfiles[-1] = frozenfiles[-1].rstrip(" \\")
- deepfreezefiles[-1] = deepfreezefiles[-1].rstrip(" \\")
print(f'# Updating {os.path.relpath(MAKEFILE)}')
with updating_file_with_tmpfile(MAKEFILE) as (infile, outfile):
@@ -632,13 +624,6 @@ def regen_makefile(modules):
)
lines = replace_block(
lines,
- "DEEPFREEZE_OBJS =",
- "# End DEEPFREEZE_OBJS",
- deepfreezefiles,
- MAKEFILE,
- )
- lines = replace_block(
- lines,
"# BEGIN: freezing modules",
"# END: freezing modules",
rules,
@@ -658,26 +643,24 @@ def regen_pcbuild(modules):
projlines = []
filterlines = []
corelines = []
+ deepfreezerules = ['\t')
projlines.append(f' {src.frozenid}')
projlines.append(f' $(IntDir){intfile}')
projlines.append(f' $(PySourcePath){header}')
- projlines.append(f' $(IntDir){deepintfile}')
- projlines.append(f' $(PySourcePath){deepoutfile}')
projlines.append(f' ')
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"\'/>' )
- corelines.append(f' ')
+ corelines.append(f' ')
print(f'# Updating {os.path.relpath(PCBUILD_PROJECT)}')
with updating_file_with_tmpfile(PCBUILD_PROJECT) as (infile, outfile):
@@ -690,6 +673,16 @@ def regen_pcbuild(modules):
PCBUILD_PROJECT,
)
outfile.writelines(lines)
+ with updating_file_with_tmpfile(PCBUILD_PROJECT) as (infile, outfile):
+ lines = infile.readlines()
+ lines = replace_block(
+ lines,
+ '',
+ '',
+ deepfreezerules,
+ PCBUILD_PROJECT,
+ )
+ outfile.writelines(lines)
print(f'# Updating {os.path.relpath(PCBUILD_FILTERS)}')
with updating_file_with_tmpfile(PCBUILD_FILTERS) as (infile, outfile):
lines = infile.readlines()
--
cgit v0.12