1 /* -*- Mode: Groovy; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
2 * This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 // The JNI wrapper generation tasks depend on the JAR creation task of the :annotations project.
7 evaluationDependsOn(':annotations')
9 // Whether to include compiled artifacts: `lib/**/*.so` and `assets/omni.ja`.
10 // Multi-locale packaging wants to include compiled artifacts but *not* rebuild
11 // them: see also `rootProject.{machStagePackage,geckoBinariesOnlyIf}`.
12 def hasCompileArtifacts() {
13 return project.mozconfig.substs.COMPILE_ENVIRONMENT // Full builds.
14 || project.mozconfig.substs.MOZ_ARTIFACT_BUILDS // Artifact builds.
15 || System.getenv("MOZ_CHROME_MULTILOCALE") // Multi-locale packaging.
18 ext.configureVariantWithGeckoBinaries = { variant ->
19 if (hasCompileArtifacts()) {
20 // Local (read, not 'official') builds want to reflect developer changes to
21 // the omnijar sources, and (when compiling) to reflect developer changes to
22 // the native binaries. To do this, the Gradle build calls out to the
23 // moz.build system, which can be re-entrant. Official builds are driven by
24 // the moz.build system and should never be re-entrant in this way.
25 def assetGenTask = tasks.findByName("generate${variant.name.capitalize()}Assets")
26 def jniLibFoldersTask = tasks.findByName("merge${variant.name.capitalize()}JniLibFolders")
27 if (!mozconfig.substs.MOZILLA_OFFICIAL) {
28 assetGenTask.dependsOn rootProject.machStagePackage
29 jniLibFoldersTask.dependsOn rootProject.machStagePackage
34 ext.configureLibraryVariantWithJNIWrappers = { variant, module ->
35 // BundleLibRuntime prepares the library for further processing to be
36 // incorporated in an app. We use this version to create the JNI wrappers.
37 def jarTask = tasks["bundleLibRuntimeToJar${variant.name.capitalize()}"]
38 def bundleJar = jarTask.outputs.files.find({ it.name == 'classes.jar' })
40 def annotationProcessorsJarTask = project(':annotations').jar
43 if (System.env.IS_LANGUAGE_REPACK == '1') {
44 // Single-locale l10n repacks set `IS_LANGUAGE_REPACK=1` and don't
45 // really have a build environment.
46 wrapperTask = task("generateJNIWrappersFor${module}${variant.name.capitalize()}")
48 wrapperTask = task("generateJNIWrappersFor${module}${variant.name.capitalize()}", type: JavaExec) {
49 classpath annotationProcessorsJarTask.archiveFile
51 // Configure the classpath at evaluation-time, not at
52 // configuration-time: see above comment.
54 classpath variant.javaCompileProvider.get().classpath.files
57 mainClass = 'org.mozilla.gecko.annotationProcessors.AnnotationProcessor'
61 workingDir "${topobjdir}/widget/android"
63 inputs.file(bundleJar)
64 inputs.file(annotationProcessorsJarTask.archiveFile)
65 inputs.property("module", module)
67 outputs.file("${topobjdir}/widget/android/GeneratedJNINatives.h")
68 outputs.file("${topobjdir}/widget/android/GeneratedJNIWrappers.cpp")
69 outputs.file("${topobjdir}/widget/android/GeneratedJNIWrappers.h")
72 dependsOn annotationProcessorsJarTask
76 if (module == 'Generated') {
77 tasks["bundle${variant.name.capitalize()}Aar"].dependsOn wrapperTask
79 tasks["assemble${variant.name.capitalize()}"].dependsOn wrapperTask