Backed out changeset 074b8a59783f (bug 1891509) for causing fenix lint failures....
[gecko.git] / mobile / android / gradle.py
blobdc273f9cce420e4d2f04b35930daf9da7f87a156
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/.
5 import os
6 import subprocess
7 import sys
8 from contextlib import contextmanager
10 import mozpack.path as mozpath
11 from mozbuild.dirutils import ensureParentDir
12 from mozbuild.lock import lock_file
15 @contextmanager
16 def gradle_lock(topobjdir, max_wait_seconds=600):
17 # Building the same Gradle root project with multiple concurrent processes
18 # is not well supported, so we use a simple lock file to serialize build
19 # steps.
20 lock_path = "{}/gradle/mach_android.lockfile".format(topobjdir)
21 ensureParentDir(lock_path)
22 lock_instance = lock_file(lock_path, max_wait=max_wait_seconds)
24 try:
25 yield
26 finally:
27 del lock_instance
30 def android(verb, *args):
31 import buildconfig
33 with gradle_lock(buildconfig.topobjdir):
34 cmd = [
35 sys.executable,
36 mozpath.join(buildconfig.topsrcdir, "mach"),
37 "android",
38 verb,
40 cmd.extend(args)
41 env = dict(os.environ)
42 # Confusingly, `MACH` is set only within `mach build`.
43 if env.get("MACH"):
44 env["GRADLE_INVOKED_WITHIN_MACH_BUILD"] = "1"
45 if env.get("LD_LIBRARY_PATH"):
46 del env["LD_LIBRARY_PATH"]
47 subprocess.check_call(cmd, env=env)
49 return 0
52 def assemble_app(dummy_output_file, *inputs):
53 return android("assemble-app")
56 def generate_sdk_bindings(dummy_output_file, *args):
57 return android("generate-sdk-bindings", *args)
60 def generate_generated_jni_wrappers(dummy_output_file, *args):
61 return android("generate-generated-jni-wrappers", *args)