summaryrefslogtreecommitdiffstats
path: root/Tools/freeze/makefreeze.py
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1998-08-25 14:06:55 (GMT)
committerGuido van Rossum <guido@python.org>1998-08-25 14:06:55 (GMT)
commitbaf0603493f6f1eee073a479497291785b067f61 (patch)
tree7b9b04abcd5d890d1d76d6cd81984b1a0f55ee11 /Tools/freeze/makefreeze.py
parent6c74fea07d42ac6bc3bc078fb13f903f6cdbbcb9 (diff)
downloadcpython-baf0603493f6f1eee073a479497291785b067f61.zip
cpython-baf0603493f6f1eee073a479497291785b067f61.tar.gz
cpython-baf0603493f6f1eee073a479497291785b067f61.tar.bz2
New version, with contributions from Sjoerd Mullender and Mark Hammond.
Sjoerd writes: This version of freeze creates one file per Python module, instead of one humongous file for all Python modules. bkfile: new module to used to write files with backups. No new file is produced if the new contents is identical to the old. New option "-x excluded-module" for modulefinder test program. New option "-i filename" for freeze main program to include a list of options in place of the -i option.
Diffstat (limited to 'Tools/freeze/makefreeze.py')
-rw-r--r--Tools/freeze/makefreeze.py19
1 files changed, 17 insertions, 2 deletions
diff --git a/Tools/freeze/makefreeze.py b/Tools/freeze/makefreeze.py
index f11c59b..4ea1905 100644
--- a/Tools/freeze/makefreeze.py
+++ b/Tools/freeze/makefreeze.py
@@ -1,5 +1,6 @@
import marshal
import string
+import bkfile
# Write a file containing frozen code for the modules in the dictionary.
@@ -30,15 +31,19 @@ main(argc, argv)
"""
-def makefreeze(outfp, dict, debug=0, entry_point = None):
+def makefreeze(base, dict, debug=0, entry_point = None):
if entry_point is None: entry_point = default_entry_point
done = []
+ files = []
mods = dict.keys()
mods.sort()
for mod in mods:
m = dict[mod]
mangled = string.join(string.split(mod, "."), "__")
if m.__code__:
+ file = 'M_' + mangled + '.c'
+ outfp = bkfile.open(base + file, 'w')
+ files.append(file)
if debug:
print "freezing", mod, "..."
str = marshal.dumps(m.__code__)
@@ -48,13 +53,19 @@ def makefreeze(outfp, dict, debug=0, entry_point = None):
size = -size
done.append((mod, mangled, size))
writecode(outfp, mangled, str)
+ outfp.close()
if debug:
print "generating table of frozen modules"
+ outfp = bkfile.open(base + 'frozen.c', 'w')
+ for mod, mangled, size in done:
+ outfp.write('extern unsigned char M_%s[];\n' % mangled)
outfp.write(header)
for mod, mangled, size in done:
outfp.write('\t{"%s", M_%s, %d},\n' % (mod, mangled, size))
outfp.write(trailer)
outfp.write(entry_point)
+ outfp.close()
+ return files
@@ -62,9 +73,13 @@ def makefreeze(outfp, dict, debug=0, entry_point = None):
# The array is called M_<mod>.
def writecode(outfp, mod, str):
- outfp.write('static unsigned char M_%s[] = {' % mod)
+ outfp.write('unsigned char M_%s[] = {' % mod)
for i in range(0, len(str), 16):
outfp.write('\n\t')
for c in str[i:i+16]:
outfp.write('%d,' % ord(c))
outfp.write('\n};\n')
+
+## def writecode(outfp, mod, str):
+## outfp.write('unsigned char M_%s[%d] = "%s";\n' % (mod, len(str),
+## string.join(map(lambda s: `s`[1:-1], string.split(str, '"')), '\\"')))