gecko-dev/mobile/android/gradle.configure
Nick Alexander ac6d84fa56 Bug 1417232 - Part 3: Extract magic Gradle configuration from |mach android *|. r=ted.mielczarek
This pushes all of the magic Gradle targets into gradle.configure,
which is the most accessible central place for them.  Some impact the
build, so they almost certainly need to be in moz.configure; and its
better to have one central place to update than many places.

Gradle has a notion of configurations.  Fennec determines many
configurations, only one of which is used in automation; and right
now, that one is "officialPhotonDebug".  Evolving the "one true"
configuration is frustrating, and this helps with that.  Post
Android-Gradle plugin 3.0+, we can do better and also extract the
configuration details for the :geckoview and :geckoview_example Gradle
projects, but right now they are ad-hoc and can't really be improved.

MozReview-Commit-ID: LdGE05zn2H1

--HG--
extra : rebase_source : db7e9fe90f2bd1ae5058af046a66edd0cd549141
2017-11-10 15:39:09 -08:00

217 lines
7.4 KiB
Python

# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
# vim: set filetype=python:
# 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/.
# If --with-gradle is specified, build mobile/android with Gradle. If no
# Gradle binary is specified, or if --without-gradle is specified, use the in
# tree Gradle wrapper. The wrapper downloads and installs Gradle, which is
# good for local developers but not good in automation.
option('--with-gradle', nargs='?',
default=True,
help='Enable building mobile/android with Gradle '
'(argument: location of binary or wrapper (gradle/gradlew))')
@depends('--with-gradle')
def with_gradle(value):
if value:
return True
set_config('MOZ_BUILD_MOBILE_ANDROID_WITH_GRADLE', with_gradle)
@depends('--with-gradle', check_build_environment)
@imports(_from='os.path', _import='isfile')
def gradle(value, build_env):
gradle = value[0] if len(value) else \
os.path.join(build_env.topsrcdir, 'gradlew')
# TODO: verify that $GRADLE is executable.
if not isfile(gradle):
die('GRADLE must be executable: %s', gradle)
return gradle
set_config('GRADLE', gradle)
@dependable
@imports(_from='itertools', _import='chain')
def gradle_android_build_config():
def capitalize(s):
# str.capitalize lower cases trailing letters.
if s:
return s[0].upper() + s[1:]
else:
return s
# It's not really possible to abstract the GeckoView details just yet; post
# Android-Gradle plugin 3.0+, the configurations can be more sensible and
# we'll do this work.
def variant(productFlavors, buildType):
return namespace(
productFlavors=productFlavors,
buildType=buildType,
# Like 'OfficialWithoutGeckoBinariesPhotonDebug'
name = ''.join(capitalize(t) for t in chain(productFlavors, (buildType, )))
)
return namespace(
app=namespace(
variant=variant(('official', 'photon'), 'debug'),
),
)
@depends(gradle_android_build_config)
def gradle_android_app_variant_name(build_config):
'''Like "officialPhotonDebug".'''
def uncapitalize(s):
if s:
return s[0].lower() + s[1:]
else:
return s
return uncapitalize(build_config.app.variant.name)
set_config('GRADLE_ANDROID_APP_VARIANT_NAME', gradle_android_app_variant_name)
@depends(gradle_android_build_config)
def gradle_android_app_tasks(build_config):
'''Gradle tasks run by |mach android assemble-app|.'''
return [
'geckoview:generateJNIWrappersForGeneratedRelease',
'app:generateJNIWrappersForFennec{app.variant.name}'.format(app=build_config.app),
'app:assemble{app.variant.name}'.format(app=build_config.app),
'app:assemble{app.variant.name}AndroidTest'.format(app=build_config.app),
]
set_config('GRADLE_ANDROID_APP_TASKS', gradle_android_app_tasks)
@depends(gradle_android_build_config, check_build_environment)
def gradle_android_app_apks(build_config, build_env):
'''Paths to APK files produced by |mach android assemble-app|.'''
flavor = '-'.join(build_config.app.variant.productFlavors)
buildType = build_config.app.variant.buildType
f = '{}/gradle/build/mobile/android/app/outputs/apk/app-{}-{}.apk'
g = '{}/gradle/build/mobile/android/app/outputs/apk/app-{}-{}-androidTest.apk'
return namespace(app_apk=f.format(build_env.topobjdir, flavor, buildType),
app_androidTest_apk=g.format(build_env.topobjdir, flavor, buildType))
set_config('GRADLE_ANDROID_APP_APK', gradle_android_app_apks.app_apk)
set_config('GRADLE_ANDROID_APP_ANDROIDTEST_APK', gradle_android_app_apks.app_androidTest_apk)
@depends(gradle_android_build_config)
def gradle_android_test_tasks(build_config):
'''Gradle tasks run by |mach android test|.'''
return [
'app:test{app.variant.name}UnitTest'.format(app=build_config.app),
]
set_config('GRADLE_ANDROID_TEST_TASKS', gradle_android_test_tasks)
@depends(gradle_android_build_config)
def gradle_android_lint_tasks(build_config):
'''Gradle tasks run by |mach android lint|.'''
return [
'app:lint{app.variant.name}'.format(app=build_config.app),
]
set_config('GRADLE_ANDROID_LINT_TASKS', gradle_android_lint_tasks)
@dependable
def gradle_android_checkstyle_tasks():
'''Gradle tasks run by |mach android checkstyle|.'''
return [
'app:checkstyle',
]
set_config('GRADLE_ANDROID_CHECKSTYLE_TASKS', gradle_android_checkstyle_tasks)
@depends(gradle_android_build_config)
def gradle_android_findbugs_tasks(build_config):
'''Gradle tasks run by |mach android findbugs|.'''
return [
'app:findbugsXml{app.variant.name}'.format(app=build_config.app),
'app:findbugsHtml{app.variant.name}'.format(app=build_config.app),
]
set_config('GRADLE_ANDROID_FINDBUGS_TASKS', gradle_android_findbugs_tasks)
@dependable
def gradle_android_archive_geckoview_tasks():
'''Gradle tasks run by |mach android archive-geckoview|.'''
return [
'geckoview:assembleWithGeckoBinaries',
'geckoview_example:assembleWithGeckoBinaries',
'geckoview_example:assembleWithGeckoBinariesAndroidTest',
'geckoview:uploadArchives',
]
set_config('GRADLE_ANDROID_ARCHIVE_GECKOVIEW_TASKS', gradle_android_archive_geckoview_tasks)
@depends(
gradle_android_app_tasks,
gradle_android_test_tasks,
gradle_android_lint_tasks,
gradle_android_checkstyle_tasks,
gradle_android_findbugs_tasks,
gradle_android_archive_geckoview_tasks,
)
@imports(_from='itertools', _import='imap')
@imports(_from='itertools', _import='chain')
@imports(_from='itertools', _import='ifilterfalse')
def gradle_android_dependencies_tasks(*tasks):
'''Gradle tasks run by |mach android dependencies|.'''
# The union, plus a bit more, of all of the Gradle tasks
# invoked by the android-* automation jobs.
def withoutGeckoBinaries(task):
return task.replace('withGeckoBinaries', 'withoutGeckoBinaries')
def isUploadArchives(task):
return 'uploadArchives' in task
return list(ifilterfalse(isUploadArchives, imap(withoutGeckoBinaries, chain(*tasks))))
set_config('GRADLE_ANDROID_DEPENDENCIES_TASKS', gradle_android_dependencies_tasks)
# Automation uses this to change log levels, not use the daemon, and use
# offline mode.
option(env='GRADLE_FLAGS', default='', help='Flags to pass to Gradle.')
@depends('GRADLE_FLAGS')
def gradle_flags(value):
return value[0] if value else ''
set_config('GRADLE_FLAGS', gradle_flags)
# Automation will set this to (file:///path/to/local, ...) via the mozconfig.
# Local developer default is (jcenter, maven.google.com).
option(env='GRADLE_MAVEN_REPOSITORIES',
nargs='+',
default=('https://jcenter.bintray.com/',
'https://maven.google.com/',
),
help='Comma-separated URLs of Maven repositories containing Gradle dependencies.')
@depends('GRADLE_MAVEN_REPOSITORIES')
@imports(_from='os.path', _import='isdir')
def gradle_maven_repositories(values):
if not values:
die('GRADLE_MAVEN_REPOSITORIES must not be empty')
if not all(values):
die('GRADLE_MAVEN_REPOSITORIES entries must not be empty')
return values
set_config('GRADLE_MAVEN_REPOSITORIES', gradle_maven_repositories)