Permalink
Browse files

make browse work for all ninja paths

Pass the path to the ninja binary in to the Python script.
Confusingly, in some places the variables were already in place
to do this, but they were accidentally used for something else
entirely.
  • Loading branch information...
1 parent e2543e4 commit 1c80bd1691f69332a8fec42080c1c341c0e2fa44 @evmar evmar committed May 13, 2011
Showing with 14 additions and 9 deletions.
  1. +3 −2 src/browse.cc
  2. +4 −2 src/browse.h
  3. +2 −2 src/browse.py
  4. +5 −3 src/ninja.cc
View
@@ -20,7 +20,8 @@
#include "../build/browse_py.h"
#include "ninja.h"
-void RunBrowsePython(State* state, const char* ninja_command) {
+void RunBrowsePython(State* state, const char* ninja_command,
+ const char* initial_target) {
// Fork off a Python process and have it run our code via its stdin.
// (Actually the Python process becomes the parent.)
int pipefd[2];
@@ -45,7 +46,7 @@ void RunBrowsePython(State* state, const char* ninja_command) {
// exec Python, telling it to run the program from stdin.
const char* command[] = {
- "python", "-", ninja_command, NULL
+ "python", "-", ninja_command, initial_target, NULL
};
execvp(command[0], (char**)command);
perror("ninja: execvp");
View
@@ -18,8 +18,10 @@
struct State;
/// Run in "browse" mode, which execs a Python webserver.
-/// |command| is the command used to invoke ninja.
+/// \a ninja_command is the command used to invoke ninja.
+/// \a initial_target is the first target to load.
/// This function does not return if it runs successfully.
-void RunBrowsePython(State* state, const char* ninja_command);
+void RunBrowsePython(State* state, const char* ninja_command,
+ const char* initial_target);
#endif // NINJA_BROWSE_H_
View
@@ -99,7 +99,7 @@ def generate_html(data):
print '</td></tr></table>'
def ninja_dump(target):
- proc = subprocess.Popen(['./ninja', '-t', 'query', target],
+ proc = subprocess.Popen([sys.argv[1], '-t', 'query', target],
stdout=subprocess.PIPE)
return proc.communicate()[0]
@@ -110,7 +110,7 @@ def do_GET(self):
if target == '':
self.send_response(302)
- self.send_header('Location', '?' + sys.argv[1])
+ self.send_header('Location', '?' + sys.argv[2])
self.end_headers()
return
View
@@ -182,13 +182,14 @@ int CmdQuery(State* state, int argc, char* argv[]) {
return 0;
}
-int CmdBrowse(State* state, int argc, char* argv[]) {
+int CmdBrowse(State* state, const char* ninja_command,
+ int argc, char* argv[]) {
#ifndef WIN32
if (argc < 1) {
Error("expected a target to browse");
return 1;
}
- RunBrowsePython(state, argv[0]);
+ RunBrowsePython(state, ninja_command, argv[0]);
#else
Error("browse mode not yet supported on Windows");
#endif
@@ -343,6 +344,7 @@ int CmdClean(State* state,
} // anonymous namespace
int main(int argc, char** argv) {
+ const char* ninja_command = argv[0];
BuildConfig config;
const char* input_file = "build.ninja";
const char* working_dir = 0;
@@ -411,7 +413,7 @@ int main(int argc, char** argv) {
if (tool == "query")
return CmdQuery(&state, argc, argv);
if (tool == "browse")
- return CmdBrowse(&state, argc, argv);
+ return CmdBrowse(&state, ninja_command, argc, argv);
if (tool == "targets")
return CmdTargets(&state, argc, argv);
if (tool == "rules")

0 comments on commit 1c80bd1

Please sign in to comment.