[IC] Add methods to write without explicit registering in a transaction
#KT-49785 In Progress
This commit is contained in:
committed by
Space Team
parent
581bc89849
commit
3dcf5af4b0
+4
-3
@@ -145,9 +145,10 @@ class AbiSnapshotImpl(override val protos: MutableMap<FqName, ProtoData>) : AbiS
|
||||
}
|
||||
|
||||
fun write(icContext: IncrementalCompilationContext, buildInfo: AbiSnapshot, file: File) {
|
||||
icContext.transaction.registerAddedOrChangedFile(file.toPath())
|
||||
ObjectOutputStream(FileOutputStream(file)).use {
|
||||
it.writeAbiSnapshot(buildInfo)
|
||||
icContext.transaction.write(file.toPath()) {
|
||||
ObjectOutputStream(FileOutputStream(file)).use {
|
||||
it.writeAbiSnapshot(buildInfo)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+10
-8
@@ -64,21 +64,23 @@ data class BuildDiffsStorage(val buildDiffs: List<BuildDifference>) {
|
||||
return null
|
||||
}
|
||||
|
||||
fun writeToFile(file: File, storage: BuildDiffsStorage, reporter: ICReporter?) {
|
||||
fun writeToFile(icContext: IncrementalCompilationContext, file: File, storage: BuildDiffsStorage) {
|
||||
file.parentFile.mkdirs()
|
||||
|
||||
try {
|
||||
ObjectOutputStream(file.outputStream().buffered()).use { output ->
|
||||
output.writeInt(CURRENT_VERSION)
|
||||
icContext.transaction.write(file.toPath()) {
|
||||
ObjectOutputStream(file.outputStream().buffered()).use { output ->
|
||||
output.writeInt(CURRENT_VERSION)
|
||||
|
||||
val diffsToWrite = storage.buildDiffs.sortedBy { it.ts }.takeLast(MAX_DIFFS_ENTRIES)
|
||||
output.writeInt(diffsToWrite.size)
|
||||
for (diff in diffsToWrite) {
|
||||
output.writeBuildDifference(diff)
|
||||
val diffsToWrite = storage.buildDiffs.sortedBy { it.ts }.takeLast(MAX_DIFFS_ENTRIES)
|
||||
output.writeInt(diffsToWrite.size)
|
||||
for (diff in diffsToWrite) {
|
||||
output.writeBuildDifference(diff)
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (e: IOException) {
|
||||
reporter?.info { "Could not write diff to file $file: $e" }
|
||||
icContext.reporter.info { "Could not write diff to file $file: $e" }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+4
-6
@@ -495,8 +495,7 @@ abstract class IncrementalCompilerRunner<
|
||||
dirtySources.addAll(compiledSources)
|
||||
allDirtySources.addAll(dirtySources)
|
||||
val text = allDirtySources.joinToString(separator = System.getProperty("line.separator")) { it.normalize().absolutePath }
|
||||
transaction.registerAddedOrChangedFile(dirtySourcesSinceLastTimeFile.toPath())
|
||||
dirtySourcesSinceLastTimeFile.writeText(text)
|
||||
transaction.writeText(dirtySourcesSinceLastTimeFile.toPath(), text)
|
||||
|
||||
val generatedFiles = outputItemsCollector.outputs.map {
|
||||
it.toGeneratedFile(jvmMetadataVersionFromLanguageVersion)
|
||||
@@ -583,7 +582,7 @@ abstract class IncrementalCompilerRunner<
|
||||
}
|
||||
|
||||
val dirtyData = DirtyData(buildDirtyLookupSymbols, buildDirtyFqNames)
|
||||
processChangesAfterBuild(compilationMode, currentBuildInfo, dirtyData, transaction)
|
||||
processChangesAfterBuild(icContext, compilationMode, currentBuildInfo, dirtyData)
|
||||
|
||||
return exitCode
|
||||
}
|
||||
@@ -615,10 +614,10 @@ abstract class IncrementalCompilerRunner<
|
||||
open fun runWithNoDirtyKotlinSources(caches: CacheManager): Boolean = false
|
||||
|
||||
private fun processChangesAfterBuild(
|
||||
icContext: IncrementalCompilationContext,
|
||||
compilationMode: CompilationMode,
|
||||
currentBuildInfo: BuildInfo,
|
||||
dirtyData: DirtyData,
|
||||
transaction: CompilationTransaction,
|
||||
) = reporter.measure(BuildTime.IC_WRITE_HISTORY_FILE) {
|
||||
val prevDiffs = BuildDiffsStorage.readFromFile(buildHistoryFile, reporter)?.buildDiffs ?: emptyList()
|
||||
val newDiff = if (compilationMode is CompilationMode.Incremental) {
|
||||
@@ -628,8 +627,7 @@ abstract class IncrementalCompilerRunner<
|
||||
BuildDifference(currentBuildInfo.startTS, false, emptyDirtyData)
|
||||
}
|
||||
|
||||
transaction.registerAddedOrChangedFile(buildHistoryFile.toPath())
|
||||
BuildDiffsStorage.writeToFile(buildHistoryFile, BuildDiffsStorage(prevDiffs + newDiff), reporter)
|
||||
BuildDiffsStorage.writeToFile(icContext, buildHistoryFile, BuildDiffsStorage(prevDiffs + newDiff))
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
+4
-3
@@ -28,6 +28,7 @@ import java.util.*
|
||||
class BuildDiffsStorageTest {
|
||||
lateinit var storageFile: File
|
||||
private val random = Random(System.currentTimeMillis())
|
||||
private val icContext = IncrementalCompilationContext(null)
|
||||
|
||||
@Before
|
||||
fun setUp() {
|
||||
@@ -54,7 +55,7 @@ class BuildDiffsStorageTest {
|
||||
@Test
|
||||
fun writeReadSimple() {
|
||||
val diffs = BuildDiffsStorage(listOf(getRandomDiff()))
|
||||
BuildDiffsStorage.writeToFile(storageFile, diffs, reporter = null)
|
||||
BuildDiffsStorage.writeToFile(icContext, storageFile, diffs)
|
||||
|
||||
val diffsDeserialized = BuildDiffsStorage.readFromFile(storageFile, reporter = null)
|
||||
Assert.assertEquals(diffs.toString(), diffsDeserialized.toString())
|
||||
@@ -64,7 +65,7 @@ class BuildDiffsStorageTest {
|
||||
fun writeReadMany() {
|
||||
val generated = Array(20) { getRandomDiff() }.toList()
|
||||
val diffs = BuildDiffsStorage(generated)
|
||||
BuildDiffsStorage.writeToFile(storageFile, diffs, reporter = null)
|
||||
BuildDiffsStorage.writeToFile(icContext, storageFile, diffs)
|
||||
|
||||
val diffsDeserialized = BuildDiffsStorage.readFromFile(storageFile, reporter = null)
|
||||
val expected = generated.sortedBy { it.ts }.takeLast(BuildDiffsStorage.MAX_DIFFS_ENTRIES).toTypedArray()
|
||||
@@ -82,7 +83,7 @@ class BuildDiffsStorageTest {
|
||||
@Test
|
||||
fun versionChanged() {
|
||||
val diffs = BuildDiffsStorage(listOf(getRandomDiff()))
|
||||
BuildDiffsStorage.writeToFile(storageFile, diffs, reporter = null)
|
||||
BuildDiffsStorage.writeToFile(icContext, storageFile, diffs)
|
||||
|
||||
val versionBackup = BuildDiffsStorage.CURRENT_VERSION
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user