Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Mac OSX + OpenJDK builds where JAVA_HOME contains libexec but not lib #119

Merged
merged 9 commits into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/env/Linux/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
setuptools
wheel
auditwheel
patchelf
1 change: 1 addition & 0 deletions .github/env/Windows/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
setuptools
wheel
1 change: 1 addition & 0 deletions .github/env/macOS/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
setuptools
wheel
3 changes: 3 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,21 @@ jobs:
- { machine: 'ubuntu-20.04', python: '3.9', pythonArchitecture: 'x64', arch: 'amd64', cmd: '.github/env/Linux/bdist-wheel.sh' }
- { machine: 'ubuntu-20.04', python: '3.10', pythonArchitecture: 'x64', arch: 'amd64', cmd: '.github/env/Linux/bdist-wheel.sh' }
- { machine: 'ubuntu-20.04', python: '3.11', pythonArchitecture: 'x64', arch: 'amd64', cmd: '.github/env/Linux/bdist-wheel.sh' }
- { machine: 'ubuntu-20.04', python: '3.12', pythonArchitecture: 'x64', arch: 'amd64', cmd: '.github/env/Linux/bdist-wheel.sh' }
- { machine: 'windows-2022', python: '3.6', pythonArchitecture: 'x64', arch: 'amd64', cmd: '.\.github\env\Windows\bdist-wheel.ps1' }
- { machine: 'windows-2022', python: '3.7', pythonArchitecture: 'x64', arch: 'amd64', cmd: '.\.github\env\Windows\bdist-wheel.ps1' }
- { machine: 'windows-2022', python: '3.8', pythonArchitecture: 'x64', arch: 'amd64', cmd: '.\.github\env\Windows\bdist-wheel.ps1' }
- { machine: 'windows-2022', python: '3.9', pythonArchitecture: 'x64', arch: 'amd64', cmd: '.\.github\env\Windows\bdist-wheel.ps1' }
- { machine: 'windows-2022', python: '3.10', pythonArchitecture: 'x64', arch: 'amd64', cmd: '.\.github\env\Windows\bdist-wheel.ps1' }
- { machine: 'windows-2022', python: '3.11', pythonArchitecture: 'x64', arch: 'amd64', cmd: '.\.github\env\Windows\bdist-wheel.ps1' }
- { machine: 'windows-2022', python: '3.12', pythonArchitecture: 'x64', arch: 'amd64', cmd: '.\.github\env\Windows\bdist-wheel.ps1' }
- { machine: 'macos-11', python: '3.6', pythonArchitecture: 'x64', arch: 'amd64', cmd: '.github/env/macOS/bdist-wheel.sh' }
- { machine: 'macos-11', python: '3.7', pythonArchitecture: 'x64', arch: 'amd64', cmd: '.github/env/macOS/bdist-wheel.sh' }
- { machine: 'macos-11', python: '3.8', pythonArchitecture: 'x64', arch: 'amd64', cmd: '.github/env/macOS/bdist-wheel.sh' }
- { machine: 'macos-11', python: '3.9', pythonArchitecture: 'x64', arch: 'amd64', cmd: '.github/env/macOS/bdist-wheel.sh' }
- { machine: 'macos-11', python: '3.10', pythonArchitecture: 'x64', arch: 'amd64', cmd: '.github/env/macOS/bdist-wheel.sh' }
- { machine: 'macos-11', python: '3.11', pythonArchitecture: 'x64', arch: 'amd64', cmd: '.github/env/macOS/bdist-wheel.sh' }
- { machine: 'macos-11', python: '3.12', pythonArchitecture: 'x64', arch: 'amd64', cmd: '.github/env/macOS/bdist-wheel.sh' }
# Add M1 powered runners when available
# https://github.com/jpy-consortium/jpy/issues/110

Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ Install a JDK 8, preferably the Oracle distribution. Set `JDK_HOME` or

$ export JDK_HOME=<your-jdk-dir>
$ export JAVA_HOME=$JDK_HOME
$ pip install setuptools wheel
$ python setup.py build maven bdist_wheel

On success, the wheel is found in the `dist` directory.
Expand All @@ -68,12 +69,14 @@ SDK 7.1::
> SET DISTUTILS_USE_SDK=1
> C:\Program Files\Microsoft SDKs\Windows\v7.1\bin\setenv /x64 /release
> SET JDK_HOME=<your-jdk-dir>
> pip install setuptools wheel
> python setup.py build maven bdist_wheel

With Visual Studio 14 and higher it is much easier::

> SET VS100COMNTOOLS=C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools\
> SET JDK_HOME=<your-jdk-dir>
> pip install setuptools wheel
> python setup.py build maven bdist_wheel

On success, the wheel can be found in the `dist` directory.
Expand Down
42 changes: 37 additions & 5 deletions jpyutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,42 @@ def find_jdk_home_dir():
dedicated environment variables.
:return: pathname if found, else None
"""

def is_jdk_dir(path):
rst = os.path.exists(os.path.join(path, 'include')) and os.path.exists(os.path.join(path, 'lib'))
logger.debug(f'Checking {path} for JDK...: {"yes" if rst else "no"}')
return rst

def walk_to_jdk(path):
if is_jdk_dir(path):
return path

for root, dir_names, file_names in os.walk(path):
for d in dir_names:
p = os.path.join(root, d)

if p and is_jdk_dir(p):
return p

return None

for name in JDK_HOME_VARS:
jdk_home_dir = os.environ.get(name, None)
if jdk_home_dir \
and os.path.exists(os.path.join(jdk_home_dir, 'include')) \
and os.path.exists(os.path.join(jdk_home_dir, 'lib')):
return jdk_home_dir
if jdk_home_dir:
logger.debug(f'JAVA_HOME set by environment variable to {jdk_home_dir}')

if is_jdk_dir(jdk_home_dir):
return jdk_home_dir

jdk_dir = walk_to_jdk(jdk_home_dir)

if jdk_dir:
logger.error(f'JAVA_HOME set by environment variable to {jdk_home_dir} but no no "include" or "lib" directory found. Possibly you meant {jdk_dir}?')
else:
logger.error(f'JAVA_HOME set by environment variable to {jdk_home_dir} but no no "include" or "lib" directory found. Does not appear to be a JDK directory.')

exit(1)

logger.debug('Checking Maven for JAVA_HOME...')
try:
output = subprocess.check_output(['mvn', '-v'])
Expand All @@ -152,7 +182,9 @@ def find_jdk_home_dir():
if part.startswith('Java home:'):
path = part.split(':')[1].strip()
if path.endswith('jre'):
return path[0:-3]
java_home = path[0:-3]
logger.debug(f'JAVA_HOME set by maven to {java_home}')
return java_home

except Exception:
# maven probably isn't installed or not on PATH
Expand Down
Loading