From 118bda675f12c598847998832d835a729f9f47d1 Mon Sep 17 00:00:00 2001 From: Svyatoslav Scherbina Date: Mon, 31 Jan 2022 14:18:49 +0300 Subject: [PATCH] [Gradle] Fix Native offline tests on Windows Don't remove the temporary KONAN_DATA_DIR because it might be still in use by the Gradle daemon process. Create a new temporary directory instead. The tests were introduced in 544447e...fa951f8 --- .../kotlin/gradle/native/GeneralNativeIT.kt | 86 +++++++++++-------- .../gradle/native/NativePlatformLibsIT.kt | 31 +++---- 2 files changed, 65 insertions(+), 52 deletions(-) diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/native/GeneralNativeIT.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/native/GeneralNativeIT.kt index 5eb1060bdaa..9850b3cc532 100644 --- a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/native/GeneralNativeIT.kt +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/native/GeneralNativeIT.kt @@ -99,6 +99,13 @@ private fun BaseGradleIT.Project.configureSingleNativeTarget(preset: String = Ho } } +internal fun BaseGradleIT.BuildOptions.withCustomKonanDataDir( + customKonanDataDir: File +) = this.copy( + customEnvironmentVariables = this.customEnvironmentVariables + + ("KONAN_DATA_DIR" to customKonanDataDir.absolutePath) +) + class GeneralNativeIT : BaseGradleIT() { val nativeHostTargetName = MPPNativeTargets.current @@ -1110,30 +1117,32 @@ class GeneralNativeIT : BaseGradleIT() { } // Check that --offline fails when there are no downloaded dependencies: - val customKonanDataDir = tempDir.newFolder("konanOffline") - val buildOptionsOfflineWithCustomKonanDataDir = buildOptionsOffline.copy( - customEnvironmentVariables = buildOptionsOffline.customEnvironmentVariables + - ("KONAN_DATA_DIR" to customKonanDataDir.absolutePath) - ) + run { + val customKonanDataDir = tempDir.newFolder() + val buildOptionsOfflineWithCustomKonanDataDir = buildOptionsOffline.withCustomKonanDataDir(customKonanDataDir) - build("clean", linkTask, options = buildOptionsOfflineWithCustomKonanDataDir) { - assertFailed() - assertTasksNotExecuted(listOf(linkTask)) + build("clean", linkTask, options = buildOptionsOfflineWithCustomKonanDataDir) { + assertFailed() + assertTasksNotExecuted(listOf(linkTask)) + } + + checkNoDependenciesDownloaded(customKonanDataDir) } - checkNoDependenciesDownloaded(customKonanDataDir) - // Check that the compiler is not extracted if it is not cached: - assertTrue(customKonanDataDir.deleteRecursively()) - build( - "clean", linkTask, "-Pkotlin.native.version=1.6.20-M1-9999", - options = buildOptionsOfflineWithCustomKonanDataDir - ) { - assertFailed() - assertTasksNotExecuted(listOf(linkTask, compileTask)) - } + run { + val customKonanDataDir = tempDir.newFolder() + val buildOptionsOfflineWithCustomKonanDataDir = buildOptionsOffline.withCustomKonanDataDir(customKonanDataDir) + build( + "clean", linkTask, "-Pkotlin.native.version=1.6.20-M1-9999", + options = buildOptionsOfflineWithCustomKonanDataDir + ) { + assertFailed() + assertTasksNotExecuted(listOf(linkTask, compileTask)) + } - assertFalse(customKonanDataDir.exists()) + assertTrue(customKonanDataDir.listFiles().isNullOrEmpty()) + } } private fun checkNoDependenciesDownloaded(customKonanDataDir: File) { @@ -1178,29 +1187,32 @@ class GeneralNativeIT : BaseGradleIT() { } // Check that --offline fails when there are no downloaded dependencies: - val customKonanDataDir = tempDir.newFolder("konanOffline") - val buildOptionsOfflineWithCustomKonanDataDir = buildOptionsOffline.copy( - customEnvironmentVariables = buildOptionsOffline.customEnvironmentVariables + - ("KONAN_DATA_DIR" to customKonanDataDir.absolutePath) - ) + run { + val customKonanDataDir = tempDir.newFolder() + val buildOptionsOfflineWithCustomKonanDataDir = buildOptionsOffline.withCustomKonanDataDir(customKonanDataDir) - build("clean", cinteropTask, options = buildOptionsOfflineWithCustomKonanDataDir) { - assertFailed() + build("clean", cinteropTask, options = buildOptionsOfflineWithCustomKonanDataDir) { + assertFailed() + } + + checkNoDependenciesDownloaded(customKonanDataDir) } - checkNoDependenciesDownloaded(customKonanDataDir) - // Check that the compiler is not extracted if it is not cached: - assertTrue(customKonanDataDir.deleteRecursively()) - build( - "clean", cinteropTask, "-Pkotlin.native.version=1.6.20-M1-9999", - options = buildOptionsOfflineWithCustomKonanDataDir - ) { - assertFailed() - assertTasksNotExecuted(listOf(cinteropTask)) - } + run { + val customKonanDataDir = tempDir.newFolder() + val buildOptionsOfflineWithCustomKonanDataDir = buildOptionsOffline.withCustomKonanDataDir(customKonanDataDir) - assertFalse(customKonanDataDir.exists()) + build( + "clean", cinteropTask, "-Pkotlin.native.version=1.6.20-M1-9999", + options = buildOptionsOfflineWithCustomKonanDataDir + ) { + assertFailed() + assertTasksNotExecuted(listOf(cinteropTask)) + } + + assertTrue(customKonanDataDir.listFiles().isNullOrEmpty()) + } } companion object { diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/native/NativePlatformLibsIT.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/native/NativePlatformLibsIT.kt index 70b5eea3acf..d7c01f69458 100644 --- a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/native/NativePlatformLibsIT.kt +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/native/NativePlatformLibsIT.kt @@ -315,26 +315,27 @@ class NativePlatformLibsIT : BaseGradleIT() { } // Check that --offline fails when there are no downloaded dependencies: - val customKonanDataDir = tempDir.newFolder("konanOffline") - val buildOptionsOfflineWithCustomKonanDataDir = buildOptionsOffline.copy( - customEnvironmentVariables = buildOptionsOffline.customEnvironmentVariables + - ("KONAN_DATA_DIR" to customKonanDataDir.absolutePath) - ) + run { + val customKonanDataDir = tempDir.newFolder() + val buildOptionsOfflineWithCustomKonanDataDir = buildOptionsOffline.withCustomKonanDataDir(customKonanDataDir) - buildWithLightDist("tasks", options = buildOptionsOfflineWithCustomKonanDataDir) { - assertFailed() - assertContains("Generate platform libraries for linux_x64") + buildWithLightDist("tasks", options = buildOptionsOfflineWithCustomKonanDataDir) { + assertFailed() + assertContains("Generate platform libraries for linux_x64") + } } // The build above have extracted the cached compiler to the custom KONAN_DATA_DIR; remove it: - assertTrue(customKonanDataDir.deleteRecursively()) + run { + val customKonanDataDir = tempDir.newFolder() + val buildOptionsOfflineWithCustomKonanDataDir = buildOptionsOffline.withCustomKonanDataDir(customKonanDataDir) + // Check that the compiler is not extracted if it is not cached: + buildWithLightDist("tasks", "-Pkotlin.native.version=1.6.20-M1-9999", options = buildOptionsOfflineWithCustomKonanDataDir) { + assertFailed() + assertNotContains("Generate platform libraries for linux_x64") + } - // Check that the compiler is not extracted if it is not cached: - buildWithLightDist("tasks", "-Pkotlin.native.version=1.6.20-M1-9999", options = buildOptionsOfflineWithCustomKonanDataDir) { - assertFailed() - assertNotContains("Generate platform libraries for linux_x64") + assertTrue(customKonanDataDir.listFiles().isNullOrEmpty()) } - - assertFalse(customKonanDataDir.exists()) } }