[BTA tests] Make the module scenario DSL cache key explicit
^KT-61860 In Progress
This commit is contained in:
committed by
Space Team
parent
3466153668
commit
74e5b4d844
+10
-21
@@ -32,12 +32,18 @@ private class CompilationOutcomeImpl(
|
||||
}
|
||||
}
|
||||
|
||||
data class AbstractModuleCacheKey(
|
||||
val moduleName: String,
|
||||
val dependencies: List<DependencyScenarioDslCacheKey>,
|
||||
val additionalCompilationArguments: List<String>,
|
||||
) : DependencyScenarioDslCacheKey
|
||||
|
||||
abstract class AbstractModule(
|
||||
override val project: Project,
|
||||
override val moduleName: String,
|
||||
final override val moduleName: String,
|
||||
val moduleDirectory: Path,
|
||||
val dependencies: List<Dependency>,
|
||||
override val additionalCompilationArguments: List<String> = emptyList(),
|
||||
final override val additionalCompilationArguments: List<String> = emptyList(),
|
||||
) : Module {
|
||||
override val sourcesDirectory: Path
|
||||
get() = moduleDirectory.resolve("src")
|
||||
@@ -60,6 +66,8 @@ abstract class AbstractModule(
|
||||
override val icCachesDir: Path
|
||||
get() = icWorkingDir.resolve("caches")
|
||||
|
||||
override val scenarioDslCacheKey = AbstractModuleCacheKey(moduleName, dependencies.map { it.scenarioDslCacheKey }, additionalCompilationArguments)
|
||||
|
||||
override fun compile(
|
||||
strategyConfig: CompilerExecutionStrategyConfiguration,
|
||||
forceOutput: LogLevel?,
|
||||
@@ -96,23 +104,4 @@ abstract class AbstractModule(
|
||||
): CompilationResult
|
||||
|
||||
override fun toString() = moduleName
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
if (other !is AbstractModule) return false
|
||||
|
||||
if (moduleName != other.moduleName) return false
|
||||
if (dependencies != other.dependencies) return false
|
||||
if (additionalCompilationArguments != other.additionalCompilationArguments) return false
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
var result = moduleName.hashCode()
|
||||
result = 31 * result + dependencies.hashCode()
|
||||
result = 31 * result + additionalCompilationArguments.hashCode()
|
||||
return result
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
+3
@@ -7,7 +7,10 @@ package org.jetbrains.kotlin.buildtools.api.tests.compilation.model
|
||||
|
||||
import java.nio.file.Path
|
||||
|
||||
interface DependencyScenarioDslCacheKey
|
||||
|
||||
interface Dependency {
|
||||
val location: Path
|
||||
val snapshotFile: Path
|
||||
val scenarioDslCacheKey: DependencyScenarioDslCacheKey
|
||||
}
|
||||
+4
-8
@@ -8,11 +8,7 @@ package org.jetbrains.kotlin.buildtools.api.tests.compilation.scenario
|
||||
import org.jetbrains.kotlin.buildtools.api.CompilerExecutionStrategyConfiguration
|
||||
import org.jetbrains.kotlin.buildtools.api.SourcesChanges
|
||||
import org.jetbrains.kotlin.buildtools.api.tests.compilation.assertions.assertOutputs
|
||||
import org.jetbrains.kotlin.buildtools.api.tests.compilation.model.BaseCompilationTest
|
||||
import org.jetbrains.kotlin.buildtools.api.tests.compilation.model.CompilationOutcome
|
||||
import org.jetbrains.kotlin.buildtools.api.tests.compilation.model.LogLevel
|
||||
import org.jetbrains.kotlin.buildtools.api.tests.compilation.model.Module
|
||||
import org.jetbrains.kotlin.buildtools.api.tests.compilation.model.Project
|
||||
import org.jetbrains.kotlin.buildtools.api.tests.compilation.model.*
|
||||
import java.nio.file.Files
|
||||
import java.nio.file.Path
|
||||
import java.util.*
|
||||
@@ -98,10 +94,10 @@ private object GlobalCompiledProjectsCache {
|
||||
private val globalTempDirectory = Files.createTempDirectory("compiled-test-projects-cache").apply {
|
||||
toFile().deleteOnExit()
|
||||
}
|
||||
private val compiledProjectsCache = mutableMapOf<Module, Pair<MutableSet<String>, Path>>()
|
||||
private val compiledProjectsCache = mutableMapOf<DependencyScenarioDslCacheKey, Pair<MutableSet<String>, Path>>()
|
||||
|
||||
fun getProjectFromCache(module: Module, strategyConfig: CompilerExecutionStrategyConfiguration): ScenarioModuleImpl? {
|
||||
val (initialOutputs, cachedBuildDirPath) = compiledProjectsCache[module] ?: return null
|
||||
val (initialOutputs, cachedBuildDirPath) = compiledProjectsCache[module.scenarioDslCacheKey] ?: return null
|
||||
cachedBuildDirPath.copyToRecursively(module.buildDirectory, followLinks = false, overwrite = true)
|
||||
return ScenarioModuleImpl(module, initialOutputs, strategyConfig)
|
||||
}
|
||||
@@ -115,7 +111,7 @@ private object GlobalCompiledProjectsCache {
|
||||
}
|
||||
val moduleCacheDirectory = globalTempDirectory.resolve(UUID.randomUUID().toString())
|
||||
module.buildDirectory.copyToRecursively(moduleCacheDirectory, followLinks = false, overwrite = false)
|
||||
compiledProjectsCache[module] = Pair(initialOutputs, moduleCacheDirectory)
|
||||
compiledProjectsCache[module.scenarioDslCacheKey] = Pair(initialOutputs, moduleCacheDirectory)
|
||||
return ScenarioModuleImpl(module, initialOutputs, strategyConfig)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user