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/.
8 from contextlib
import contextmanager
10 import mozpack
.path
as mozpath
11 from mozbuild
.dirutils
import ensureParentDir
12 from mozbuild
.lock
import lock_file
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
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
)
30 def android(verb
, *args
):
33 with
gradle_lock(buildconfig
.topobjdir
):
36 mozpath
.join(buildconfig
.topsrcdir
, "mach"),
41 env
= dict(os
.environ
)
42 # Confusingly, `MACH` is set only within `mach build`.
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
)
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
)