Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Fix" to Compile on OS X as well as "Waiting on" messages from todo list #3

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/ninja.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "graphviz.h"

// Import browse.py as binary data.
#if !defined(__APPLE__)
asm(
".data\n"
"browse_data_begin:\n"
Expand All @@ -38,6 +39,7 @@ asm(
// Declare the symbols defined above.
extern const char browse_data_begin[];
extern const char browse_data_end[];
#endif

option options[] = {
{ "help", no_argument, NULL, 'h' },
Expand Down Expand Up @@ -130,6 +132,10 @@ int CmdQuery(State* state, int argc, char* argv[]) {
}

int CmdBrowse(State* state, int argc, char* argv[]) {
#if defined(__APPLE__)
printf("Error: browse not supported in mac OS X\n");
return 1;
#else
// Create a temporary file, dump the Python code into it, and
// delete the file, keeping our open handle to it.
char tmpl[] = "browsepy-XXXXXX";
Expand All @@ -151,6 +157,7 @@ int CmdBrowse(State* state, int argc, char* argv[]) {
// If we get here, the exec failed.
printf("ERROR: Failed to spawn python for graph browsing, aborting.\n");
return 1;
#endif
}

int main(int argc, char** argv) {
Expand Down
18 changes: 17 additions & 1 deletion src/subprocess.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ Subprocess::~Subprocess() {
}

bool Subprocess::Start(const string& command) {
command_ = command;

int stdout_pipe[2];
if (pipe(stdout_pipe) < 0)
Fatal("pipe: %s", strerror(errno));
Expand Down Expand Up @@ -154,12 +156,26 @@ void SubprocessSet::DoWork() {
}
}

int ret = poll(fds.data(), fds.size(), -1);
int ret = poll(fds.data(), fds.size(), POLL_TIMEOUT);
if (ret == -1) {
if (errno != EINTR)
perror("poll");
return;
}
else if (ret == 0) {
fprintf(stderr, "\nStill waiting on\n");
for (vector<Subprocess*>::iterator i = running_.begin();
i != running_.end(); ++i) {
fprintf(stderr, "\t%s\n", (*i)->get_command().c_str());
}

ret = poll(fds.data(), fds.size(), -1);
if(ret == -1) {
if (errno != EINTR)
perror("poll");
return;
}
}

for (size_t i = 0; i < fds.size(); ++i) {
if (fds[i].revents) {
Expand Down
7 changes: 7 additions & 0 deletions src/subprocess.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#include <queue>
using namespace std;

const int POLL_TIMEOUT = 1000;

// Subprocess wraps a single async subprocess. It is entirely
// passive: it expects the caller to notify it when its fds are ready
// for reading, as well as call Finish() to reap the child once done()
Expand All @@ -33,6 +35,10 @@ struct Subprocess {
return stdout_.fd_ == -1 && stderr_.fd_ == -1;
}

const string& get_command() const {
return command_;
}

struct Stream {
Stream();
~Stream();
Expand All @@ -41,6 +47,7 @@ struct Subprocess {
};
Stream stdout_, stderr_;
pid_t pid_;
string command_;
};

// SubprocessSet runs a poll() loop around a set of Subprocesses.
Expand Down