Avoid generating too long path for temp module file
#KT-21841 fixed
Original commit: 37b00b91fc
This commit is contained in:
+24
-3
@@ -39,6 +39,7 @@ import org.jetbrains.kotlin.modules.TargetId
|
||||
import org.jetbrains.kotlin.utils.addIfNotNull
|
||||
import org.jetbrains.kotlin.utils.alwaysNull
|
||||
import java.io.File
|
||||
import java.io.IOException
|
||||
import java.lang.reflect.Method
|
||||
import java.util.*
|
||||
|
||||
@@ -126,13 +127,33 @@ object KotlinBuilderModuleScriptGenerator {
|
||||
|
||||
if (noSources) return null
|
||||
|
||||
val scriptFile = File.createTempFile("kjps", StringUtil.sanitizeJavaIdentifier(chunk.name) + ".script.xml")
|
||||
|
||||
val scriptFile = createTempFileForModuleDesc(chunk)
|
||||
FileUtil.writeToFile(scriptFile, builder.asText().toString())
|
||||
|
||||
return scriptFile
|
||||
}
|
||||
|
||||
private fun createTempFileForModuleDesc(chunk: ModuleChunk): File {
|
||||
val readableSuffix = buildString {
|
||||
append(StringUtil.sanitizeJavaIdentifier(chunk.representativeTarget().module.name))
|
||||
if (chunk.containsTests()) {
|
||||
append("-test")
|
||||
}
|
||||
}
|
||||
return try {
|
||||
File.createTempFile("kjps", readableSuffix + ".script.xml")
|
||||
}
|
||||
catch (e: IOException) {
|
||||
// sometimes files cannot be created, because file name is too long (Windows, Mac OS)
|
||||
// see https://bugs.openjdk.java.net/browse/JDK-8148023
|
||||
try {
|
||||
File.createTempFile("kjps", ".script.xml")
|
||||
}
|
||||
catch (e: IOException) {
|
||||
throw RuntimeException("Could not create module file when building $chunk", e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun getOutputDirSafe(target: ModuleBuildTarget): File =
|
||||
target.outputDir ?: throw ProjectBuildException("No output directory found for " + target)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user