From 83507e413fa34d0edc4af6c4c1aa0d7b6f60220d Mon Sep 17 00:00:00 2001 From: rdb Date: Mon, 5 Dec 2016 16:30:44 -0500 Subject: [PATCH] Fix Mac OS X Snow Leopard build --- direct/src/showbase/PythonUtil.py | 37 ++++++++++++++++++++++++++++++- makepanda/makepanda.py | 2 +- makepanda/makepandacore.py | 5 +++++ 3 files changed, 42 insertions(+), 2 deletions(-) diff --git a/direct/src/showbase/PythonUtil.py b/direct/src/showbase/PythonUtil.py index ebf8bce63f..0c850f51a0 100644 --- a/direct/src/showbase/PythonUtil.py +++ b/direct/src/showbase/PythonUtil.py @@ -38,7 +38,6 @@ import os import sys import random import time -import importlib __report_indent = 3 @@ -61,6 +60,42 @@ def Functor(function, *args, **kArgs): return functor """ +try: + import importlib +except ImportError: + # Backward compatibility for Python 2.6. + def _resolve_name(name, package, level): + if not hasattr(package, 'rindex'): + raise ValueError("'package' not set to a string") + dot = len(package) + for x in xrange(level, 1, -1): + try: + dot = package.rindex('.', 0, dot) + except ValueError: + raise ValueError("attempted relative import beyond top-level " + "package") + return "%s.%s" % (package[:dot], name) + + def import_module(name, package=None): + if name.startswith('.'): + if not package: + raise TypeError("relative imports require the 'package' argument") + level = 0 + for character in name: + if character != '.': + break + level += 1 + name = _resolve_name(name[level:], package, level) + __import__(name) + return sys.modules[name] + + imp = import_module('imp') + importlib = imp.new_module("importlib") + importlib._resolve_name = _resolve_name + importlib.import_module = import_module + sys.modules['importlib'] = importlib + + class Functor: def __init__(self, function, *args, **kargs): assert callable(function), "function should be a callable obj" diff --git a/makepanda/makepanda.py b/makepanda/makepanda.py index 6d0bd9638c..990c32f5e5 100755 --- a/makepanda/makepanda.py +++ b/makepanda/makepanda.py @@ -4599,7 +4599,7 @@ if (GetTarget() == 'darwin' and PkgSkip("COCOA")==0 and PkgSkip("GL")==0 and not if (PkgSkip('PANDAFX')==0): TargetAdd('libpandagl.dll', input='libpandafx.dll') TargetAdd('libpandagl.dll', input=COMMON_PANDA_LIBS) - TargetAdd('libpandagl.dll', opts=['MODULE', 'GL', 'NVIDIACG', 'CGGL', 'COCOA']) + TargetAdd('libpandagl.dll', opts=['MODULE', 'GL', 'NVIDIACG', 'CGGL', 'COCOA', 'CARBON']) # # DIRECTORY: panda/src/osxdisplay/ diff --git a/makepanda/makepandacore.py b/makepanda/makepandacore.py index b9899f6adb..2eb4342b06 100644 --- a/makepanda/makepandacore.py +++ b/makepanda/makepandacore.py @@ -2002,6 +2002,11 @@ def SdkLocatePython(prefer_thirdparty_python=False): SDK["PYTHONVERSION"] = "python" + ver SDK["PYTHONEXEC"] = "/System/Library/Frameworks/Python.framework/Versions/" + ver + "/bin/python" + ver + # Avoid choosing the one in the thirdparty package dir. + PkgSetCustomLocation("PYTHON") + IncDirectory("PYTHON", py_fwx + "/include") + LibDirectory("PYTHON", "%s/usr/lib" % (SDK.get("MACOSX", ""))) + 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]))