mirror of
https://github.com/ldc-developers/ldc.git
synced 2025-05-05 09:31:03 +03:00
Merge pull request #482 from klickverbot/ldmd-create-directory
LDMD: Create output directories if they do not exist.
This commit is contained in:
commit
ca82589e25
1 changed files with 23 additions and 1 deletions
|
@ -939,7 +939,7 @@ void buildCommandLine(std::vector<const char*>& 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.
|
* subprocesses.
|
||||||
*/
|
*/
|
||||||
size_t maxCommandLineLen()
|
size_t maxCommandLineLen()
|
||||||
|
@ -977,6 +977,15 @@ std::string locateBinary(std::string exeName, const char* argv0)
|
||||||
return "";
|
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)
|
static size_t addStrlen(size_t acc, const char* str)
|
||||||
{
|
{
|
||||||
if (!str) return acc;
|
if (!str) return acc;
|
||||||
|
@ -1007,6 +1016,19 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
args.push_back(NULL);
|
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.
|
// Check if we need to write out a response file.
|
||||||
size_t totalLen = std::accumulate(args.begin(), args.end(), 0, addStrlen);
|
size_t totalLen = std::accumulate(args.begin(), args.end(), 0, addStrlen);
|
||||||
if (totalLen > maxCommandLineLen())
|
if (totalLen > maxCommandLineLen())
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue