Bug 1666032: ensure java from PATH == java from JDK_BIN_DIR r=rstewart

In the build process, there's two ways that java is used:
* From the path
* From the java-bin-path specified in the mozconfig

Before, to assert that both "java" usages would be consistent, the
implementation assumed that there was only a single "java" binary
per-JDK-version, and all duplicate "binaries" were symlinks to the
original.

However, in Fedora, it has two identical full binaries: one in
$JDK/bin, and one in $JDK/jre/bin. The symlink theory was incorrect.

So instead, we can assert that both "java" usages are consistent
by checking their versions and asserting that they are equivalent.

Differential Revision: https://phabricator.services.mozilla.com/D90918
This commit is contained in:
Mitchell Hentges 2020-09-21 20:59:32 +00:00
Родитель fe776d35ce
Коммит 862d284885
1 изменённых файлов: 45 добавлений и 32 удалений

Просмотреть файл

@ -858,13 +858,22 @@ class BaseBootstrapper(object):
if jarsigner and java:
jdk_bin_dir = os.path.dirname(os.path.realpath(jarsigner))
if (os.path.realpath(java) !=
os.path.realpath(which('java', path=jdk_bin_dir))):
jdk_bin_java = which('java', path=jdk_bin_dir)
# Different parts of the build process reference "java" differently.
# In bootstrap, we run some Android tooling which uses "java" from the PATH.
# Meanwhile, in build, we'll use the "java" found in the --with-java-bin-path.
# To ensure we don't run into surprises, we check that both of our "java"s are
# from the same JDK version.
path_java_version = _resolve_java_version(java)[0]
jdk_bin_version = _resolve_java_version(jdk_bin_java)[0]
if path_java_version != jdk_bin_version:
# This can happen on Ubuntu if "update-alternatives" has been
# manually overridden once for either "java" or "jarsigner".
raise Exception('The "java" and "jarsigner" binaries on the PATH are '
'currently coming from two different JDKs. Please '
'resolve this, or explicitly set JAVA_HOME.')
# manually overridden for either "java" or "jarsigner".
raise Exception('The "java" (JDK {}) and "jarsigner" (JDK {}) binaries on the '
'PATH are currently coming from two different JDKs. Please '
'resolve this, or explicitly set JAVA_HOME.'
.format(path_java_version, jdk_bin_version))
if not jdk_bin_dir:
raise Exception('You need to have Java Development Kit version 1.8 installed. '
@ -872,7 +881,29 @@ class BaseBootstrapper(object):
java = which('java', path=jdk_bin_dir)
try:
output = subprocess.check_output([java,
version, output = _resolve_java_version(java)
if not version or version not in ['1.8', '8']:
raise Exception('You need to have Java Development Kit version '
'1.8 installed (found {} but could not parse '
'version "{}"). Check the JAVA_HOME environment '
'variable. Please install JDK 1.8 from '
'https://adoptopenjdk.net/?variant=openjdk8.'
.format(java, output))
mozconfig_builder.append('''
# Use the same Java binary that was used in bootstrap in case the global
# system default version is changed.
ac_add_options --with-java-bin-path={}
'''.format(jdk_bin_dir))
except subprocess.CalledProcessError as e:
raise Exception('Failed to get java version from {}: {}'.format(java, e.output))
print('Your version of Java ({}) is at least 1.8 ({}).'.format(java, version))
def _resolve_java_version(java_path):
output = subprocess.check_output([java_path,
'-XshowSettings:properties',
'-version'],
stderr=subprocess.STDOUT,
@ -886,26 +917,8 @@ class BaseBootstrapper(object):
version = [line for line in output.splitlines()
if 'java.specification.version' in line]
unknown_version_exception = Exception('You need to have Java Development Kit version '
'1.8 installed (found {} but could not parse '
'version "{}"). Check the JAVA_HOME environment '
'variable. Please install JDK 1.8 from '
'https://adoptopenjdk.net/?variant=openjdk8.'
.format(java, output))
if not len(version) == 1:
raise unknown_version_exception
if len(version) != 1:
return None, output
version = version[0].split(' = ')[-1]
if version not in ['1.8', '8']:
raise unknown_version_exception
mozconfig_builder.append('''
# Use the same Java binary that was used in bootstrap in case the global
# system default version is changed.
ac_add_options --with-java-bin-path={}
'''.format(jdk_bin_dir))
except subprocess.CalledProcessError as e:
raise Exception('Failed to get java version from {}: {}'.format(java, e.output))
print('Your version of Java ({}) is at least 1.8 ({}).'.format(java, version))
return version, output