diff --git a/direct/src/ffi/genPyCode b/direct/src/ffi/genPyCode index feba38400b..ebb742777d 100755 --- a/direct/src/ffi/genPyCode +++ b/direct/src/ffi/genPyCode @@ -13,7 +13,7 @@ base_dir=$(pwd) extra_genPyCode_libs="" -fSqueeze="squeezeMe" +squeezeFlag="" optimizeFlag="" ppython=ppython ppythonOptimizeFlag="" @@ -26,7 +26,7 @@ while getopts ogtpven flag; do p) extra_genPyCode_libs="$extra_genPyCode_libs libpirates" ;; v) extra_genPyCode_libs="$extra_genPyCode_libs libvrpn" ;; e) extra_genPyCode_libs="$extra_genPyCode_libs libpandaegg" ;; - n) fSqueeze="" ;; + n) doSqueeze="-n" ;; esac done @@ -63,7 +63,7 @@ pSqueezer=$DIRECT/src/showbase/pandaSqueezer.py if [ "$buildType" = "linux" ]; then cd $DIRECT/bin - ppython -d generatePythonCode -v -d $pyDir -e $extDir -i libdtoolconfig libpandaexpress libpanda libpandaphysics libdirect $extra_genPyCode_libs || exit + ppython -d generatePythonCode -v -d $pyDir $doSqueeze -e $extDir -i libdtoolconfig libpandaexpress libpanda libpandaphysics libdirect $extra_genPyCode_libs || exit pSqueezer=$DIRECT/src/showbase/pandaSqueezer.py elif [ "$buildType" = "win-debug" ]; then @@ -71,20 +71,20 @@ elif [ "$buildType" = "win-debug" ]; then pyDir="$(cygpath -w $pyDir)" extDir="$(cygpath -w $extDir)" pSqueezer="$(cygpath -w $pSqueezer)" - ppython -d generatePythonCode -v -d $pyDir -e $extDir -i libdtoolconfig libpandaexpress libpanda libpandaphysics libdirect $extra_genPyCode_libs || exit + ppython -d generatePythonCode -v -d $pyDir $doSqueeze -e $extDir -i libdtoolconfig libpandaexpress libpanda libpandaphysics libdirect $extra_genPyCode_libs || exit elif [ "$buildType" = "win-release" ]; then cd $DIRECT/bin pyDir="$(cygpath -w $pyDir)" extDir="$(cygpath -w $extDir)" pSqueezer="$(cygpath -w $pSqueezer)" - ppython generatePythonCode -v -d $pyDir -e $extDir -i libdtoolconfig libpandaexpress libpanda libpandaphysics libdirect $extra_genPyCode_libs || exit + ppython generatePythonCode -v -d $pyDir $doSqueeze -e $extDir -i libdtoolconfig libpandaexpress libpanda libpandaphysics libdirect $extra_genPyCode_libs || exit elif [ "$buildType" = "win-publish" ]; then # no assertions, no comments, no docstrings cd $DIRECT/bin pyDir="$(cygpath -w $pyDir)" extDir="$(cygpath -w $extDir)" pSqueezer="$(cygpath -w $pSqueezer)" - ppython -OO generatePythonCode -O -v -d $pyDir -e $extDir -i libdtoolconfig libpandaexpress libpanda libpandaphysics libdirect $extra_genPyCode_libs || exit + ppython -OO generatePythonCode -O -v -d $pyDir $doSqueeze -e $extDir -i libdtoolconfig libpandaexpress libpanda libpandaphysics libdirect $extra_genPyCode_libs || exit optimizeFlag="-O" ppythonOptimizeFlag="-OO" @@ -93,30 +93,32 @@ elif [ "$buildType" = "install" ]; then pyDir=$install_dir/lib/pandac ppython=$install_dir/bin/ppython pSqueezer=$DIRECT/src/showbase/pandaSqueezer.py - $ppython -d $install_dir/bin/generatePythonCode -O -v -d $pyDir -e $DIRECT/src/extensions -i libdtoolconfig libpandaexpress libpanda libpandaphysics libdirect $extra_genPyCode_libs || exit + $ppython -d $install_dir/bin/generatePythonCode -O -v -d $pyDir $doSqueeze -e $DIRECT/src/extensions -i libdtoolconfig libpandaexpress libpanda libpandaphysics libdirect $extra_genPyCode_libs || exit elif [ "$buildType" = "release" ]; then # Use relative paths; as installed on a machine without ctattach etc. pyDir=$install_dir/lib/pandac ppython=$install_dir/bin/ppython pSqueezer=$DIRECT/src/showbase/pandaSqueezer.py - $ppython $install_dir/bin/generatePythonCode -v -d $pyDir -e $DIRECT/src/extensions -i libdtoolconfig libpandaexpress libpanda libpandaphysics libdirect $extra_genPyCode_libs || exit + $ppython $install_dir/bin/generatePythonCode -v -d $pyDir $doSqueeze -e $DIRECT/src/extensions -i libdtoolconfig libpandaexpress libpanda libpandaphysics libdirect $extra_genPyCode_libs || exit else echo "Invalid parameter: $buildType" exit 1 fi -if [ "$fSqueeze" = "squeezeMe" ]; then - echo SQUEEZING PandaModules - rm -f $pyDir/PandaModules.py* $pyDir/__init__.py || exit - $ppython $ppythonOptimizeFlag $pSqueezer $optimizeFlag -d $pyDir || exit - touch $pyDir/__init__.py || exit -else - # renaming PandaModulesUnsqueezed.py to PandaModules.py - cd $pyDir || exit - rm -f PandaModules.py* || exit - echo # junk line needed to keep mv from failing - mv PandaModulesUnsqueezed.py PandaModules.py || exit -fi +# The squeeze step is now performed as part of generatePythonCode. + +#if [ "$fSqueeze" = "squeezeMe" ]; then +# echo SQUEEZING PandaModules +# rm -f $pyDir/PandaModules.py* $pyDir/__init__.py || exit +# $ppython $ppythonOptimizeFlag $pSqueezer $optimizeFlag -d $pyDir || exit +# touch $pyDir/__init__.py || exit +#else +# # renaming PandaModulesUnsqueezed.py to PandaModules.py +# cd $pyDir || exit +# rm -f PandaModules.py* || exit +# echo # junk line needed to keep mv from failing +# mv PandaModulesUnsqueezed.py PandaModules.py || exit +#fi echo DONE diff --git a/direct/src/ffi/generatePythonCode b/direct/src/ffi/generatePythonCode index c419f192e5..4283b75491 100644 --- a/direct/src/ffi/generatePythonCode +++ b/direct/src/ffi/generatePythonCode @@ -4,6 +4,7 @@ import getopt import sys import os +import glob from direct.ffi import FFIConstants # Define a help string for the user @@ -33,10 +34,7 @@ Options: -e dir directory to pull extension code from -i lib interrogate library -O no C++ comments or assertion statements - linux - windows-debug - windows-release - windows-publish + -n Don't use squeezeTool to squeeze the result into one .pyz file """ # Initialize variables @@ -44,11 +42,12 @@ outputDir = '' extensionsDir = '' interrogateLib = '' codeLibs = [] +doSqueeze = True # Extract the args the user passed in try: - opts, pargs = getopt.getopt(sys.argv[1:], 'hvOd:e:i:') + opts, pargs = getopt.getopt(sys.argv[1:], 'hvOd:e:i:n') except Exception, e: # User passed in a bad option, print the error and the help, then exit print e @@ -77,6 +76,8 @@ for opt in opts: elif (flag == '-O'): FFIConstants.wantComments = 0 FFIConstants.wantTypeChecking = 0 + elif (flag == '-n'): + doSqueeze = False else: FFIConstants.notify.error('illegal option: ' + flag) @@ -121,3 +122,36 @@ from direct.ffi import FFIInterrogateDatabase db = FFIInterrogateDatabase.FFIInterrogateDatabase() db.generateCode(outputDir, extensionsDir) + +# Remove any leftover junk files in outputDir from a previous run. +print "outputDir = %s, doSqueeze = %s" % (outputDir, doSqueeze) +for file in glob.glob(os.path.join(outputDir, 'PandaModules.py*')): + print "removing junk %s" % (file) + os.remove(file) + +if doSqueeze: + # Invoke the squeezer. + files = glob.glob(os.path.join(outputDir, '*.py')) + init = os.path.join(outputDir, '__init__.py') + try: + files.remove(init) + except: + pass + + print "Squeezing %s files." % (len(files)) + + from direct.showbase import pandaSqueezeTool + pandaSqueezeTool.squeeze("PandaModules", "PandaModulesUnsqueezed", + files, outputDir) + + # Remove the squeezed source files. + for file in files: + os.remove(file) + +else: + print "Not squeezing." + os.rename(os.path.join(outputDir, 'PandaModulesUnsqueezed.py'), + os.path.join(outputDir, 'PandaModules.py')) + + + diff --git a/direct/src/showbase/pandaSqueezeTool.py b/direct/src/showbase/pandaSqueezeTool.py index d9e088ff62..1d2591274b 100755 --- a/direct/src/showbase/pandaSqueezeTool.py +++ b/direct/src/showbase/pandaSqueezeTool.py @@ -249,12 +249,13 @@ import zlib embed = 0 explode = 0 -def squeeze(app, start, filelist): +def squeeze(app, start, filelist, outputDir): localMagic = MAGIC data = None - bootstrap = app + ".py" - archive = app + ".pyz" + bootstrap = os.path.join(outputDir, app + ".py") + archiveBase = app + ".pyz" + archive = os.path.join(outputDir, archiveBase) archiveid = app @@ -348,8 +349,8 @@ def searchPath(filename): return None -# Look for %(archive)s along pandac.__path__. -archiveName = "%(archive)s" +# Look for %(archiveBase)s along pandac.__path__. +archiveName = "%(archiveBase)s" archivePath = searchPath(archiveName) if archivePath == None: raise ImportError, "Could not locate pandac.%%s." %% (archiveName)