move squeeze into generatePythonCode

This commit is contained in:
David Rose 2004-06-02 22:08:31 +00:00
parent ff8ac9f0a4
commit 1cd0c6cbcf
3 changed files with 67 additions and 30 deletions

View File

@ -13,7 +13,7 @@
base_dir=$(pwd) base_dir=$(pwd)
extra_genPyCode_libs="" extra_genPyCode_libs=""
fSqueeze="squeezeMe" squeezeFlag=""
optimizeFlag="" optimizeFlag=""
ppython=ppython ppython=ppython
ppythonOptimizeFlag="" ppythonOptimizeFlag=""
@ -26,7 +26,7 @@ while getopts ogtpven flag; do
p) extra_genPyCode_libs="$extra_genPyCode_libs libpirates" ;; p) extra_genPyCode_libs="$extra_genPyCode_libs libpirates" ;;
v) extra_genPyCode_libs="$extra_genPyCode_libs libvrpn" ;; v) extra_genPyCode_libs="$extra_genPyCode_libs libvrpn" ;;
e) extra_genPyCode_libs="$extra_genPyCode_libs libpandaegg" ;; e) extra_genPyCode_libs="$extra_genPyCode_libs libpandaegg" ;;
n) fSqueeze="" ;; n) doSqueeze="-n" ;;
esac esac
done done
@ -63,7 +63,7 @@ pSqueezer=$DIRECT/src/showbase/pandaSqueezer.py
if [ "$buildType" = "linux" ]; then if [ "$buildType" = "linux" ]; then
cd $DIRECT/bin 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 pSqueezer=$DIRECT/src/showbase/pandaSqueezer.py
elif [ "$buildType" = "win-debug" ]; then elif [ "$buildType" = "win-debug" ]; then
@ -71,20 +71,20 @@ elif [ "$buildType" = "win-debug" ]; then
pyDir="$(cygpath -w $pyDir)" pyDir="$(cygpath -w $pyDir)"
extDir="$(cygpath -w $extDir)" extDir="$(cygpath -w $extDir)"
pSqueezer="$(cygpath -w $pSqueezer)" 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 elif [ "$buildType" = "win-release" ]; then
cd $DIRECT/bin cd $DIRECT/bin
pyDir="$(cygpath -w $pyDir)" pyDir="$(cygpath -w $pyDir)"
extDir="$(cygpath -w $extDir)" extDir="$(cygpath -w $extDir)"
pSqueezer="$(cygpath -w $pSqueezer)" 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 elif [ "$buildType" = "win-publish" ]; then
# no assertions, no comments, no docstrings # no assertions, no comments, no docstrings
cd $DIRECT/bin cd $DIRECT/bin
pyDir="$(cygpath -w $pyDir)" pyDir="$(cygpath -w $pyDir)"
extDir="$(cygpath -w $extDir)" extDir="$(cygpath -w $extDir)"
pSqueezer="$(cygpath -w $pSqueezer)" 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" optimizeFlag="-O"
ppythonOptimizeFlag="-OO" ppythonOptimizeFlag="-OO"
@ -93,30 +93,32 @@ elif [ "$buildType" = "install" ]; then
pyDir=$install_dir/lib/pandac pyDir=$install_dir/lib/pandac
ppython=$install_dir/bin/ppython ppython=$install_dir/bin/ppython
pSqueezer=$DIRECT/src/showbase/pandaSqueezer.py 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 elif [ "$buildType" = "release" ]; then
# Use relative paths; as installed on a machine without ctattach etc. # Use relative paths; as installed on a machine without ctattach etc.
pyDir=$install_dir/lib/pandac pyDir=$install_dir/lib/pandac
ppython=$install_dir/bin/ppython ppython=$install_dir/bin/ppython
pSqueezer=$DIRECT/src/showbase/pandaSqueezer.py 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 else
echo "Invalid parameter: $buildType" echo "Invalid parameter: $buildType"
exit 1 exit 1
fi fi
if [ "$fSqueeze" = "squeezeMe" ]; then # The squeeze step is now performed as part of generatePythonCode.
echo SQUEEZING PandaModules
rm -f $pyDir/PandaModules.py* $pyDir/__init__.py || exit #if [ "$fSqueeze" = "squeezeMe" ]; then
$ppython $ppythonOptimizeFlag $pSqueezer $optimizeFlag -d $pyDir || exit # echo SQUEEZING PandaModules
touch $pyDir/__init__.py || exit # rm -f $pyDir/PandaModules.py* $pyDir/__init__.py || exit
else # $ppython $ppythonOptimizeFlag $pSqueezer $optimizeFlag -d $pyDir || exit
# renaming PandaModulesUnsqueezed.py to PandaModules.py # touch $pyDir/__init__.py || exit
cd $pyDir || exit #else
rm -f PandaModules.py* || exit # # renaming PandaModulesUnsqueezed.py to PandaModules.py
echo # junk line needed to keep mv from failing # cd $pyDir || exit
mv PandaModulesUnsqueezed.py PandaModules.py || exit # rm -f PandaModules.py* || exit
fi # echo # junk line needed to keep mv from failing
# mv PandaModulesUnsqueezed.py PandaModules.py || exit
#fi
echo DONE echo DONE

View File

@ -4,6 +4,7 @@
import getopt import getopt
import sys import sys
import os import os
import glob
from direct.ffi import FFIConstants from direct.ffi import FFIConstants
# Define a help string for the user # Define a help string for the user
@ -33,10 +34,7 @@ Options:
-e dir directory to pull extension code from -e dir directory to pull extension code from
-i lib interrogate library -i lib interrogate library
-O no C++ comments or assertion statements -O no C++ comments or assertion statements
linux -n Don't use squeezeTool to squeeze the result into one .pyz file
windows-debug
windows-release
windows-publish
""" """
# Initialize variables # Initialize variables
@ -44,11 +42,12 @@ outputDir = ''
extensionsDir = '' extensionsDir = ''
interrogateLib = '' interrogateLib = ''
codeLibs = [] codeLibs = []
doSqueeze = True
# Extract the args the user passed in # Extract the args the user passed in
try: 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: except Exception, e:
# User passed in a bad option, print the error and the help, then exit # User passed in a bad option, print the error and the help, then exit
print e print e
@ -77,6 +76,8 @@ for opt in opts:
elif (flag == '-O'): elif (flag == '-O'):
FFIConstants.wantComments = 0 FFIConstants.wantComments = 0
FFIConstants.wantTypeChecking = 0 FFIConstants.wantTypeChecking = 0
elif (flag == '-n'):
doSqueeze = False
else: else:
FFIConstants.notify.error('illegal option: ' + flag) FFIConstants.notify.error('illegal option: ' + flag)
@ -121,3 +122,36 @@ from direct.ffi import FFIInterrogateDatabase
db = FFIInterrogateDatabase.FFIInterrogateDatabase() db = FFIInterrogateDatabase.FFIInterrogateDatabase()
db.generateCode(outputDir, extensionsDir) 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'))

View File

@ -249,12 +249,13 @@ import zlib
embed = 0 embed = 0
explode = 0 explode = 0
def squeeze(app, start, filelist): def squeeze(app, start, filelist, outputDir):
localMagic = MAGIC localMagic = MAGIC
data = None data = None
bootstrap = app + ".py" bootstrap = os.path.join(outputDir, app + ".py")
archive = app + ".pyz" archiveBase = app + ".pyz"
archive = os.path.join(outputDir, archiveBase)
archiveid = app archiveid = app
@ -348,8 +349,8 @@ def searchPath(filename):
return None return None
# Look for %(archive)s along pandac.__path__. # Look for %(archiveBase)s along pandac.__path__.
archiveName = "%(archive)s" archiveName = "%(archiveBase)s"
archivePath = searchPath(archiveName) archivePath = searchPath(archiveName)
if archivePath == None: if archivePath == None:
raise ImportError, "Could not locate pandac.%%s." %% (archiveName) raise ImportError, "Could not locate pandac.%%s." %% (archiveName)