Skip to content

Commit

Permalink
[K/N][tests] Fixed CachesAutoBuildTest
Browse files Browse the repository at this point in the history
In auto-cache mode, the compiler itself chooses the system cache directory,
and it is important to not pass it explicitly.
  • Loading branch information
homuroll authored and qodana-bot committed Aug 11, 2023
1 parent 084479f commit d3b8607
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ class CachesAutoBuildTest : AbstractNativeSimpleTest() {
private fun compileToExecutable(sourcesDir: File, autoCacheFrom: File, cacheDirectories: List<File>, vararg dependencies: KLIB) =
compileToExecutable(
sourcesDir,
tryPassSystemCacheDirectory = false, // With auto-cache mode, the compiler chooses the system cache directory itself.
freeCompilerArgs = TestCompilerArgs(
listOf(
"-Xauto-cache-from=${autoCacheFrom.absolutePath}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,30 @@ internal fun AbstractNativeSimpleTest.cinteropToLibrary(

internal fun AbstractNativeSimpleTest.compileToExecutable(
sourcesDir: File,
tryPassSystemCacheDirectory: Boolean,
freeCompilerArgs: TestCompilerArgs,
vararg dependencies: TestCompilationArtifact.KLIB
): TestCompilationResult<out TestCompilationArtifact.Executable> {
val testCase: TestCase = generateTestCaseWithSingleModule(sourcesDir, freeCompilerArgs)
return compileToExecutable(testCase, dependencies.map { it.asLibraryDependency() })
return compileToExecutable(testCase, tryPassSystemCacheDirectory, dependencies.map { it.asLibraryDependency() })
}

internal fun AbstractNativeSimpleTest.compileToExecutable(testCase: TestCase, vararg dependencies: TestCompilationDependency<*>) =
compileToExecutable(testCase, dependencies.asList())
internal fun AbstractNativeSimpleTest.compileToExecutable(
sourcesDir: File,
freeCompilerArgs: TestCompilerArgs,
vararg dependencies: TestCompilationArtifact.KLIB
) = compileToExecutable(sourcesDir, true, freeCompilerArgs, *dependencies)

internal fun AbstractNativeSimpleTest.compileToExecutable(
testCase: TestCase,
tryPassSystemCacheDirectory: Boolean,
vararg dependencies: TestCompilationDependency<*>
) = compileToExecutable(testCase, tryPassSystemCacheDirectory, dependencies.asList())

internal fun AbstractNativeSimpleTest.compileToExecutable(
testCase: TestCase,
vararg dependencies: TestCompilationDependency<*>
) = compileToExecutable(testCase, true, dependencies.asList())

internal fun AbstractNativeSimpleTest.compileToStaticCache(
klib: TestCompilationArtifact.KLIB,
Expand Down Expand Up @@ -188,6 +203,7 @@ private fun AbstractNativeSimpleTest.compileToLibrary(

private fun AbstractNativeSimpleTest.compileToExecutable(
testCase: TestCase,
tryPassSystemCacheDirectory: Boolean,
dependencies: List<TestCompilationDependency<*>>
): TestCompilationResult<out TestCompilationArtifact.Executable> {
val compilation = ExecutableCompilation(
Expand All @@ -196,7 +212,8 @@ private fun AbstractNativeSimpleTest.compileToExecutable(
sourceModules = testCase.modules,
extras = testCase.extras,
dependencies = dependencies,
expectedArtifact = getExecutableArtifact()
expectedArtifact = getExecutableArtifact(),
tryPassSystemCacheDirectory = tryPassSystemCacheDirectory
)
return compilation.result
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,8 @@ internal class ExecutableCompilation(
sourceModules: Collection<TestModule>,
private val extras: Extras,
dependencies: Iterable<TestCompilationDependency<*>>,
expectedArtifact: Executable
expectedArtifact: Executable,
val tryPassSystemCacheDirectory: Boolean = true,
) : SourceBasedCompilation<Executable>(
targets = settings.get(),
home = settings.get(),
Expand Down Expand Up @@ -322,7 +323,9 @@ internal class ExecutableCompilation(

override fun applyDependencies(argsBuilder: ArgsBuilder): Unit = with(argsBuilder) {
super.applyDependencies(argsBuilder)
cacheMode.staticCacheForDistributionLibrariesRootDir?.let { cacheRootDir -> add("-Xcache-directory=$cacheRootDir") }
cacheMode.staticCacheForDistributionLibrariesRootDir
?.takeIf { tryPassSystemCacheDirectory }
?.let { cacheRootDir -> add("-Xcache-directory=$cacheRootDir") }
add(dependencies.uniqueCacheDirs) { libraryCacheDir -> "-Xcache-directory=${libraryCacheDir.path}" }
}

Expand Down

0 comments on commit d3b8607

Please sign in to comment.