diff --git a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/AbstractNativeKlibEvolutionTest.kt b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/AbstractNativeKlibEvolutionTest.kt index d4e457e4c01..09cf64f94ad 100644 --- a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/AbstractNativeKlibEvolutionTest.kt +++ b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/AbstractNativeKlibEvolutionTest.kt @@ -17,9 +17,9 @@ import org.jetbrains.kotlin.konan.blackboxtest.support.compilation.TestCompilati import org.jetbrains.kotlin.konan.blackboxtest.support.group.UsePartialLinkage import org.jetbrains.kotlin.konan.blackboxtest.support.runner.TestExecutable import org.jetbrains.kotlin.konan.blackboxtest.support.runner.TestRunChecks +import org.jetbrains.kotlin.konan.blackboxtest.support.settings.Binaries import org.jetbrains.kotlin.konan.blackboxtest.support.settings.CacheMode import org.jetbrains.kotlin.konan.blackboxtest.support.settings.KotlinNativeTargets -import org.jetbrains.kotlin.konan.blackboxtest.support.settings.SimpleTestDirectories import org.jetbrains.kotlin.konan.blackboxtest.support.settings.Timeouts import org.jetbrains.kotlin.konan.blackboxtest.support.util.* import org.jetbrains.kotlin.test.Directives @@ -284,7 +284,7 @@ abstract class AbstractNativeKlibEvolutionTest : AbstractNativeSimpleTest() { initialize(null, null) } - private val buildDir: File get() = testRunSettings.get().testBuildDir + private val buildDir: File get() = testRunSettings.get().testBinariesDir private val useStaticCacheForUserLibraries: Boolean get() = testRunSettings.get().useStaticCacheForUserLibraries companion object { diff --git a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/AbstractNativePartialLinkageTest.kt b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/AbstractNativePartialLinkageTest.kt index a7952c1fda5..caa30444b58 100644 --- a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/AbstractNativePartialLinkageTest.kt +++ b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/AbstractNativePartialLinkageTest.kt @@ -213,7 +213,7 @@ abstract class AbstractNativePartialLinkageTest : AbstractNativeSimpleTest() { klib = this ) - private val buildDir: File get() = testRunSettings.get().testBuildDir + private val buildDir: File get() = testRunSettings.get().testBinariesDir private val stdlibFile: File get() = testRunSettings.get().stdlibFile private val useStaticCacheForUserLibraries: Boolean get() = testRunSettings.get().useStaticCacheForUserLibraries diff --git a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/NativeSimpleTestUtils.kt b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/NativeSimpleTestUtils.kt index 1730981b75d..3d0fe884d7b 100644 --- a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/NativeSimpleTestUtils.kt +++ b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/NativeSimpleTestUtils.kt @@ -6,29 +6,14 @@ package org.jetbrains.kotlin.konan.blackboxtest import com.intellij.openapi.util.io.FileUtil -import org.jetbrains.kotlin.konan.blackboxtest.support.PackageName -import org.jetbrains.kotlin.konan.blackboxtest.support.TestCase -import org.jetbrains.kotlin.konan.blackboxtest.support.TestCaseId -import org.jetbrains.kotlin.konan.blackboxtest.support.TestCompilerArgs -import org.jetbrains.kotlin.konan.blackboxtest.support.TestDirectives -import org.jetbrains.kotlin.konan.blackboxtest.support.TestFile -import org.jetbrains.kotlin.konan.blackboxtest.support.TestKind -import org.jetbrains.kotlin.konan.blackboxtest.support.TestModule -import org.jetbrains.kotlin.konan.blackboxtest.support.TestRunnerType -import org.jetbrains.kotlin.konan.blackboxtest.support.compilation.ExecutableCompilation -import org.jetbrains.kotlin.konan.blackboxtest.support.compilation.ExistingDependency -import org.jetbrains.kotlin.konan.blackboxtest.support.compilation.LibraryCompilation -import org.jetbrains.kotlin.konan.blackboxtest.support.compilation.StaticCacheCompilation -import org.jetbrains.kotlin.konan.blackboxtest.support.compilation.TestCompilationArtifact -import org.jetbrains.kotlin.konan.blackboxtest.support.compilation.TestCompilationDependency -import org.jetbrains.kotlin.konan.blackboxtest.support.compilation.TestCompilationDependencyType -import org.jetbrains.kotlin.konan.blackboxtest.support.compilation.TestCompilationResult +import org.jetbrains.kotlin.konan.blackboxtest.support.* +import org.jetbrains.kotlin.konan.blackboxtest.support.compilation.* import org.jetbrains.kotlin.konan.blackboxtest.support.compilation.TestCompilationResult.Companion.assertSuccess import org.jetbrains.kotlin.konan.blackboxtest.support.runner.TestExecutable import org.jetbrains.kotlin.konan.blackboxtest.support.runner.TestRunChecks +import org.jetbrains.kotlin.konan.blackboxtest.support.settings.Binaries import org.jetbrains.kotlin.konan.blackboxtest.support.settings.KotlinNativeTargets import org.jetbrains.kotlin.konan.blackboxtest.support.settings.PipelineType -import org.jetbrains.kotlin.konan.blackboxtest.support.settings.SimpleTestDirectories import org.jetbrains.kotlin.konan.blackboxtest.support.settings.Timeouts import org.jetbrains.kotlin.konan.blackboxtest.support.util.LAUNCHER_MODULE_NAME import org.jetbrains.kotlin.test.InTextDirectivesUtils @@ -114,7 +99,7 @@ internal class ExecutableBuilder( ) } -internal val AbstractNativeSimpleTest.buildDir: File get() = testRunSettings.get().testBuildDir +internal val AbstractNativeSimpleTest.buildDir: File get() = testRunSettings.get().testBinariesDir internal fun TestCompilationArtifact.KLIB.asLibraryDependency() = ExistingDependency(this, TestCompilationDependencyType.Library) diff --git a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/NativeTestSupport.kt b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/NativeTestSupport.kt index cd935b49aba..6578fb209fa 100644 --- a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/NativeTestSupport.kt +++ b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/NativeTestSupport.kt @@ -207,7 +207,6 @@ private object NativeTestSupport { output += computePipelineType(testClass.get()) output += computeUsedPartialLinkageConfig(enclosingTestClass) output += computeCompilerOutputInterceptor(enforcedProperties) - output += computeBinariesDirs(getOrCreateTestProcessSettings().get(), nativeTargets, enclosingTestClass) return nativeTargets } @@ -338,6 +337,7 @@ private object NativeTestSupport { // Put settings that are always required: this += computedTestConfiguration + this += computeBinariesForBlackBoxTests(testProcessSettings.get(), nativeTargets, enclosingTestClass) // Add custom settings: computedTestConfiguration.configuration.requiredSettings.forEach { clazz -> @@ -435,21 +435,22 @@ private object NativeTestSupport { return GeneratedSources(testSourcesDir, sharedSourcesDir) } - private fun computeBinariesDirs(baseDirs: BaseDirs, targets: KotlinNativeTargets, enclosingTestClass: Class<*>): Binaries { + /** See also [computeBinariesForSimpleTests] */ + private fun computeBinariesForBlackBoxTests( + baseDirs: BaseDirs, + targets: KotlinNativeTargets, + enclosingTestClass: Class<*> + ): Binaries { val testBinariesDir = baseDirs.testBuildDir .resolve("bb.out") // "bb" for black box .resolve("${targets.testTarget.compressedName}_${enclosingTestClass.compressedSimpleName}") .ensureExistsAndIsEmptyDirectory() // Clean-up the directory with all potentially stale artifacts. - val sharedBinariesDir = testBinariesDir - .resolve(SHARED_MODULES_DIR_NAME) - .ensureExistsAndIsEmptyDirectory() - - val givenBinariesDir = testBinariesDir - .resolve(GIVEN_MODULES_DIR_NAME) - .ensureExistsAndIsEmptyDirectory() - - return Binaries(testBinariesDir, sharedBinariesDir, givenBinariesDir) + return Binaries( + testBinariesDir = testBinariesDir, + lazySharedBinariesDir = { testBinariesDir.resolve(SHARED_MODULES_DIR_NAME).ensureExistsAndIsEmptyDirectory() }, + lazyGivenBinariesDir = { testBinariesDir.resolve(GIVEN_MODULES_DIR_NAME).ensureExistsAndIsEmptyDirectory() } + ) } private fun computePipelineType(testClass: Class<*>): PipelineType { @@ -515,23 +516,28 @@ private object NativeTestSupport { parent = testClassSettings, listOf( computeSimpleTestInstances(), - computeSimpleTestDirectories(testClassSettings.get(), testClassSettings.get()) + computeBinariesForSimpleTests(testClassSettings.get(), testClassSettings.get()) ) ) } private fun ExtensionContext.computeSimpleTestInstances(): SimpleTestInstances = SimpleTestInstances(requiredTestInstances.allInstances) - private fun ExtensionContext.computeSimpleTestDirectories(baseDirs: BaseDirs, targets: KotlinNativeTargets): SimpleTestDirectories { + /** See also [computeBinariesForBlackBoxTests] */ + private fun ExtensionContext.computeBinariesForSimpleTests(baseDirs: BaseDirs, targets: KotlinNativeTargets): Binaries { val compressedClassNames = testClasses.map(Class<*>::compressedSimpleName).joinToString(separator = "_") - val testBuildDir = baseDirs.testBuildDir + val testBinariesDir = baseDirs.testBuildDir .resolve("s") // "s" for simple .resolve("${targets.testTarget.compressedName}_$compressedClassNames") .resolve(requiredTestMethod.name) .ensureExistsAndIsEmptyDirectory() // Clean-up the directory with all potentially stale artifacts. - return SimpleTestDirectories(testBuildDir) + return Binaries( + testBinariesDir = testBinariesDir, + lazySharedBinariesDir = { testBinariesDir.resolve(SHARED_MODULES_DIR_NAME).ensureExistsAndIsEmptyDirectory() }, + lazyGivenBinariesDir = { testBinariesDir.resolve(GIVEN_MODULES_DIR_NAME).ensureExistsAndIsEmptyDirectory() } + ) } /*************** Test run provider (for black box tests only) ***************/ diff --git a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/settings/SimpleTestRunSettings.kt b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/settings/SimpleTestRunSettings.kt index 83bc3d9ea59..6b8e8789809 100644 --- a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/settings/SimpleTestRunSettings.kt +++ b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/settings/SimpleTestRunSettings.kt @@ -6,7 +6,6 @@ package org.jetbrains.kotlin.konan.blackboxtest.support.settings import org.jetbrains.kotlin.konan.blackboxtest.AbstractNativeSimpleTest -import java.io.File /** * All instances of test classes. @@ -18,10 +17,3 @@ internal class SimpleTestInstances(val allInstances: List) { val enclosingTestInstance: AbstractNativeSimpleTest get() = allInstances.firstOrNull() as AbstractNativeSimpleTest } - -/** - * The build directory specifically for the current test function. - */ -internal class SimpleTestDirectories(val testBuildDir: File) - - diff --git a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/settings/TestClassSettings.kt b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/settings/TestClassSettings.kt index 0294badf653..4030f9eb090 100644 --- a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/settings/TestClassSettings.kt +++ b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/settings/TestClassSettings.kt @@ -26,7 +26,10 @@ internal class GeneratedSources(val testSourcesDir: File, val sharedSourcesDir: * [sharedBinariesDir] - The directory with compiled shared modules (klibs). * [givenBinariesDir] - The directory with the given (external) modules (klibs). */ -internal class Binaries(val testBinariesDir: File, val sharedBinariesDir: File, val givenBinariesDir: File) +internal class Binaries(val testBinariesDir: File, lazySharedBinariesDir: () -> File, lazyGivenBinariesDir: () -> File) { + val sharedBinariesDir: File by lazy { lazySharedBinariesDir() } + val givenBinariesDir: File by lazy { lazyGivenBinariesDir() } +} /** * The [TestConfiguration] of the current test class and the [Annotation] with specific parameters.