Bug 1405124 - Set appropriate version code and string for GeckoView AAR r=nalexander draft
authorJames Willcox <snorp@snorp.net>
Mon, 02 Oct 2017 15:49:28 -0500
changeset 681010 c5ad3faad3a2c01071bad3f18d2405dab2fa5ca6
parent 681009 37262485adbe6dc4edd229bfb7dbd6f4eb318924
child 736050 2829458839b9520c1eba8a8744be18705c8ca9ba
push id84717
push userbmo:snorp@snorp.net
push dateMon, 16 Oct 2017 19:47:22 +0000
reviewersnalexander
bugs1405124
milestone58.0a1
Bug 1405124 - Set appropriate version code and string for GeckoView AAR r=nalexander MozReview-Commit-ID: DZAxlp7zBHv
mobile/android/geckoview/build.gradle
--- a/mobile/android/geckoview/build.gradle
+++ b/mobile/android/geckoview/build.gradle
@@ -1,31 +1,60 @@
 buildDir "${topobjdir}/gradle/build/mobile/android/geckoview"
 
 apply plugin: 'com.android.library'
 
-def VERSION_NAME = '0.0.1'
+// This converts MOZ_APP_VERSION into an integer
+// version code.
+//
+// We take something like 58.1.2a1 and come out with 5800102
+// This gives us 3 digits for the major number, and 2 digits
+// each for the minor and build number. Beta and Release
+def computeVersionCode() {
+    String appVersion = mozconfig.substs.MOZ_APP_VERSION
+
+    // Split on the dot delimiter, e.g. 58.1.1a1 -> ["58, "1", "1a1"]
+    String[] parts = appVersion.split('\\.')
+
+    assert parts.size() == 2 || parts.size() == 3
+
+    // Strip out any milestone string ('a1' in the above example)
+    // Present in Nightly (or local) builds only.
+    parts.eachWithIndex { ver, index ->
+        parts[index] = ver.replaceFirst(/[a-zA-Z].*/, "")
+    }
+
+    // Major
+    int code = Integer.parseInt(parts[0]) * 100000
+
+    // Minor
+    code += Integer.parseInt(parts[1]) * 100
+
+    // Build
+    if (parts.size() == 3) {
+        code += Integer.parseInt(parts[2])
+    }
+
+    return code;
+}
 
 android {
     compileSdkVersion project.ext.compileSdkVersion
     buildToolsVersion project.ext.buildToolsVersion
 
     defaultConfig {
         defaultPublishConfig 'release'
         publishNonDefault true
 
         targetSdkVersion project.ext.targetSdkVersion
         minSdkVersion project.ext.minSdkVersion
         manifestPlaceholders = project.ext.manifestPlaceholders
 
-        // TODO: version GeckoView explicitly.  We'd like to avoid
-        // mozconfig.substs.ANDROID_VERSION_CODE, which won't be intuitive to
-        // consumer (and advances very quickly on pre-release channels).
-        versionCode 1
-        versionName VERSION_NAME
+        versionCode computeVersionCode()
+        versionName "${mozconfig.substs.MOZ_APP_VERSION}-${mozconfig.substs.MOZ_UPDATE_CHANNEL}"
         consumerProguardFiles 'proguard-rules.txt'
 
         // TODO: ensure these fields always agree with mobile/android/geckoview/BuildConfig.java.in,
         // either by diffing the processed files or by generating the output from a single source.
         buildConfigField 'String', "GRE_MILESTONE", "\"${mozconfig.substs.GRE_MILESTONE}\""
         buildConfigField 'String', "MOZ_APP_ABI", "\"${mozconfig.substs.MOZ_APP_ABI}\"";
         buildConfigField 'String', "MOZ_APP_BASENAME", "\"${mozconfig.substs.MOZ_APP_BASENAME}\"";
 
@@ -34,16 +63,17 @@ android {
         // on XULRunner, which is never the case on Android.
         buildConfigField 'String', "MOZ_APP_BUILDID", "\"${mozconfig.substs.MOZ_BUILDID}\"";
         buildConfigField 'String', "MOZ_APP_ID", "\"${mozconfig.substs.MOZ_APP_ID}\"";
         buildConfigField 'String', "MOZ_APP_NAME", "\"${mozconfig.substs.MOZ_APP_NAME}\"";
         buildConfigField 'String', "MOZ_APP_VENDOR", "\"${mozconfig.substs.MOZ_APP_VENDOR}\"";
         buildConfigField 'String', "MOZ_APP_VERSION", "\"${mozconfig.substs.MOZ_APP_VERSION}\"";
         buildConfigField 'String', "MOZ_APP_DISPLAYNAME", "\"${mozconfig.substs.MOZ_APP_DISPLAYNAME}\"";
         buildConfigField 'String', "MOZ_APP_UA_NAME", "\"${mozconfig.substs.MOZ_APP_UA_NAME}\"";
+        buildConfigField 'String', "MOZ_UPDATE_CHANNEL", "\"${mozconfig.substs.MOZ_UPDATE_CHANNEL}\"";
 
         // MOZILLA_VERSION is oddly quoted from autoconf, but we don't have to handle it specially in Gradle.
         buildConfigField 'String', "MOZILLA_VERSION", "\"${mozconfig.substs.MOZILLA_VERSION}\"";
         buildConfigField 'String', "OMNIJAR_NAME", "\"${mozconfig.substs.OMNIJAR_NAME}\"";
 
         buildConfigField 'String', "USER_AGENT_GECKOVIEW_MOBILE", "\"Mozilla/5.0 (Android \" + android.os.Build.VERSION.RELEASE + \"; Mobile; rv: ${mozconfig.substs.MOZ_APP_VERSION}) Gecko/${mozconfig.substs.MOZ_APP_VERSION} GeckoView/${mozconfig.substs.MOZ_APP_VERSION}\"";
         buildConfigField 'String', "USER_AGENT_GECKOVIEW_TABLET", "\"Mozilla/5.0 (Android \" + android.os.Build.VERSION.RELEASE + \"; Tablet; rv: ${mozconfig.substs.MOZ_APP_VERSION}) Gecko/${mozconfig.substs.MOZ_APP_VERSION} GeckoView/${mozconfig.substs.MOZ_APP_VERSION}\"";
 
@@ -138,19 +168,19 @@ android.libraryVariants.all { variant ->
     // and amended from numerous Stackoverflow posts.
     def name = variant.name
     def javadoc = task "javadoc${name.capitalize()}"(type: Javadoc) {
         description = "Generate Javadoc for build variant $name"
         failOnError = false
         destinationDir = new File(destinationDir, variant.baseName)
         source = files(variant.javaCompile.source)
         classpath = files(variant.javaCompile.classpath.files) + files(android.bootClasspath)
-        options.windowTitle("Mozilla GeckoView Android API $VERSION_NAME Reference")
-        options.docTitle("Mozilla GeckoView Android API $VERSION_NAME")
-        options.header("Mozilla GeckoView Android API $VERSION_NAME Reference")
+        options.windowTitle("Mozilla GeckoView ${mozconfig.substs.MOZ_APP_VERSION} API Reference")
+        options.docTitle("Mozilla GeckoView ${mozconfig.substs.MOZ_APP_VERSION}")
+        options.header("Mozilla GeckoView ${mozconfig.substs.MOZ_APP_VERSION} API Reference")
         options.bottom("&copy; 2016 Mozilla. All rights reserved.")
         options.links("http://docs.oracle.com/javase/7/docs/api/")
         options.linksOffline("http://d.android.com/reference/", "$System.env.ANDROID_HOME/docs/reference")
         // TODO: options.overview("src/main/java/overview.html")
         options.group("Mozilla GeckoView", "org.mozilla.gecko*") // TODO: narrow this down.
         exclude '**/R.java', '**/BuildConfig.java', 'com/googlecode/**'
     }
 
@@ -167,18 +197,18 @@ android.libraryVariants.all { variant ->
     }
 }
 
 apply plugin: 'maven'
  
 uploadArchives {
     repositories.mavenDeployer {
         pom.groupId = 'org.mozilla'
-        pom.artifactId = 'geckoview'
-        pom.version = VERSION_NAME
+        pom.artifactId = "geckoview-${mozconfig.substs.MOZ_UPDATE_CHANNEL}-${mozconfig.substs.ANDROID_CPU_ARCH}"
+        pom.version = mozconfig.substs.MOZ_APP_VERSION
         pom.project {
             licenses {
                 license {
                     name 'The Mozilla Public License, v. 2.0'
                     url 'http://mozilla.org/MPL/2.0/'
                     distribution 'repo'
                 }
             }