Strip path when inferring exe/lib name from first object file

This is what DMD does and crucial for `ldmd2 -od=objects foo.d` with
relative -od path (and no -of). The object file path will be
`objects/foo.o[bj]`. As it's relative, LDC used to prepend the objects
dir (again) in LDMD mode, resulting in the inferred executable file name
`objects/objects/foo[.exe]`.

So while this is a breaking change, it fixes DMD compatibility of LDMD
and makes a lot of sense for 'pure' LDC too IMO (use the first object's
file name, replace the extension and save it in the working dir, not in
the directory containing the first object file).

This fixes the dmd-testsuite regressions with relative RESULTS_DIR and
a few long-standing non-fatal dmd-testsuite errors (failing file
removals).
This commit is contained in:
Martin 2018-01-25 03:09:32 +01:00
parent 0896d38d2d
commit fd9c1d1b72
2 changed files with 10 additions and 9 deletions

View file

@ -338,8 +338,9 @@ int createStaticLibrary() {
? FileName::defaultExt(global.params.libname, global.lib_ext)
: global.params.libname;
} else { // infer from first object file
libName = global.params.objfiles.dim
? FileName::removeExt(global.params.objfiles[0])
libName =
global.params.objfiles.dim
? FileName::removeExt(FileName::name(global.params.objfiles[0]))
: "a.out";
libName += '.';
libName += global.lib_ext;

View file

@ -60,8 +60,9 @@ static std::string getOutputName() {
}
// Infer output name from first object file.
std::string result = global.params.objfiles.dim
? FileName::removeExt(global.params.objfiles[0])
std::string result =
global.params.objfiles.dim
? FileName::removeExt(FileName::name(global.params.objfiles[0]))
: "a.out";
if (sharedLib && !triple.isWindowsMSVCEnvironment())
@ -72,9 +73,8 @@ static std::string getOutputName() {
// 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(FileName::name(result.c_str()),
extension ? extension : "",
tempFilename);
auto EC = llvm::sys::fs::createTemporaryFile(
result, extension ? extension : "", tempFilename);
if (!EC)
result = tempFilename.str();
} else if (extension) {