mirror of
https://github.com/ldc-developers/ldc.git
synced 2025-05-10 12:59:21 +03:00
Merge pull request #1470 from JohanEngelen/random_file
Use random output filenames for `-run`.
This commit is contained in:
commit
4515033381
2 changed files with 68 additions and 26 deletions
|
@ -70,18 +70,32 @@ static std::string getOutputName(bool const sharedLib) {
|
|||
} else {
|
||||
result = "a.out";
|
||||
}
|
||||
|
||||
const char *extension = nullptr;
|
||||
if (sharedLib) {
|
||||
std::string libExt = std::string(".") + global.dll_ext;
|
||||
if (!endsWith(result, libExt)) {
|
||||
if (global.params.targetTriple->getOS() != llvm::Triple::Win32) {
|
||||
result = "lib" + result + libExt;
|
||||
} else {
|
||||
result.append(libExt);
|
||||
}
|
||||
extension = global.dll_ext;
|
||||
if (global.params.targetTriple->getOS() != llvm::Triple::Win32) {
|
||||
result = "lib" + result;
|
||||
}
|
||||
} else if (global.params.targetTriple->isOSWindows()) {
|
||||
extension = "exe";
|
||||
}
|
||||
|
||||
if (global.params.run) {
|
||||
// If `-run` is passed, the executable is temporary and is removed
|
||||
// after execution. Make sure the name does not collide with other files
|
||||
// from other processes by creating a unique filename.
|
||||
llvm::SmallString<128> tempFilename;
|
||||
auto EC = llvm::sys::fs::createTemporaryFile(
|
||||
result, extension ? extension : "", tempFilename);
|
||||
if (!EC) {
|
||||
result = tempFilename.str();
|
||||
}
|
||||
} else {
|
||||
if (extension) {
|
||||
result += ".";
|
||||
result += extension;
|
||||
}
|
||||
} else if (global.params.targetTriple->isOSWindows() &&
|
||||
!endsWith(result, ".exe")) {
|
||||
result.append(".exe");
|
||||
}
|
||||
|
||||
return result;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue