tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

java.configure (2852B)


      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 # ========================================================
     10 option(
     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, want_bootstrap)
     18 @imports(_from="mozboot.android", _import="ensure_java")
     19 @imports(_from="mozboot.android", _import="JavaLocationFailedException")
     20 @imports(_from="mozboot.android", _import="locate_java_bin_path")
     21 @imports(_from="os", _import="environ")
     22 @imports(_from="os.path", _import="dirname")
     23 @imports(_from="__builtin__", _import="Exception")
     24 def java_search_paths(path, host, toolchains_base_dir, want_bootstrap):
     25     if path:
     26         # Look for javac and jar in the specified path.
     27         return path
     28 
     29     try:
     30         path = locate_java_bin_path(host.kernel, toolchains_base_dir)
     31 
     32         java_home = environ.get("JAVA_HOME")
     33         if java_home and java_home != dirname(path):
     34             log.info(
     35                 "Ignoring JAVA_HOME value. Use --with-java-bin-path "
     36                 "to override the default Java location."
     37             )
     38         return [path]
     39     except JavaLocationFailedException as e:
     40         if not want_bootstrap("jdk"):
     41             die(str(e))
     42 
     43         os_name = {"Linux": "linux", "Darwin": "macosx", "WINNT": "windows"}.get(
     44             host.kernel
     45         )
     46         if os_name is None:
     47             die(
     48                 "We don't support bootstrapping the Java SDK on {0} yet!".format(
     49                     host.kernel
     50                 )
     51             )
     52         os_arch = host.cpu
     53 
     54         try:
     55             # FIXME: should use the bootstrap.configure mechanism instead
     56             return [str(ensure_java(os_name, os_arch))]
     57         except Exception as e:
     58             die(str(e))
     59 
     60 
     61 # Finds the given java tool, failing with a custom error message if we can't
     62 # find it.
     63 
     64 
     65 @template
     66 def check_java_tool(tool):
     67     check = check_prog(
     68         tool.upper(), (tool,), paths=java_search_paths, allow_missing=True
     69     )
     70 
     71     @depends(check)
     72     def require_tool(result):
     73         if result is None:
     74             die(
     75                 "The program %s was not found. Use '--with-java-bin-path={java-bin-dir}'"
     76                 % tool
     77             )
     78         return result
     79 
     80     return require_tool
     81 
     82 
     83 check_java_tool("java")
     84 
     85 
     86 # Java Code Coverage
     87 # ========================================================
     88 option(
     89     "--enable-java-coverage",
     90     env="MOZ_JAVA_CODE_COVERAGE",
     91     help="Enable Java code coverage",
     92 )
     93 
     94 set_config(
     95     "MOZ_JAVA_CODE_COVERAGE", depends("--enable-java-coverage")(lambda v: bool(v))
     96 )