[go: nahoru, domu]

blob: a10ab82b98628d7b55ac1bf17c2fd99bc7a5c16b [file] [log] [blame]
/*
* Copyright (C) 2023 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.KmpPlatformsKt
import org.apache.commons.io.FileUtils
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
import org.jetbrains.kotlin.gradle.tasks.KotlinNativeLink
import org.jetbrains.kotlin.konan.target.Family
plugins {
id("AndroidXPlugin")
id("com.android.library")
id("com.google.devtools.ksp")
id("androidx.room")
}
// Disabled due to https://youtrack.jetbrains.com/issue/KT-65761
ext["kotlin.native.disableCompilerDaemon"] = 'true'
androidXMultiplatform {
android()
ios()
jvm()
linux()
mac()
sourceSets {
commonTest {
dependencies {
implementation(libs.kotlinStdlib)
implementation(project(":room:room-runtime"))
implementation(project(":room:room-testing"))
implementation(project(":sqlite:sqlite-bundled"))
implementation(project(":kruth:kruth"))
implementation(libs.kotlinTest)
implementation(libs.kotlinCoroutinesTest)
}
}
androidInstrumentedTest {
dependsOn(commonTest)
dependencies {
implementation(libs.kotlinTestJunit)
implementation(libs.testRunner)
implementation(libs.testCore)
}
}
jvmTest {
dependsOn(commonTest)
dependencies {
implementation(libs.kotlinTestJunit)
}
}
nativeTest {
dependsOn(commonTest)
}
nonIosNativeTest {
dependsOn(nativeTest)
}
if (KmpPlatformsKt.enableMac(project)) {
iosTest {
dependsOn(nativeTest)
}
}
targets.all { target ->
if (target.platformType == KotlinPlatformType.native) {
def test = target.compilations["test"]
if (target.konanTarget.family == Family.IOS) {
test.defaultSourceSet {
dependsOn(iosTest)
}
} else {
test.defaultSourceSet {
dependsOn(nonIosNativeTest)
}
}
}
}
}
}
// TODO(b/325111583): Create a helper function to configure KSP with KMP targets
dependencies {
def roomCompilerDependency = project(":room:room-compiler")
add("kspAndroidAndroidTest", roomCompilerDependency)
add("kspJvmTest", roomCompilerDependency)
add("kspLinuxX64Test", roomCompilerDependency)
if (KmpPlatformsKt.enableMac(project)) {
add("kspIosSimulatorArm64Test", roomCompilerDependency)
add("kspIosX64Test", roomCompilerDependency)
add("kspMacosX64Test", roomCompilerDependency)
add("kspMacosArm64Test", roomCompilerDependency)
}
}
android {
namespace "androidx.room.integration.multiplatformtestapp"
// TODO(b/317909626): Should be configured by Room Gradle Plugin
sourceSets {
androidTest.assets.srcDirs += files("$projectDir/schemas-ksp".toString())
}
}
// Copy schema files to the iOS binary output test directory that will be part of the bundle's
// resources and read with NSBundle. This needs to be replaced with a more proper mechanism.
// TODO(b/317909626): Should be configured by Room Gradle Plugin
tasks.withType(KotlinNativeLink).configureEach { task ->
if (name.contains("linkDebugTestIos")) {
def inputSchemaDir = layout.projectDirectory.dir("schemas-ksp").getAsFile()
def outputSchemaDir = new File(task.destinationDirectory.getAsFile().get(), "/schemas-ksp")
task.doLast {
FileUtils.copyDirectory(inputSchemaDir, outputSchemaDir)
}
}
}
room {
schemaDirectory(
provider { layout.projectDirectory.dir("schemas-ksp").getAsFile().getAbsolutePath() }
)
}