Bug 1444546 - Part 2: Build annotationProcessors with Gradle. r=jchen

We want annotationProcessors to be compiled and archived into a JAR at
build time, ready to generate JNI wrappers.  (That is, until we turn
the whole thing into a real annotation processor.)  But even if we do
use a real annotation processor, we still need to generate SDK
bindings, which is less clearly expressed as an annotation processor.
(It's more of a build step.)

Gradle provides a huge number of ways to organize build logic to
achieve this: see
https://docs.gradle.org/current/userguide/organizing_build_logic.html.
Unfortunately, the best such way -- putting the code into
$topsrcdir/buildSrc -- has key disadvantages:

1) it pollutes the top-level $topsrcdir, and there's no way to change the
location of buildSrc (https://github.com/gradle/gradle/issues/2472);

2) it's complicated to have a dependent project
(mobile/android/annotations) expose its code via a buildSrc project;

3) using buildSrc at all appears to conflict with the Android-Gradle
plugin version that we are using.

Therefore, this commit does something much simpler: it adds a
Java-only project and uses the resulting Gradle "Jar" task and archive
output as input to the existing Gradle "generate JNI wrappers" task.

MozReview-Commit-ID: 2OyYLPneE1M

--HG--
extra : rebase_source : d99b74a0a1e0bb3e8f4d4540978328388e5c2e42
This commit is contained in:
Nick Alexander 2018-02-22 16:11:14 -08:00
parent 90a4b9e4b1
commit 520b63c85e
7 changed files with 23 additions and 39 deletions

View File

@ -1,10 +0,0 @@
# 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/.
include $(topsrcdir)/config/rules.mk
# Include Android specific java flags, instead of what's in rules.mk.
include $(topsrcdir)/config/android-common.mk
export:: annotationProcessors.jar

View File

@ -1,21 +0,0 @@
# -*- 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/.
jar = add_java_jar('annotationProcessors')
jar.sources += [
'AnnotationInfo.java',
'AnnotationProcessor.java',
'classloader/AnnotatableEntity.java',
'classloader/ClassWithOptions.java',
'classloader/IterableJarLoadingURLClassLoader.java',
'classloader/JarClassIterator.java',
'CodeGenerator.java',
'SDKProcessor.java',
'utils/AlphabeticAnnotatableEntityComparator.java',
'utils/GeneratableElementIterator.java',
'utils/Utils.java',
]
jar.extra_jars += CONFIG['ANDROID_LINT_CLASSPATH'].split()

View File

@ -24,9 +24,6 @@ CRAMTEST_MANIFESTS += [
'tests/cram/cram.ini',
]
if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'android':
DIRS += ['annotationProcessors']
DEFINES['ACCEPTED_MAR_CHANNEL_IDS'] = CONFIG['ACCEPTED_MAR_CHANNEL_IDS']
if CONFIG['MOZ_BUILD_APP'] == 'browser':

View File

@ -165,9 +165,6 @@ ifeq (.,$(DEPTH))
js/xpconnect/src/export: dom/bindings/export xpcom/xpidl/export
accessible/xpcom/export: xpcom/xpidl/export
# The widget binding generator code is part of the annotationProcessors.
widget/android/bindings/export: build/annotationProcessors/export
# .xpt generation needs the xpidl lex/yacc files
xpcom/xpidl/export: xpcom/idl-parser/xpidl/export

View File

@ -0,0 +1,11 @@
buildDir "${topobjdir}/gradle/build/mobile/android/annotations"
apply plugin: 'java'
dependencies {
compile 'com.android.tools.lint:lint:25.3.1'
compile 'com.android.tools.lint:lint-checks:25.3.1'
}
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8

View File

@ -119,6 +119,8 @@ ext.configureLibraryVariantWithJNIWrappers = { variant, module ->
def jarTask = tasks["transformClassesAndResourcesWithPrepareIntermediateJarsFor${variant.name.capitalize()}"]
def output = jarTask.outputs.files.find({ it.absolutePath.contains('/classes.jar') })
def annotationProcessorsJarTask = project(':annotations').jar
def wrapperTask
if (System.env.IS_LANGUAGE_REPACK == '1') {
// Single-locale l10n repacks set `IS_LANGUAGE_REPACK=1` and don't
@ -126,7 +128,7 @@ ext.configureLibraryVariantWithJNIWrappers = { variant, module ->
wrapperTask = task("generateJNIWrappersFor${module}${variant.name.capitalize()}")
} else {
wrapperTask = task("generateJNIWrappersFor${module}${variant.name.capitalize()}", type: JavaExec) {
classpath "${topobjdir}/build/annotationProcessors/annotationProcessors.jar"
classpath annotationProcessorsJarTask.archivePath
// Configure the classpath at evaluation-time, not at
// configuration-time: see above comment.
@ -143,6 +145,7 @@ ext.configureLibraryVariantWithJNIWrappers = { variant, module ->
workingDir "${topobjdir}/mobile/android/base"
dependsOn jarTask
dependsOn annotationProcessorsJarTask
}
}
@ -157,6 +160,8 @@ ext.configureApplicationVariantWithJNIWrappers = { variant, module ->
def jarTask = tasks["bundleAppClasses${variant.name.capitalize()}"]
def output = jarTask.outputs.files.find({ it.absolutePath.contains('/classes.jar') })
def annotationProcessorsJarTask = project(':annotations').jar
def wrapperTask
if (System.env.IS_LANGUAGE_REPACK == '1') {
// Single-locale l10n repacks set `IS_LANGUAGE_REPACK=1` and don't
@ -164,7 +169,7 @@ ext.configureApplicationVariantWithJNIWrappers = { variant, module ->
wrapperTask = task("generateJNIWrappersFor${module}${variant.name.capitalize()}")
} else {
wrapperTask = task("generateJNIWrappersFor${module}${variant.name.capitalize()}", type: JavaExec) {
classpath "${topobjdir}/build/annotationProcessors/annotationProcessors.jar"
classpath annotationProcessorsJarTask.archivePath
// Configure the classpath at evaluation-time, not at
// configuration-time: see above comment.
@ -182,6 +187,8 @@ ext.configureApplicationVariantWithJNIWrappers = { variant, module ->
// This forces bundling, which isn't usually part of the assemble* process.
dependsOn jarTask
dependsOn annotationProcessorsJarTask
}
}
}

View File

@ -14,6 +14,7 @@ if (proc.exitValue() != 0) {
}
import groovy.json.JsonSlurper
def slurper = new JsonSlurper()
def json = slurper.parseText(standardOutput.toString())
@ -28,12 +29,14 @@ if (json.substs.MOZ_BUILD_APP != 'mobile/android') {
// but it's hard to automatically arrange better.
System.setProperty('android.home', json.substs.ANDROID_SDK_ROOT)
include ':annotations'
include ':app'
include ':geckoview'
include ':geckoview_example'
include ':omnijar'
include ':thirdparty'
project(':annotations').projectDir = new File("${json.topsrcdir}/mobile/android/annotations")
project(':app').projectDir = new File("${json.topsrcdir}/mobile/android/app")
project(':geckoview').projectDir = new File("${json.topsrcdir}/mobile/android/geckoview")
project(':geckoview_example').projectDir = new File("${json.topsrcdir}/mobile/android/geckoview_example")