Browse Source

Added compilation to packpanda

Josh Yelon 20 years ago
parent
commit
cd99196f6e

+ 31 - 29
direct/src/directscripts/packpanda.nsi

@@ -5,44 +5,45 @@
 ; mangled by Josh Yelon <[email protected]>
 
 ; Caller needs to define these variables:
+;
 ;   COMPRESSOR    - either zlib or lzma
-;   FULLNAME      - full name of what we're building            (ie, "Panda3D" or "Airblade")
-;   SMDIRECTORY   - where to put this in the start menu         (ie, "Panda3D VERSION" or "Airblade VERSION")
-;   INSTALLDIR    - where to install the program                (ie, "C:\Program Files\Panda3D-VERSION")
+;   NAME          - name of what we're building                 (ie, "Panda3D" or "Airblade")
+;   SMDIRECTORY   - where to put this in the start menu         (ie, "Panda3D 1.1.0" or "Airblade 1.1.0")
+;   INSTALLDIR    - where to install the program                (ie, "C:\Program Files\Panda3D-1.1.0")
 ;   OUTFILE       - where to put the output file                (ie, "..\nsis-output.exe")
+;   LICENSE       - location of the license file                (ie, "C:\Airblade\LICENSE.TXT")
+;   LANGUAGE      - name of the Language file to use            (ie, "English" or "Panda3DEnglish")
+;   RUNTEXT       - text for run-box at end of installation     (ie, "Run the Panda Greeting Card")
+;   IBITMAP       - name of installer bitmap                    (ie, "C:\Airblade\Airblade.bmp")
+;   UBITMAP       - name of uninstaller bitmap                  (ie, "C:\Airblade\Airblade.bmp")
 ;
 ;   PANDA         - location of panda install tree.
 ;   PSOURCE       - location of the panda source-tree if available, OR location of panda install tree.
 ;   PYEXTRAS      - directory containing python extras, if any.
 ;
-;   PPGAMEID      - id of prepackaged game, if any                      (ie, "airblade")
-;   PPGAMEPATH    - directory containing prepagaged game, if any        (ie, "C:\My Games\Airblade")
-;   PPGAMEPY      - python program containing prepackaged game, if any  (ie, "Airblade.py")
-
-; Use the Modern UI
-!include "PandaMUI.nsh"
-; Windows system messaging support
-!include "${NSISDIR}\Include\WinMessages.nsh"
+;   PPGAME    - directory containing prepagaged game, if any        (ie, "C:\My Games\Airblade")
+;   PPMAIN      - python program containing prepackaged game, if any  (ie, "Airblade.py")
 
-Name "${FULLNAME}"
+!include "MUI.nsh"
+!include "WinMessages.nsh"
+Name "${NAME}"
 InstallDir "${INSTALLDIR}"
 OutFile "${OUTFILE}"
 
 SetCompress auto
 SetCompressor ${COMPRESSOR}
 
+!define MUI_WELCOMEFINISHPAGE_BITMAP "${IBITMAP}"
+!define MUI_UNWELCOMEFINISHPAGE_BITMAP "${UBITMAP}"
+
 !define MUI_ABORTWARNING
 !define MUI_FINISHPAGE_NOREBOOTSUPPORT
 !define MUI_FINISHPAGE_RUN
 !define MUI_FINISHPAGE_RUN_FUNCTION runFunction
-!ifdef PPGAMEID
-!define MUI_FINISHPAGE_RUN_TEXT "Play ${FULLNAME}"
-!else
-!define MUI_FINISHPAGE_RUN_TEXT "Run the Panda Greeting Card"
-!endif
+!define MUI_FINISHPAGE_RUN_TEXT "${RUNTEXT}"
 
 !insertmacro MUI_PAGE_WELCOME
-!insertmacro MUI_PAGE_LICENSE "${PANDA}\LICENSE"
+!insertmacro MUI_PAGE_LICENSE "${LICENSE}"
 !insertmacro MUI_PAGE_DIRECTORY
 !insertmacro MUI_PAGE_INSTFILES
 !insertmacro MUI_PAGE_FINISH
@@ -52,11 +53,12 @@ SetCompressor ${COMPRESSOR}
 !insertmacro MUI_UNPAGE_INSTFILES
 !insertmacro MUI_UNPAGE_FINISH
 
-!insertmacro MUI_LANGUAGE "Panda3DEnglish"
+!insertmacro MUI_LANGUAGE "${LANGUAGE}"
 
 ShowInstDetails nevershow
 ShowUninstDetails nevershow
-LicenseData ${PANDA}\LICENSE
+
+LicenseData ${LICENSE}
 
 InstType "Typical"
 
@@ -66,8 +68,8 @@ var READABLE
 var TUTNAME
 
 Function runFunction
-        !ifdef PPGAMEID
-        ExecShell "open" "$SMPROGRAMS\${SMDIRECTORY}\Play ${FULLNAME}.lnk"
+        !ifdef PPGAME
+        ExecShell "open" "$SMPROGRAMS\${SMDIRECTORY}\Play ${NAME}.lnk"
         !else
         ExecShell "open" "$SMPROGRAMS\${SMDIRECTORY}\Panda Greeting Card.lnk"
         !endif        
@@ -98,13 +100,13 @@ Section "${SMDIRECTORY}" SecCore
         RMDir /r "$SMPROGRAMS\${SMDIRECTORY}"
         CreateDirectory "$SMPROGRAMS\${SMDIRECTORY}"
 
-        !ifdef PPGAMEID
+        !ifdef PPGAME
 
             SetOutPath $INSTDIR\bin
             File /r ${PANDA}\bin\ppython.exe
-            SetOutpath $INSTDIR\${PPGAMEID}
-            File /r ${PPGAMEPATH}\*
-            CreateShortCut "$SMPROGRAMS\${SMDIRECTORY}\Play ${FULLNAME}.lnk" "$INSTDIR\bin\ppython.exe" "${PPGAMEPY}" "$INSTDIR\bin\ppython.exe" 0 SW_SHOWMINIMIZED "" "Play ${FULLNAME}"
+            SetOutpath $INSTDIR\game
+            File /r ${PPGAME}\*
+            CreateShortCut "$SMPROGRAMS\${SMDIRECTORY}\Play ${NAME}.lnk" "$INSTDIR\bin\ppython.exe" "${PPMAIN}" "$INSTDIR\bin\ppython.exe" 0 SW_SHOWMINIMIZED "" "Play ${NAME}"
 
         !else
 
@@ -193,7 +195,7 @@ SectionEnd
 
 Section -post
 
-        !ifndef PPGAMEID
+        !ifndef PPGAME
         # Add the "bin" directory to the PATH.
         Push "$INSTDIR\bin"
         Call AddToPath
@@ -210,13 +212,13 @@ Section -post
         WriteUninstaller "$INSTDIR\uninst.exe"
         WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${SMDIRECTORY}" "DisplayName" "${SMDIRECTORY}"
         WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${SMDIRECTORY}" "UninstallString" '"$INSTDIR\uninst.exe"'
-        CreateShortcut "$SMPROGRAMS\${SMDIRECTORY}\Uninstall ${FULLNAME}.lnk" "$INSTDIR\uninst.exe" ""
+        CreateShortcut "$SMPROGRAMS\${SMDIRECTORY}\Uninstall ${NAME}.lnk" "$INSTDIR\uninst.exe" ""
 
 SectionEnd
 
 Section Uninstall
 
-        !ifndef PPGAMEID
+        !ifndef PPGAME
         Push "$INSTDIR\bin"
         Call un.RemoveFromPath
         !endif

+ 105 - 39
direct/src/directscripts/packpanda.py

@@ -12,14 +12,14 @@
 #
 ##############################################################################
 
-import sys,os,getopt,compileall
+import sys,os,getopt,string,shutil,py_compile
 
 OPTIONLIST = [
 ("game",      1, "Name of directory containing game"),
 ("version",   1, "Version number to add to game name"),
 ("fast",      0, "Use fast compression instead of good compression"),
-("bam",       0, "Convert all EGG files to BAM"),
-("pyc",       0, "Convert all PY files to PYC"),
+("cplegg",    0, "Convert all EGG files to BAM"),
+("cplpy",     0, "Convert all PY files to PYC"),
 ]
 
 def ParseFailure():
@@ -55,7 +55,27 @@ OPTIONS = ParseOptions(sys.argv[1:])
 
 ##############################################################################
 #
-# Identify the main parts of the game: GAME, NAME, MAIN, ICON, IMAGE
+# Locate the relevant trees.
+#
+##############################################################################
+
+PANDA=None
+for dir in sys.path:
+    if os.path.exists(os.path.join(dir,"direct")) and os.path.exists(os.path.join(dir,"pandac")) and os.path.exists(os.path.join(dir,"python")):
+        PANDA=os.path.abspath(dir)
+if (PANDA is None):
+  sys.exit("Cannot locate the panda root directory in the python path (cannot locate directory containing direct and pandac).")
+
+if (os.path.exists(os.path.join("PANDA","..","makepanda","makepanda.py"))) and (os.path.exists(os.path.join("PANDA","..","thirdparty","win-nsis","makensis.exe"))):
+  PSOURCE=os.path.abspath(os.path.join(PANDA,".."))
+  NSIS=os.path.abspath(os.path.join(PANDA,"..","thirdparty","win-nsis"))
+else:
+  PSOURCE=PANDA
+  NSIS=os.path.join(PANDA,"nsis")
+
+##############################################################################
+#
+# Identify the main parts of the game: GAME, NAME, MAIN, ICON, BITMAP, etc
 #
 ##############################################################################
 
@@ -66,16 +86,18 @@ if (GAME==""):
   ParseFailure()
 GAME=os.path.abspath(GAME)
 NAME=os.path.basename(GAME)
-STARTMENU=os.path.basename(GAME)
-if (VER!=""): STARTMENU=STARTMENU+" "+VER
-MAIN=NAME+".py"
+SMDIRECTORY=os.path.basename(GAME)
+if (VER!=""): SMDIRECTORY=SMDIRECTORY+" "+VER
+if (OPTIONS["cplpy"]): MAIN=NAME+".pyc"
+else: MAIN=NAME+".py"
 ICON=os.path.join(GAME,NAME+".ico")
-IMAGE=os.path.join(GAME,NAME+".bmp")
-OUTPUT=os.path.basename(GAME)
-if (VER!=""): OUTPUT=OUTPUT+"-"+VER
-OUTPUT=os.path.abspath(OUTPUT+".exe")
-INSTALLTO='C:\\'+os.path.basename(GAME)
-if (VER!=""): INSTALLTO=INSTALLTO+"-"+VER
+BITMAP=os.path.join(GAME,NAME+".bmp")
+LICENSE=os.path.join(GAME,"LICENSE.TXT")
+OUTFILE=os.path.basename(GAME)
+if (VER!=""): OUTFILE=OUTFILE+"-"+VER
+OUTFILE=os.path.abspath(OUTFILE+".exe")
+INSTALLDIR='C:\\'+os.path.basename(GAME)
+if (VER!=""): INSTALLDIR=INSTALLDIR+"-"+VER
 COMPRESS="lzma"
 if (OPTIONS["fast"]): COMPRESS="zlib"
 
@@ -87,38 +109,76 @@ def PrintFileStatus(label, file):
   
 PrintFileStatus("Game",GAME)
 print "%-15s: %s"%("Name",NAME)
-print "%-15s: %s"%("Start Menu",STARTMENU)
+print "%-15s: %s"%("Start Menu",SMDIRECTORY)
 PrintFileStatus("Main",os.path.join(GAME,MAIN))
 PrintFileStatus("Icon",ICON)
-PrintFileStatus("Image",IMAGE)
-print "%-15s: %s"%("Output",OUTPUT)
-print "%-15s: %s"%("Install To",INSTALLTO)
+PrintFileStatus("Bitmap",BITMAP)
+PrintFileStatus("License",LICENSE)
+print "%-15s: %s"%("Output",OUTFILE)
+print "%-15s: %s"%("Install Dir",INSTALLDIR)
 
 if (os.path.isdir(GAME)==0):
   sys.exit("Difficulty reading "+GAME+". Cannot continue.")
 
-if (os.path.isfile(os.path.join(GAME,MAIN))==0):
-  sys.exit("Difficulty reading "+MAIN+". Cannot continue.")
+if (os.path.isfile(os.path.join(GAME,NAME+".py"))==0):
+  sys.exit("Difficulty reading "+NAME+".py. Cannot continue.")
+
+if (os.path.isfile(LICENSE)==0):
+  LICENSE=os.path.join(PANDA,"LICENSE")
+
+if (os.path.isfile(BITMAP)==0):
+  BITMAP=os.path.join(NSIS,"Contrib","Modern UI","Graphics","Wizard","nsis.bmp")
 
 ##############################################################################
 #
-# Locate the relevant trees.
+# If necessary, make a copy of the game for compilation purposes.
 #
 ##############################################################################
 
-PANDA=None
-for dir in sys.path:
-    if os.path.exists(os.path.join(dir,"direct")) and os.path.exists(os.path.join(dir,"pandac")) and os.path.exists(os.path.join(dir,"python")):
-        PANDA=os.path.abspath(dir)
-if (PANDA is None):
-  sys.exit("Cannot locate the panda root directory in the python path (cannot locate directory containing direct and pandac).")
-
-if (os.path.exists(os.path.join("PANDA","..","makepanda","makepanda.py"))) and (os.path.exists(os.path.join("PANDA","..","thirdparty","win-nsis","makensis.exe"))):
-  PSOURCE=os.path.abspath(os.path.join(PANDA,".."))
-  NSIS=os.path.abspath(os.path.join(PANDA,"..","thirdparty","win-nsis"))
+EGG2BAM=os.path.join(PANDA,"bin","egg2bam.exe")
+
+def egg2bam(file):
+    orig = os.getcwd()
+    dir = os.path.dirname(file)
+    base = os.path.basename(file)
+    pre = base[:-4]
+    cmd = 'egg2bam -noabs "'+base+'" -o "'+pre+'.bam"'
+    print "Executing: "+cmd
+    os.chdir(dir)
+    res = os.spawnl(os.P_WAIT, EGG2BAM, cmd)
+    if (res != 0): sys.exit("Cannot convert egg to bam")
+    os.chdir(orig)
+    os.unlink(file)
+
+def py2pyc(file):
+    print "Compiling python "+file
+    try: py_compile.compile(file)
+    except: sys.exit("Cannot compile "+file)
+    os.unlink(file)
+
+def CompileFiles(file):
+    if (os.path.isfile(file)):
+        if OPTIONS["cplegg"] and (string.lower(file[-4:])==".egg"):
+            egg2bam(file)
+        elif OPTIONS["cplpy"] and (string.lower(file[-3:])==".py"):
+            py2pyc(file)
+        else: pass
+    elif (os.path.isdir(file)):
+        for x in os.listdir(file):
+            CompileFiles(os.path.join(file,x))
+
+if (OPTIONS["cplpy"] or OPTIONS["cplegg"]):
+    TMPDIR=os.path.abspath("packpanda-TMP")
+    print "Copying the game to "+TMPDIR+"..."
+    if (os.path.exists(TMPDIR)):
+        try: shutil.rmtree(TMPDIR)
+        except: sys.exit("Cannot delete "+TMPDIR)
+    try: shutil.copytree(GAME, TMPDIR)
+    except: sys.exit("Cannot copy game to "+TMPDIR)
+    print "Searching for files to compile in "+TMPDIR+"..."
+    CompileFiles(TMPDIR)
 else:
-  PSOURCE=PANDA
-  NSIS=os.path.join(PANDA,"nsis")
+    TMPDIR=GAME
 
 ##############################################################################
 #
@@ -128,18 +188,24 @@ else:
 
 CMD=NSIS+"\\makensis.exe /V2 "
 CMD=CMD+'/DCOMPRESSOR="'+COMPRESS+'" '
-CMD=CMD+'/DFULLNAME="'+NAME+'" '
-CMD=CMD+'/DSMDIRECTORY="'+STARTMENU+'" '
-CMD=CMD+'/DINSTALLDIR="'+INSTALLTO+'" '
+CMD=CMD+'/DNAME="'+NAME+'" '
+CMD=CMD+'/DSMDIRECTORY="'+SMDIRECTORY+'" '
+CMD=CMD+'/DINSTALLDIR="'+INSTALLDIR+'" '
+CMD=CMD+'/DOUTFILE="'+OUTFILE+'" '
+CMD=CMD+'/DLICENSE="'+LICENSE+'" '
+CMD=CMD+'/DLANGUAGE="English" '
+CMD=CMD+'/DRUNTEXT="Play '+NAME+'" '
+CMD=CMD+'/DIBITMAP="'+BITMAP+'" '
+CMD=CMD+'/DUBITMAP="'+BITMAP+'" '
 CMD=CMD+'/DPANDA="'+PANDA+'" '
 CMD=CMD+'/DPSOURCE="'+PSOURCE+'" '
-CMD=CMD+'/DOUTFILE="'+OUTPUT+'" '
-CMD=CMD+'/DPPGAMEID="'+NAME+'" '
-CMD=CMD+'/DPPGAMEPATH="'+GAME+'" '
-CMD=CMD+'/DPPGAMEPY="'+MAIN+'" '
+CMD=CMD+'/DPPGAME="'+TMPDIR+'" '
+CMD=CMD+'/DPPMAIN="'+MAIN+'" '
 CMD=CMD+'"'+PSOURCE+'\\direct\\src\\directscripts\\packpanda.nsi"'
 
 print ""
 print CMD
 print "packing..."
 os.system(CMD)
+
+

BIN
direct/src/directscripts/panda-install.bmp


BIN
direct/src/directscripts/panda-uninstall.bmp