tor-browser

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

gradle.py (1595B)


      1 # This Source Code Form is subject to the terms of the Mozilla Public
      2 # License, v. 2.0. If a copy of the MPL was not distributed with this
      3 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
      4 
      5 import os
      6 import subprocess
      7 import sys
      8 import time
      9 from contextlib import contextmanager
     10 
     11 import mozpack.path as mozpath
     12 from filelock import SoftFileLock
     13 from mozbuild.dirutils import ensureParentDir
     14 
     15 
     16 @contextmanager
     17 def gradle_lock(topobjdir, max_wait_seconds=600):
     18    # Building the same Gradle root project with multiple concurrent processes
     19    # is not well supported, so we use a simple lock file to serialize build
     20    # steps.
     21    lock_path = f"{topobjdir}/gradle/mach_android.lockfile"
     22    ensureParentDir(lock_path)
     23    with SoftFileLock(lock_path, timeout=max_wait_seconds):
     24        yield
     25 
     26 
     27 def main(dummy_output_file, *args):
     28    env = dict(os.environ)
     29    import buildconfig
     30 
     31    cmd = [
     32        sys.executable,
     33        mozpath.join(buildconfig.topsrcdir, "mach"),
     34        "android",
     35        "export",
     36    ]
     37    cmd.extend(args)
     38    # Confusingly, `MACH` is set only within `mach build`.
     39    if env.get("MACH"):
     40        env["GRADLE_INVOKED_WITHIN_MACH_BUILD"] = "1"
     41    if env.get("LD_LIBRARY_PATH"):
     42        del env["LD_LIBRARY_PATH"]
     43 
     44    should_print_status = env.get("MACH") and not env.get("NO_BUILDSTATUS_MESSAGES")
     45    if should_print_status:
     46        print("BUILDSTATUS " + str(time.time()) + " START_Gradle export")
     47 
     48    subprocess.check_call(cmd, env=env)
     49 
     50    if should_print_status:
     51        print("BUILDSTATUS " + str(time.time()) + " END_Gradle export")
     52    return 0