Use Files API for creating temp files and directories
(cherry picked from commit b9df8591d043c79f2032b782efc7539c747c2625)
This commit is contained in:
committed by
Stanislav Erokhin
parent
a15d82c698
commit
bf4e53ae06
+3
-2
@@ -2,6 +2,7 @@ package org.jetbrains.kotlin.native.interop.indexer
|
||||
|
||||
import clang.*
|
||||
import kotlinx.cinterop.*
|
||||
import java.nio.file.Files
|
||||
|
||||
data class ModulesInfo(val topLevelHeaders: List<String>, val ownHeaders: Set<String>)
|
||||
|
||||
@@ -39,13 +40,13 @@ internal open class ModularCompilation(compilation: Compilation): Compilation by
|
||||
}
|
||||
|
||||
private val moduleCacheDirectory = if (compilation.compilerArgs.none { it.startsWith(moduleCacheFlag) }) {
|
||||
createTempDir("ModuleCache")
|
||||
Files.createTempDirectory("ModuleCache").toAbsolutePath().toFile()
|
||||
} else {
|
||||
null
|
||||
}
|
||||
|
||||
override val compilerArgs: List<String> = compilation.compilerArgs +
|
||||
listOfNotNull("-fmodules", moduleCacheDirectory?.let { "$moduleCacheFlag${it.absolutePath}" })
|
||||
listOfNotNull("-fmodules", moduleCacheDirectory?.let { "$moduleCacheFlag${it}" })
|
||||
|
||||
override fun dispose() {
|
||||
moduleCacheDirectory?.deleteRecursively()
|
||||
|
||||
+7
-9
@@ -100,7 +100,7 @@ internal fun parseTranslationUnit(
|
||||
)
|
||||
|
||||
if (errorCode != CXErrorCode.CXError_Success) {
|
||||
val copiedSourceFile = sourceFile.copyTo(createTempFile(suffix = sourceFile.name), overwrite = true)
|
||||
val copiedSourceFile = sourceFile.copyTo(Files.createTempFile(null, sourceFile.name).toFile(), overwrite = true)
|
||||
|
||||
error("""
|
||||
clang_parseTranslationUnit2 failed with $errorCode;
|
||||
@@ -241,7 +241,7 @@ internal fun Appendable.appendPreamble(compilation: Compilation) = this.apply {
|
||||
* Creates temporary source file which includes the library.
|
||||
*/
|
||||
internal fun Compilation.createTempSource(): File {
|
||||
val result = createTempFile(suffix = ".${language.sourceFileExtension}")
|
||||
val result = Files.createTempFile(null, ".${language.sourceFileExtension}").toFile()
|
||||
result.deleteOnExit()
|
||||
|
||||
result.bufferedWriter().use { writer ->
|
||||
@@ -292,7 +292,7 @@ fun Compilation.precompileHeaders(): CompilationWithPCH = withIndex { index ->
|
||||
}
|
||||
|
||||
internal fun Compilation.withPrecompiledHeader(translationUnit: CXTranslationUnit): CompilationWithPCH {
|
||||
val precompiledHeader = createTempFile(suffix = ".pch").apply { this.deleteOnExit() }
|
||||
val precompiledHeader = Files.createTempFile(null, ".pch").toFile().apply { this.deleteOnExit() }
|
||||
clang_saveTranslationUnit(translationUnit, precompiledHeader.absolutePath, 0)
|
||||
|
||||
return CompilationWithPCH(this.compilerArgs, precompiledHeader.absolutePath, this.language)
|
||||
@@ -740,12 +740,10 @@ private fun createVfsOverlayFileContents(virtualPathToReal: Map<Path, Path>): By
|
||||
fun createVfsOverlayFile(virtualPathToReal: Map<Path, Path>): Path {
|
||||
val bytes = createVfsOverlayFileContents(virtualPathToReal)
|
||||
|
||||
return createTempFile(prefix = "konan", suffix = ".vfsoverlay").apply {
|
||||
bufferedWriter().use {
|
||||
writeBytes(bytes)
|
||||
}
|
||||
deleteOnExit()
|
||||
}.toPath()
|
||||
return Files.createTempFile("konan", ".vfsoverlay").also {
|
||||
Files.write(it, bytes)
|
||||
it.toFile().deleteOnExit()
|
||||
}
|
||||
}
|
||||
|
||||
tailrec fun Type.unwrapTypedefs(): Type = if (this is Typedef) {
|
||||
|
||||
@@ -98,7 +98,7 @@ fun loadKonanLibrary(name: String) {
|
||||
try {
|
||||
System.load("$dir/$fullLibraryName")
|
||||
} catch (e: UnsatisfiedLinkError) {
|
||||
val tempDir = createTempDir(directory = File(dir)).absolutePath
|
||||
val tempDir = Files.createTempDirectory(Paths.get(dir), null).toAbsolutePath().toString()
|
||||
Files.createLink(Paths.get(tempDir, fullLibraryName), Paths.get(dir, fullLibraryName))
|
||||
// TODO: Does not work on Windows. May be use FILE_FLAG_DELETE_ON_CLOSE?
|
||||
File(tempDir).deleteOnExit()
|
||||
|
||||
Reference in New Issue
Block a user