Ninja: onyl use pre processor for rc file parsing

This commit is contained in:
Peter Kuemmel 2012-06-13 19:20:01 +02:00
parent 4b43999ca3
commit ab8a2a57f2
1 changed files with 12 additions and 16 deletions

View File

@ -604,7 +604,8 @@ bool contains(const std::string& str, const std::string& what) {
return str.find(what) != std::string::npos; return str.find(what) != std::string::npos;
} }
std::string replace(const std::string& str, const std::string& what, const std::string& replacement) { std::string replace(const std::string& str, const std::string& what,
const std::string& replacement) {
size_t pos = str.find(what); size_t pos = str.find(what);
if (pos == std::string::npos) if (pos == std::string::npos)
return str; return str;
@ -614,12 +615,12 @@ std::string replace(const std::string& str, const std::string& what, const std::
static int process(bool ignoreErrors, static int process( const string& srcfile,
const string& srcfile,
const string& dfile, const string& dfile,
const string& objfile, const string& objfile,
const string& prefix, const string& prefix,
const string& cmd) { const string& cmd,
bool quiet = false) {
SubprocessSet subprocs; SubprocessSet subprocs;
Subprocess* subproc = subprocs.Add(cmd); Subprocess* subproc = subprocs.Add(cmd);
@ -652,8 +653,7 @@ static int process(bool ignoreErrors,
} }
} else { } else {
if (!isFirstLine || !startsWith(line, srcfile)) { if (!isFirstLine || !startsWith(line, srcfile)) {
if (!ignoreErrors) { if (!quiet) {
// suppress errors when cl is fed with a rc file
fprintf(stdout, "%s\n", line.c_str()); fprintf(stdout, "%s\n", line.c_str());
} }
} else { } else {
@ -663,10 +663,6 @@ static int process(bool ignoreErrors,
} }
if (!success) { if (!success) {
if (ignoreErrors) {
//printf("\n-- RC file %i dependencies in %s\n\n", includes.size(), dfile.c_str());
outputDepFile(dfile, objfile, includes);
}
return exit_code; return exit_code;
} }
@ -699,19 +695,19 @@ int main() {
#endif #endif
if (lang != "RC") { if (lang != "RC") {
return process(false, srcfile, dfile, objfile, prefix, binpath + " /showIncludes " + rest); return process(srcfile, dfile, objfile, prefix,
binpath + " /showIncludes " + rest);
} else { } else {
// "misuse" cl.exe to get headers from .rc files // "misuse" cl.exe to get headers from .rc files
// rc: /fo x\CMakeFiles\x.dir\x.rc.res src\x\x.rc // rc: /fo x\CMakeFiles\x.dir\x.rc.res src\x\x.rc
// cl: /out:x\CMakeFiles\x.dir\x.rc.res.dep.obj /Tc src\x\x.rc // cl: /out:x\CMakeFiles\x.dir\x.rc.res.dep.obj /Tc src\x\x.rc
cl = "\"" + cl + "\" /showIncludes "; cl = "\"" + cl + "\" /P /DRC_INVOKED /showIncludes " +
string clRest = rest; replace(rest, "/fo" + objfile, "/out:" + objfile + ".dep.obj /Tc ");
clRest = replace(clRest, "/fo" + objfile, "/out:" + objfile + ".dep.obj /Tc ");
int ret; int ret;
ret = process(true, srcfile, dfile, objfile, prefix, cl + clRest); ret = process(srcfile, dfile, objfile, prefix, cl, true);
ret = process(false, srcfile, "" , objfile, prefix, binpath + " " + rest); ret = process(srcfile, "" , objfile, prefix, binpath + " " + rest);
return ret; return ret;
} }