[go: nahoru, domu]

blob: 36c5f72b22d86a2831b04c5cd3a1d1486c85f553 [file] [log] [blame]
/*
* Copyright (C) 2017 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import androidx.build.BuildServerConfigurationKt
import androidx.build.dependencyTracker.AffectedModuleDetector
import androidx.build.gmaven.GMavenVersionChecker
import com.android.build.gradle.internal.coverage.JacocoReportTask
import com.android.build.gradle.internal.tasks.DeviceProviderInstrumentTestTask
def supportRoot = ext.supportRootFolder
if (supportRoot == null) {
throw new RuntimeException("variable supportRootFolder is not set. you must set it before" +
" including this script")
}
def init = new Properties()
ext.init = init
rootProject.ext.versionChecker = new GMavenVersionChecker(rootProject.logger)
apply from: "${supportRoot}/buildSrc/dependencies.gradle"
def setupRepoOutAndBuildNumber() {
/*
* The OUT_DIR is a temporary directory you can use to put things during the build.
*/
if (BuildServerConfigurationKt.isRunningOnBuildServer()) {
buildDir = new File(System.env.OUT_DIR + '/gradle/frameworks/support/build')
.getCanonicalFile()
// the build server should always print out full stack traces for any failures.
gradle.startParameter.showStacktrace = ShowStacktrace.ALWAYS
} else {
buildDir = file("${ext.supportRootFolder}/../../out/host/gradle/frameworks/support/build")
}
subprojects {
// Change buildDir first so that all plugins pick up the new value.
project.buildDir = new File("$project.parent.buildDir/../$project.name/build")
}
ext.supportRepoOut = new File(buildDir, 'support_repo')
ext.supportRepoOut.mkdirs()
ext.docsDir = new File(buildDir, 'javadoc')
}
def configureSubProjects() {
subprojects {
repos.addMavenRepositories(repositories)
}
setupSubprojectsForBuildServer()
}
def setupSubprojectsForBuildServer() {
subprojects {
project.plugins.whenPluginAdded { plugin ->
def isAndroidLibrary = "com.android.build.gradle.LibraryPlugin"
.equals(plugin.class.name)
def isAndroidApp = "com.android.build.gradle.AppPlugin".equals(plugin.class.name)
if (isAndroidLibrary || isAndroidApp) {
// Copy the class files in a jar to be later used to generate code coverage report
project.android.testVariants.all { v ->
// check if the variant has any source files
// and test coverage is enabled
if (v.buildType.testCoverageEnabled
&& v.sourceSets.any { !it.java.sourceFiles.isEmpty() }) {
def jarifyTask = project.tasks.create(
name: "package${v.name.capitalize()}ClassFilesForCoverageReport",
type: Jar) {
from v.testedVariant.javaCompileProvider.get().destinationDir
exclude "**/R.class"
exclude "**/R\$*.class"
exclude "**/BuildConfig.class"
destinationDir BuildServerConfigurationKt.getDistributionDirectory(rootProject)
archiveName "${project.name}-${v.baseName}-allclasses.jar"
}
jarifyTask.dependsOn v.getJavaCompileProvider()
v.assemble.dependsOn jarifyTask
}
}
}
}
// Copy instrumentation test APKs and app APKs into the dist dir
// For test apks, they are uploaded only if we have java test sources.
// For regular app apks, they are uploaded only if they have java sources.
project.tasks.configureEach { task ->
if (task.name.startsWith("packageDebug")) {
// run this task only if we should run it
def testApk = task.name.contains("AndroidTest")
if (testApk) {
AffectedModuleDetector.configureTaskGuard(task)
}
task.doLast {
def source = testApk ? project.android.sourceSets.androidTest
: project.android.sourceSets.main
def hasKotlinSources = false
if (source.hasProperty('kotlin')) {
if (!source.kotlin.files.isEmpty()) {
hasKotlinSources = true
} else {
// kotlin files does not show in java sources due to the *.java filter
// so we need to check them manually
hasKotlinSources = source.java.sourceDirectoryTrees.any {
!fileTree(dir: it.dir, include:'**/*.kt').files.isEmpty()
}
}
}
def hasSourceCode = !source.java.sourceFiles.isEmpty() || hasKotlinSources
if (task.hasProperty("outputDirectory") && (hasSourceCode || !testApk)) {
copy {
from(task.outputDirectory)
include '*.apk'
into(BuildServerConfigurationKt.getDistributionDirectory(rootProject))
rename { String fileName ->
// Exclude media-compat-test-* and media2-test-* modules from
// existing support library presubmit tests.
if (fileName.contains("media-compat-test")
|| fileName.contains("media2-test")) {
fileName.replace("-debug-androidTest", "")
} else {
// multiple modules may have the same name so prefix the name with
// the module's path to ensure it is unique.
// e.g. palette-v7-debug-androidTest.apk becomes
// support-palette-v7_palette-v7-debug-androidTest.apk
"${project.getPath().replace(':', '-').substring(1)}_${fileName}"
}
}
}
}
}
}
}
// copy host side test results to DIST
project.tasks.withType(Test) { task ->
def junitReport = task.reports.junitXml
if (junitReport.enabled) {
def zipTask = project.tasks.create(
name: "zipResultsOf${task.name.capitalize()}", type: Zip) {
destinationDir(BuildServerConfigurationKt.getHostTestResultDirectory(project))
// first one is always :, drop it.
archiveName("${project.getPath().split(":").join("_").substring(1)}.zip")
}
if (BuildServerConfigurationKt.isRunningOnBuildServer()) {
task.ignoreFailures = true
}
task.finalizedBy zipTask
task.doFirst {
zipTask.from(junitReport.destination)
}
}
}
}
}
ext.init.setupRepoOutAndBuildNumber = this.&setupRepoOutAndBuildNumber
ext.init.configureSubProjects = this.&configureSubProjects