Andi Vajda <va...@apache.org> wrote:

> Ok then, provide a tested patch that works and applies out of the box
> to JCC's trunk, and that puts this code into a new helper file like is
> done for linux and windows (thus not adding pages of code to setup.py)
> and I'll integrate it.

Here it is.  I happened to have both old and new Snow Leopard machines
around to test it on, as well as my Leopard machines.  Works on all of
them.  This applies to the trunk of pylucene.

Bill

Index: jcc/setup.py
===================================================================
--- jcc/setup.py	(revision 1044561)
+++ jcc/setup.py	(working copy)
@@ -43,8 +43,16 @@
 else:
     JAVAHOME = None
 
+if platform in ("darwin",):
+    try:
+        from helpers.darwin import JAVAHOME
+    except ImportError:
+        JAVAHOME = None
+else:
+    JAVAHOME = None
+
 JDK = {
-    'darwin': '/Developer/SDKs/MacOSX10.6.sdk/System/Library/Frameworks/JavaVM.framework/Versions/Current',
+    'darwin': JAVAHOME,
     'ipod': '/usr/include/gcc',
     'linux2': '/usr/lib/jvm/java-6-openjdk',
     'sunos5': '/usr/jdk/instances/jdk1.6.0',
--- /dev/null	2010-12-10 18:20:10.000000000 -0800
+++ jcc/helpers/darwin.py	2010-12-10 18:29:44.000000000 -0800
@@ -0,0 +1,31 @@
+#   Licensed under the Apache License, Version 2.0 (the "License");
+#   you may not use this file except in compliance with the License.
+#   You may obtain a copy of the License at
+#
+#       http://www.apache.org/licenses/LICENSE-2.0
+#
+#   Unless required by applicable law or agreed to in writing, software
+#   distributed under the License is distributed on an "AS IS" BASIS,
+#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#   See the License for the specific language governing permissions and
+#   limitations under the License.
+
+import sys, os
+
+global JAVAHOME
+JAVAHOME = None
+
+if sys.platform == "darwin":
+    # figure out where the JDK lives
+    import platform, re
+    _os_version = re.match("[0-9]+\.[0-9]+", platform.mac_ver()[0]).group(0)
+    # this is where Apple says we should look for headers
+    _path = "/System/Library/Frameworks/JavaVM.framework"
+    if os.path.exists(os.path.join(_path, "Headers", "jni.h")):
+        JAVAHOME = _path
+    else:
+        # but their updates don't always match their documentation, so look here
+        _path = ("/Developer/SDKs/MacOSX" + _os_version + ".sdk/"
+                "System/Library/Frameworks/JavaVM.framework/Versions/Current")
+        if os.path.exists(os.path.join(_path, "Headers", "jni.h")):
+            JAVAHOME = _path

Reply via email to