[Gradle, K/N] Move build cache tests into appropriate class
This commit is contained in:
+33
-6
@@ -25,11 +25,13 @@ import org.junit.runners.Parameterized
|
|||||||
import java.io.File
|
import java.io.File
|
||||||
import kotlin.test.assertEquals
|
import kotlin.test.assertEquals
|
||||||
|
|
||||||
|
private val DEFAULT_GRADLE_VERSION = GradleVersionRequired.AtLeast("5.6.4")
|
||||||
|
|
||||||
@RunWith(Parameterized::class)
|
@RunWith(Parameterized::class)
|
||||||
class BuildCacheRelocationIT : BaseGradleIT() {
|
class BuildCacheRelocationIT : BaseGradleIT() {
|
||||||
|
|
||||||
override val defaultGradleVersion: GradleVersionRequired
|
override val defaultGradleVersion: GradleVersionRequired
|
||||||
get() = GradleVersionRequired.AtLeast("5.6.4")
|
get() = DEFAULT_GRADLE_VERSION
|
||||||
|
|
||||||
override fun defaultBuildOptions(): BuildOptions =
|
override fun defaultBuildOptions(): BuildOptions =
|
||||||
super.defaultBuildOptions().copy(
|
super.defaultBuildOptions().copy(
|
||||||
@@ -51,7 +53,7 @@ class BuildCacheRelocationIT : BaseGradleIT() {
|
|||||||
|
|
||||||
val (firstProject, secondProject) = (0..1).map { id ->
|
val (firstProject, secondProject) = (0..1).map { id ->
|
||||||
workingDir = workingDirs[id]
|
workingDir = workingDirs[id]
|
||||||
Project(projectName, directoryPrefix = projectDirectoryPrefix).apply {
|
Project(projectName, directoryPrefix = projectDirectoryPrefix, gradleVersionRequirement = gradleVersionRequired).apply {
|
||||||
setupWorkingDir()
|
setupWorkingDir()
|
||||||
initProject()
|
initProject()
|
||||||
prepareLocalBuildCache(localBuildCacheDirectory)
|
prepareLocalBuildCache(localBuildCacheDirectory)
|
||||||
@@ -69,7 +71,13 @@ class BuildCacheRelocationIT : BaseGradleIT() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
workingDir = workingDirs[1]
|
workingDir = workingDirs[1]
|
||||||
secondProject.build(*testCase.taskToExecute) {
|
val alternateBuildEnvOptions = if (withAnotherGradleHome) {
|
||||||
|
val alternateGradleHome = File(firstProject.projectDir.parentFile, "gradleUserHome")
|
||||||
|
defaultBuildOptions().copy(gradleUserHome = alternateGradleHome)
|
||||||
|
} else {
|
||||||
|
defaultBuildOptions()
|
||||||
|
}
|
||||||
|
secondProject.build(*testCase.taskToExecute, options = alternateBuildEnvOptions) {
|
||||||
assertSuccessful()
|
assertSuccessful()
|
||||||
val secondOutputHashes = hashOutputFiles(outputRoots)
|
val secondOutputHashes = hashOutputFiles(outputRoots)
|
||||||
assertEquals(firstOutputHashes, secondOutputHashes)
|
assertEquals(firstOutputHashes, secondOutputHashes)
|
||||||
@@ -86,8 +94,10 @@ class BuildCacheRelocationIT : BaseGradleIT() {
|
|||||||
val cacheableTaskNames: List<String>,
|
val cacheableTaskNames: List<String>,
|
||||||
val projectDirectoryPrefix: String? = null,
|
val projectDirectoryPrefix: String? = null,
|
||||||
val outputRootPaths: List<String> = listOf("build"),
|
val outputRootPaths: List<String> = listOf("build"),
|
||||||
val initProject: Project.() -> Unit = { },
|
val initProject: Project.() -> Unit = {},
|
||||||
val taskToExecute: Array<String>
|
val taskToExecute: Array<String>,
|
||||||
|
val withAnotherGradleHome: Boolean = false,
|
||||||
|
val gradleVersionRequired: GradleVersionRequired = DEFAULT_GRADLE_VERSION
|
||||||
) {
|
) {
|
||||||
|
|
||||||
override fun toString(): String = (projectDirectoryPrefix?.plus("/") ?: "") + projectName
|
override fun toString(): String = (projectDirectoryPrefix?.plus("/") ?: "") + projectName
|
||||||
@@ -158,7 +168,24 @@ class BuildCacheRelocationIT : BaseGradleIT() {
|
|||||||
},
|
},
|
||||||
outputRootPaths = listOf("app/build"),
|
outputRootPaths = listOf("app/build"),
|
||||||
initProject = { File(projectDir, "app/build.gradle").appendText("\nkapt.useBuildCache = true") }
|
initProject = { File(projectDir, "app/build.gradle").appendText("\nkapt.useBuildCache = true") }
|
||||||
)
|
),
|
||||||
|
TestCase("native-build-cache",
|
||||||
|
taskToExecute = arrayOf("build-cache-lib:publish", "build-cache-app:assemble"),
|
||||||
|
cacheableTaskNames = listOf("build-cache-lib:compileKotlinHost", "build-cache-app:compileKotlinHost",
|
||||||
|
"build-cache-app:lib-module:compileKotlinHost",
|
||||||
|
"build-cache-app:linkDebugStaticHost", "build-cache-app:linkDebugSharedHost"),
|
||||||
|
outputRootPaths = listOf("build-cache-app/build", "build-cache-lib/build", "build-cache-app/lib-module/build"),
|
||||||
|
initProject = {
|
||||||
|
val localRepoUri = projectDir.resolve("repo").toURI()
|
||||||
|
val buildKtsApp = projectDir.resolve("build-cache-app").resolve("build.gradle.kts")
|
||||||
|
val buildKtsLib = projectDir.resolve("build-cache-lib").resolve("build.gradle.kts")
|
||||||
|
buildKtsApp.appendText("\nrepositories { maven { setUrl(\"$localRepoUri\") } }")
|
||||||
|
buildKtsApp.modify(::transformBuildScriptWithPluginsDsl)
|
||||||
|
buildKtsLib.modify(::transformBuildScriptWithPluginsDsl)
|
||||||
|
},
|
||||||
|
withAnotherGradleHome = true,
|
||||||
|
gradleVersionRequired = GradleVersionRequired.FOR_MPP_SUPPORT
|
||||||
|
),
|
||||||
).map { arrayOf(it) }
|
).map { arrayOf(it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-104
@@ -14,7 +14,6 @@ import org.jetbrains.kotlin.gradle.internals.DISABLED_NATIVE_TARGETS_REPORTER_WA
|
|||||||
import org.jetbrains.kotlin.gradle.internals.NO_NATIVE_STDLIB_PROPERTY_WARNING
|
import org.jetbrains.kotlin.gradle.internals.NO_NATIVE_STDLIB_PROPERTY_WARNING
|
||||||
import org.jetbrains.kotlin.gradle.internals.NO_NATIVE_STDLIB_WARNING
|
import org.jetbrains.kotlin.gradle.internals.NO_NATIVE_STDLIB_WARNING
|
||||||
import org.jetbrains.kotlin.gradle.plugin.mpp.NativeOutputKind
|
import org.jetbrains.kotlin.gradle.plugin.mpp.NativeOutputKind
|
||||||
import org.jetbrains.kotlin.gradle.prepareLocalBuildCache
|
|
||||||
import org.jetbrains.kotlin.gradle.transformProjectWithPluginsDsl
|
import org.jetbrains.kotlin.gradle.transformProjectWithPluginsDsl
|
||||||
import org.jetbrains.kotlin.gradle.util.isWindows
|
import org.jetbrains.kotlin.gradle.util.isWindows
|
||||||
import org.jetbrains.kotlin.gradle.util.modify
|
import org.jetbrains.kotlin.gradle.util.modify
|
||||||
@@ -26,7 +25,6 @@ import org.junit.Assume
|
|||||||
import org.junit.Ignore
|
import org.junit.Ignore
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.nio.file.Files
|
|
||||||
import kotlin.test.assertEquals
|
import kotlin.test.assertEquals
|
||||||
import kotlin.test.assertFalse
|
import kotlin.test.assertFalse
|
||||||
import kotlin.test.assertTrue
|
import kotlin.test.assertTrue
|
||||||
@@ -88,8 +86,6 @@ class GeneralNativeIT : BaseGradleIT() {
|
|||||||
|
|
||||||
val nativeHostTargetName = MPPNativeTargets.current
|
val nativeHostTargetName = MPPNativeTargets.current
|
||||||
|
|
||||||
private val buildCacheEnabledOptions = super.defaultBuildOptions().copy(withBuildCache = true)
|
|
||||||
|
|
||||||
private fun Project.targetClassesDir(targetName: String, sourceSetName: String = "main") =
|
private fun Project.targetClassesDir(targetName: String, sourceSetName: String = "main") =
|
||||||
classesDir(sourceSet = "$targetName/$sourceSetName")
|
classesDir(sourceSet = "$targetName/$sourceSetName")
|
||||||
|
|
||||||
@@ -142,8 +138,6 @@ class GeneralNativeIT : BaseGradleIT() {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testCanProduceNativeLibraries() = with(transformNativeTestProjectWithPluginDsl("libraries", directoryPrefix = "native-binaries")) {
|
fun testCanProduceNativeLibraries() = with(transformNativeTestProjectWithPluginDsl("libraries", directoryPrefix = "native-binaries")) {
|
||||||
prepareLocalBuildCache()
|
|
||||||
|
|
||||||
val baseName = "native_library"
|
val baseName = "native_library"
|
||||||
|
|
||||||
val sharedPrefix = CompilerOutputKind.DYNAMIC.prefix(HostManager.host)
|
val sharedPrefix = CompilerOutputKind.DYNAMIC.prefix(HostManager.host)
|
||||||
@@ -180,16 +174,9 @@ class GeneralNativeIT : BaseGradleIT() {
|
|||||||
|
|
||||||
val klibTask = ":compileKotlinHost"
|
val klibTask = ":compileKotlinHost"
|
||||||
|
|
||||||
// Building to local build cache
|
build(":assemble") {
|
||||||
build("assemble", options = buildCacheEnabledOptions) {
|
|
||||||
assertSuccessful()
|
assertSuccessful()
|
||||||
assertTasksExecuted(linkTasks + klibTask)
|
assertTasksExecuted(linkTasks + klibTask)
|
||||||
}
|
|
||||||
|
|
||||||
// Retrieving from build cache
|
|
||||||
build(":clean", ":assemble", options = buildCacheEnabledOptions) {
|
|
||||||
assertSuccessful()
|
|
||||||
assertTasksRetrievedFromCache(linkTasks + klibTask)
|
|
||||||
|
|
||||||
sharedPaths.forEach { assertFileExists(it) }
|
sharedPaths.forEach { assertFileExists(it) }
|
||||||
staticPaths.forEach { assertFileExists(it) }
|
staticPaths.forEach { assertFileExists(it) }
|
||||||
@@ -225,7 +212,6 @@ class GeneralNativeIT : BaseGradleIT() {
|
|||||||
|
|
||||||
data class BinaryMeta(val name: String, val isStatic: Boolean = false)
|
data class BinaryMeta(val name: String, val isStatic: Boolean = false)
|
||||||
|
|
||||||
val baseName = "main"
|
|
||||||
val frameworkPrefix = CompilerOutputKind.FRAMEWORK.prefix(HostManager.host)
|
val frameworkPrefix = CompilerOutputKind.FRAMEWORK.prefix(HostManager.host)
|
||||||
val frameworkSuffix = CompilerOutputKind.FRAMEWORK.suffix(HostManager.host)
|
val frameworkSuffix = CompilerOutputKind.FRAMEWORK.suffix(HostManager.host)
|
||||||
val targets = listOf("ios", "iosSim")
|
val targets = listOf("ios", "iosSim")
|
||||||
@@ -841,93 +827,4 @@ class GeneralNativeIT : BaseGradleIT() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
fun testNativeDependenciesBuildCache() {
|
|
||||||
val libProject = transformNativeTestProjectWithPluginDsl("build-cache-lib", directoryPrefix = "native-build-cache")
|
|
||||||
val appProject = transformNativeTestProjectWithPluginDsl("build-cache-app", directoryPrefix = "native-build-cache")
|
|
||||||
val appProjectAltPath = Project("build-cache-app2", directoryPrefix = "native-build-cache")
|
|
||||||
|
|
||||||
val libLocalRepoUri = libProject.projectDir.resolve("repo").toURI()
|
|
||||||
|
|
||||||
with(libProject) {
|
|
||||||
prepareLocalBuildCache()
|
|
||||||
|
|
||||||
val compileTask = ":compileKotlinHost"
|
|
||||||
|
|
||||||
build("assemble", options = buildCacheEnabledOptions) {
|
|
||||||
assertSuccessful()
|
|
||||||
assertTasksExecuted(compileTask)
|
|
||||||
}
|
|
||||||
|
|
||||||
build("clean", "publish", options = buildCacheEnabledOptions) {
|
|
||||||
assertSuccessful()
|
|
||||||
assertTasksRetrievedFromCache(compileTask)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
val compileAppTasks = listOf(
|
|
||||||
":compileKotlinHost",
|
|
||||||
":lib-module:compileKotlinHost",
|
|
||||||
)
|
|
||||||
|
|
||||||
with(appProject) {
|
|
||||||
prepareLocalBuildCache()
|
|
||||||
|
|
||||||
val klibPrefix = CompilerOutputKind.LIBRARY.prefix(HostManager.host)
|
|
||||||
val klibSuffix = CompilerOutputKind.LIBRARY.suffix(HostManager.host)
|
|
||||||
val klibPaths = listOf(
|
|
||||||
"${targetClassesDir("host")}${klibPrefix}app$klibSuffix",
|
|
||||||
"lib-module/${targetClassesDir("host")}${klibPrefix}lib-module$klibSuffix",
|
|
||||||
)
|
|
||||||
|
|
||||||
gradleBuildScript().appendText("\nrepositories { maven { setUrl(\"$libLocalRepoUri\") } }")
|
|
||||||
|
|
||||||
build("assemble", options = buildCacheEnabledOptions) {
|
|
||||||
assertSuccessful()
|
|
||||||
assertTasksExecuted(compileAppTasks)
|
|
||||||
klibPaths.forEach { assertFileExists(it) }
|
|
||||||
}
|
|
||||||
|
|
||||||
build("clean", "assemble", options = buildCacheEnabledOptions) {
|
|
||||||
assertSuccessful()
|
|
||||||
assertTasksRetrievedFromCache(compileAppTasks)
|
|
||||||
klibPaths.forEach { assertFileExists(it) }
|
|
||||||
}
|
|
||||||
|
|
||||||
assertTrue(projectDir.resolve(klibPaths[0]).delete())
|
|
||||||
|
|
||||||
build("clean", ":lib-module:assemble") {
|
|
||||||
assertSuccessful()
|
|
||||||
assertTasksExecuted(compileAppTasks[1])
|
|
||||||
}
|
|
||||||
|
|
||||||
build("assemble", options = buildCacheEnabledOptions) {
|
|
||||||
assertSuccessful()
|
|
||||||
assertTasksRetrievedFromCache(compileAppTasks[0])
|
|
||||||
assertTasksUpToDate(compileAppTasks[1])
|
|
||||||
klibPaths.forEach { assertFileExists(it) }
|
|
||||||
}
|
|
||||||
|
|
||||||
build("clean") {
|
|
||||||
assertSuccessful()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Files.move(appProject.projectDir.toPath(), appProjectAltPath.projectDir.toPath())
|
|
||||||
|
|
||||||
// It's very time-consuming check so on Mac TC agent we test only source relocation
|
|
||||||
val alternateBuildEnvOptions = if (isTeamCityRun && HostManager.hostIsMac) {
|
|
||||||
buildCacheEnabledOptions
|
|
||||||
} else {
|
|
||||||
val alternateGradleHome = File(appProject.projectDir.parentFile, "gradleUserHome")
|
|
||||||
buildCacheEnabledOptions.copy(gradleUserHome = alternateGradleHome)
|
|
||||||
}
|
|
||||||
with(appProjectAltPath) {
|
|
||||||
build("assemble", options = alternateBuildEnvOptions) {
|
|
||||||
assertSuccessful()
|
|
||||||
assertTasksRetrievedFromCache(compileAppTasks)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
+7
-2
@@ -8,13 +8,18 @@ repositories {
|
|||||||
}
|
}
|
||||||
|
|
||||||
kotlin {
|
kotlin {
|
||||||
<SingleNativeTarget>("host")
|
linuxX64("host") {
|
||||||
|
binaries {
|
||||||
|
sharedLib(listOf(DEBUG))
|
||||||
|
staticLib(listOf(DEBUG))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
sourceSets {
|
sourceSets {
|
||||||
val hostMain by getting {
|
val hostMain by getting {
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation("com.example:build-cache-lib:1.0")
|
implementation("com.example:build-cache-lib:1.0")
|
||||||
api(project(":lib-module"))
|
api(project(":build-cache-app:lib-module"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -8,5 +8,5 @@ repositories {
|
|||||||
}
|
}
|
||||||
|
|
||||||
kotlin {
|
kotlin {
|
||||||
<SingleNativeTarget>("host")
|
linuxX64("host")
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -12,11 +12,11 @@ repositories {
|
|||||||
}
|
}
|
||||||
|
|
||||||
kotlin {
|
kotlin {
|
||||||
<SingleNativeTarget>("host")
|
linuxX64("host")
|
||||||
}
|
}
|
||||||
|
|
||||||
publishing {
|
publishing {
|
||||||
repositories {
|
repositories {
|
||||||
maven(url = "file://${projectDir.absolutePath.replace('\\', '/')}/repo")
|
maven(url = "file://${projectDir.absolutePath.replace('\\', '/')}/../repo")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
-7
@@ -1,7 +0,0 @@
|
|||||||
pluginManagement {
|
|
||||||
repositories {
|
|
||||||
mavenLocal()
|
|
||||||
jcenter()
|
|
||||||
gradlePluginPortal()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+1
-2
@@ -6,5 +6,4 @@ pluginManagement {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
include ":lib-module"
|
include ':build-cache-app:lib-module', ':build-cache-app', ':build-cache-lib'
|
||||||
rootProject.name = "app"
|
|
||||||
Reference in New Issue
Block a user