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
.util
import ensureParentDir
, lock_file
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
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
)
29 def android(verb
, *args
):
32 with
gradle_lock(buildconfig
.topobjdir
):
35 mozpath
.join(buildconfig
.topsrcdir
, "mach"),
40 env
= dict(os
.environ
)
41 # Confusingly, `MACH` is set only within `mach build`.
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
)
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
)