Merge "Support multiple library test APKs"
This commit is contained in:
commit
e4aaa62e8f
|
@ -1,8 +1,10 @@
|
||||||
/**
|
/**
|
||||||
* This self.gradle build file is only run when built in ub-setupwizard-* branches.
|
* This self.gradle build file is only run when built in ub-setupwizard-* branches.
|
||||||
*/
|
*/
|
||||||
apply plugin: 'dist'
|
|
||||||
apply from: 'standalone-rules.gradle'
|
apply from: 'standalone-rules.gradle'
|
||||||
|
apply from: '../tools/gradle/dist-library-instrumentation-tests.gradle'
|
||||||
|
apply from: '../tools/gradle/dist-unit-tests.gradle'
|
||||||
|
|
||||||
// Add targets for tests
|
// Add targets for tests
|
||||||
android.sourceSets {
|
android.sourceSets {
|
||||||
androidTest {
|
androidTest {
|
||||||
|
@ -62,36 +64,14 @@ android.lintOptions {
|
||||||
android.libraryVariants.all { variant ->
|
android.libraryVariants.all { variant ->
|
||||||
variant.assemble.dependsOn(tasks.findByName('lint'))
|
variant.assemble.dependsOn(tasks.findByName('lint'))
|
||||||
}
|
}
|
||||||
def distTask = tasks.findByName('dist')
|
|
||||||
if (distTask) {
|
// For compatibility with existing continuous test configurations, copy the file to
|
||||||
// Output all test APKs to the distribution folder
|
// setup-wizard-libTest.apk
|
||||||
android.testVariants.all { variant ->
|
// TODO: Remove this once continuous test configurations are updated to handle the new file name
|
||||||
// Make the dist task depend on the test variant, so the test APK will be built
|
task createLegacyTestApk(type: Copy) {
|
||||||
distTask.dependsOn variant.assemble
|
from "${project.ext.distDir}/setup-wizard-lib-gingerbreadCompat-debug-androidTest.apk"
|
||||||
// TODO: remap the different test variants to different file names
|
into "${project.ext.distDir}"
|
||||||
|
rename ('setup-wizard-lib-gingerbreadCompat-debug-androidTest.apk', 'setup-wizard-libTest.apk')
|
||||||
}
|
}
|
||||||
|
|
||||||
// Output the Robolectric test results to host-test-reports/*.zip
|
tasks.dist.finalizedBy createLegacyTestApk
|
||||||
afterEvaluate {
|
|
||||||
android.unitTestVariants.all { variant ->
|
|
||||||
def task = tasks.findByName('test' + variant.name.capitalize())
|
|
||||||
gradle.taskGraph.whenReady { taskGraph ->
|
|
||||||
task.ignoreFailures = taskGraph.hasTask(distTask)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create a zip file of the XML test reports and dist it to host-test-reports.
|
|
||||||
// The file path and format should match GradleHostBasedTest class in TradeFed.
|
|
||||||
def junitReport = task.reports.junitXml
|
|
||||||
if (junitReport.enabled) {
|
|
||||||
def zipTask = project.tasks.create("zipResultsOf${task.name.capitalize()}", Zip) {
|
|
||||||
from junitReport.destination
|
|
||||||
archiveName = task.name + 'Result.zip'
|
|
||||||
destinationDir = junitReport.destination.parentFile
|
|
||||||
}
|
|
||||||
tasks.dist.dependsOn zipTask
|
|
||||||
zipTask.mustRunAfter task
|
|
||||||
dist.file zipTask.archivePath.path, "host-test-reports/${zipTask.archiveName}"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
33
tools/gradle/dist-library-instrumentation-tests.gradle
Normal file
33
tools/gradle/dist-library-instrumentation-tests.gradle
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
/**
|
||||||
|
* This script plugin is used to build and dist the test APK outputs of a library with multiple
|
||||||
|
* build flavors.
|
||||||
|
*
|
||||||
|
* Compared to the defaults of the 'dist' plugin, it does two additional things:
|
||||||
|
* 1. It builds the "debug" test APKs when the 'dist' task is run.
|
||||||
|
* 2. It dist the test APKs using the original output file name instead of hard coding
|
||||||
|
* "${project.archivesBaseName}Tests.apk". This allows multiple flavors of test APKs to be built
|
||||||
|
* without conflicting file names.
|
||||||
|
*/
|
||||||
|
|
||||||
|
apply plugin: 'dist'
|
||||||
|
|
||||||
|
// Set the dist files to empty map, and to tell DistExtension to not include the default files,
|
||||||
|
// because the default output only supports one test APK output for libraries.
|
||||||
|
dist.files = [:]
|
||||||
|
android.testVariants.all { variant ->
|
||||||
|
// "Debug" tests are not built by BuildSrc by default. Depend on the task so it will be built.
|
||||||
|
tasks.dist.dependsOn variant.assemble
|
||||||
|
|
||||||
|
// Output all test APKs to the distribution folder.
|
||||||
|
// For a project named "setup-wizard-lib" with build flavor "platform" and build type "debug",
|
||||||
|
// the output file will be named "setup-wizard-lib-platform-debug-androidTest.apk"
|
||||||
|
variant.outputs.each { output ->
|
||||||
|
dist.file output.outputFile.canonicalPath, output.outputFile.name
|
||||||
|
}
|
||||||
|
}
|
||||||
|
android.libraryVariants.all { variant ->
|
||||||
|
// Output all library AARs to the distribution folder
|
||||||
|
variant.outputs.each { output ->
|
||||||
|
dist.file output.outputFile.canonicalPath, output.outputFile.name
|
||||||
|
}
|
||||||
|
}
|
38
tools/gradle/dist-unit-tests.gradle
Normal file
38
tools/gradle/dist-unit-tests.gradle
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
/**
|
||||||
|
* This script plugin is used to bundle the host test (e.g. Robolectric) results and dist it in
|
||||||
|
* a location where TradeFed knows how to parse.
|
||||||
|
*
|
||||||
|
* - If a non-dist build is run with test, it will run the normal unit tests, failing the build if
|
||||||
|
* there are test failures.
|
||||||
|
* - If a dist build is run with test (e.g. ./gradlew dist test), the build will ignore any test
|
||||||
|
* failures, and will create a zip of the XML test reports for each test run, and copy them to
|
||||||
|
* dist/host-test-reports for consumption by TradeFed.
|
||||||
|
*/
|
||||||
|
|
||||||
|
apply plugin: 'dist'
|
||||||
|
|
||||||
|
// If unit tests are run as part of the build, dist the test XML reports to host-test-reports/*.zip
|
||||||
|
android.unitTestVariants.all { variant ->
|
||||||
|
def task = tasks.findByName('test' + variant.name.capitalize())
|
||||||
|
gradle.taskGraph.whenReady { taskGraph ->
|
||||||
|
// Ignore the failures, so the build continues even on test errors when the build is
|
||||||
|
// running with 'dist'. (Usually as part of a build server build)
|
||||||
|
task.ignoreFailures = taskGraph.hasTask(tasks.dist)
|
||||||
|
}
|
||||||
|
|
||||||
|
def junitReport = task.reports.junitXml
|
||||||
|
if (junitReport.enabled) {
|
||||||
|
// Create a zip file of the XML test reports
|
||||||
|
def zipTask = tasks.create("zipResultsOf${task.name.capitalize()}", Zip) {
|
||||||
|
from junitReport.destination
|
||||||
|
archiveName = task.name + 'Result.zip'
|
||||||
|
destinationDir = junitReport.destination.parentFile
|
||||||
|
}
|
||||||
|
zipTask.mustRunAfter task
|
||||||
|
|
||||||
|
// Copy the test reports to dist/host-test-reports
|
||||||
|
// The file path and format should match GradleHostBasedTest class in TradeFed.
|
||||||
|
tasks.dist.dependsOn zipTask
|
||||||
|
dist.file zipTask.archivePath.path, "host-test-reports/${zipTask.archiveName}"
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue