Ninja: build server fixes

- disable cldeps on cygwin
- don't "use" namespace std
This commit is contained in:
Peter Kuemmel 2012-06-16 12:31:50 +02:00
parent f1abdce1cc
commit 57156a5d30
2 changed files with 52 additions and 53 deletions

View File

@ -383,7 +383,7 @@ IF(CMAKE_ENABLE_NINJA)
cmNinjaUtilityTargetGenerator.h cmNinjaUtilityTargetGenerator.h
) )
ADD_DEFINITIONS(-DCMAKE_USE_NINJA) ADD_DEFINITIONS(-DCMAKE_USE_NINJA)
IF(WIN32) IF(WIN32 AND NOT CYGWIN)
SET_SOURCE_FILES_PROPERTIES(cmcldeps.cxx PROPERTIES COMPILE_DEFINITIONS _WIN32_WINNT=0x0501) SET_SOURCE_FILES_PROPERTIES(cmcldeps.cxx PROPERTIES COMPILE_DEFINITIONS _WIN32_WINNT=0x0501)
ADD_EXECUTABLE(cmcldeps cmcldeps.cxx) ADD_EXECUTABLE(cmcldeps cmcldeps.cxx)
INSTALL_TARGETS(/bin cmcldeps) INSTALL_TARGETS(/bin cmcldeps)

View File

@ -24,7 +24,6 @@
#include <queue> #include <queue>
#include <cstdio> #include <cstdio>
using namespace std;
#ifdef _WIN32 #ifdef _WIN32
#include <windows.h> #include <windows.h>
@ -52,16 +51,16 @@ struct Subprocess {
bool Done() const; bool Done() const;
const string& GetOutput() const; const std::string& GetOutput() const;
int ExitCode() const { return exit_code_; } int ExitCode() const { return exit_code_; }
private: private:
Subprocess(); Subprocess();
bool Start(struct SubprocessSet* set, const string& command, const string& dir); bool Start(struct SubprocessSet* set, const std::string& command, const std::string& dir);
void OnPipeReady(); void OnPipeReady();
string buf_; std::string buf_;
#ifdef _WIN32 #ifdef _WIN32
/// Set up pipe_ as the parent-side pipe of the subprocess; return the /// Set up pipe_ as the parent-side pipe of the subprocess; return the
@ -89,13 +88,13 @@ struct SubprocessSet {
SubprocessSet(); SubprocessSet();
~SubprocessSet(); ~SubprocessSet();
Subprocess* Add(const string& command, const string& dir); Subprocess* Add(const std::string& command, const std::string& dir);
bool DoWork(); bool DoWork();
Subprocess* NextFinished(); Subprocess* NextFinished();
void Clear(); void Clear();
vector<Subprocess*> running_; std::vector<Subprocess*> running_;
queue<Subprocess*> finished_; std::queue<Subprocess*> finished_;
#ifdef _WIN32 #ifdef _WIN32
static BOOL WINAPI NotifyInterrupted(DWORD dwCtrlType); static BOOL WINAPI NotifyInterrupted(DWORD dwCtrlType);
@ -137,7 +136,7 @@ static void Fatal(const char* msg, ...) {
#ifdef _WIN32 #ifdef _WIN32
string GetLastErrorString() { std::string GetLastErrorString() {
DWORD err = GetLastError(); DWORD err = GetLastError();
char* msg_buf; char* msg_buf;
@ -151,7 +150,7 @@ string GetLastErrorString() {
(char*)&msg_buf, (char*)&msg_buf,
0, 0,
NULL); NULL);
string msg = msg_buf; std::string msg = msg_buf;
LocalFree(msg_buf); LocalFree(msg_buf);
return msg; return msg;
} }
@ -244,8 +243,8 @@ HANDLE Subprocess::SetupPipe(HANDLE ioport) {
return output_write_child; return output_write_child;
} }
bool Subprocess::Start(SubprocessSet* set, const string& command, bool Subprocess::Start(SubprocessSet* set, const std::string& command,
const string& dir) { const std::string& dir) {
HANDLE child_pipe = SetupPipe(set->ioport_); HANDLE child_pipe = SetupPipe(set->ioport_);
SECURITY_ATTRIBUTES security_attributes; SECURITY_ATTRIBUTES security_attributes;
@ -358,7 +357,7 @@ bool Subprocess::Done() const {
return pipe_ == NULL; return pipe_ == NULL;
} }
const string& Subprocess::GetOutput() const { const std::string& Subprocess::GetOutput() const {
return buf_; return buf_;
} }
@ -389,7 +388,7 @@ BOOL WINAPI SubprocessSet::NotifyInterrupted(DWORD dwCtrlType) {
return FALSE; return FALSE;
} }
Subprocess *SubprocessSet::Add(const string& command, const string& dir) { Subprocess *SubprocessSet::Add(const std::string& command, const std::string& dir) {
Subprocess *subprocess = new Subprocess; Subprocess *subprocess = new Subprocess;
if (!subprocess->Start(this, command, dir)) { if (!subprocess->Start(this, command, dir)) {
delete subprocess; delete subprocess;
@ -420,7 +419,7 @@ bool SubprocessSet::DoWork() {
subproc->OnPipeReady(); subproc->OnPipeReady();
if (subproc->Done()) { if (subproc->Done()) {
vector<Subprocess*>::iterator end = std::vector<Subprocess*>::iterator end =
std::remove(running_.begin(), running_.end(), subproc); std::remove(running_.begin(), running_.end(), subproc);
if (running_.end() != end) { if (running_.end() != end) {
finished_.push(subproc); finished_.push(subproc);
@ -440,14 +439,14 @@ Subprocess* SubprocessSet::NextFinished() {
} }
void SubprocessSet::Clear() { void SubprocessSet::Clear() {
for (vector<Subprocess*>::iterator i = running_.begin(); for (std::vector<Subprocess*>::iterator i = running_.begin();
i != running_.end(); ++i) { i != running_.end(); ++i) {
if ((*i)->child_) if ((*i)->child_)
if (!GenerateConsoleCtrlEvent(CTRL_BREAK_EVENT, if (!GenerateConsoleCtrlEvent(CTRL_BREAK_EVENT,
GetProcessId((*i)->child_))) GetProcessId((*i)->child_)))
Win32Fatal("GenerateConsoleCtrlEvent"); Win32Fatal("GenerateConsoleCtrlEvent");
} }
for (vector<Subprocess*>::iterator i = running_.begin(); for (std::vector<Subprocess*>::iterator i = running_.begin();
i != running_.end(); ++i) i != running_.end(); ++i)
delete *i; delete *i;
running_.clear(); running_.clear();
@ -498,16 +497,16 @@ static void usage(const char* msg) {
"<rest of command ...>\n", msg); "<rest of command ...>\n", msg);
} }
static string trimLeadingSpace(const string& cmdline) { static std::string trimLeadingSpace(const std::string& cmdline) {
int i = 0; int i = 0;
for (; cmdline[i] == ' '; ++i) for (; cmdline[i] == ' '; ++i)
; ;
return cmdline.substr(i); return cmdline.substr(i);
} }
static void doEscape(string& str, const string& search, const string& repl) { static void doEscape(std::string& str, const std::string& search, const std::string& repl) {
string::size_type pos = 0; std::string::size_type pos = 0;
while ((pos = str.find(search, pos)) != string::npos) { while ((pos = str.find(search, pos)) != std::string::npos) {
str.replace(pos, search.size(), repl); str.replace(pos, search.size(), repl);
pos += repl.size(); pos += repl.size();
} }
@ -515,8 +514,8 @@ static void doEscape(string& str, const string& search, const string& repl) {
// Strips one argument from the cmdline and returns it. "surrounding quotes" // Strips one argument from the cmdline and returns it. "surrounding quotes"
// are removed from the argument if there were any. // are removed from the argument if there were any.
static string getArg(string& cmdline) { static std::string getArg(std::string& cmdline) {
string ret; std::string ret;
bool in_quoted = false; bool in_quoted = false;
unsigned int i = 0; unsigned int i = 0;
@ -539,15 +538,15 @@ static string getArg(string& cmdline) {
} }
static void parseCommandLine(LPTSTR wincmdline, static void parseCommandLine(LPTSTR wincmdline,
string& lang, std::string& lang,
string& srcfile, std::string& srcfile,
string& dfile, std::string& dfile,
string& objfile, std::string& objfile,
string& prefix, std::string& prefix,
string& clpath, std::string& clpath,
string& binpath, std::string& binpath,
string& rest) { std::string& rest) {
string cmdline(wincmdline); std::string cmdline(wincmdline);
/* self */ getArg(cmdline); /* self */ getArg(cmdline);
lang = getArg(cmdline); lang = getArg(cmdline);
srcfile = getArg(cmdline); srcfile = getArg(cmdline);
@ -559,8 +558,8 @@ static void parseCommandLine(LPTSTR wincmdline,
rest = trimLeadingSpace(cmdline); rest = trimLeadingSpace(cmdline);
} }
static void outputDepFile(const string& dfile, const string& objfile, static void outputDepFile(const std::string& dfile, const std::string& objfile,
vector<string>& incs) { std::vector<std::string>& incs) {
if (dfile.empty()) if (dfile.empty())
return; return;
@ -575,11 +574,11 @@ static void outputDepFile(const string& dfile, const string& objfile,
if (!out) if (!out)
return; return;
string tmp = objfile; std::string tmp = objfile;
doEscape(tmp, " ", "\\ "); doEscape(tmp, " ", "\\ ");
fprintf(out, "%s: \\\n", tmp.c_str()); fprintf(out, "%s: \\\n", tmp.c_str());
for (vector<string>::iterator i(incs.begin()); i != incs.end(); ++i) { for (std::vector<std::string>::iterator i(incs.begin()); i != incs.end(); ++i) {
tmp = *i; tmp = *i;
doEscape(tmp, "\\", "/"); doEscape(tmp, "\\", "/");
doEscape(tmp, " ", "\\ "); doEscape(tmp, " ", "\\ ");
@ -611,12 +610,12 @@ std::string replace(const std::string& str, const std::string& what,
static int process( const string& srcfilename, static int process( const std::string& srcfilename,
const string& dfile, const std::string& dfile,
const string& objfile, const std::string& objfile,
const string& prefix, const std::string& prefix,
const string& cmd, const std::string& cmd,
const string& dir = "", const std::string& dir = "",
bool quiet = false) { bool quiet = false) {
SubprocessSet subprocs; SubprocessSet subprocs;
@ -632,17 +631,17 @@ static int process( const string& srcfilename,
bool success = subproc->Finish() == ExitSuccess; bool success = subproc->Finish() == ExitSuccess;
int exit_code = subproc->ExitCode(); int exit_code = subproc->ExitCode();
string output = subproc->GetOutput(); std::string output = subproc->GetOutput();
delete subproc; delete subproc;
// process the include directives and output everything else // process the include directives and output everything else
stringstream ss(output); std::stringstream ss(output);
string line; std::string line;
vector<string> includes; std::vector<std::string> includes;
bool isFirstLine = true; // cl prints always first the source filename bool isFirstLine = true; // cl prints always first the source filename
while (getline(ss, line)) { while (getline(ss, line)) {
if (startsWith(line, prefix)) { if (startsWith(line, prefix)) {
string inc = trimLeadingSpace(line.substr(prefix.size()).c_str()); std::string inc = trimLeadingSpace(line.substr(prefix.size()).c_str());
if (inc[inc.size() - 1] == '\r') // blech, stupid \r\n if (inc[inc.size() - 1] == '\r') // blech, stupid \r\n
inc = inc.substr(0, inc.size() - 1); inc = inc.substr(0, inc.size() - 1);
includes.push_back(inc); includes.push_back(inc);
@ -676,14 +675,14 @@ int main() {
// subprocesses, so by avoiding argc/argv, the subprocess is called with // subprocesses, so by avoiding argc/argv, the subprocess is called with
// the same command line verbatim. // the same command line verbatim.
string lang, srcfile, dfile, objfile, prefix, cl, binpath, rest; std::string lang, srcfile, dfile, objfile, prefix, cl, binpath, rest;
parseCommandLine(GetCommandLine(), lang, srcfile, dfile, objfile, parseCommandLine(GetCommandLine(), lang, srcfile, dfile, objfile,
prefix, cl, binpath, rest); prefix, cl, binpath, rest);
// needed to suppress filename output of msvc tools // needed to suppress filename output of msvc tools
string srcfilename; std::string srcfilename;
std::string::size_type pos = srcfile.rfind("\\"); std::string::size_type pos = srcfile.rfind("\\");
if (pos != string::npos) { if (pos != std::string::npos) {
srcfilename = srcfile.substr(pos + 1); srcfilename = srcfile.substr(pos + 1);
} }
@ -695,7 +694,7 @@ int main() {
} else if (lang == "RC") { } else if (lang == "RC") {
// "misuse" cl.exe to get headers from .rc files // "misuse" cl.exe to get headers from .rc files
string clrest = rest; std::string clrest = rest;
// rc: /fo x.dir\x.rc.res -> cl: /out:x.dir\x.rc.res.dep.obj // rc: /fo x.dir\x.rc.res -> cl: /out:x.dir\x.rc.res.dep.obj
clrest = replace(clrest, "/fo", "/out:"); clrest = replace(clrest, "/fo", "/out:");
clrest = replace(clrest, objfile, objfile + ".dep.obj "); clrest = replace(clrest, objfile, objfile + ".dep.obj ");
@ -705,9 +704,9 @@ int main() {
cl = "\"" + cl + "\" /P /DRC_INVOKED "; cl = "\"" + cl + "\" /P /DRC_INVOKED ";
// call cl in object dir so the .i is generated there // call cl in object dir so the .i is generated there
string objdir; std::string objdir;
std::string::size_type pos = objfile.rfind("\\"); std::string::size_type pos = objfile.rfind("\\");
if (pos != string::npos) { if (pos != std::string::npos) {
objdir = objfile.substr(0, pos); objdir = objfile.substr(0, pos);
} }