Streamline output filenames and -singleObj behavior some more with DMD

This commit is contained in:
Martin 2016-08-31 23:26:06 +02:00
parent c748eb9ed0
commit 6c03a3d725
4 changed files with 57 additions and 50 deletions

View file

@ -56,13 +56,8 @@ static void CreateDirectoryOnDisk(llvm::StringRef fileName) {
//////////////////////////////////////////////////////////////////////////////
static std::string getOutputName(bool const sharedLib) {
if (!sharedLib && global.params.exefile) {
if (global.params.exefile)
return global.params.exefile;
}
if (sharedLib && global.params.objname) {
return global.params.objname;
}
// Output name is inferred.
std::string result;
@ -71,8 +66,7 @@ static std::string getOutputName(bool const sharedLib) {
if (Module::rootModule) {
result = Module::rootModule->toChars();
} else if (global.params.objfiles->dim) {
result = FileName::removeExt(
static_cast<const char *>(global.params.objfiles->data[0]));
result = FileName::removeExt((*global.params.objfiles)[0]);
} else {
result = "a.out";
}
@ -80,9 +74,8 @@ static std::string getOutputName(bool const sharedLib) {
const char *extension = nullptr;
if (sharedLib) {
extension = global.dll_ext;
if (global.params.targetTriple->getOS() != llvm::Triple::Win32) {
if (!global.params.mscoff)
result = "lib" + result;
}
} else if (global.params.targetTriple->isOSWindows()) {
extension = "exe";
}
@ -92,11 +85,11 @@ static std::string getOutputName(bool const sharedLib) {
// 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) {
auto EC = llvm::sys::fs::createTemporaryFile(FileName::name(result.c_str()),
extension ? extension : "",
tempFilename);
if (!EC)
result = tempFilename.str();
}
} else {
if (extension) {
result += ".";
@ -721,28 +714,23 @@ int createStaticLibrary() {
// output filename
std::string libName;
if (global.params.objname) { // explicit
libName = global.params.objname;
if (global.params.libname) { // explicit
libName = global.params.libname;
} else { // inferred
// try root module name
if (Module::rootModule) {
libName = Module::rootModule->toChars();
} else if (global.params.objfiles->dim) {
libName = FileName::removeExt(
static_cast<const char *>(global.params.objfiles->data[0]));
libName = FileName::removeExt((*global.params.objfiles)[0]);
} else {
libName = "a.out";
}
libName.push_back('.');
libName.append(global.lib_ext);
}
// KN: The following lines were added to fix a test case failure
// (runnable/test13774.sh).
// Root cause is that dmd handles it in this why.
// As a side effect this change broke compiling with dub.
// if (!FileName::absolute(libName.c_str()))
// libName = FileName::combine(global.params.objdir, libName.c_str());
if (llvm::sys::path::extension(libName).empty()) {
libName.append(std::string(".") + global.lib_ext);
}
if (global.params.objdir && !FileName::absolute(libName.c_str()))
libName = FileName::combine(global.params.objdir, libName.c_str());
if (isTargetWindows) {
args.push_back("/OUT:" + libName);
} else {
@ -750,10 +738,8 @@ int createStaticLibrary() {
}
// object files
for (unsigned i = 0; i < global.params.objfiles->dim; i++) {
const char *p = static_cast<const char *>(global.params.objfiles->data[i]);
args.push_back(p);
}
for (unsigned i = 0; i < global.params.objfiles->dim; i++)
args.push_back((*global.params.objfiles)[i]);
// create path to the library
CreateDirectoryOnDisk(libName);