Don't call File.getCanonicalPath in KGP
Relates to KT-54579.
This commit is contained in:
@@ -23,7 +23,7 @@ abstract class ICReporterBase(private val pathsBase: File? = null) : ICReporter
|
||||
}
|
||||
|
||||
protected fun relativizeIfPossible(files: Iterable<File>): List<File> =
|
||||
files.map { it.relativeOrCanonical() }
|
||||
files.map { it.relativeOrAbsolute() }
|
||||
|
||||
protected fun pathsAsString(files: Iterable<File>): String =
|
||||
relativizeIfPossible(files).map { it.path }.sorted().joinToString()
|
||||
@@ -31,6 +31,6 @@ abstract class ICReporterBase(private val pathsBase: File? = null) : ICReporter
|
||||
protected fun pathsAsString(vararg files: File): String =
|
||||
pathsAsString(files.toList())
|
||||
|
||||
protected fun File.relativeOrCanonical(): File =
|
||||
pathsBase?.let { relativeToOrNull(it) } ?: canonicalFile
|
||||
protected fun File.relativeOrAbsolute(): File =
|
||||
pathsBase?.let { relativeToOrNull(it) } ?: normalize().absoluteFile
|
||||
}
|
||||
@@ -104,7 +104,7 @@ open class IncrementalJvmCache(
|
||||
className in multifileFacadeToParts
|
||||
|
||||
override fun getClassFilePath(internalClassName: String): String {
|
||||
return toSystemIndependentName(File(outputDir, "$internalClassName.class").canonicalPath)
|
||||
return toSystemIndependentName(File(outputDir, "$internalClassName.class").normalize().absolutePath)
|
||||
}
|
||||
|
||||
fun saveModuleMappingToCache(sourceFiles: Collection<File>, file: File) {
|
||||
|
||||
@@ -126,7 +126,7 @@ class FileAgeComparator : Comparator<File> {
|
||||
leftTS == 0L || rightTS == 0L -> 0 // cannot read any file timestamp, => undecidable
|
||||
leftTS > rightTS -> -1
|
||||
leftTS < rightTS -> 1
|
||||
else -> compareValues(left.canonicalPath, right.canonicalPath)
|
||||
else -> compareValues(left.normalize().absolutePath, right.normalize().absolutePath)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1063,7 +1063,7 @@ class CompileServiceImpl(
|
||||
}
|
||||
daemon.scheduleShutdown(true)
|
||||
} catch (e: Throwable) {
|
||||
log.info("Cannot connect to a daemon, assuming dying ('${runFile.canonicalPath}'): ${e.message}")
|
||||
log.info("Cannot connect to a daemon, assuming dying ('${runFile.normalize().absolutePath}'): ${e.message}")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -527,7 +527,7 @@ class CompileServiceServerSideImpl(
|
||||
daemon.scheduleShutdown(true)
|
||||
log.fine("other : SHUTDOWN_OK")
|
||||
} catch (e: Throwable) {
|
||||
log.info("Cannot connect to a daemon, assuming dying ('${runFile.canonicalPath}'): ${e.message}")
|
||||
log.info("Cannot connect to a daemon, assuming dying ('${runFile.normalize().absolutePath}'): ${e.message}")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ class BuildReportICReporter(
|
||||
icLogLines.add("Compile iteration:")
|
||||
for (file in sourceFiles) {
|
||||
val reason = recompilationReason[file]?.let { " <- $it" } ?: ""
|
||||
icLogLines.add(" ${file.relativeOrCanonical()}$reason")
|
||||
icLogLines.add(" ${file.relativeOrAbsolute()}$reason")
|
||||
}
|
||||
recompilationReason.clear()
|
||||
}
|
||||
|
||||
+1
-1
@@ -80,7 +80,7 @@ internal class BuildReportICReporterAsync(
|
||||
icLogLines.add("Compile iteration:")
|
||||
for (file in sourceFiles) {
|
||||
val reason = recompilationReason[file]?.let { " <- $it" } ?: ""
|
||||
icLogLines.add(" ${file.relativeOrCanonical()}$reason")
|
||||
icLogLines.add(" ${file.relativeOrAbsolute()}$reason")
|
||||
}
|
||||
recompilationReason.clear()
|
||||
}
|
||||
|
||||
+1
-1
@@ -435,7 +435,7 @@ abstract class IncrementalCompilerRunner<
|
||||
|
||||
dirtySources.addAll(compiledSources)
|
||||
allDirtySources.addAll(dirtySources)
|
||||
val text = allDirtySources.joinToString(separator = System.getProperty("line.separator")) { it.canonicalPath }
|
||||
val text = allDirtySources.joinToString(separator = System.getProperty("line.separator")) { it.normalize().absolutePath }
|
||||
dirtySourcesSinceLastTimeFile.writeText(text)
|
||||
|
||||
|
||||
|
||||
+1
-1
@@ -23,7 +23,7 @@ import java.io.File
|
||||
|
||||
object FileSnapshotExternalizer : DataExternalizer<FileSnapshot> {
|
||||
override fun save(out: DataOutput, value: FileSnapshot) {
|
||||
out.writeUTF(value.file.canonicalPath)
|
||||
out.writeUTF(value.file.normalize().absolutePath)
|
||||
out.writeLong(value.length)
|
||||
out.writeInt(value.hash.size)
|
||||
out.write(value.hash)
|
||||
|
||||
@@ -50,10 +50,10 @@ class KotlinDirtySourceFilesHolder(
|
||||
*/
|
||||
internal fun _markDirty(file: File, root: JavaSourceRootDescriptor) {
|
||||
val isCrossCompiled = root is KotlinIncludedModuleSourceRoot
|
||||
val old = _dirty.put(file.canonicalFile, KotlinModuleBuildTarget.Source(file, isCrossCompiled))
|
||||
val old = _dirty.put(file.normalize().absoluteFile, KotlinModuleBuildTarget.Source(file, isCrossCompiled))
|
||||
|
||||
check(old == null || old.isCrossCompiled == isCrossCompiled) {
|
||||
"`${file.canonicalFile}` already marked as dirty: " +
|
||||
"`${file.normalize().absoluteFile}` already marked as dirty: " +
|
||||
"old is cross compiled: ${old!!.isCrossCompiled}, " +
|
||||
"new is cross compiled: $isCrossCompiled"
|
||||
}
|
||||
|
||||
@@ -400,8 +400,8 @@ class KotlinJvmModuleBuildTarget(kotlinContext: KotlinCompileContext, jpsModuleB
|
||||
}
|
||||
|
||||
callback.associate(
|
||||
FileUtil.toSystemIndependentName(output.outputFile.canonicalPath),
|
||||
sourceFiles.map { FileUtil.toSystemIndependentName(it.canonicalPath) },
|
||||
FileUtil.toSystemIndependentName(output.outputFile.normalize().absolutePath),
|
||||
sourceFiles.map { FileUtil.toSystemIndependentName(it.normalize().absolutePath) },
|
||||
ClassReader(output.outputClass.fileContents)
|
||||
)
|
||||
}
|
||||
|
||||
+2
-2
@@ -33,7 +33,7 @@ class FilesSubpluginOption(
|
||||
key: String,
|
||||
val files: Iterable<File>,
|
||||
val kind: FilesOptionKind = FilesOptionKind.INTERNAL,
|
||||
lazyValue: Lazy<String> = lazy { files.joinToString(File.pathSeparator) { it.canonicalPath } }
|
||||
lazyValue: Lazy<String> = lazy { files.joinToString(File.pathSeparator) { it.normalize().absolutePath } }
|
||||
) : SubpluginOption(key, lazyValue) {
|
||||
|
||||
constructor(
|
||||
@@ -41,7 +41,7 @@ class FilesSubpluginOption(
|
||||
files: List<File>,
|
||||
kind: FilesOptionKind = FilesOptionKind.INTERNAL,
|
||||
value: String? = null
|
||||
) : this(key, files, kind, lazy { value ?: files.joinToString(File.pathSeparator) { it.canonicalPath } })
|
||||
) : this(key, files, kind, lazy { value ?: files.joinToString(File.pathSeparator) { it.normalize().absolutePath } })
|
||||
}
|
||||
|
||||
class CompositeSubpluginOption(
|
||||
|
||||
+8
-7
@@ -347,12 +347,13 @@ internal open class GradleCompilerRunner(
|
||||
kotlinTask.abiSnapshotFile.get().asFile
|
||||
)
|
||||
val jarTask = project.tasks.findByName(target.artifactsTaskName) as? AbstractArchiveTask ?: continue
|
||||
jarToModule[jarTask.archivePathCompatible.canonicalFile] = module
|
||||
jarToModule[jarTask.archivePathCompatible.normalize().absoluteFile] = module
|
||||
if (target is KotlinWithJavaTarget<*, *>) {
|
||||
val jar = project.tasks.getByName(target.artifactsTaskName) as Jar
|
||||
jarToClassListFile[jar.archivePathCompatible.canonicalFile] = target.defaultArtifactClassesListFile.get()
|
||||
jarToClassListFile[jar.archivePathCompatible.normalize().absoluteFile] =
|
||||
target.defaultArtifactClassesListFile.get()
|
||||
//configure abiSnapshot mapping for jars
|
||||
jarToAbiSnapshot[jar.archivePathCompatible.canonicalFile] =
|
||||
jarToAbiSnapshot[jar.archivePathCompatible.normalize().absoluteFile] =
|
||||
target.buildDir.get().file(kotlinTask.abiSnapshotRelativePath).get().asFile
|
||||
}
|
||||
|
||||
@@ -414,9 +415,9 @@ internal open class GradleCompilerRunner(
|
||||
internal fun getOrCreateClientFlagFile(log: Logger, projectName: String): File {
|
||||
if (clientIsAliveFlagFile == null || !clientIsAliveFlagFile!!.exists()) {
|
||||
clientIsAliveFlagFile = newTmpFile(prefix = "kotlin-compiler-in-${projectName}-", suffix = ".alive")
|
||||
log.kotlinDebug { CREATED_CLIENT_FILE_PREFIX + clientIsAliveFlagFile!!.canonicalPath }
|
||||
log.kotlinDebug { CREATED_CLIENT_FILE_PREFIX + clientIsAliveFlagFile!!.normalize().absoluteFile }
|
||||
} else {
|
||||
log.kotlinDebug { EXISTING_CLIENT_FILE_PREFIX + clientIsAliveFlagFile!!.canonicalPath }
|
||||
log.kotlinDebug { EXISTING_CLIENT_FILE_PREFIX + clientIsAliveFlagFile!!.normalize().absoluteFile }
|
||||
}
|
||||
|
||||
return clientIsAliveFlagFile!!
|
||||
@@ -437,9 +438,9 @@ internal open class GradleCompilerRunner(
|
||||
if (sessionFlagFile == null || !sessionFlagFile!!.exists()) {
|
||||
val sessionFilesDir = sessionsDir.apply { mkdirs() }
|
||||
sessionFlagFile = newTmpFile(prefix = "kotlin-compiler-", suffix = ".salive", directory = sessionFilesDir)
|
||||
log.kotlinDebug { CREATED_SESSION_FILE_PREFIX + sessionFlagFile!!.relativeOrCanonical(projectCacheDirProvider) }
|
||||
log.kotlinDebug { CREATED_SESSION_FILE_PREFIX + sessionFlagFile!!.relativeOrAbsolute(projectCacheDirProvider) }
|
||||
} else {
|
||||
log.kotlinDebug { EXISTING_SESSION_FILE_PREFIX + sessionFlagFile!!.relativeOrCanonical(projectCacheDirProvider) }
|
||||
log.kotlinDebug { EXISTING_SESSION_FILE_PREFIX + sessionFlagFile!!.relativeOrAbsolute(projectCacheDirProvider) }
|
||||
}
|
||||
|
||||
return sessionFlagFile!!
|
||||
|
||||
+1
-1
@@ -149,7 +149,7 @@ internal class GradleKotlinCompilerWork @Inject constructor(
|
||||
private fun compileWithDaemonOrFallbackImpl(messageCollector: MessageCollector): Pair<ExitCode, KotlinCompilerExecutionStrategy> {
|
||||
with(log) {
|
||||
kotlinDebug { "Kotlin compiler class: ${compilerClassName}" }
|
||||
kotlinDebug { "Kotlin compiler classpath: ${compilerFullClasspath.joinToString { it.canonicalPath }}" }
|
||||
kotlinDebug { "Kotlin compiler classpath: ${compilerFullClasspath.joinToString { it.normalize().absolutePath }}" }
|
||||
kotlinDebug { "$taskPath Kotlin compiler args: ${compilerArgs.joinToString(" ")}" }
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -198,7 +198,7 @@ internal open class ProcessedFilesCache(
|
||||
state.remove(existedTarget)
|
||||
}
|
||||
}
|
||||
state[hash] = Element(file.canonicalPath, key)
|
||||
state[hash] = Element(file.normalize().absolutePath, key)
|
||||
|
||||
return key
|
||||
}
|
||||
|
||||
+1
-1
@@ -57,7 +57,7 @@ internal fun CompilerPluginOptions.withWrappedKaptOptions(
|
||||
subpluginOptionsByPluginId.toMutableMap()
|
||||
|
||||
resultOptionsByPluginId.compute(Kapt3GradleSubplugin.KAPT_SUBPLUGIN_ID) { _, kaptOptions ->
|
||||
val changedFilesOption = changedFiles.map { SubpluginOption("changedFile", it.canonicalPath) }
|
||||
val changedFilesOption = changedFiles.map { SubpluginOption("changedFile", it.normalize().absolutePath) }
|
||||
val classpathChangesOption = classpathChanges.map { SubpluginOption("classpathChange", it) }
|
||||
val processIncrementallyOption = SubpluginOption("processIncrementally", processIncrementally.toString())
|
||||
val compiledSourcesOption =
|
||||
|
||||
+1
-1
@@ -81,7 +81,7 @@ internal abstract class AbstractKotlinPlugin(
|
||||
}
|
||||
|
||||
val inspectTask = project.registerTask<InspectClassesForMultiModuleIC>(INSPECT_IC_CLASSES_TASK_NAME) { inspectTask ->
|
||||
inspectTask.archivePath.set(jarTask.map { it.archivePathCompatible.canonicalPath })
|
||||
inspectTask.archivePath.set(jarTask.map { it.archivePathCompatible.normalize().absolutePath })
|
||||
inspectTask.archivePath.disallowChanges()
|
||||
|
||||
inspectTask.sourceSetName.set(SourceSet.MAIN_SOURCE_SET_NAME)
|
||||
|
||||
+3
-3
@@ -11,7 +11,7 @@ import org.jetbrains.kotlin.compilerRunner.GradleCompilerRunner
|
||||
import org.jetbrains.kotlin.gradle.logging.kotlinDebug
|
||||
import org.jetbrains.kotlin.gradle.plugin.internal.state.TaskExecutionResults
|
||||
import org.jetbrains.kotlin.gradle.plugin.internal.state.TaskLoggers
|
||||
import org.jetbrains.kotlin.gradle.utils.relativeOrCanonical
|
||||
import org.jetbrains.kotlin.gradle.utils.relativeOrAbsolute
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.sumByLong
|
||||
import java.io.File
|
||||
import java.lang.management.ManagementFactory
|
||||
@@ -45,11 +45,11 @@ internal class KotlinGradleFinishBuildHandler {
|
||||
// it is expected that only one session file per build exists
|
||||
// afaik is is not possible to run multiple gradle builds in one project since gradle locks some dirs
|
||||
if (sessionFiles.size > 1) {
|
||||
log.warn("w: Detected multiple Kotlin daemon sessions at ${sessionsDir.relativeOrCanonical(projectCacheDir)}")
|
||||
log.warn("w: Detected multiple Kotlin daemon sessions at ${sessionsDir.relativeOrAbsolute(projectCacheDir)}")
|
||||
}
|
||||
for (file in sessionFiles) {
|
||||
file.delete()
|
||||
log.kotlinDebug { DELETED_SESSION_FILE_PREFIX + file.relativeOrCanonical(projectCacheDir) }
|
||||
log.kotlinDebug { DELETED_SESSION_FILE_PREFIX + file.relativeOrAbsolute(projectCacheDir) }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -168,7 +168,7 @@ class AndroidSubplugin : KotlinCompilerPluginSupportPlugin {
|
||||
buildString {
|
||||
append(name)
|
||||
append(';')
|
||||
resDirectories.map { it.dir }.joinTo(this, separator = ";") { it.canonicalPath }
|
||||
resDirectories.map { it.dir }.joinTo(this, separator = ";") { it.normalize().absolutePath }
|
||||
}
|
||||
}
|
||||
pluginOptions += CompositeSubpluginOption(
|
||||
|
||||
+1
-1
@@ -144,7 +144,7 @@ open class RewriteSourceMapFilterReader(
|
||||
protected open fun transformString(value: String): String {
|
||||
val sourceFileResolved = File(srcSourceRoot)
|
||||
.resolve(value)
|
||||
.canonicalFile
|
||||
.normalize().absoluteFile
|
||||
|
||||
val transformedPath = sourceFileResolved.relativeToOrNull(File(targetSourceRoot))?.path ?: return sourceFileResolved.path
|
||||
|
||||
|
||||
+1
-1
@@ -82,7 +82,7 @@ abstract class KotlinCompileCommon @Inject constructor(
|
||||
|
||||
with(args) {
|
||||
classpath = classpathList.joinToString(File.pathSeparator)
|
||||
destination = destinationDirectory.get().asFile.canonicalPath
|
||||
destination = destinationDirectory.get().asFile.normalize().absolutePath
|
||||
|
||||
friendPaths = this@KotlinCompileCommon.friendPaths.files.map { it.absolutePath }.toTypedArray()
|
||||
refinesPaths = refinesMetadataPaths.map { it.absolutePath }.toTypedArray()
|
||||
|
||||
+2
-2
@@ -33,7 +33,7 @@ import org.jetbrains.kotlin.gradle.dsl.KotlinJsDceCompilerToolOptionsDefault
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinJsDce
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinJsDceOptions
|
||||
import org.jetbrains.kotlin.gradle.logging.GradleKotlinLogger
|
||||
import org.jetbrains.kotlin.gradle.utils.canonicalPathWithoutExtension
|
||||
import org.jetbrains.kotlin.gradle.utils.absolutePathWithoutExtension
|
||||
import org.jetbrains.kotlin.gradle.utils.fileExtensionCasePermutations
|
||||
import org.jetbrains.kotlin.gradle.utils.newInstance
|
||||
import java.io.File
|
||||
@@ -160,7 +160,7 @@ abstract class KotlinJsDce @Inject constructor(
|
||||
return false
|
||||
}
|
||||
|
||||
return File("${file.canonicalPathWithoutExtension()}.meta.js").exists()
|
||||
return File("${file.absolutePathWithoutExtension()}.meta.js").exists()
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
+1
-1
@@ -1150,7 +1150,7 @@ abstract class Kotlin2JsCompile @Inject constructor(
|
||||
|
||||
val dependencies = libraries
|
||||
.filter { it.exists() && libraryFilter(it) }
|
||||
.map { it.canonicalPath }
|
||||
.map { it.normalize().absolutePath }
|
||||
|
||||
args.libraries = dependencies.distinct().let {
|
||||
if (it.isNotEmpty())
|
||||
|
||||
+7
-8
@@ -5,7 +5,6 @@
|
||||
|
||||
package org.jetbrains.kotlin.gradle.utils
|
||||
|
||||
import org.gradle.api.InvalidUserCodeException
|
||||
import org.gradle.api.Project
|
||||
import java.io.File
|
||||
import java.io.IOException
|
||||
@@ -44,17 +43,17 @@ internal fun String.fileExtensionCasePermutations(): List<String> {
|
||||
return result
|
||||
}
|
||||
|
||||
internal fun File.relativeOrCanonical(base: File): String =
|
||||
relativeToOrNull(base)?.path ?: canonicalPath
|
||||
internal fun File.relativeOrAbsolute(base: File): String =
|
||||
relativeToOrNull(base)?.path ?: normalize().absolutePath
|
||||
|
||||
internal fun Iterable<File>.pathsAsStringRelativeTo(base: File): String =
|
||||
map { it.relativeOrCanonical(base) }.sorted().joinToString()
|
||||
map { it.relativeOrAbsolute(base) }.sorted().joinToString()
|
||||
|
||||
internal fun File.relativeToRoot(project: Project): String =
|
||||
relativeOrCanonical(project.rootProject.rootDir)
|
||||
relativeOrAbsolute(project.rootProject.rootDir)
|
||||
|
||||
internal fun Iterable<File>.toPathsArray(): Array<String> =
|
||||
map { it.canonicalPath }.toTypedArray()
|
||||
map { it.normalize().absolutePath }.toTypedArray()
|
||||
|
||||
internal fun newTmpFile(prefix: String, suffix: String? = null, directory: File? = null, deleteOnExit: Boolean = true): File {
|
||||
return try {
|
||||
@@ -82,8 +81,8 @@ internal fun File.isParentOf(childCandidate: File, strict: Boolean = false): Boo
|
||||
}
|
||||
}
|
||||
|
||||
internal fun File.canonicalPathWithoutExtension(): String =
|
||||
canonicalPath.substringBeforeLast(".")
|
||||
internal fun File.absolutePathWithoutExtension(): String =
|
||||
normalize().absolutePath.substringBeforeLast(".")
|
||||
|
||||
internal fun File.listFilesOrEmpty() = (if (exists()) listFiles() else null).orEmpty()
|
||||
|
||||
|
||||
@@ -127,8 +127,8 @@ open class KaptContext(val options: KaptOptions, val withJdk: Boolean, val logge
|
||||
@Suppress("SpellCheckingInspection")
|
||||
putJavacOption("PROCESSORPATH", "PROCESSOR_PATH", options.processingClasspath.makePathsString())
|
||||
|
||||
put(Option.S, options.sourcesOutputDir.canonicalPath)
|
||||
put(Option.D, options.classesOutputDir.canonicalPath)
|
||||
put(Option.S, options.sourcesOutputDir.normalize().absolutePath)
|
||||
put(Option.D, options.classesOutputDir.normalize().absolutePath)
|
||||
put(Option.ENCODING, "UTF-8")
|
||||
}
|
||||
|
||||
@@ -168,6 +168,6 @@ open class KaptContext(val options: KaptOptions, val withJdk: Boolean, val logge
|
||||
companion object {
|
||||
const val MODULE_INFO_FILE = "module-info.java"
|
||||
|
||||
private fun Iterable<File>.makePathsString(): String = joinToString(File.pathSeparator) { it.canonicalPath }
|
||||
private fun Iterable<File>.makePathsString(): String = joinToString(File.pathSeparator) { it.normalize().absolutePath }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -157,7 +157,7 @@ fun KaptOptions.collectJavaSourceFiles(sourcesToReprocess: SourcesToReprocess =
|
||||
.sortedBy { Files.isSymbolicLink(it.toPath()) } // Get non-symbolic paths first
|
||||
.flatMap { root -> root.walk().filter { it.isFile && it.extension == "java" }.toList() }
|
||||
.sortedBy { Files.isSymbolicLink(it.toPath()) } // This time is for .java files
|
||||
.distinctBy { it.canonicalPath }
|
||||
.distinctBy { it.normalize().absolutePath }
|
||||
}
|
||||
|
||||
return when (sourcesToReprocess) {
|
||||
|
||||
@@ -230,7 +230,7 @@ abstract class AbstractKapt3Extension(
|
||||
if (!options.mode.runAnnotationProcessing) return
|
||||
|
||||
val javaSourceFiles = options.collectJavaSourceFiles(kaptContext.sourcesToReprocess)
|
||||
logger.info { "Java source files: " + javaSourceFiles.joinToString { it.canonicalPath } }
|
||||
logger.info { "Java source files: " + javaSourceFiles.joinToString { it.normalize().absolutePath } }
|
||||
|
||||
val (annotationProcessingTime) = measureTimeMillis {
|
||||
kaptContext.doAnnotationProcessing(javaSourceFiles, processors.processors)
|
||||
|
||||
Reference in New Issue
Block a user