Don't call File.getCanonicalPath in KGP
Relates to KT-54579.
This commit is contained in:
+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()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user