Fix unstable testIncrementalCompilationAfterCacheHit test

This commit is contained in:
nataliya.valtman
2022-02-11 20:35:14 +03:00
parent 0463b5ec3c
commit c38dd1c004
19 changed files with 99 additions and 78 deletions
@@ -35,7 +35,6 @@ enum class CompilerSystemProperties(val property: String, val alwaysDirectAccess
DAEMON_RMI_SOCKET_CONNECT_INTERVAL_PROPERTY("kotlin.daemon.socket.connect.interval"),
KOTLIN_COMPILER_ENVIRONMENT_KEEPALIVE_PROPERTY("kotlin.environment.keepalive"),
COMPILE_DAEMON_CUSTOM_RUN_FILES_PATH_FOR_TESTS("kotlin.daemon.custom.run.files.path.for.tests"),
COMPILE_INCREMENTAL_WITH_CLASSPATH_SNAPSHOTS("kotlin.incremental.classpath.snapshot.enabled"),
COMPILE_INCREMENTAL_WITH_ARTIFACT_TRANSFORM("kotlin.incremental.useClasspathSnapshot"),
KOTLIN_COLORS_ENABLED_PROPERTY("kotlin.colors.enabled"),
LANGUAGE_VERSION_SETTINGS("kotlin.language.settings"),
@@ -65,12 +65,13 @@ class IncrementalCompilationOptions(
requestedCompilationResults: Array<Int>,
val usePreciseJavaTracking: Boolean,
/**
* Directories that should be cleared when IC decides to rebuild
*/
val outputFiles: List<File>,
* Directories that should be cleared when IC decides to rebuild
*/
val outputFiles: List<File>,
val multiModuleICSettings: MultiModuleICSettings,
val modulesInfo: IncrementalModuleInfo,
kotlinScriptExtensions: Array<String>? = null
kotlinScriptExtensions: Array<String>? = null,
val withAbiSnapshot: Boolean = false
) : CompilationOptions(
compilerMode,
targetPlatform,
@@ -312,8 +312,6 @@ fun configureDaemonJVMOptions(opts: DaemonJVMOptions,
if (inheritAdditionalProperties) {
CompilerSystemProperties.COMPILE_DAEMON_LOG_PATH_PROPERTY.value?.let { opts.jvmParams.add("D${CompilerSystemProperties.COMPILE_DAEMON_LOG_PATH_PROPERTY.property}=\"$it\"") }
CompilerSystemProperties.KOTLIN_COMPILER_ENVIRONMENT_KEEPALIVE_PROPERTY.value?.let { opts.jvmParams.add("D${CompilerSystemProperties.KOTLIN_COMPILER_ENVIRONMENT_KEEPALIVE_PROPERTY.property}") }
//Temporary solution to test abi snapshot
CompilerSystemProperties.COMPILE_INCREMENTAL_WITH_CLASSPATH_SNAPSHOTS.value?.let { opts.jvmParams.add("D${CompilerSystemProperties.COMPILE_INCREMENTAL_WITH_CLASSPATH_SNAPSHOTS.property}") }
}
if (opts.jvmParams.none { it.matches(jvmAssertArgsRegex) }) {
@@ -559,7 +559,8 @@ abstract class CompileServiceImplBase(
reporter = reporter,
buildHistoryFile = incrementalCompilationOptions.multiModuleICSettings.buildHistoryFile,
scopeExpansion = if (args.isIrBackendEnabled()) CompileScopeExpansionMode.ALWAYS else CompileScopeExpansionMode.NEVER,
modulesApiHistory = modulesApiHistory
modulesApiHistory = modulesApiHistory,
withAbiSnapshot = incrementalCompilationOptions.withAbiSnapshot
)
return try {
compiler.compile(allKotlinFiles, args, compilerMessageCollector, changedFiles)
@@ -617,7 +618,8 @@ abstract class CompileServiceImplBase(
usePreciseJavaTracking = incrementalCompilationOptions.usePreciseJavaTracking,
modulesApiHistory = modulesApiHistory,
kotlinSourceFilesExtensions = allKotlinExtensions,
classpathChanges = incrementalCompilationOptions.classpathChanges
classpathChanges = incrementalCompilationOptions.classpathChanges,
withAbiSnapshot = incrementalCompilationOptions.withAbiSnapshot
)
return try {
compiler.compile(allKotlinFiles, k2jvmArgs, compilerMessageCollector, changedFiles, projectRoot)
@@ -49,18 +49,16 @@ abstract class IncrementalCompilerRunner<
protected val buildHistoryFile: File,
// there might be some additional output directories (e.g. for generated java in kapt)
// to remove them correctly on rebuild, we pass them as additional argument
private val additionalOutputFiles: Collection<File> = emptyList()
private val additionalOutputFiles: Collection<File> = emptyList(),
protected val withAbiSnapshot: Boolean = false
) {
protected val cacheDirectory = File(workingDir, cacheDirName)
private val dirtySourcesSinceLastTimeFile = File(workingDir, DIRTY_SOURCES_FILE_NAME)
protected val lastBuildInfoFile = File(workingDir, LAST_BUILD_INFO_FILE_NAME)
protected val abiSnapshotFile = File(workingDir, ABI_SNAPSHOT_FILE_NAME)
private val abiSnapshotFile = File(workingDir, ABI_SNAPSHOT_FILE_NAME)
protected open val kotlinSourceFilesExtensions: List<String> = DEFAULT_KOTLIN_SOURCE_FILES_EXTENSIONS
//TODO(valtman) temporal measure to ensure quick disable, should be deleted after successful release
protected val withSnapshot: Boolean = CompilerSystemProperties.COMPILE_INCREMENTAL_WITH_CLASSPATH_SNAPSHOTS.value.toBooleanLenient() ?: false
protected abstract fun createCacheManager(args: Args, projectDir: File?): CacheManager
protected abstract fun destinationDir(args: Args): File
@@ -85,14 +83,14 @@ abstract class IncrementalCompilerRunner<
): ExitCode {
var caches = createCacheManager(args, projectDir)
if (withSnapshot) {
if (withAbiSnapshot) {
reporter.report { "Incremental compilation with ABI snapshot enabled" }
}
//TODO if abi-snapshot is corrupted unable to rebuild. Should roll back to withSnapshot = false?
val classpathAbiSnapshot =
if (withSnapshot) {
if (withAbiSnapshot) {
reporter.measure(BuildTime.SET_UP_ABI_SNAPSHOTS) {
setupJarDependencies(args, withSnapshot, reporter)
setupJarDependencies(args, withAbiSnapshot, reporter)
}
} else {
emptyMap()
@@ -110,8 +108,10 @@ abstract class IncrementalCompilerRunner<
caches.inputsCache.sourceSnapshotMap.compareAndUpdate(allSourceFiles)
}
val allKotlinFiles = allSourceFiles.filter { it.isKotlinFile(kotlinSourceFilesExtensions) }
return compileIncrementally(args, caches, allKotlinFiles, CompilationMode.Rebuild(reason), messageCollector, withSnapshot,
classpathAbiSnapshot = classpathAbiSnapshot)
return compileIncrementally(
args, caches, allKotlinFiles, CompilationMode.Rebuild(reason), messageCollector, withAbiSnapshot,
classpathAbiSnapshot = classpathAbiSnapshot
)
}
// If compilation has crashed or we failed to close caches we have to clear them
@@ -134,7 +134,7 @@ abstract class IncrementalCompilerRunner<
val exitCode = when (compilationMode) {
is CompilationMode.Incremental -> {
if (withSnapshot) {
if (withAbiSnapshot) {
val abiSnapshot = AbiSnapshotImpl.read(abiSnapshotFile, reporter)
if (abiSnapshot != null) {
compileIncrementally(
@@ -143,7 +143,7 @@ abstract class IncrementalCompilerRunner<
allSourceFiles,
compilationMode,
messageCollector,
withSnapshot,
withAbiSnapshot,
abiSnapshot,
classpathAbiSnapshot
)
@@ -157,7 +157,7 @@ abstract class IncrementalCompilerRunner<
allSourceFiles,
compilationMode,
messageCollector,
withSnapshot
withAbiSnapshot
)
}
}
@@ -84,12 +84,14 @@ class IncrementalJsCompilerRunner(
reporter: BuildReporter,
buildHistoryFile: File,
private val modulesApiHistory: ModulesApiHistory,
private val scopeExpansion: CompileScopeExpansionMode = CompileScopeExpansionMode.NEVER
private val scopeExpansion: CompileScopeExpansionMode = CompileScopeExpansionMode.NEVER,
withAbiSnapshot: Boolean = false
) : IncrementalCompilerRunner<K2JSCompilerArguments, IncrementalJsCachesManager>(
workingDir,
"caches-js",
reporter,
buildHistoryFile = buildHistoryFile
buildHistoryFile = buildHistoryFile,
withAbiSnapshot = withAbiSnapshot
) {
override fun createCacheManager(args: K2JSCompilerArguments, projectDir: File?): IncrementalJsCachesManager {
@@ -99,7 +101,7 @@ class IncrementalJsCompilerRunner(
projectDir,
reporter,
serializerProtocol,
storeFullFqNamesInLookupCache = withSnapshot
storeFullFqNamesInLookupCache = withAbiSnapshot
)
}
@@ -118,7 +120,7 @@ class IncrementalJsCompilerRunner(
messageCollector: MessageCollector,
classpathAbiSnapshots: Map<String, AbiSnapshot> //Ignore for now
): CompilationMode {
if (!withSnapshot && !buildHistoryFile.isFile) {
if (!withAbiSnapshot && !buildHistoryFile.isFile) {
return CompilationMode.Rebuild(BuildAttribute.NO_BUILD_HISTORY)
}
val lastBuildInfo = BuildInfo.read(lastBuildInfoFile)
@@ -98,7 +98,6 @@ fun makeIncrementally(
kotlinSourceFilesExtensions = kotlinExtensions,
classpathChanges = ClasspathSnapshotDisabled
)
//TODO set properly
compiler.compile(sourceFiles, args, messageCollector, providedChangedFiles = null)
}
}
@@ -135,13 +134,15 @@ class IncrementalJvmCompilerRunner(
outputFiles: Collection<File>,
private val modulesApiHistory: ModulesApiHistory,
override val kotlinSourceFilesExtensions: List<String> = DEFAULT_KOTLIN_SOURCE_FILES_EXTENSIONS,
private val classpathChanges: ClasspathChanges
private val classpathChanges: ClasspathChanges,
withAbiSnapshot: Boolean = false
) : IncrementalCompilerRunner<K2JVMCompilerArguments, IncrementalJvmCachesManager>(
workingDir,
"caches-jvm",
reporter,
additionalOutputFiles = outputFiles,
buildHistoryFile = buildHistoryFile
buildHistoryFile = buildHistoryFile,
withAbiSnapshot = withAbiSnapshot
) {
override fun createCacheManager(args: K2JVMCompilerArguments, projectDir: File?): IncrementalJvmCachesManager =
IncrementalJvmCachesManager(
@@ -149,7 +150,7 @@ class IncrementalJvmCompilerRunner(
projectDir,
File(args.destination),
reporter,
storeFullFqNamesInLookupCache = withSnapshot || classpathChanges is ClasspathChanges.ClasspathSnapshotEnabled,
storeFullFqNamesInLookupCache = withAbiSnapshot || classpathChanges is ClasspathChanges.ClasspathSnapshotEnabled,
trackChangesInLookupCache = classpathChanges is ClasspathChanges.ClasspathSnapshotEnabled.IncrementalRun
)
@@ -191,7 +192,7 @@ class IncrementalJvmCompilerRunner(
classpathAbiSnapshots: Map<String, AbiSnapshot>
): CompilationMode {
return try {
calculateSourcesToCompileImpl(caches, changedFiles, args, classpathAbiSnapshots)
calculateSourcesToCompileImpl(caches, changedFiles, args, classpathAbiSnapshots, withAbiSnapshot)
} finally {
psiFileProvider.messageCollector.flush(messageCollector)
psiFileProvider.messageCollector.clear()
@@ -228,7 +229,8 @@ class IncrementalJvmCompilerRunner(
caches: IncrementalJvmCachesManager,
changedFiles: ChangedFiles.Known,
args: K2JVMCompilerArguments,
abiSnapshots: Map<String, AbiSnapshot> = HashMap()
abiSnapshots: Map<String, AbiSnapshot> = HashMap(),
withAbiSnapshot: Boolean
): CompilationMode {
val dirtyFiles = DirtyFilesContainer(caches, reporter, kotlinSourceFilesExtensions)
initDirtyFiles(dirtyFiles, changedFiles)
@@ -264,7 +266,7 @@ class IncrementalJvmCompilerRunner(
is NotAvailableDueToMissingClasspathSnapshot -> ChangesEither.Unknown(BuildAttribute.CLASSPATH_SNAPSHOT_NOT_FOUND)
is NotAvailableForNonIncrementalRun -> ChangesEither.Unknown(BuildAttribute.UNKNOWN_CHANGES_IN_GRADLE_INPUTS)
is ClasspathSnapshotDisabled -> reporter.measure(BuildTime.IC_ANALYZE_CHANGES_IN_DEPENDENCIES) {
if (!withSnapshot && !buildHistoryFile.isFile) {
if (!withAbiSnapshot && !buildHistoryFile.isFile) {
// If the previous build was a Gradle cache hit, the build history file must have been deleted as it is marked as
// @LocalState in the Gradle task. Therefore, this compilation will need to run non-incrementally.
// (Note that buildHistoryFile is outside workingDir. We don't need to perform the same check for files inside
@@ -276,7 +278,7 @@ class IncrementalJvmCompilerRunner(
val scopes = caches.lookupCache.lookupSymbols.map { it.scope.ifBlank { it.name } }.distinct()
getClasspathChanges(
args.classpathAsList, changedFiles, lastBuildInfo, modulesApiHistory, reporter, abiSnapshots, withSnapshot,
args.classpathAsList, changedFiles, lastBuildInfo, modulesApiHistory, reporter, abiSnapshots, withAbiSnapshot,
caches.platformCache, scopes
)
}