Browse Source

makepanda: improve Python location code on Linux and macOS, support Python 3.x builds on macOS, drop use of pythonX-config

rdb 9 years ago
parent
commit
92dab31d80
2 changed files with 31 additions and 22 deletions
  1. 10 5
      makepanda/makepanda.py
  2. 21 17
      makepanda/makepandacore.py

+ 10 - 5
makepanda/makepanda.py

@@ -840,7 +840,7 @@ if (COMPILER=="GCC"):
             if not RTDIST:
             if not RTDIST:
                 # We don't link anything in the SDK with libpython.
                 # We don't link anything in the SDK with libpython.
                 python_lib = ""
                 python_lib = ""
-            SmartPkgEnable("PYTHON", "", python_lib, (SDK["PYTHONVERSION"], SDK["PYTHONVERSION"] + "/Python.h"), tool = SDK["PYTHONVERSION"] + "-config")
+            SmartPkgEnable("PYTHON", "", python_lib, (SDK["PYTHONVERSION"], SDK["PYTHONVERSION"] + "/Python.h"))
 
 
     SmartPkgEnable("OPENSSL",   "openssl",   ("ssl", "crypto"), ("openssl/ssl.h", "openssl/crypto.h"))
     SmartPkgEnable("OPENSSL",   "openssl",   ("ssl", "crypto"), ("openssl/ssl.h", "openssl/crypto.h"))
     SmartPkgEnable("ZLIB",      "zlib",      ("z"), "zlib.h")
     SmartPkgEnable("ZLIB",      "zlib",      ("z"), "zlib.h")
@@ -6825,7 +6825,7 @@ deps: {DEPENDS}
 
 
 def MakeInstallerLinux():
 def MakeInstallerLinux():
     if not RUNTIME and not PkgSkip("PYTHON"):
     if not RUNTIME and not PkgSkip("PYTHON"):
-        PYTHONV = SDK["PYTHONVERSION"]
+        PYTHONV = SDK["PYTHONVERSION"].rstrip('dmu')
     else:
     else:
         PYTHONV = "python"
         PYTHONV = "python"
     PV = PYTHONV.replace("python", "")
     PV = PYTHONV.replace("python", "")
@@ -6980,8 +6980,13 @@ def MakeInstallerOSX():
         oscmd(cmdstr)
         oscmd(cmdstr)
         return
         return
 
 
+    dmg_name = "Panda3D-" + VERSION
+    if not SDK["PYTHONVERSION"].startswith("python2."):
+        dmg_name += '-py' + SDK["PYTHONVERSION"][6:9]
+    dmg_name += ".dmg"
+
     import compileall
     import compileall
-    if (os.path.isfile("Panda3D-%s.dmg" % VERSION)): oscmd("rm -f Panda3D-%s.dmg" % VERSION)
+    if (os.path.isfile(dmg_name)): oscmd("rm -f %s" % dmg_name)
     if (os.path.exists("dstroot")): oscmd("rm -rf dstroot")
     if (os.path.exists("dstroot")): oscmd("rm -rf dstroot")
     if (os.path.exists("Panda3D-rw.dmg")): oscmd('rm -f Panda3D-rw.dmg')
     if (os.path.exists("Panda3D-rw.dmg")): oscmd('rm -f Panda3D-rw.dmg')
 
 
@@ -7022,7 +7027,7 @@ def MakeInstallerOSX():
         oscmd("cp -R " + GetOutputDir() + "/bin/" + base + " " + binname)
         oscmd("cp -R " + GetOutputDir() + "/bin/" + base + " " + binname)
 
 
     if PkgSkip("PYTHON")==0:
     if PkgSkip("PYTHON")==0:
-        PV = SDK["PYTHONVERSION"].replace("python", "")
+        PV = SDK["PYTHONVERSION"][6:9]
         oscmd("mkdir -p dstroot/pythoncode/usr/local/bin")
         oscmd("mkdir -p dstroot/pythoncode/usr/local/bin")
         oscmd("mkdir -p dstroot/pythoncode/Developer/Panda3D/panda3d")
         oscmd("mkdir -p dstroot/pythoncode/Developer/Panda3D/panda3d")
         oscmd("mkdir -p dstroot/pythoncode/Library/Python/%s/site-packages" % PV)
         oscmd("mkdir -p dstroot/pythoncode/Library/Python/%s/site-packages" % PV)
@@ -7177,7 +7182,7 @@ def MakeInstallerOSX():
     dist.close()
     dist.close()
 
 
     oscmd('hdiutil create Panda3D-rw.dmg -volname "Panda3D SDK %s" -srcfolder dstroot/Panda3D' % (VERSION))
     oscmd('hdiutil create Panda3D-rw.dmg -volname "Panda3D SDK %s" -srcfolder dstroot/Panda3D' % (VERSION))
-    oscmd('hdiutil convert Panda3D-rw.dmg -format UDBZ -o Panda3D-%s.dmg' % (VERSION))
+    oscmd('hdiutil convert Panda3D-rw.dmg -format UDBZ -o %s' % (dmg_name))
     oscmd('rm -f Panda3D-rw.dmg')
     oscmd('rm -f Panda3D-rw.dmg')
 
 
 def MakeInstallerFreeBSD():
 def MakeInstallerFreeBSD():

+ 21 - 17
makepanda/makepandacore.py

@@ -1928,6 +1928,8 @@ def SdkLocatePython(prefer_thirdparty_python=False):
         SDK["PYTHONEXEC"] = os.path.realpath(sys.executable)
         SDK["PYTHONEXEC"] = os.path.realpath(sys.executable)
         return
         return
 
 
+    abiflags = getattr(sys, 'abiflags', '')
+
     if GetTarget() == 'windows':
     if GetTarget() == 'windows':
         sdkdir = GetThirdpartyBase() + "/win-python"
         sdkdir = GetThirdpartyBase() + "/win-python"
 
 
@@ -1992,26 +1994,28 @@ def SdkLocatePython(prefer_thirdparty_python=False):
         SDK["PYTHON"] = tp_python + "/include/" + SDK["PYTHONVERSION"]
         SDK["PYTHON"] = tp_python + "/include/" + SDK["PYTHONVERSION"]
 
 
     elif GetTarget() == 'darwin':
     elif GetTarget() == 'darwin':
-         # On Mac OS X, use the system Python framework.
-         py_fwx = SDK.get("MACOSX", "") + "/System/Library/Frameworks/Python.framework/Versions/Current"
+        # On macOS, search for the Python framework directory matching the
+        # version number of our current Python version.
+        sysroot = SDK.get("MACOSX", "")
+        version = sysconfig.get_python_version()
 
 
-         if not os.path.islink(py_fwx):
-             exit("Could not locate Python installation at %s" % (py_fwx))
+        py_fwx = "{0}/System/Library/Frameworks/Python.framework/Versions/{1}".format(sysroot, version)
 
 
-         ver = os.path.basename(os.readlink(py_fwx))
-         py_fwx = SDK.get("MACOSX", "") + "/System/Library/Frameworks/Python.framework/Versions/%s" % ver
+        if not os.path.exists(py_fwx):
+            # Fall back to looking on the system.
+            py_fwx = "/Library/Frameworks/Python.framework/Versions/" + version
 
 
-         SDK["PYTHON"] = py_fwx + "/Headers"
-         SDK["PYTHONVERSION"] = "python" + ver
-         SDK["PYTHONEXEC"] = "/System/Library/Frameworks/Python.framework/Versions/" + ver + "/bin/python" + ver
+        if not os.path.exists(py_fwx):
+            exit("Could not locate Python installation at %s" % (py_fwx))
 
 
-         # Avoid choosing the one in the thirdparty package dir.
-         PkgSetCustomLocation("PYTHON")
-         IncDirectory("PYTHON", py_fwx + "/include")
-         LibDirectory("PYTHON", "%s/usr/lib" % (SDK.get("MACOSX", "")))
+        SDK["PYTHON"] = py_fwx + "/Headers"
+        SDK["PYTHONVERSION"] = "python" + version + abiflags
+        SDK["PYTHONEXEC"] = py_fwx + "/bin/python" + version
 
 
-         if sys.version[:3] != ver:
-             print("Warning: building with Python %s instead of %s since you targeted a specific Mac OS X version." % (ver, sys.version[:3]))
+        # Avoid choosing the one in the thirdparty package dir.
+        PkgSetCustomLocation("PYTHON")
+        IncDirectory("PYTHON", py_fwx + "/include")
+        LibDirectory("PYTHON", "%s/usr/lib" % (sysroot))
 
 
     #elif GetTarget() == 'windows':
     #elif GetTarget() == 'windows':
     #    SDK["PYTHON"] = os.path.dirname(sysconfig.get_python_inc())
     #    SDK["PYTHON"] = os.path.dirname(sysconfig.get_python_inc())
@@ -2020,13 +2024,13 @@ def SdkLocatePython(prefer_thirdparty_python=False):
 
 
     else:
     else:
         SDK["PYTHON"] = sysconfig.get_python_inc()
         SDK["PYTHON"] = sysconfig.get_python_inc()
-        SDK["PYTHONVERSION"] = "python" + sysconfig.get_python_version()
+        SDK["PYTHONVERSION"] = "python" + sysconfig.get_python_version() + abiflags
         SDK["PYTHONEXEC"] = os.path.realpath(sys.executable)
         SDK["PYTHONEXEC"] = os.path.realpath(sys.executable)
 
 
     if CrossCompiling():
     if CrossCompiling():
         # We need a version of Python we can run.
         # We need a version of Python we can run.
         SDK["PYTHONEXEC"] = sys.executable
         SDK["PYTHONEXEC"] = sys.executable
-        host_version = "python" + sysconfig.get_python_version()
+        host_version = "python" + sysconfig.get_python_version() + abiflags
         if SDK["PYTHONVERSION"] != host_version:
         if SDK["PYTHONVERSION"] != host_version:
             exit("Host Python version (%s) must be the same as target Python version (%s)!" % (host_version, SDK["PYTHONVERSION"]))
             exit("Host Python version (%s) must be the same as target Python version (%s)!" % (host_version, SDK["PYTHONVERSION"]))