55usage: freeze [options...] script [module]...
66
77Options:
8-
98-p prefix: This is the prefix used when you ran ``make install''
109 in the Python build directory.
1110 (If you never ran this, freeze won't work.)
2221-e extension: A directory containing additional .o files that
2322 may be used to resolve modules. This directory
2423 should also have a Setup file describing the .o files.
24+ On Windows, the name of a .INI file describing one
25+ or more extensions is passed.
2526 More than one -e option may be given.
2627
2728-o dir: Directory where the output files are created; default '.'.
4142
4243-h: Print this help message.
4344
44- -w: Toggle Windows (NT or 95) behavior.
45- (For debugging only -- on a win32 platform, win32 behaviour
46- is automatic.)
47-
4845-x module Exclude the specified module.
4946
47+ -i filename: Include a file with additional command line options. Used
48+ to prevent command lines growing beyond the capabilities of
49+ the shell/OS. All arguments specified in filename
50+ are read and the -i option replaced with the parsed
51+ params (note - quoting args in this file is NOT supported)
52+
5053-s subsystem: Specify the subsystem (For Windows only.);
5154 'console' (default), 'windows', 'service' or 'com_dll'
5255
56+ -w: Toggle Windows (NT or 95) behavior.
57+ (For debugging only -- on a win32 platform, win32 behaviour
58+ is automatic.)
5359
5460Arguments:
5561
8793import makefreeze
8894import makemakefile
8995import parsesetup
96+ import bkfile
9097
9198
9299# Main program
@@ -105,8 +112,8 @@ def main():
105112 win = sys .platform [:3 ] == 'win'
106113
107114 # default the exclude list for each platform
108- ## if win: exclude = exclude + [
109- ## 'dos', 'dospath', 'mac', 'macpath', 'MACFS', 'posix', 'os2']
115+ if win : exclude = exclude + [
116+ 'dos' , 'dospath' , 'mac' , 'macpath' , 'macfs ' , 'MACFS' , 'posix' , 'os2' ]
110117
111118 # modules that are imported by the Python runtime
112119 implicits = ["site" , "exceptions" ]
@@ -118,7 +125,20 @@ def main():
118125 makefile = 'Makefile'
119126 subsystem = 'console'
120127
121- # parse command line
128+ # parse command line by first replacing any "-i" options with the file contents.
129+ pos = 1
130+ while pos < len (sys .argv )- 1 : # last option can not be "-i", so this ensures "pos+1" is in range!
131+ if sys .argv [pos ] == '-i' :
132+ try :
133+ options = string .split (open (sys .argv [pos + 1 ]).read ())
134+ except IOError , why :
135+ usage ("File name '%s' specified with the -i option can not be read - %s" % (sys .argv [pos + 1 ], why ) )
136+ # Replace the '-i' and the filename with the read params.
137+ sys .argv [pos :pos + 2 ] = options
138+ pos = pos + len (options ) - 1 # Skip the name and the included args.
139+ pos = pos + 1
140+
141+ # Now parse the command line with the extras inserted.
122142 try :
123143 opts , args = getopt .getopt (sys .argv [1 :], 'a:de:hmo:p:P:qs:wx:l:' )
124144 except getopt .error , msg :
@@ -197,13 +217,15 @@ def main():
197217 includes = ['-I' + incldir , '-I' + config_h_dir ]
198218
199219 # sanity check of directories and files
200- for dir in [prefix , exec_prefix , binlib , incldir ] + extensions :
220+ check_dirs = [prefix , exec_prefix , binlib , incldir ]
221+ if not win : check_dirs = check_dirs + extensions # These are not directories on Windows.
222+ for dir in check_dirs :
201223 if not os .path .exists (dir ):
202224 usage ('needed directory %s not found' % dir )
203225 if not os .path .isdir (dir ):
204226 usage ('%s: not a directory' % dir )
205227 if win :
206- files = supp_sources
228+ files = supp_sources + extensions # extensions are files on Windows.
207229 else :
208230 files = [config_c_in , makefile_in ] + supp_sources
209231 for file in supp_sources :
@@ -260,7 +282,9 @@ def main():
260282 print "Created output directory" , odir
261283 except os .error , msg :
262284 usage ('%s: mkdir failed (%s)' % (odir , str (msg )))
285+ base = ''
263286 if odir :
287+ base = os .path .join (odir , '' )
264288 frozen_c = os .path .join (odir , frozen_c )
265289 config_c = os .path .join (odir , config_c )
266290 target = os .path .join (odir , target )
@@ -323,21 +347,7 @@ def main():
323347 dict = mf .modules
324348
325349 # generate output for frozen modules
326- backup = frozen_c + '~'
327- try :
328- os .rename (frozen_c , backup )
329- except os .error :
330- backup = None
331- outfp = open (frozen_c , 'w' )
332- try :
333- makefreeze .makefreeze (outfp , dict , debug , custom_entry_point )
334- finally :
335- outfp .close ()
336- if backup :
337- if cmp .cmp (backup , frozen_c ):
338- sys .stderr .write ('%s not changed, not written\n ' % frozen_c )
339- os .unlink (frozen_c )
340- os .rename (backup , frozen_c )
350+ files = makefreeze .makefreeze (base , dict , debug , custom_entry_point )
341351
342352 # look for unfrozen modules (builtin and of unknown origin)
343353 builtins = []
@@ -387,7 +397,7 @@ def main():
387397 frozen_extensions )
388398 # Create a module definition for the bootstrap C code.
389399 xtras = [frozenmain_c , os .path .basename (frozen_c ),
390- frozendllmain_c , extensions_c ]
400+ frozendllmain_c , extensions_c ] + files
391401 maindefn = checkextensions_win32 .CExtension ( '__main__' , xtras )
392402 frozen_extensions .append ( maindefn )
393403 outfp = open (makefile , 'w' )
@@ -403,22 +413,12 @@ def main():
403413 # generate config.c and Makefile
404414 builtins .sort ()
405415 infp = open (config_c_in )
406- backup = config_c + '~'
407- try :
408- os .rename (config_c , backup )
409- except os .error :
410- backup = None
411- outfp = open (config_c , 'w' )
416+ outfp = bkfile .open (config_c , 'w' )
412417 try :
413418 makeconfig .makeconfig (infp , outfp , builtins )
414419 finally :
415420 outfp .close ()
416421 infp .close ()
417- if backup :
418- if cmp .cmp (backup , config_c ):
419- sys .stderr .write ('%s not changed, not written\n ' % config_c )
420- os .unlink (config_c )
421- os .rename (backup , config_c )
422422
423423 cflags = defines + includes + ['$(OPT)' ]
424424 libs = [os .path .join (binlib , 'libpython$(VERSION).a' )]
@@ -431,31 +431,14 @@ def main():
431431
432432 somevars ['CFLAGS' ] = string .join (cflags ) # override
433433 files = ['$(OPT)' , '$(LDFLAGS)' , base_config_c , base_frozen_c ] + \
434- supp_sources + addfiles + libs + \
434+ files + supp_sources + addfiles + libs + \
435435 ['$(MODLIBS)' , '$(LIBS)' , '$(SYSLIBS)' ]
436436
437- backup = makefile + '~'
438- if os .path .exists (makefile ):
439- try :
440- os .unlink (backup )
441- except os .error :
442- pass
443- try :
444- os .rename (makefile , backup )
445- except os .error :
446- backup = None
447- outfp = open (makefile , 'w' )
437+ outfp = bkfile .open (makefile , 'w' )
448438 try :
449439 makemakefile .makemakefile (outfp , somevars , files , base_target )
450440 finally :
451441 outfp .close ()
452- if backup :
453- if not cmp .cmp (backup , makefile ):
454- print 'previous Makefile saved as' , backup
455- else :
456- sys .stderr .write ('%s not changed, not written\n ' % makefile )
457- os .unlink (makefile )
458- os .rename (backup , makefile )
459442
460443 # Done!
461444
0 commit comments