mirror of
https://github.com/python/cpython.git
synced 2025-11-01 10:45:30 +00:00
Lawrence Hudson, SF #401702: Modify co_filename in frozen programs
This patch was developed primarily to reduce the size of the
frozen binary. It is particularly useful when freezing for 'small'
platforms, such as Palm OS, where you really want to save that
last miserable byte.
A limitation of this patch is that it does not provide any feedback
about the replacements being made. As the path matching
is case-sensitive this may lead to unexpected behaviour for DOS
and Windows people, eg
> freeze.py -r C:\Python\Lib\=py\ goats.py
should probably be:
> freeze.py -r c:\python\lib\=py\ goats.py
This commit is contained in:
parent
b845cb0946
commit
6b767ac81a
2 changed files with 42 additions and 3 deletions
|
|
@ -57,6 +57,10 @@ Options:
|
|||
(For debugging only -- on a win32 platform, win32 behavior
|
||||
is automatic.)
|
||||
|
||||
-r prefix=f: Replace path prefix.
|
||||
Replace prefix with f in the source path references
|
||||
contained in the resulting binary.
|
||||
|
||||
Arguments:
|
||||
|
||||
script: The Python script to be executed by the resulting binary.
|
||||
|
|
@ -109,6 +113,7 @@ def main():
|
|||
debug = 1
|
||||
odir = ''
|
||||
win = sys.platform[:3] == 'win'
|
||||
replace_paths = [] # settable with -r option
|
||||
|
||||
# default the exclude list for each platform
|
||||
if win: exclude = exclude + [
|
||||
|
|
@ -139,7 +144,7 @@ def main():
|
|||
|
||||
# Now parse the command line with the extras inserted.
|
||||
try:
|
||||
opts, args = getopt.getopt(sys.argv[1:], 'a:de:hmo:p:P:qs:wx:l:')
|
||||
opts, args = getopt.getopt(sys.argv[1:], 'r:a:de:hmo:p:P:qs:wx:l:')
|
||||
except getopt.error, msg:
|
||||
usage('getopt error: ' + str(msg))
|
||||
|
||||
|
|
@ -174,6 +179,9 @@ def main():
|
|||
addn_link.append(a)
|
||||
if o == '-a':
|
||||
apply(modulefinder.AddPackagePath, tuple(string.split(a,"=", 2)))
|
||||
if o == '-r':
|
||||
f,r = string.split(a,"=", 2)
|
||||
replace_paths.append( (f,r) )
|
||||
|
||||
# default prefix and exec_prefix
|
||||
if not exec_prefix:
|
||||
|
|
@ -310,7 +318,7 @@ def main():
|
|||
# collect all modules of the program
|
||||
dir = os.path.dirname(scriptfile)
|
||||
path[0] = dir
|
||||
mf = modulefinder.ModuleFinder(path, debug, exclude)
|
||||
mf = modulefinder.ModuleFinder(path, debug, exclude, replace_paths)
|
||||
|
||||
if win and subsystem=='service':
|
||||
# If a Windows service, then add the "built-in" module.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue