[Native][tests] Don't compile given KLIB libraries

This commit is contained in:
Dmitriy Dolovov
2022-10-07 00:18:25 +02:00
committed by Space Team
parent a8b0f8a145
commit fbfb564b41
4 changed files with 35 additions and 19 deletions
@@ -81,13 +81,15 @@ internal abstract class LoggedData {
}
}
class CompilerCall(
abstract class CompilerCall : LoggedData()
class RealCompilerCall(
private val parameters: CompilerParameters,
private val exitCode: ExitCode,
private val compilerOutput: String,
private val compilerOutputHasErrors: Boolean,
private val duration: Duration
) : LoggedData() {
) : CompilerCall() {
override fun computeText(): String {
val problems = listOfNotNull(
"- Non-zero exit code".takeIf { exitCode != ExitCode.OK },
@@ -112,6 +114,10 @@ internal abstract class LoggedData {
}
}
class NoopCompilerCall(val artifactFile: File) : CompilerCall() {
override fun computeText() = "No compiler call performed for external (given) artifact $artifactFile"
}
class CompilerCallUnexpectedFailure(parameters: CompilerParameters, throwable: Throwable) : UnexpectedFailure(parameters, throwable)
class TestRunParameters(
@@ -89,7 +89,7 @@ internal abstract class BasicCompilation<A : TestCompilationArtifact>(
)
val loggedCompilerCall =
LoggedData.CompilerCall(loggedCompilerParameters, exitCode, compilerOutput, compilerOutputHasErrors, duration)
LoggedData.RealCompilerCall(loggedCompilerParameters, exitCode, compilerOutput, compilerOutputHasErrors, duration)
val result = if (exitCode != ExitCode.OK || compilerOutputHasErrors)
TestCompilationResult.CompilerFailure(loggedCompilerCall)
@@ -185,6 +185,10 @@ internal class LibraryCompilation(
}
}
internal class GivenLibraryCompilation(givenArtifact: KLIB) : TestCompilation<KLIB>() {
override val result = TestCompilationResult.Success(givenArtifact, LoggedData.NoopCompilerCall(givenArtifact.klibFile))
}
internal class ExecutableCompilation(
settings: Settings,
freeCompilerArgs: TestCompilerArgs,
@@ -141,22 +141,27 @@ internal class TestCompilationFactory {
val dependencies = collectDependencies(sourceModules, freeCompilerArgs, settings)
val klibArtifact = KLIB(settings.artifactFileForKlib(sourceModules, freeCompilerArgs))
val isGivenKlibArtifact = sourceModules.singleOrNull() is TestModule.Given
val staticCacheArtifactAndOptions: Pair<KLIBStaticCache, StaticCacheCompilation.Options>? = when (produceStaticCache) {
is ProduceStaticCache.No -> null // No artifact means no static cache should be compiled.
is ProduceStaticCache.Yes -> KLIBStaticCache(
cacheDir = settings.cacheDirForStaticCache(klibArtifact),
cacheDir = settings.cacheDirForStaticCache(klibArtifact, isGivenKlibArtifact),
klib = klibArtifact
) to produceStaticCache.options
}
return cachedKlibCompilations.computeIfAbsent(cacheKey) {
val klibCompilation = LibraryCompilation(
settings = settings,
freeCompilerArgs = freeCompilerArgs,
sourceModules = sourceModules,
dependencies = dependencies.forKlib(),
expectedArtifact = klibArtifact
)
val klibCompilation = if (isGivenKlibArtifact)
GivenLibraryCompilation(klibArtifact)
else
LibraryCompilation(
settings = settings,
freeCompilerArgs = freeCompilerArgs,
sourceModules = sourceModules,
dependencies = dependencies.forKlib(),
expectedArtifact = klibArtifact
)
val staticCacheCompilation: StaticCacheCompilation? =
staticCacheArtifactAndOptions?.let { (staticCacheArtifact, staticCacheOptions) ->
@@ -227,19 +232,20 @@ internal class TestCompilationFactory {
assertTrue(modules.none { module -> module is TestModule.Shared }) {
"Can't compile shared module together with any other module"
}
assertTrue(modules.none { module -> module is TestModule.Given }) {
"Can't compile given module together with any other module"
}
multiModuleArtifactFile(modules, "klib")
}
}
private fun Settings.cacheDirForStaticCache(klibArtifact: KLIB): File {
val binaries = get<Binaries>()
val artifactBaseDir = if (klibArtifact.klibFile.startsWith(binaries.testBinariesDir)) {
private fun Settings.cacheDirForStaticCache(klibArtifact: KLIB, isGivenKlibArtifact: Boolean): File {
val artifactBaseDir = if (isGivenKlibArtifact) {
// Special case for the given (external) KLIB artifacts.
get<Binaries>().givenBinariesDir
} else {
// The KLIB artifact is located inside the build dir. This means it was built just a moment ago.
klibArtifact.klibFile.parentFile
} else {
// Special case for the given (external) KLIB artifacts.
binaries.givenBinariesDir
}
return artifactBaseDir.resolve(STATIC_CACHE_DIR_NAME).apply { mkdirs() }
@@ -18,7 +18,7 @@ internal sealed interface TestCompilationResult<A : TestCompilationArtifact> {
data class Success<A : TestCompilationArtifact>(val resultingArtifact: A, override val loggedData: LoggedData.CompilerCall) :
ImmediateResult<A>
data class CompilerFailure(override val loggedData: LoggedData.CompilerCall) : Failure
data class CompilerFailure(override val loggedData: LoggedData.RealCompilerCall) : Failure
data class UnexpectedFailure(override val loggedData: LoggedData.CompilerCallUnexpectedFailure) : Failure
data class DependencyFailures(val causes: Set<Failure>) : TestCompilationResult<Nothing>