[IC] Allow to not specify the modules info

This commit is contained in:
Alexander.Likhachev
2023-03-27 16:56:15 +02:00
committed by Space Team
parent e33611a88a
commit b3677fa0ca
13 changed files with 34 additions and 19 deletions
@@ -21,7 +21,6 @@ data class IncrementalModuleEntry(
}
class IncrementalModuleInfo(
val projectRoot: File,
val rootProjectBuildDir: File,
val dirToModule: Map<File, IncrementalModuleEntry>,
val nameToModules: Map<String, Set<IncrementalModuleEntry>>,
@@ -69,7 +69,11 @@ class IncrementalCompilationOptions(
*/
val outputFiles: List<File>,
val multiModuleICSettings: MultiModuleICSettings? = null,
val modulesInfo: IncrementalModuleInfo,
val modulesInfo: IncrementalModuleInfo? = null,
/**
* Root project directory, used to resolve relative paths
*/
val rootProjectDir: File,
kotlinScriptExtensions: Array<String>? = null,
val withAbiSnapshot: Boolean = false,
val preciseCompilationResultsBackup: Boolean = false,
@@ -556,7 +556,12 @@ abstract class CompileServiceImplBase(
}
val workingDir = incrementalCompilationOptions.workingDir
val modulesApiHistory = ModulesApiHistoryJs(incrementalCompilationOptions.modulesInfo)
val modulesApiHistory = incrementalCompilationOptions.multiModuleICSettings?.run {
val modulesInfo = incrementalCompilationOptions.modulesInfo
?: error("The build is configured to use the history-file based IC approach, but doesn't provide the modulesInfo")
ModulesApiHistoryJs(incrementalCompilationOptions.rootProjectDir, modulesInfo)
} ?: EmptyModulesApiHistory
val compiler = IncrementalJsCompilerRunner(
workingDir = workingDir,
@@ -606,17 +611,20 @@ abstract class CompileServiceImplBase(
val workingDir = incrementalCompilationOptions.workingDir
val projectRoot = incrementalCompilationOptions.rootProjectDir
val modulesApiHistory = incrementalCompilationOptions.multiModuleICSettings?.run {
reporter.info { "Use module detection: ${useModuleDetection}" }
reporter.info { "Use module detection: $useModuleDetection" }
val modulesInfo = incrementalCompilationOptions.modulesInfo
?: error("The build is configured to use the history-file based IC approach, but doesn't provide the modulesInfo")
if (!useModuleDetection) {
ModulesApiHistoryJvm(incrementalCompilationOptions.modulesInfo)
ModulesApiHistoryJvm(projectRoot, modulesInfo)
} else {
ModulesApiHistoryAndroid(incrementalCompilationOptions.modulesInfo)
ModulesApiHistoryAndroid(projectRoot, modulesInfo)
}
} ?: EmptyModulesApiHistory
val projectRoot = incrementalCompilationOptions.modulesInfo.projectRoot
val useK2 = k2jvmArgs.useK2 || LanguageVersion.fromVersionString(k2jvmArgs.languageVersion)?.usesK2 == true
// TODO: This should be reverted after implementing of fir-based java tracker (KT-57147).
// See org.jetbrains.kotlin.incremental.CompilerRunnerUtilsKt.makeJvmIncrementally
@@ -30,7 +30,7 @@ fun getBuildReporter(
compilationResults: CompilationResults,
compilationOptions: IncrementalCompilationOptions
): RemoteBuildReporter<GradleBuildTime, GradleBuildPerformanceMetric> {
val root = compilationOptions.modulesInfo.projectRoot
val root = compilationOptions.rootProjectDir
val reporters = ArrayList<RemoteICReporter>()
if (ReportCategory.IC_MESSAGE.code in compilationOptions.reportCategories) {
@@ -25,14 +25,14 @@ object EmptyModulesApiHistory : ModulesApiHistory {
override fun abiSnapshot(jar: File): Either<Set<File>> = Either.Error("Not supported")
}
abstract class ModulesApiHistoryBase(protected val modulesInfo: IncrementalModuleInfo) : ModulesApiHistory {
abstract class ModulesApiHistoryBase(rootProjectDir: File, protected val modulesInfo: IncrementalModuleInfo) : ModulesApiHistory {
// All project build dirs should have this dir as their parent. For a default project setup, this will
// be the same as root project path. Some projects map output outside of the root project dir, typically
// with <some_dir>/<project_path>/build, and in that case, this path will be <some_dir>.
// This is using set in order to de-dup paths, and avoid duplicate checks when possible.
protected val possibleParentsToBuildDirs: Set<Path> = setOf(
Paths.get(modulesInfo.rootProjectBuildDir.parentFile.absolutePath),
Paths.get(modulesInfo.projectRoot.absolutePath)
Paths.get(rootProjectDir.absolutePath)
)
private val dirToHistoryFileCache = HashMap<File, Set<File>>()
@@ -107,7 +107,7 @@ abstract class ModulesApiHistoryBase(protected val modulesInfo: IncrementalModul
protected abstract fun getBuildHistoryFilesForJar(jar: File): Either<Set<File>>
}
class ModulesApiHistoryJvm(modulesInfo: IncrementalModuleInfo) : ModulesApiHistoryBase(modulesInfo) {
class ModulesApiHistoryJvm(rootProjectDir: File, modulesInfo: IncrementalModuleInfo) : ModulesApiHistoryBase(rootProjectDir, modulesInfo) {
override fun getBuildHistoryFilesForJar(jar: File): Either<Set<File>> {
val moduleInfoFromJar = modulesInfo.jarToModule[jar]
if (moduleInfoFromJar != null) {
@@ -144,7 +144,7 @@ class ModulesApiHistoryJvm(modulesInfo: IncrementalModuleInfo) : ModulesApiHisto
}
}
class ModulesApiHistoryJs(modulesInfo: IncrementalModuleInfo) : ModulesApiHistoryBase(modulesInfo) {
class ModulesApiHistoryJs(rootProjectDir: File, modulesInfo: IncrementalModuleInfo) : ModulesApiHistoryBase(rootProjectDir, modulesInfo) {
override fun getBuildHistoryFilesForJar(jar: File): Either<Set<File>> {
val moduleEntry = modulesInfo.jarToModule[jar]
@@ -160,8 +160,8 @@ class ModulesApiHistoryJs(modulesInfo: IncrementalModuleInfo) : ModulesApiHistor
}
}
class ModulesApiHistoryAndroid(modulesInfo: IncrementalModuleInfo) : ModulesApiHistoryBase(modulesInfo) {
private val delegate = ModulesApiHistoryJvm(modulesInfo)
class ModulesApiHistoryAndroid(rootProjectDir: File, modulesInfo: IncrementalModuleInfo) : ModulesApiHistoryBase(rootProjectDir, modulesInfo) {
private val delegate = ModulesApiHistoryJvm(rootProjectDir, modulesInfo)
override fun historyFilesForChangedFiles(changedFiles: Set<File>): Either<Set<File>> {
val historyFromDelegate = delegate.historyFilesForChangedFiles(changedFiles)
@@ -33,7 +33,7 @@ abstract class AbstractIncrementalMultiModuleCompilerRunnerTest<Args : CommonCom
private val jarToAbiSnapshot = mutableMapOf<File, File>()
protected val incrementalModuleInfo: IncrementalModuleInfo by lazy {
IncrementalModuleInfo(workingDir, workingDir, dirToModule, nameToModules, jarToClassListFile, jarToModule, jarToAbiSnapshot)
IncrementalModuleInfo(workingDir, dirToModule, nameToModules, jarToClassListFile, jarToModule, jarToAbiSnapshot)
}
protected abstract val modulesApiHistory: ApiHistory
@@ -55,7 +55,7 @@ abstract class AbstractIncrementalMultiModuleJsKlibCompilerRunnerTest :
}
override val modulesApiHistory: ModulesApiHistoryJs by lazy {
ModulesApiHistoryJs(incrementalModuleInfo)
ModulesApiHistoryJs(workingDir, incrementalModuleInfo)
}
override val scopeExpansionMode: CompileScopeExpansionMode get() = CompileScopeExpansionMode.NEVER
@@ -59,7 +59,6 @@ class ModulesApiHistoryAndroidTest {
}
val info = IncrementalModuleInfo(
projectRoot = projectRoot,
rootProjectBuildDir = projectRoot.resolve("build"),
dirToModule = mapOf(appKotlinDestination to appEntry, libKotlinDestination to libEntry),
nameToModules = mapOf("app" to setOf(appEntry), "lib" to setOf(libEntry)),
@@ -68,7 +67,7 @@ class ModulesApiHistoryAndroidTest {
jarToAbiSnapshot = mapOf()
)
androidHistory = ModulesApiHistoryAndroid(info)
androidHistory = ModulesApiHistoryAndroid(projectRoot, info)
}
@Test
@@ -397,7 +397,6 @@ internal open class GradleCompilerRunner(
}
return IncrementalModuleInfo(
projectRoot = gradle.rootProject.projectDir,
rootProjectBuildDir = gradle.rootProject.buildDir,
dirToModule = dirToModule,
nameToModules = nameToModules,
@@ -330,6 +330,7 @@ internal class GradleKotlinCompilerWork @Inject constructor(
outputFiles = outputFiles,
multiModuleICSettings = icEnv.multiModuleICSettings,
modulesInfo = incrementalModuleInfo!!,
rootProjectDir = icEnv.rootProjectDir,
kotlinScriptExtensions = kotlinScriptExtensions,
withAbiSnapshot = icEnv.withAbiSnapshot,
preciseCompilationResultsBackup = icEnv.preciseCompilationResultsBackup,
@@ -15,6 +15,7 @@ internal class IncrementalCompilationEnvironment(
val changedFiles: ChangedFiles,
val classpathChanges: ClasspathChanges,
val workingDir: File,
val rootProjectDir: File,
val usePreciseJavaTracking: Boolean = false,
val disableMultiModuleIC: Boolean = false,
val multiModuleICSettings: MultiModuleICSettings,
@@ -328,6 +328,7 @@ abstract class Kotlin2JsCompile @Inject constructor(
getChangedFiles(inputChanges, incrementalProps),
ClasspathChanges.NotAvailableForJSCompiler,
taskBuildCacheableOutputDirectory.get().asFile,
projectRootDir,
multiModuleICSettings = multiModuleICSettings,
preciseCompilationResultsBackup = preciseCompilationResultsBackup.get(),
keepIncrementalCompilationCachesInMemory = keepIncrementalCompilationCachesInMemory.get(),
@@ -302,6 +302,8 @@ abstract class KotlinCompile @Inject constructor(
}
}
private val projectRootDir = project.rootDir
override fun callCompilerAsync(
args: K2JVMCompilerArguments,
inputChanges: InputChanges,
@@ -323,6 +325,7 @@ abstract class KotlinCompile @Inject constructor(
changedFiles = getChangedFiles(inputChanges, incrementalProps),
classpathChanges = getClasspathChanges(inputChanges),
workingDir = taskBuildCacheableOutputDirectory.get().asFile,
rootProjectDir = projectRootDir,
usePreciseJavaTracking = usePreciseJavaTracking,
disableMultiModuleIC = disableMultiModuleIC,
multiModuleICSettings = multiModuleICSettings,