Bug 1650206 - If set, check JAVA_HOME for java instead of path. r=nalexander

Prior to this patch JAVA_HOME was appended to path and then the first instance
of java on those paths was used and checked for version compatibility. This
meant that if an incompatible version on java is on the path JAVA_HOME could not
be used to point to a different, compatible version.

Following this patch, JAVA_HOME can be used as a more fine grained selector of
java. Only if JAVA_HOME is not set will we check the path. To be clear, even if
JAVA_HOME is set incorrectly, we will not fall back to path -- only if JAVA_HOME
is not set will we try and use the path.

Differential Revision: https://phabricator.services.mozilla.com/D82418
This commit is contained in:
Bryce 2020-07-06 19:58:01 +00:00
parent 14464b938b
commit 79bb99c145

View File

@ -836,9 +836,15 @@ class BaseBootstrapper(object):
Gradle.
"""
java = None
if 'JAVA_HOME' in os.environ:
extra_search_dirs += (os.path.join(os.environ['JAVA_HOME'], 'bin'),)
java = self.which('java', *extra_search_dirs)
# Search JAVA_HOME if it is set as it's finer grained than looking at PATH.
possible_java_path = os.path.join(os.environ['JAVA_HOME'], 'bin', 'java')
if os.path.isfile(possible_java_path) and os.access(possible_java_path, os.X_OK):
java = possible_java_path
else:
# Search the path if JAVA_HOME is not set.
java = self.which('java', *extra_search_dirs)
if not java:
raise Exception('You need to have Java Development Kit version 1.8 installed. '