mirror of
https://github.com/ldc-developers/ldc.git
synced 2025-05-07 19:36:06 +03:00
Streamline output filenames and -singleObj behavior some more with DMD
This commit is contained in:
parent
c748eb9ed0
commit
6c03a3d725
4 changed files with 57 additions and 50 deletions
|
@ -1297,18 +1297,10 @@ extern (C++) int mars_mainBody(ref Strings files, ref Strings libmodules)
|
|||
continue;
|
||||
}
|
||||
if (FileName.equals(ext, "exe"))
|
||||
{
|
||||
version (IN_LLVM)
|
||||
{
|
||||
global.params.exefile = files[i];
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
assert(0); // should have already been handled
|
||||
}
|
||||
}
|
||||
}
|
||||
/* Examine extension to see if it is a valid
|
||||
* D source file extension
|
||||
*/
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -645,16 +645,34 @@ static void parseCommandLine(int argc, char **argv, Strings &sourceFiles,
|
|||
mRelocModel = llvm::Reloc::PIC_;
|
||||
}
|
||||
|
||||
if (global.params.link && !global.params.dll) {
|
||||
if (global.params.link) {
|
||||
global.params.exefile = global.params.objname;
|
||||
if (sourceFiles.dim > 1) {
|
||||
global.params.objname = nullptr;
|
||||
global.params.oneobj = true;
|
||||
if (global.params.objname) {
|
||||
/* Use this to name the one object file with the same
|
||||
* name as the exe file.
|
||||
*/
|
||||
global.params.objname =
|
||||
FileName::forceExt(global.params.objname, global.obj_ext);
|
||||
/* If output directory is given, use that path rather than
|
||||
* the exe file path.
|
||||
*/
|
||||
if (global.params.objdir) {
|
||||
const char *name = FileName::name(global.params.objname);
|
||||
global.params.objname = FileName::combine(global.params.objdir, name);
|
||||
}
|
||||
}
|
||||
} else if (global.params.run) {
|
||||
error(Loc(), "flags conflict with -run");
|
||||
} else if (global.params.objname && sourceFiles.dim > 1) {
|
||||
if (!(global.params.lib || global.params.dll) && !global.params.oneobj) {
|
||||
error(Loc(), "multiple source files, but only one .obj name");
|
||||
fatal();
|
||||
} else if (global.params.lib) {
|
||||
global.params.libname = global.params.objname;
|
||||
global.params.objname = nullptr;
|
||||
} else {
|
||||
if (global.params.objname && sourceFiles.dim > 1) {
|
||||
global.params.oneobj = true;
|
||||
// error("multiple source files, but only one .obj name");
|
||||
// fatal();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -358,7 +358,8 @@ void writeObjectFile(llvm::Module *m, std::string &filename) {
|
|||
codegenModule(*gTargetMachine, *m, out,
|
||||
llvm::TargetMachine::CGFT_ObjectFile);
|
||||
} else {
|
||||
error(Loc(), "cannot write object file: %s", ERRORINFO_STRING(errinfo));
|
||||
error(Loc(), "cannot write object file '%s': %s", filename.c_str(),
|
||||
ERRORINFO_STRING(errinfo));
|
||||
fatal();
|
||||
}
|
||||
}
|
||||
|
@ -399,6 +400,16 @@ void writeModule(llvm::Module *m, std::string filename) {
|
|||
// eventually do our own path stuff, dmd's is a bit strange.
|
||||
using LLPath = llvm::SmallString<128>;
|
||||
|
||||
// make sure the output directory exists
|
||||
const auto directory = llvm::sys::path::parent_path(filename);
|
||||
if (!directory.empty()) {
|
||||
if (auto ec = llvm::sys::fs::create_directories(directory)) {
|
||||
error(Loc(), "failed to create output directory: %s\n%s",
|
||||
directory.data(), ec.message().c_str());
|
||||
fatal();
|
||||
}
|
||||
}
|
||||
|
||||
// write LLVM bitcode
|
||||
if (global.params.output_bc) {
|
||||
LLPath bcpath(filename);
|
||||
|
@ -418,11 +429,11 @@ void writeModule(llvm::Module *m, std::string filename) {
|
|||
if (global.params.output_ll) {
|
||||
LLPath llpath(filename);
|
||||
llvm::sys::path::replace_extension(llpath, global.ll_ext);
|
||||
Logger::println("Writing LLVM asm to: %s\n", llpath.c_str());
|
||||
Logger::println("Writing LLVM IR to: %s\n", llpath.c_str());
|
||||
LLErrorInfo errinfo;
|
||||
llvm::raw_fd_ostream aos(llpath.c_str(), errinfo, llvm::sys::fs::F_None);
|
||||
if (aos.has_error()) {
|
||||
error(Loc(), "cannot write LLVM asm file '%s': %s", llpath.c_str(),
|
||||
error(Loc(), "cannot write LLVM IR file '%s': %s", llpath.c_str(),
|
||||
ERRORINFO_STRING(errinfo));
|
||||
fatal();
|
||||
}
|
||||
|
@ -438,7 +449,7 @@ void writeModule(llvm::Module *m, std::string filename) {
|
|||
llvm::sys::fs::createUniqueFile("ldc-%%%%%%%.s", spath);
|
||||
}
|
||||
|
||||
Logger::println("Writing native asm to: %s\n", spath.c_str());
|
||||
Logger::println("Writing asm to: %s\n", spath.c_str());
|
||||
LLErrorInfo errinfo;
|
||||
{
|
||||
llvm::raw_fd_ostream out(spath.c_str(), errinfo, llvm::sys::fs::F_None);
|
||||
|
@ -451,7 +462,7 @@ void writeModule(llvm::Module *m, std::string filename) {
|
|||
codegenModule(*gTargetMachine, *m, out,
|
||||
llvm::TargetMachine::CGFT_AssemblyFile);
|
||||
} else {
|
||||
error(Loc(), "cannot write native asm: %s", ERRORINFO_STRING(errinfo));
|
||||
error(Loc(), "cannot write asm: %s", ERRORINFO_STRING(errinfo));
|
||||
fatal();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue