# HG changeset patch # User Tomas Lindquist Olsen # Date 1249231027 -7200 # Node ID 68dea5bae9e9cbf45c1be28c1a7e65fd64b2434c # Parent b0a691de8cc71f7991c3dc143a81935188415e8a Added check and error in case two same named modules - with different packages and compiled at once - would overwrite each other's output files. diff -r b0a691de8cc7 -r 68dea5bae9e9 dmd/module.c --- 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 static llvm::cl::opt 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 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()