Bug 1411688 - Part 1: Make --with-gradle handle single-locale repacks. r=snorp draft
authorNick Alexander <nalexander@mozilla.com>
Mon, 23 Oct 2017 13:24:58 -0700
changeset 693057 b0440ceb318662bf3c08f2139c51dae5775a6b38
parent 693056 e57b49e32c80906bdb513850c370d64e5a140978
child 693058 2d23e0e0c51a61e50acf24123b316bdbb0b579ff
push id87692
push usernalexander@mozilla.com
push dateSat, 04 Nov 2017 00:26:38 +0000
reviewerssnorp
bugs1411688
milestone58.0a1
Bug 1411688 - Part 1: Make --with-gradle handle single-locale repacks. r=snorp Single-locale repacks do the following: Download existing APK; unzip APK; update l10n resources; |mach package| with IS_LANGUAGE_REPACK=1. This is pretty hard to accommodate, but we can try. The key issues here are to recognize when IS_LANGUAGE_REPACK=1 and not ask for l10n resources (in particular, strings.xml) to be generated. We do need to include the freshly built classes.dex when repackaging, because newer Gradle/aapt doesn't preserve the R.java IDs. MozReview-Commit-ID: 9FvQtmPOUjg
build.gradle
mobile/android/gradle/with_gecko_binaries.gradle
toolkit/mozapps/installer/upload-files-APK.mk
--- a/build.gradle
+++ b/build.gradle
@@ -62,16 +62,20 @@ if ('multi' == System.env.AB_CD) {
     // Multi-l10n builds set `AB_CD=multi`, which isn't a valid locale.  This
     // causes the
     //
     // |mach build| > |mach gradle| > |make gradle-targets| > AndroidManifest.xml > strings.xml > multi/brand.dtd
     //
     // dependency chain to fail, since multi isn't a real locale.  To avoid
     // this, if Gradle is invoked with AB_CD=multi, we don't invoke Make at all.
     task generateCodeAndResources()
+} else if (System.env.IS_LANGUAGE_REPACK == '1') {
+    // Single-locale l10n repacks set `IS_LANGUAGE_REPACK=1` and handle resource
+    // and code generation themselves.
+    task generateCodeAndResources()
 } else {
     task generateCodeAndResources(type:Exec) {
         workingDir "${topobjdir}"
 
         commandLine mozconfig.substs.GMAKE
         args '-C'
         args "${topobjdir}/mobile/android/base"
         args 'gradle-targets'
--- a/mobile/android/gradle/with_gecko_binaries.gradle
+++ b/mobile/android/gradle/with_gecko_binaries.gradle
@@ -147,35 +147,42 @@ ext.configureVariantWithJNIWrappers = { 
     // by configuring the classpath at evaluation-time, not configuration-time.
     //
     // The specific dependency on the `prepareDependencies` task may not be
     // necessary, but commits like
     // https://github.com/evant/gradle-retrolambda/commit/15108c65ee43be499a1359d9d4f88b0851d46769
     // suggest that it is.  It certainly doesn't hurt.
     def prepareDependenciesTask = tasks.getByName("prepare${variant.name.capitalize()}Dependencies")
 
-    def wrapperTask = task("generateJNIWrappersFor${module}${variant.name.capitalize()}", type: JavaExec) {
-        classpath "${topobjdir}/build/annotationProcessors/annotationProcessors.jar"
-
-        // Configure the classpath at evaluation-time, not at
-        // configuration-time: see above comment.
-        doFirst {
-            classpath variant.javaCompile.classpath
-            // Include android.jar.
-            classpath variant.javaCompile.options.bootClasspath
+    def wrapperTask
+    if (System.env.IS_LANGUAGE_REPACK == '1') {
+        // Single-locale l10n repacks set `IS_LANGUAGE_REPACK=1` and don't
+        // really have a build environment.
+        wrapperTask = task("generateJNIWrappersFor${module}${variant.name.capitalize()}")
+    } else {
+        wrapperTask = task("generateJNIWrappersFor${module}${variant.name.capitalize()}", type: JavaExec) {
+            classpath "${topobjdir}/build/annotationProcessors/annotationProcessors.jar"
+    
+            // Configure the classpath at evaluation-time, not at
+            // configuration-time: see above comment.
+            doFirst {
+                classpath variant.javaCompile.classpath
+                // Include android.jar.
+                classpath variant.javaCompile.options.bootClasspath
+            }
+    
+            main = 'org.mozilla.gecko.annotationProcessors.AnnotationProcessor'
+            args module
+            args jarTask.outputs.files.iterator().next()
+    
+            workingDir "${topobjdir}/mobile/android/base"
+    
+            dependsOn jarTask
+            dependsOn prepareDependenciesTask
         }
-
-        main = 'org.mozilla.gecko.annotationProcessors.AnnotationProcessor'
-        args module
-        args jarTask.outputs.files.iterator().next()
-
-        workingDir "${topobjdir}/mobile/android/base"
-
-        dependsOn jarTask
-        dependsOn prepareDependenciesTask
     }
 
     if (module == 'Generated') {
         tasks["bundle${variant.name.capitalize()}"].dependsOn wrapperTask
     } else {
         tasks["assemble${variant.name.capitalize()}"].dependsOn wrapperTask
     }
 }
--- a/toolkit/mozapps/installer/upload-files-APK.mk
+++ b/toolkit/mozapps/installer/upload-files-APK.mk
@@ -89,16 +89,17 @@ package_fennec = \
 repackage_fennec = \
   $(MAKE) -C $(GECKO_APP_AP_PATH) gecko-nodeps.ap_ && \
   $(PYTHON) -m mozbuild.action.package_fennec_apk \
     --verbose \
     --inputs \
       $(UNPACKAGE) \
       $(GECKO_APP_AP_PATH)/gecko-nodeps.ap_ \
     --omnijar $(MOZ_PKG_DIR)/$(OMNIJAR_NAME) \
+    --classes-dex $(GECKO_APP_AP_PATH)/classes.dex \
     --output $(PACKAGE:.apk=-unsigned-unaligned.apk) && \
   $(call RELEASE_SIGN_ANDROID_APK,$(PACKAGE:.apk=-unsigned-unaligned.apk),$(PACKAGE))
 
 INNER_MAKE_PACKAGE = $(if $(UNPACKAGE),$(repackage_fennec),$(package_fennec))
 
 # Language repacks root the resources contained in assets/omni.ja
 # under assets/, but the repacks expect them to be rooted at /.
 # Therefore, we we move the omnijar back to / so the resources are