make browse work for all ninja paths
authorEvan Martin <martine@danga.com>
Fri, 13 May 2011 15:53:02 +0000 (08:53 -0700)
committerEvan Martin <martine@danga.com>
Fri, 13 May 2011 23:28:07 +0000 (16:28 -0700)
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.

src/browse.cc
src/browse.h
src/browse.py
src/ninja.cc

index f65e537..d51bb44 100644 (file)
@@ -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");
index d46cbf0..263641f 100644 (file)
 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_
index 1860df3..c671535 100755 (executable)
@@ -99,7 +99,7 @@ tt {
     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 @@ class RequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
 
         if target == '':
             self.send_response(302)
-            self.send_header('Location', '?' + sys.argv[1])
+            self.send_header('Location', '?' + sys.argv[2])
             self.end_headers()
             return
 
index 8b4206c..ee76fb3 100644 (file)
@@ -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")