Mercurial > projects > ldc
comparison dmd/module.c @ 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 | 7af860e4f403 |
children | def7a1d494fd |
comparison
equal
deleted
inserted
replaced
1563:b0a691de8cc7 | 1564:68dea5bae9e9 |
---|---|
44 #include "d-dmd-gcc.h" | 44 #include "d-dmd-gcc.h" |
45 #endif | 45 #endif |
46 | 46 |
47 | 47 |
48 #include "llvm/Support/CommandLine.h" | 48 #include "llvm/Support/CommandLine.h" |
49 #include <map> | |
49 | 50 |
50 static llvm::cl::opt<bool> preservePaths("op", | 51 static llvm::cl::opt<bool> preservePaths("op", |
51 llvm::cl::desc("Do not strip paths from source file"), | 52 llvm::cl::desc("Do not strip paths from source file"), |
52 llvm::cl::ZeroOrMore); | 53 llvm::cl::ZeroOrMore); |
53 | 54 |
199 return new File((char*)argobj); | 200 return new File((char*)argobj); |
200 #endif | 201 #endif |
201 return new File(FileName::forceExt(argobj, ext)); | 202 return new File(FileName::forceExt(argobj, ext)); |
202 } | 203 } |
203 | 204 |
205 // LDC | |
206 static void check_and_add_output_file(Module* NewMod, const std::string& str) | |
207 { | |
208 typedef std::map<std::string, Module*> map_t; | |
209 static map_t files; | |
210 | |
211 map_t::iterator i = files.find(str); | |
212 if (i != files.end()) | |
213 { | |
214 Module* ThisMod = i->second; | |
215 error("Output file '%s' for module '%s' collides with previous module '%s'. See the -oq option", | |
216 str.c_str(), NewMod->toPrettyChars(), ThisMod->toPrettyChars()); | |
217 fatal(); | |
218 } | |
219 files.insert(std::make_pair(str, NewMod)); | |
220 } | |
221 | |
204 void Module::buildTargetFiles() | 222 void Module::buildTargetFiles() |
205 { | 223 { |
206 if(objfile && | 224 if(objfile && |
207 (!doDocComment || docfile) && | 225 (!doDocComment || docfile) && |
208 (!doHdrGen || hdrfile)) | 226 (!doHdrGen || hdrfile)) |
229 if(hdrfile && stricmp(FileName::name(hdrfile->name->str), FileName::name((char*)this->arg)) == 0) | 247 if(hdrfile && stricmp(FileName::name(hdrfile->name->str), FileName::name((char*)this->arg)) == 0) |
230 { | 248 { |
231 error("Output header files with the same name as the source file are forbidden"); | 249 error("Output header files with the same name as the source file are forbidden"); |
232 fatal(); | 250 fatal(); |
233 } | 251 } |
252 | |
253 // LDC | |
254 // another safety check to make sure we don't overwrite previous output files | |
255 check_and_add_output_file(this, objfile->name->str); | |
256 if (docfile) | |
257 check_and_add_output_file(this, docfile->name->str); | |
258 if (hdrfile) | |
259 check_and_add_output_file(this, hdrfile->name->str); | |
234 } | 260 } |
235 | 261 |
236 void Module::deleteObjFile() | 262 void Module::deleteObjFile() |
237 { | 263 { |
238 if (global.params.obj) | 264 if (global.params.obj) |