Bug 1220887 - Make 'base' Gradle project in the srcdir. r=sebastian
authorNick Alexander <nalexander@mozilla.com>
Tue, 03 Nov 2015 15:04:39 -0800
changeset 271310 319e09c9668b8d2937c49dabdfd84a30d8771ac1
parent 271309 4e951da373d703bce17600cea9ac9b0f509c84e5
child 271311 d23a0521caf37354a413d141496a8e2d065f62da
push id16108
push usernalexander@mozilla.com
push dateThu, 05 Nov 2015 22:05:26 +0000
treeherderfx-team@319e09c9668b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssebastian
bugs1220887
milestone45.0a1
Bug 1220887 - Make 'base' Gradle project in the srcdir. r=sebastian This is the last Gradle project that isn't in the srcdir. Since base/ doesn't have the correct package prefix directory structure, we still need to symlink, but we only need one link. This effectively deprecates |mach gradle-install|. This should improve the robustness of our Gradle configuration, ensuring that we always have projects to import. Since settings.gradle executes very early in the IDE import project sequence: before Gradle project evaluation time, and thus before any Gradle task is executed, we should always see a complete project. (It was possible to see incomplete Gradle configurations if |mach gradle-install| hadn't been run at just the right time.)
build.gradle
mobile/android/base/AndroidManifest.xml
mobile/android/base/build.gradle
mobile/android/base/lint.xml
settings.gradle
--- a/build.gradle
+++ b/build.gradle
@@ -110,17 +110,16 @@ idea {
             .findAll({it.startsWith('obj') && !it.startsWith('.') && !it.equals('mobile/')}))
 
         // If topobjdir is below topsrcdir, hide only some portions of that tree.
         def topobjdirURI = file(topobjdir).toURI()
         if (!topsrcdirURI.relativize(topobjdirURI).isAbsolute()) {
             excludeDirs -= file(topobjdir)
             excludeDirs += files(file(topobjdir).listFiles())
             excludeDirs -= file("${topobjdir}/gradle")
-            excludeDirs -= file("${topobjdir}/mobile")
         }
 
         if (!mozconfig.substs.MOZ_INSTALL_TRACKING) {
             excludeDirs += file("${topsrcdir}/mobile/android/thirdparty/com/adjust")
         }
     }
 }
 
new file mode 100644
--- /dev/null
+++ b/mobile/android/base/AndroidManifest.xml
@@ -0,0 +1,6 @@
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+    package="org.mozilla.gecko">
+<!-- THIS IS NOT THE REAL MANIFEST!  This is for Gradle only.  See
+     AndroidManifest.xml.in. -->
+
+</manifest>
new file mode 100644
--- /dev/null
+++ b/mobile/android/base/build.gradle
@@ -0,0 +1,131 @@
+buildDir "${topobjdir}/gradle/build/mobile/android/base"
+
+apply plugin: 'com.android.library'
+
+android {
+    compileSdkVersion 23
+    buildToolsVersion "23.0.1"
+
+    defaultConfig {
+        targetSdkVersion 22
+        minSdkVersion 9
+    }
+
+    compileOptions {
+        sourceCompatibility JavaVersion.VERSION_1_7
+        targetCompatibility JavaVersion.VERSION_1_7
+    }
+
+    lintOptions {
+        abortOnError false
+    }
+
+    sourceSets {
+        main {
+            manifest.srcFile 'AndroidManifest.xml'
+            java {
+                srcDir "${topobjdir}/gradle/base/src"
+                exclude 'org/mozilla/gecko/resources/**'
+
+                srcDir "${topsrcdir}/mobile/android/search/java"
+                srcDir "${topsrcdir}/mobile/android/javaaddons/java"
+
+                if (mozconfig.substs.MOZ_ANDROID_MLS_STUMBLER) {
+                    srcDir "${topsrcdir}/mobile/android/stumbler/java"
+                }
+
+                if (!mozconfig.substs.MOZ_CRASHREPORTER) {
+                    exclude 'org/mozilla/gecko/CrashReporter.java'
+                }
+
+                if (!mozconfig.substs.MOZ_NATIVE_DEVICES) {
+                    exclude 'org/mozilla/gecko/ChromeCast.java'
+                    exclude 'org/mozilla/gecko/GeckoMediaPlayer.java'
+                    exclude 'org/mozilla/gecko/MediaPlayerManager.java'
+                }
+
+                if (mozconfig.substs.MOZ_WEBRTC) {
+                    srcDir "${topsrcdir}/media/webrtc/trunk/webrtc/modules/audio_device/android/java/src"
+                    srcDir "${topsrcdir}/media/webrtc/trunk/webrtc/modules/video_capture/android/java/src"
+                    srcDir "${topsrcdir}/media/webrtc/trunk/webrtc/modules/video_render/android/java/src"
+                }
+
+                if (mozconfig.substs.MOZ_INSTALL_TRACKING) {
+                    exclude 'org/mozilla/gecko/adjust/StubAdjustHelper.java'
+                } else {
+                    exclude 'org/mozilla/gecko/adjust/AdjustHelper.java'
+                }
+
+                srcDir "${project.buildDir}/generated/source/preprocessed_code" // See syncPreprocessedCode.
+            }
+
+            res {
+                srcDir "${topsrcdir}/${mozconfig.substs.MOZ_BRANDING_DIRECTORY}/res"
+                srcDir "${project.buildDir}/generated/source/preprocessed_resources" // See syncPreprocessedResources.
+                srcDir 'resources'
+                if (mozconfig.substs.MOZ_CRASHREPORTER) {
+                    srcDir 'crashreporter/res'
+                }
+            }
+        }
+
+        test {
+            java {
+                srcDir "${topsrcdir}/mobile/android/tests/background/junit4/src"
+            }
+
+            resources {
+                srcDir "${topsrcdir}/mobile/android/tests/background/junit4/resources"
+            }
+        }
+    }
+}
+
+task syncPreprocessedCode(type: Sync, dependsOn: rootProject.generateCodeAndResources) {
+    into("${project.buildDir}/generated/source/preprocessed_code")
+    from("${topobjdir}/mobile/android/base/generated/preprocessed")
+}
+
+task syncPreprocessedResources(type: Sync, dependsOn: rootProject.generateCodeAndResources) {
+    into("${project.buildDir}/generated/source/preprocessed_resources")
+    from("${topobjdir}/mobile/android/base/res")
+}
+
+android.libraryVariants.all { variant ->
+    variant.preBuild.dependsOn syncPreprocessedCode
+    variant.preBuild.dependsOn syncPreprocessedResources
+}
+
+dependencies {
+    compile 'com.android.support:support-v4:23.0.1'
+    compile 'com.android.support:appcompat-v7:23.0.1'
+    compile 'com.android.support:recyclerview-v7:23.0.1'
+    compile 'com.android.support:design:23.0.1'
+
+    if (mozconfig.substs.MOZ_NATIVE_DEVICES) {
+        compile 'com.android.support:mediarouter-v7:23.0.1'
+        compile 'com.google.android.gms:play-services-basement:8.1.0'
+        compile 'com.google.android.gms:play-services-base:8.1.0'
+        compile 'com.google.android.gms:play-services-cast:8.1.0'
+    }
+
+    if (mozconfig.substs.MOZ_ANDROID_GCM) {
+        compile 'com.google.android.gms:play-services-basement:8.1.0'
+        compile 'com.google.android.gms:play-services-base:8.1.0'
+        compile 'com.google.android.gms:play-services-gcm:8.1.0'
+    }
+
+    compile project(':thirdparty')
+
+    testCompile 'junit:junit:4.12'
+    testCompile 'org.robolectric:robolectric:3.0'
+    testCompile 'org.simpleframework:simple-http:4.1.13'
+}
+
+apply plugin: 'idea'
+
+idea {
+    module {
+        excludeDirs += file("${topobjdir}/gradle/base/src/org/mozilla/gecko/resources")
+    }
+}
new file mode 100644
--- /dev/null
+++ b/mobile/android/base/lint.xml
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<lint>
+    <!-- Enable relevant checks disabled by default -->
+    <issue id="NegativeMargin" severity="warning" />
+
+    <!-- We have a custom menu and don't conform to the recommended styles. -->
+    <issue id="IconColors" severity="ignore" />
+</lint>
--- a/settings.gradle
+++ b/settings.gradle
@@ -16,24 +16,42 @@ if (proc.exitValue() != 0) {
 import groovy.json.JsonSlurper
 def slurper = new JsonSlurper()
 def json = slurper.parseText(standardOutput.toString())
 
 if (json.substs.MOZ_BUILD_APP != 'mobile/android') {
     throw new GradleException("Building with Gradle is only supported for Fennec, i.e., MOZ_BUILD_APP == 'mobile/android'.");
 }
 
+def srcdir = { dst, src ->
+    def d = java.nio.file.Paths.get("${json.topobjdir}/gradle/${dst}")
+    def s = java.nio.file.Paths.get("${json.topsrcdir}/${src}")
+    try {
+        java.nio.file.Files.createDirectories(d.getParent())
+    } catch (java.nio.file.FileAlreadyExistsException e) {
+        // Do nothing.
+    }
+    try {
+        java.nio.file.Files.createSymbolicLink(d, s)
+    } catch (java.nio.file.FileAlreadyExistsException e) {
+        // Do nothing.
+    }
+}
+
+// Since base/ doesn't have the correct package prefix directory structure, we
+// still need to symlink.
+srcdir('base/src/org/mozilla/gecko', 'mobile/android/base')
+
 include ':app'
 include ':base'
 include ':omnijar'
 include ':thirdparty'
 
-def gradleRoot = new File("${json.topobjdir}/mobile/android/gradle")
 project(':app').projectDir = new File("${json.topsrcdir}/mobile/android/app")
-project(':base').projectDir = new File(gradleRoot, 'base')
+project(':base').projectDir = new File("${json.topsrcdir}/mobile/android/base")
 project(':omnijar').projectDir = new File("${json.topsrcdir}/mobile/android/app/omnijar")
 project(':thirdparty').projectDir = new File("${json.topsrcdir}/mobile/android/thirdparty")
 
 // The Gradle instance is shared between settings.gradle and all the
 // other build.gradle files (see
 // http://forums.gradle.org/gradle/topics/define_extension_properties_from_settings_xml).
 // We use this ext property to pass the per-object-directory mozconfig
 // between scripts.  This lets us execute set-up code before we gradle