2018-03-20 22:41:49 +03:00
|
|
|
# This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
|
2019-07-16 20:46:25 +03:00
|
|
|
from __future__ import absolute_import, print_function
|
2018-03-20 22:41:49 +03:00
|
|
|
|
2019-08-02 23:29:46 +03:00
|
|
|
from contextlib import contextmanager
|
2019-05-09 23:39:10 +03:00
|
|
|
import os
|
2018-03-20 22:41:49 +03:00
|
|
|
import subprocess
|
2019-02-12 08:45:36 +03:00
|
|
|
import sys
|
2018-03-20 22:41:49 +03:00
|
|
|
|
|
|
|
from mozbuild.util import (
|
|
|
|
ensureParentDir,
|
|
|
|
lock_file,
|
|
|
|
)
|
|
|
|
import mozpack.path as mozpath
|
|
|
|
|
|
|
|
|
2019-08-02 23:29:46 +03:00
|
|
|
@contextmanager
|
|
|
|
def gradle_lock(topobjdir, max_wait_seconds=600):
|
2018-03-20 22:41:49 +03:00
|
|
|
# Building the same Gradle root project with multiple concurrent processes
|
|
|
|
# is not well supported, so we use a simple lock file to serialize build
|
|
|
|
# steps.
|
2019-08-02 23:29:46 +03:00
|
|
|
lock_path = '{}/gradle/mach_android.lockfile'.format(topobjdir)
|
2018-03-20 22:41:49 +03:00
|
|
|
ensureParentDir(lock_path)
|
2019-08-02 23:29:46 +03:00
|
|
|
lock_instance = lock_file(lock_path, max_wait=max_wait_seconds)
|
|
|
|
|
2018-03-20 22:41:49 +03:00
|
|
|
try:
|
2019-08-02 23:29:46 +03:00
|
|
|
yield
|
|
|
|
finally:
|
|
|
|
del lock_instance
|
|
|
|
|
|
|
|
|
|
|
|
def android(verb, *args):
|
|
|
|
import buildconfig
|
|
|
|
|
|
|
|
with gradle_lock(buildconfig.topobjdir):
|
2018-03-20 22:41:49 +03:00
|
|
|
cmd = [
|
2019-02-12 08:45:36 +03:00
|
|
|
sys.executable,
|
2018-03-20 22:41:49 +03:00
|
|
|
mozpath.join(buildconfig.topsrcdir, 'mach'),
|
|
|
|
'android',
|
|
|
|
verb,
|
|
|
|
]
|
|
|
|
cmd.extend(args)
|
2019-05-09 23:39:10 +03:00
|
|
|
env = dict(os.environ)
|
|
|
|
# Confusingly, `MACH` is set only within `mach build`.
|
|
|
|
if env.get('MACH'):
|
|
|
|
env['GRADLE_INVOKED_WITHIN_MACH_BUILD'] = '1'
|
|
|
|
subprocess.check_call(cmd, env=env)
|
2018-03-20 22:41:49 +03:00
|
|
|
|
|
|
|
return 0
|
|
|
|
|
|
|
|
|
|
|
|
def assemble_app(dummy_output_file, *inputs):
|
|
|
|
return android('assemble-app')
|
2018-03-07 06:19:48 +03:00
|
|
|
|
|
|
|
|
|
|
|
def generate_sdk_bindings(dummy_output_file, *args):
|
|
|
|
return android('generate-sdk-bindings', *args)
|
2018-03-07 07:09:37 +03:00
|
|
|
|
|
|
|
|
|
|
|
def generate_generated_jni_wrappers(dummy_output_file, *args):
|
|
|
|
return android('generate-generated-jni-wrappers', *args)
|