Print file paths relative to project root in gradle incremental compilation logs

KT-8487
This commit is contained in:
Alexey Tsvetkov
2016-03-01 15:56:03 +03:00
parent 8a0bd9446b
commit 6ab868ae33
2 changed files with 9 additions and 7 deletions
@@ -220,13 +220,14 @@ fun mapLookupSymbolsToFiles(
lookupStorage: LookupStorage,
lookupSymbols: Iterable<LookupSymbol>,
log: (String)->Unit,
getLogFilePath: (File)->String = { it.canonicalPath },
excludes: Set<File> = emptySet()
): Set<File> {
val dirtyFiles = HashSet<File>()
for (lookup in lookupSymbols) {
val affectedFiles = lookupStorage.get(lookup).map(::File).filter { it !in excludes }
log("${lookup.scope}#${lookup.name} caused recompilation of: $affectedFiles")
log("${lookup.scope}#${lookup.name} caused recompilation of: ${affectedFiles.map(getLogFilePath)}")
dirtyFiles.addAll(affectedFiles)
}
@@ -237,6 +238,7 @@ fun <Target> mapClassesFqNamesToFiles(
caches: Iterable<IncrementalCacheImpl<Target>>,
classesFqNames: Iterable<FqName>,
log: (String)->Unit,
getLogFilePath: (File)->String = { it.canonicalPath },
excludes: Set<File> = emptySet()
): Set<File> {
val dirtyFiles = HashSet<File>()
@@ -246,7 +248,7 @@ fun <Target> mapClassesFqNamesToFiles(
val srcFile = cache.getSourceFileIfClass(dirtyClassFqName)
if (srcFile == null || srcFile in excludes) continue
log("Class $dirtyClassFqName caused recompilation of: $srcFile")
log("Class $dirtyClassFqName caused recompilation of: ${getLogFilePath(srcFile)}")
dirtyFiles.add(srcFile)
}
}
@@ -161,8 +161,6 @@ open class KotlinCompile() : AbstractKotlinCompile<K2JVMCompilerArguments>() {
"compileReleaseUnitTestKotlin" to "compileReleaseKotlin"
)
fun projectRelativePath(f: File) = f.toRelativeString(project.projectDir)
// TODO: find out whether we really need to be able to override destination dir here, and how it should work with destinationDir property
private val compilerDestinationDir: String get() = if (StringUtils.isEmpty(kotlinOptions.destination)) { kotlinDestinationDir?.path.orEmpty() } else { kotlinOptions.destination }
@@ -220,6 +218,8 @@ open class KotlinCompile() : AbstractKotlinCompile<K2JVMCompilerArguments>() {
override fun callCompiler(args: K2JVMCompilerArguments, sources: List<File>, isIncrementalRequested: Boolean, modified: List<File>, removed: List<File>, cachesBaseDir: File) {
fun projectRelativePath(f: File) = f.toRelativeString(project.projectDir)
if (experimentalIncremental) {
// TODO: consider other ways to pass incremental flag to compiler/builder
System.setProperty("kotlin.incremental.compilation", "true")
@@ -280,7 +280,7 @@ open class KotlinCompile() : AbstractKotlinCompile<K2JVMCompilerArguments>() {
if (lookupSymbols.any()) {
val kotlinModifiedFilesSet = modifiedKotlinFiles.toHashSet()
val dirtyFilesFromLookups = mapLookupSymbolsToFiles(lookupStorage, lookupSymbols, logAction, excludes = kotlinModifiedFilesSet)
val dirtyFilesFromLookups = mapLookupSymbolsToFiles(lookupStorage, lookupSymbols, logAction, ::projectRelativePath, excludes = kotlinModifiedFilesSet)
modifiedKotlinFiles.addAll(dirtyFilesFromLookups)
}
@@ -434,8 +434,8 @@ open class KotlinCompile() : AbstractKotlinCompile<K2JVMCompilerArguments>() {
if (!isIncrementalDecided) break;
val (dirtyLookupSymbols, dirtyClassFqNames) = compilationResult.getDirtyData(caches.values, logAction)
sourcesToCompile = mapLookupSymbolsToFiles(lookupStorage, dirtyLookupSymbols, logAction, excludes = sourcesToCompile) +
mapClassesFqNamesToFiles(caches.values, dirtyClassFqNames, logAction)
sourcesToCompile = mapLookupSymbolsToFiles(lookupStorage, dirtyLookupSymbols, logAction, ::projectRelativePath, excludes = sourcesToCompile) +
mapClassesFqNamesToFiles(caches.values, dirtyClassFqNames, logAction, ::projectRelativePath)
if (currentRemoved.any()) {
currentRemoved = listOf()