Bug 1690340 - Part 4: Insert the "Page Source" before the "Extensions for Developers...
[gecko.git] / mobile / android / gradle.py
blob59595652c5d062e1ea4ea3660049fa28f0fcc54f
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 from __future__ import absolute_import, print_function
7 from contextlib import contextmanager
8 import os
9 import subprocess
10 import sys
12 from mozbuild.util import (
13 ensureParentDir,
14 lock_file,
16 import mozpack.path as mozpath
19 @contextmanager
20 def gradle_lock(topobjdir, max_wait_seconds=600):
21 # Building the same Gradle root project with multiple concurrent processes
22 # is not well supported, so we use a simple lock file to serialize build
23 # steps.
24 lock_path = "{}/gradle/mach_android.lockfile".format(topobjdir)
25 ensureParentDir(lock_path)
26 lock_instance = lock_file(lock_path, max_wait=max_wait_seconds)
28 try:
29 yield
30 finally:
31 del lock_instance
34 def android(verb, *args):
35 import buildconfig
37 with gradle_lock(buildconfig.topobjdir):
38 cmd = [
39 sys.executable,
40 mozpath.join(buildconfig.topsrcdir, "mach"),
41 "android",
42 verb,
44 cmd.extend(args)
45 env = dict(os.environ)
46 # Confusingly, `MACH` is set only within `mach build`.
47 if env.get("MACH"):
48 env["GRADLE_INVOKED_WITHIN_MACH_BUILD"] = "1"
49 if env.get("LD_LIBRARY_PATH"):
50 del env["LD_LIBRARY_PATH"]
51 subprocess.check_call(cmd, env=env)
53 return 0
56 def assemble_app(dummy_output_file, *inputs):
57 return android("assemble-app")
60 def generate_sdk_bindings(dummy_output_file, *args):
61 return android("generate-sdk-bindings", *args)
64 def generate_generated_jni_wrappers(dummy_output_file, *args):
65 return android("generate-generated-jni-wrappers", *args)