Called system <rename> for atomic moving of compiler's output
This commit is contained in:
@@ -105,6 +105,22 @@ kotlinNativeInterop {
|
||||
|
||||
pkg 'org.jetbrains.kotlin.backend.konan.hash'
|
||||
}
|
||||
|
||||
files {
|
||||
if (!project.parent.convention.plugins.platformInfo.isWindows()) {
|
||||
compilerOpts '-fPIC'
|
||||
linkerOpts '-fPIC'
|
||||
}
|
||||
linker 'clang++'
|
||||
linkOutputs ":common:${hostName}Files"
|
||||
|
||||
headers fileTree('../common/src/files/headers') {
|
||||
include '**/*.h'
|
||||
include '**/*.hpp'
|
||||
}
|
||||
|
||||
pkg 'org.jetbrains.kotlin.backend.konan.files'
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -144,6 +160,7 @@ dependencies {
|
||||
compilerCompile kotlinCompilerModule
|
||||
compilerCompile kotlinNativeInterop['llvm'].configuration
|
||||
compilerCompile kotlinNativeInterop['hash'].configuration
|
||||
compilerCompile kotlinNativeInterop['files'].configuration
|
||||
compilerCompile "org.jetbrains.kotlin:kotlin-native-shared:$konanVersion"
|
||||
compilerCompile "org.jetbrains.kotlin:konan.serializer:$konanVersion"
|
||||
|
||||
@@ -229,6 +246,7 @@ jar {
|
||||
from sourceSets.cli_bc.output,
|
||||
sourceSets.compiler.output,
|
||||
sourceSets.hashInteropStubs.output,
|
||||
sourceSets.filesInteropStubs.output,
|
||||
sourceSets.llvmInteropStubs.output
|
||||
|
||||
dependsOn ':runtime:hostRuntime', 'external_jars'
|
||||
|
||||
+2
-1
@@ -5,6 +5,7 @@ import org.jetbrains.kotlin.konan.file.File
|
||||
import org.jetbrains.kotlin.konan.target.CompilerOutputKind
|
||||
import org.jetbrains.kotlin.konan.target.Family
|
||||
import org.jetbrains.kotlin.konan.target.LinkerOutputKind
|
||||
import org.jetbrains.kotlin.backend.konan.files.renameAtomic
|
||||
|
||||
internal fun determineLinkerOutput(context: Context): LinkerOutputKind =
|
||||
when (context.config.produce) {
|
||||
@@ -45,7 +46,7 @@ internal class Linker(val context: Context) {
|
||||
val outputFiles = context.config.outputFiles
|
||||
val outputFile = java.io.File(outputFiles.mainFileMangled)
|
||||
val outputDsymBundle = java.io.File(outputFiles.mainFileMangled + ".dSYM")
|
||||
if (outputFile.renameTo(java.io.File(outputFiles.mainFile)))
|
||||
if (renameAtomic(outputFile.absolutePath, outputFiles.mainFile, /* replaceExisting = */ false))
|
||||
outputDsymBundle.renameTo(java.io.File(outputFiles.mainFile + ".dSYM"))
|
||||
else {
|
||||
outputFile.delete()
|
||||
|
||||
@@ -13,8 +13,16 @@ targetList.each { targetName ->
|
||||
}
|
||||
}
|
||||
|
||||
targetList.each { targetName ->
|
||||
task ("${targetName}Files", type: CompileCppToBitcode) {
|
||||
name 'files'
|
||||
target targetName
|
||||
}
|
||||
}
|
||||
|
||||
task build {
|
||||
dependsOn "${hostName}Hash"
|
||||
dependsOn "${hostName}Files"
|
||||
}
|
||||
|
||||
task clean {
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
#include "Files.h"
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
#ifdef __APPLE__
|
||||
|
||||
bool renameAtomic(const char* from, const char* to, bool replaceExisting) {
|
||||
return renamex_np(from, to, replaceExisting ? 0 : RENAME_EXCL) == 0;
|
||||
}
|
||||
|
||||
#elif _WIN32
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
bool renameAtomic(const char* from, const char* to, bool replaceExisting) {
|
||||
return MoveFileEx(from, to, replaceExisting ? MOVEFILE_REPLACE_EXISTING : 0) != 0;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
#include <unistd.h>
|
||||
#include <sys/syscall.h>
|
||||
#include <linux/fs.h>
|
||||
|
||||
bool renameAtomic(const char* from, const char* to, bool replaceExisting) {
|
||||
return syscall(SYS_renameat2, 0, from, 0, to, replaceExisting ? 0 : RENAME_NOREPLACE) == 0;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
#ifndef COMMON_FILES_H
|
||||
#define COMMON_FILES_H
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
bool renameAtomic(const char* from, const char* to, bool replaceExisting);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // COMMON_FILES_H
|
||||
Reference in New Issue
Block a user