Mercurial > projects > ldc
changeset 1564:68dea5bae9e9
Added check and error in case two same named modules - with different packages and compiled at once - would overwrite each other's output files.
author | Tomas Lindquist Olsen <tomas.l.olsen gmail com> |
---|---|
date | Sun, 02 Aug 2009 18:37:07 +0200 |
parents | b0a691de8cc7 |
children | b1e5f8001904 |
files | dmd/module.c |
diffstat | 1 files changed, 26 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/dmd/module.c Sun Aug 02 17:56:30 2009 +0200 +++ b/dmd/module.c Sun Aug 02 18:37:07 2009 +0200 @@ -46,6 +46,7 @@ #include "llvm/Support/CommandLine.h" +#include <map> static llvm::cl::opt<bool> preservePaths("op", llvm::cl::desc("Do not strip paths from source file"), @@ -201,6 +202,23 @@ return new File(FileName::forceExt(argobj, ext)); } +// LDC +static void check_and_add_output_file(Module* NewMod, const std::string& str) +{ + typedef std::map<std::string, Module*> map_t; + static map_t files; + + map_t::iterator i = files.find(str); + if (i != files.end()) + { + Module* ThisMod = i->second; + error("Output file '%s' for module '%s' collides with previous module '%s'. See the -oq option", + str.c_str(), NewMod->toPrettyChars(), ThisMod->toPrettyChars()); + fatal(); + } + files.insert(std::make_pair(str, NewMod)); +} + void Module::buildTargetFiles() { if(objfile && @@ -231,6 +249,14 @@ error("Output header files with the same name as the source file are forbidden"); fatal(); } + + // LDC + // another safety check to make sure we don't overwrite previous output files + check_and_add_output_file(this, objfile->name->str); + if (docfile) + check_and_add_output_file(this, docfile->name->str); + if (hdrfile) + check_and_add_output_file(this, hdrfile->name->str); } void Module::deleteObjFile()