1# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*- 2# vim: set filetype=python: 3# This Source Code Form is subject to the terms of the Mozilla Public 4# License, v. 2.0. If a copy of the MPL was not distributed with this 5# file, You can obtain one at http://mozilla.org/MPL/2.0/. 6 7 8# Java detection 9# ======================================================== 10option( 11 "--with-java-bin-path", 12 nargs=1, 13 help="Location of Java binaries", 14) 15 16 17@depends("--with-java-bin-path", host, toolchains_base_dir) 18@imports(_from="mozboot.android", _import="JavaLocationFailedException") 19@imports(_from="mozboot.android", _import="locate_java_bin_path") 20@imports(_from="os", _import="environ") 21@imports(_from="os.path", _import="dirname") 22def java_search_paths(path, host, toolchains_base_dir): 23 if path: 24 # Look for javac and jar in the specified path. 25 return path 26 27 try: 28 path = locate_java_bin_path(host.kernel, toolchains_base_dir) 29 30 java_home = environ.get("JAVA_HOME") 31 if java_home and java_home != dirname(path): 32 log.info( 33 "Ignoring JAVA_HOME value. Use --with-java-bin-path " 34 "to override the default Java location." 35 ) 36 return [path] 37 except JavaLocationFailedException as e: 38 die(str(e)) 39 40 41# Finds the given java tool, failing with a custom error message if we can't 42# find it. 43 44 45@template 46def check_java_tool(tool): 47 check = check_prog( 48 tool.upper(), (tool,), paths=java_search_paths, allow_missing=True 49 ) 50 51 @depends(check) 52 def require_tool(result): 53 if result is None: 54 die( 55 "The program %s was not found. Use '--with-java-bin-path={java-bin-dir}'" 56 % tool 57 ) 58 return result 59 60 return require_tool 61 62 63check_java_tool("java") 64 65 66# Java Code Coverage 67# ======================================================== 68option( 69 "--enable-java-coverage", 70 env="MOZ_JAVA_CODE_COVERAGE", 71 help="Enable Java code coverage", 72) 73 74set_config( 75 "MOZ_JAVA_CODE_COVERAGE", depends("--enable-java-coverage")(lambda v: bool(v)) 76) 77