no bug - Import translations from android-l10n r=release a=l10n CLOSED TREE
[gecko.git] / mobile / android / gradle.py
blob9f310ddb7bd8c9b7fdcb146782cddb39548dd872
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.util import ensureParentDir, lock_file
14 @contextmanager
15 def gradle_lock(topobjdir, max_wait_seconds=600):
16 # Building the same Gradle root project with multiple concurrent processes
17 # is not well supported, so we use a simple lock file to serialize build
18 # steps.
19 lock_path = "{}/gradle/mach_android.lockfile".format(topobjdir)
20 ensureParentDir(lock_path)
21 lock_instance = lock_file(lock_path, max_wait=max_wait_seconds)
23 try:
24 yield
25 finally:
26 del lock_instance
29 def android(verb, *args):
30 import buildconfig
32 with gradle_lock(buildconfig.topobjdir):
33 cmd = [
34 sys.executable,
35 mozpath.join(buildconfig.topsrcdir, "mach"),
36 "android",
37 verb,
39 cmd.extend(args)
40 env = dict(os.environ)
41 # Confusingly, `MACH` is set only within `mach build`.
42 if env.get("MACH"):
43 env["GRADLE_INVOKED_WITHIN_MACH_BUILD"] = "1"
44 if env.get("LD_LIBRARY_PATH"):
45 del env["LD_LIBRARY_PATH"]
46 subprocess.check_call(cmd, env=env)
48 return 0
51 def assemble_app(dummy_output_file, *inputs):
52 return android("assemble-app")
55 def generate_sdk_bindings(dummy_output_file, *args):
56 return android("generate-sdk-bindings", *args)
59 def generate_generated_jni_wrappers(dummy_output_file, *args):
60 return android("generate-generated-jni-wrappers", *args)