From c58c833be98c391007e895896c666ce7f90547b3 Mon Sep 17 00:00:00 2001 From: David Nadlinger Date: Wed, 2 Oct 2013 18:02:41 +0200 Subject: [PATCH 1/2] Trivial indentation fix. --- driver/ldmd.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/driver/ldmd.cpp b/driver/ldmd.cpp index 34d94e6f70..26c665ad73 100644 --- a/driver/ldmd.cpp +++ b/driver/ldmd.cpp @@ -939,7 +939,7 @@ void buildCommandLine(std::vector& r, const Params& p) } /** - * Returns the OS-dependent length limit for the command line when invoking + * Returns the OS-dependent length limit for the command line when invoking * subprocesses. */ size_t maxCommandLineLen() From 7f20de16cf30ab4cae6b30e5aa4f30ffb3054ce2 Mon Sep 17 00:00:00 2001 From: David Nadlinger Date: Wed, 2 Oct 2013 18:09:47 +0200 Subject: [PATCH 2/2] LDMD: Create output directories if they do not exist. There might be other cases using the LLVM output code as well that I haven't handled here, but the changes are sufficient to make LDC work with rdmd on Linux. GitHub: Fixes #480. --- driver/ldmd.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/driver/ldmd.cpp b/driver/ldmd.cpp index 26c665ad73..d3edbce5cd 100644 --- a/driver/ldmd.cpp +++ b/driver/ldmd.cpp @@ -977,6 +977,15 @@ std::string locateBinary(std::string exeName, const char* argv0) return ""; } +/** + * Makes sure the given directory (absolute or relative) exists on disk. + */ +static void createOutputDir(const char* dir) { + bool dirExisted; // ignored + if (ls::fs::create_directories(dir, dirExisted) != llvm::errc::success) + error("Could not create output directory '%s'.", dir); +} + static size_t addStrlen(size_t acc, const char* str) { if (!str) return acc; @@ -1007,6 +1016,19 @@ int main(int argc, char *argv[]) args.push_back(NULL); + // On Linux, DMD creates output directores that don't already exist, while + // LDC does not (and neither does GDC). Do this here for rdmd compatibility. + if (p.objName) + { + llvm::SmallString<256> outputPath(p.objName); + ls::path::remove_filename(outputPath); + if (!outputPath.empty()) + createOutputDir(outputPath.c_str()); + } + + if (p.objDir) + createOutputDir(p.objDir); + // Check if we need to write out a response file. size_t totalLen = std::accumulate(args.begin(), args.end(), 0, addStrlen); if (totalLen > maxCommandLineLen())