Access cache version file in tests using CacheVersionFormat
This commit is contained in:
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.jps.incremental
|
package org.jetbrains.kotlin.jps.incremental
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.TestOnly
|
||||||
import org.jetbrains.kotlin.jps.build.KotlinBuilder
|
import org.jetbrains.kotlin.jps.build.KotlinBuilder
|
||||||
import org.jetbrains.kotlin.load.java.JvmAbi
|
import org.jetbrains.kotlin.load.java.JvmAbi
|
||||||
import java.io.File
|
import java.io.File
|
||||||
@@ -30,7 +31,7 @@ class CacheFormatVersion(targetDataRoot: File) {
|
|||||||
JvmAbi.VERSION.major * 1000 +
|
JvmAbi.VERSION.major * 1000 +
|
||||||
JvmAbi.VERSION.minor
|
JvmAbi.VERSION.minor
|
||||||
|
|
||||||
val FORMAT_VERSION_FILE_PATH: String = "$CACHE_DIRECTORY_NAME/format-version.txt"
|
private val FORMAT_VERSION_FILE_PATH: String = "$CACHE_DIRECTORY_NAME/format-version.txt"
|
||||||
}
|
}
|
||||||
|
|
||||||
private val file = File(targetDataRoot, FORMAT_VERSION_FILE_PATH)
|
private val file = File(targetDataRoot, FORMAT_VERSION_FILE_PATH)
|
||||||
@@ -59,4 +60,8 @@ class CacheFormatVersion(targetDataRoot: File) {
|
|||||||
fun clean() {
|
fun clean() {
|
||||||
file.delete()
|
file.delete()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestOnly
|
||||||
|
val formatVersionFile: File
|
||||||
|
get() = file
|
||||||
}
|
}
|
||||||
@@ -75,6 +75,8 @@ public abstract class AbstractIncrementalJpsTest(
|
|||||||
|
|
||||||
protected var workDir: File by Delegates.notNull()
|
protected var workDir: File by Delegates.notNull()
|
||||||
|
|
||||||
|
protected var projectDescriptor: ProjectDescriptor by Delegates.notNull()
|
||||||
|
|
||||||
private fun enableDebugLogging() {
|
private fun enableDebugLogging() {
|
||||||
com.intellij.openapi.diagnostic.Logger.setFactory(javaClass<TestLoggerFactory>())
|
com.intellij.openapi.diagnostic.Logger.setFactory(javaClass<TestLoggerFactory>())
|
||||||
TestLoggerFactory.dumpLogToStdout("")
|
TestLoggerFactory.dumpLogToStdout("")
|
||||||
@@ -106,19 +108,20 @@ public abstract class AbstractIncrementalJpsTest(
|
|||||||
|
|
||||||
protected open fun createLookupTracker(): LookupTracker = LookupTracker.DO_NOTHING
|
protected open fun createLookupTracker(): LookupTracker = LookupTracker.DO_NOTHING
|
||||||
|
|
||||||
protected open fun checkLookups(@Suppress("UNUSED_PARAMETER") lookupTracker: LookupTracker) {}
|
protected open fun checkLookups(@Suppress("UNUSED_PARAMETER") lookupTracker: LookupTracker) {
|
||||||
|
}
|
||||||
|
|
||||||
fun build(scope: CompileScopeTestBuilder = CompileScopeTestBuilder.make().all()): MakeResult {
|
fun build(scope: CompileScopeTestBuilder = CompileScopeTestBuilder.make().all()): MakeResult {
|
||||||
val workDirPath = FileUtil.toSystemIndependentName(workDir.absolutePath)
|
val workDirPath = FileUtil.toSystemIndependentName(workDir.absolutePath)
|
||||||
val logger = MyLogger(workDirPath)
|
val logger = MyLogger(workDirPath)
|
||||||
val descriptor = createProjectDescriptor(BuildLoggingManager(logger))
|
projectDescriptor = createProjectDescriptor(BuildLoggingManager(logger))
|
||||||
|
|
||||||
val lookupTracker = createLookupTracker()
|
val lookupTracker = createLookupTracker()
|
||||||
val dataContainer = JpsElementFactory.getInstance().createSimpleElement(lookupTracker)
|
val dataContainer = JpsElementFactory.getInstance().createSimpleElement(lookupTracker)
|
||||||
descriptor.project.container.setChild(KotlinBuilder.LOOKUP_TRACKER, dataContainer)
|
projectDescriptor.project.container.setChild(KotlinBuilder.LOOKUP_TRACKER, dataContainer)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
val builder = IncProjectBuilder(descriptor, BuilderRegistry.getInstance(), myBuildParams, CanceledStatus.NULL, mockConstantSearch, true)
|
val builder = IncProjectBuilder(projectDescriptor, BuilderRegistry.getInstance(), myBuildParams, CanceledStatus.NULL, mockConstantSearch, true)
|
||||||
val buildResult = BuildResult()
|
val buildResult = BuildResult()
|
||||||
builder.addMessageHandler(buildResult)
|
builder.addMessageHandler(buildResult)
|
||||||
builder.build(scope.build(), false)
|
builder.build(scope.build(), false)
|
||||||
@@ -135,11 +138,12 @@ public abstract class AbstractIncrementalJpsTest(
|
|||||||
return MakeResult(logger.log + "$COMPILATION_FAILED\n" + errorMessages + "\n", true, null)
|
return MakeResult(logger.log + "$COMPILATION_FAILED\n" + errorMessages + "\n", true, null)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return MakeResult(logger.log, false, createMappingsDump(descriptor))
|
return MakeResult(logger.log, false, createMappingsDump(projectDescriptor))
|
||||||
}
|
}
|
||||||
} finally {
|
}
|
||||||
descriptor.dataManager.flush(false)
|
finally {
|
||||||
descriptor.release()
|
projectDescriptor.dataManager.flush(false)
|
||||||
|
projectDescriptor.release()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -289,10 +293,7 @@ public abstract class AbstractIncrementalJpsTest(
|
|||||||
|
|
||||||
private fun createKotlinIncrementalCacheDump(project: ProjectDescriptor): String {
|
private fun createKotlinIncrementalCacheDump(project: ProjectDescriptor): String {
|
||||||
return StringBuilder {
|
return StringBuilder {
|
||||||
val allTargets = project.buildTargetIndex.allTargets
|
for (target in project.allModuleTargets.sortedBy { it.presentableName }) {
|
||||||
val moduleTargets = allTargets.filterIsInstance(ModuleBuildTarget::class.java)
|
|
||||||
|
|
||||||
for (target in moduleTargets.sortedBy { it.presentableName }) {
|
|
||||||
append("<target $target>\n")
|
append("<target $target>\n")
|
||||||
append(project.dataManager.getKotlinCache(target).dump())
|
append(project.dataManager.getKotlinCache(target).dump())
|
||||||
append("</target $target>\n\n\n")
|
append("</target $target>\n\n\n")
|
||||||
@@ -307,7 +308,7 @@ public abstract class AbstractIncrementalJpsTest(
|
|||||||
result.println("Begin of SourceToOutputMap")
|
result.println("Begin of SourceToOutputMap")
|
||||||
result.pushIndent()
|
result.pushIndent()
|
||||||
|
|
||||||
for (target in project.buildTargetIndex.allTargets) {
|
for (target in project.allModuleTargets) {
|
||||||
result.println(target)
|
result.println(target)
|
||||||
result.pushIndent()
|
result.pushIndent()
|
||||||
|
|
||||||
@@ -445,3 +446,6 @@ public abstract class AbstractIncrementalJpsTest(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal val ProjectDescriptor.allModuleTargets: Collection<ModuleBuildTarget>
|
||||||
|
get() = buildTargetIndex.allTargets.filterIsInstance<ModuleBuildTarget>()
|
||||||
|
|||||||
+7
-13
@@ -16,11 +16,8 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.jps.build
|
package org.jetbrains.kotlin.jps.build
|
||||||
|
|
||||||
import org.jetbrains.jps.builders.impl.BuildDataPathsImpl
|
import org.jetbrains.kotlin.jps.incremental.getKotlinCacheVersion
|
||||||
import java.io.File
|
|
||||||
import org.jetbrains.jps.builders.java.JavaModuleBuildTargetType
|
|
||||||
import kotlin.test.assertTrue
|
import kotlin.test.assertTrue
|
||||||
import org.jetbrains.kotlin.jps.incremental.CacheFormatVersion
|
|
||||||
|
|
||||||
public class IncrementalCacheVersionChangedTest : AbstractIncrementalJpsTest(allowNoFilesWithSuffixInTestData = true) {
|
public class IncrementalCacheVersionChangedTest : AbstractIncrementalJpsTest(allowNoFilesWithSuffixInTestData = true) {
|
||||||
fun testCacheVersionChanged() {
|
fun testCacheVersionChanged() {
|
||||||
@@ -36,16 +33,13 @@ public class IncrementalCacheVersionChangedTest : AbstractIncrementalJpsTest(all
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun performAdditionalModifications() {
|
override fun performAdditionalModifications() {
|
||||||
val storageForTargetType = BuildDataPathsImpl(myDataStorageRoot).getTargetTypeDataRoot(JavaModuleBuildTargetType.PRODUCTION)
|
val targets = projectDescriptor.allModuleTargets
|
||||||
|
val paths = projectDescriptor.dataManager.dataPaths
|
||||||
|
|
||||||
|
for (target in targets) {
|
||||||
val moduleNames = if (getTestName(false) == "CacheVersionChangedMultiModule") listOf("module1", "module2") else listOf("module")
|
val cacheVersion = paths.getKotlinCacheVersion(target)
|
||||||
|
val cacheVersionFile = cacheVersion.formatVersionFile
|
||||||
for (moduleName in moduleNames) {
|
assertTrue(cacheVersionFile.exists(), "Cache version file does not exists: $cacheVersionFile")
|
||||||
val relativePath = "$moduleName/${CacheFormatVersion.FORMAT_VERSION_FILE_PATH}"
|
|
||||||
val cacheVersionFile = File(storageForTargetType, relativePath)
|
|
||||||
|
|
||||||
assertTrue(cacheVersionFile.exists())
|
|
||||||
cacheVersionFile.writeText("777")
|
cacheVersionFile.writeText("777")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user