gecko-dev/build/moz.configure/java.configure

124 строки
4.2 KiB
Plaintext
Исходник Обычный вид История

# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
# vim: set filetype=python:
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
# Java detection
# ========================================================
option('--with-java-bin-path', nargs=1,
help='Location of Java binaries (java, javac, jar)')
@depends('--with-java-bin-path')
@imports(_from='os', _import='environ')
def java_search_paths(path):
if path:
# Look for javac and jar in the specified path.
return path
# With no path specified, look for javac and jar in $JAVA_HOME (if set)
# and $PATH.
if 'JAVA_HOME' in environ:
return [os.path.join(environ['JAVA_HOME'], 'bin'),
environ.get('PATH', '')]
return [environ.get('PATH')]
# Finds the given java tool, failing with a custom error message if we can't
# find it.
@template
def check_java_tool(tool):
check = check_prog(tool.upper(), (tool,), paths=java_search_paths,
allow_missing=True)
@depends(check)
def require_tool(result):
if result is None:
die("The program %s was not found. Set $JAVA_HOME to your Java "
"SDK directory or use '--with-java-bin-path={java-bin-dir}'"
% tool)
return result
return require_tool
java = check_java_tool('java')
check_java_tool('javah')
check_java_tool('jar')
check_java_tool('jarsigner')
check_java_tool('keytool')
javac = check_java_tool('javac')
@depends(javac)
@checking('for javac version')
@imports('subprocess')
def javac_version(javac):
try:
output = subprocess.check_output([javac, '-version'],
stderr=subprocess.STDOUT).rstrip()
version = Version(output.split(' ')[-1])
if version < '1.8':
die('javac 1.8 or higher is required (found %s). '
'Check the JAVA_HOME environment variable.' % version)
return version
except subprocess.CalledProcessError as e:
die('Failed to get javac version: %s', e.output)
# Proguard detection
# ========================================================
@depends('--help')
@imports('os')
def proguard_jar_default(_):
# By default, look for proguard.jar in the location to which `mach
# bootstrap` or `mach artifact toolchain` will install Proguard.
default = os.path.expanduser(os.path.join('~', '.mozbuild'))
mozbuild_state_dir = os.environ.get('MOZBUILD_STATE_PATH', default)
return os.path.join(mozbuild_state_dir, 'proguard', 'lib', 'proguard.jar')
# Proguard is really required; we provide a good error message when
# validating.
option(env='PROGUARD_JAR', nargs=1, default=proguard_jar_default,
help='Path to proguard.jar')
@depends(java, 'PROGUARD_JAR')
@checking('for proguard.jar version')
# Do not change, this is fragile! This form works with the test
# configure sandbox.
@imports(_from='os', _import='path')
@imports('subprocess')
def valid_proguard(java, proguard_jar):
if not proguard_jar or not path.isfile(proguard_jar[0]):
die('proguard.jar 5.3.3 or higher is required (looked for {}). '
'Run |mach artifact install --from-build proguard-jar| or add '
'`export PROGUARD_JAR=/path/to/proguard.jar` to your mozconfig.'
.format(proguard_jar[0]))
try:
output = subprocess.check_output([java, '-jar', proguard_jar[0]])
# Exit code zero shouldn't happen.
die('Expected `java -jar {}` to fail (with version in output) '
'but got exit code 0'
.format(proguard_jar[0]))
except subprocess.CalledProcessError as e:
# Exit code is non zero and output is like
# ProGuard, version 5.3.3
# Usage: java proguard.ProGuard [options ...]
output = e.output
version = Version(output.splitlines()[0].split(' ')[-1])
if version < '5.3.3':
die('proguard.jar 5.3.3 or higher is required (found %s). '
'Run |mach bootstrap| to upgrade. ' % version)
return proguard_jar[0]
set_config('PROGUARD_JAR', valid_proguard)