diff options
author | Nico Weber <nicolasweber@gmx.de> | 2016-04-19 21:23:44 (GMT) |
---|---|---|
committer | Nico Weber <nicolasweber@gmx.de> | 2016-04-19 21:23:44 (GMT) |
commit | 73b672ebbf1a28227b070f1f3191c9fd51d8e3ad (patch) | |
tree | 99c4675151f594f9182629871916b2adaf2a3946 | |
parent | bfe8cd9b34d117201ffecd639e4b694f18648242 (diff) | |
parent | bff4010e561b7d5f366262ef3d1415dcd50a3d94 (diff) | |
download | Ninja-73b672ebbf1a28227b070f1f3191c9fd51d8e3ad.zip Ninja-73b672ebbf1a28227b070f1f3191c9fd51d8e3ad.tar.gz Ninja-73b672ebbf1a28227b070f1f3191c9fd51d8e3ad.tar.bz2 |
Merge pull request #1116 from colincross/browse
Pass location of build.ninja file to browse script
-rw-r--r-- | src/browse.cc | 4 | ||||
-rw-r--r-- | src/browse.h | 2 | ||||
-rwxr-xr-x | src/browse.py | 6 | ||||
-rw-r--r-- | src/ninja.cc | 54 |
4 files changed, 35 insertions, 31 deletions
diff --git a/src/browse.cc b/src/browse.cc index 46434d7..14900f8 100644 --- a/src/browse.cc +++ b/src/browse.cc @@ -22,7 +22,7 @@ #include "build/browse_py.h" void RunBrowsePython(State* state, const char* ninja_command, - int argc, char* argv[]) { + const char* input_file, int argc, char* argv[]) { // Fork off a Python process and have it run our code via its stdin. // (Actually the Python process becomes the parent.) int pipefd[2]; @@ -50,6 +50,8 @@ void RunBrowsePython(State* state, const char* ninja_command, command.push_back("-"); command.push_back("--ninja-command"); command.push_back(ninja_command); + command.push_back("-f"); + command.push_back(input_file); for (int i = 0; i < argc; i++) { command.push_back(argv[i]); } diff --git a/src/browse.h b/src/browse.h index 842c6ff..8d6d285 100644 --- a/src/browse.h +++ b/src/browse.h @@ -23,6 +23,6 @@ struct State; /// \a argv are arguments to be passed to the Python script. /// This function does not return if it runs successfully. void RunBrowsePython(State* state, const char* ninja_command, - int argc, char* argv[]); + const char* input_file, int argc, char* argv[]); #endif // NINJA_BROWSE_H_ diff --git a/src/browse.py b/src/browse.py index 63c60aa..32792f3 100755 --- a/src/browse.py +++ b/src/browse.py @@ -150,8 +150,8 @@ def generate_html(node): return '\n'.join(document) def ninja_dump(target): - proc = subprocess.Popen([args.ninja_command, '-t', 'query', target], - stdout=subprocess.PIPE, stderr=subprocess.PIPE, + cmd = [args.ninja_command, '-f', args.f, '-t', 'query', target] + proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True) return proc.communicate() + (proc.returncode,) @@ -194,6 +194,8 @@ parser.add_argument('--no-browser', action='store_true', parser.add_argument('--ninja-command', default='ninja', help='Path to ninja binary (default %(default)s)') +parser.add_argument('-f', default='build.ninja', + help='Path to build.ninja file (default %(default)s)') parser.add_argument('initial_target', default='all', nargs='?', help='Initial target to show (default %(default)s)') diff --git a/src/ninja.cc b/src/ninja.cc index b3b9bed..25eafe8 100644 --- a/src/ninja.cc +++ b/src/ninja.cc @@ -97,7 +97,7 @@ struct NinjaMain : public BuildLogUser { DepsLog deps_log_; /// The type of functions that are the entry points to tools (subcommands). - typedef int (NinjaMain::*ToolFunc)(int, char**); + typedef int (NinjaMain::*ToolFunc)(const Options*, int, char**); /// Get the Node for a given command-line path, handling features like /// spell correction. @@ -108,17 +108,17 @@ struct NinjaMain : public BuildLogUser { vector<Node*>* targets, string* err); // The various subcommands, run via "-t XXX". - int ToolGraph(int argc, char* argv[]); - int ToolQuery(int argc, char* argv[]); - int ToolDeps(int argc, char* argv[]); - int ToolBrowse(int argc, char* argv[]); - int ToolMSVC(int argc, char* argv[]); - int ToolTargets(int argc, char* argv[]); - int ToolCommands(int argc, char* argv[]); - int ToolClean(int argc, char* argv[]); - int ToolCompilationDatabase(int argc, char* argv[]); - int ToolRecompact(int argc, char* argv[]); - int ToolUrtle(int argc, char** argv); + int ToolGraph(const Options* options, int argc, char* argv[]); + int ToolQuery(const Options* options, int argc, char* argv[]); + int ToolDeps(const Options* options, int argc, char* argv[]); + int ToolBrowse(const Options* options, int argc, char* argv[]); + int ToolMSVC(const Options* options, int argc, char* argv[]); + int ToolTargets(const Options* options, int argc, char* argv[]); + int ToolCommands(const Options* options, int argc, char* argv[]); + int ToolClean(const Options* options, int argc, char* argv[]); + int ToolCompilationDatabase(const Options* options, int argc, char* argv[]); + int ToolRecompact(const Options* options, int argc, char* argv[]); + int ToolUrtle(const Options* options, int argc, char** argv); /// Open the build log. /// @return false on error. @@ -314,7 +314,7 @@ bool NinjaMain::CollectTargetsFromArgs(int argc, char* argv[], return true; } -int NinjaMain::ToolGraph(int argc, char* argv[]) { +int NinjaMain::ToolGraph(const Options* options, int argc, char* argv[]) { vector<Node*> nodes; string err; if (!CollectTargetsFromArgs(argc, argv, &nodes, &err)) { @@ -331,7 +331,7 @@ int NinjaMain::ToolGraph(int argc, char* argv[]) { return 0; } -int NinjaMain::ToolQuery(int argc, char* argv[]) { +int NinjaMain::ToolQuery(const Options* options, int argc, char* argv[]) { if (argc == 0) { Error("expected a target to query"); return 1; @@ -370,15 +370,15 @@ int NinjaMain::ToolQuery(int argc, char* argv[]) { } #if defined(NINJA_HAVE_BROWSE) -int NinjaMain::ToolBrowse(int argc, char* argv[]) { - RunBrowsePython(&state_, ninja_command_, argc, argv); +int NinjaMain::ToolBrowse(const Options* options, int argc, char* argv[]) { + RunBrowsePython(&state_, ninja_command_, options->input_file, argc, argv); // If we get here, the browse failed. return 1; } #endif // _WIN32 #if defined(_MSC_VER) -int NinjaMain::ToolMSVC(int argc, char* argv[]) { +int NinjaMain::ToolMSVC(const Options* options, int argc, char* argv[]) { // Reset getopt: push one argument onto the front of argv, reset optind. argc++; argv--; @@ -453,7 +453,7 @@ int ToolTargetsList(State* state) { return 0; } -int NinjaMain::ToolDeps(int argc, char** argv) { +int NinjaMain::ToolDeps(const Options* options, int argc, char** argv) { vector<Node*> nodes; if (argc == 0) { for (vector<Node*>::const_iterator ni = deps_log_.nodes().begin(); @@ -493,7 +493,7 @@ int NinjaMain::ToolDeps(int argc, char** argv) { return 0; } -int NinjaMain::ToolTargets(int argc, char* argv[]) { +int NinjaMain::ToolTargets(const Options* options, int argc, char* argv[]) { int depth = 1; if (argc >= 1) { string mode = argv[0]; @@ -547,7 +547,7 @@ void PrintCommands(Edge* edge, set<Edge*>* seen) { puts(edge->EvaluateCommand().c_str()); } -int NinjaMain::ToolCommands(int argc, char* argv[]) { +int NinjaMain::ToolCommands(const Options* options, int argc, char* argv[]) { vector<Node*> nodes; string err; if (!CollectTargetsFromArgs(argc, argv, &nodes, &err)) { @@ -562,7 +562,7 @@ int NinjaMain::ToolCommands(int argc, char* argv[]) { return 0; } -int NinjaMain::ToolClean(int argc, char* argv[]) { +int NinjaMain::ToolClean(const Options* options, int argc, char* argv[]) { // The clean tool uses getopt, and expects argv[0] to contain the name of // the tool, i.e. "clean". argc++; @@ -620,7 +620,7 @@ void EncodeJSONString(const char *str) { } } -int NinjaMain::ToolCompilationDatabase(int argc, char* argv[]) { +int NinjaMain::ToolCompilationDatabase(const Options* options, int argc, char* argv[]) { bool first = true; vector<char> cwd; @@ -660,7 +660,7 @@ int NinjaMain::ToolCompilationDatabase(int argc, char* argv[]) { return 0; } -int NinjaMain::ToolRecompact(int argc, char* argv[]) { +int NinjaMain::ToolRecompact(const Options* options, int argc, char* argv[]) { if (!EnsureBuildDirExists()) return 1; @@ -671,7 +671,7 @@ int NinjaMain::ToolRecompact(int argc, char* argv[]) { return 0; } -int NinjaMain::ToolUrtle(int argc, char** argv) { +int NinjaMain::ToolUrtle(const Options* options, int argc, char** argv) { // RLE encoded. const char* urtle = " 13 ,3;2!2;\n8 ,;<11!;\n5 `'<10!(2`'2!\n11 ,6;, `\\. `\\9 .,c13$ec,.\n6 " @@ -1097,7 +1097,7 @@ int real_main(int argc, char** argv) { // None of the RUN_AFTER_FLAGS actually use a NinjaMain, but it's needed // by other tools. NinjaMain ninja(ninja_command, config); - return (ninja.*options.tool->func)(argc, argv); + return (ninja.*options.tool->func)(&options, argc, argv); } // Limit number of rebuilds, to prevent infinite loops. @@ -1116,7 +1116,7 @@ int real_main(int argc, char** argv) { } if (options.tool && options.tool->when == Tool::RUN_AFTER_LOAD) - return (ninja.*options.tool->func)(argc, argv); + return (ninja.*options.tool->func)(&options, argc, argv); if (!ninja.EnsureBuildDirExists()) return 1; @@ -1125,7 +1125,7 @@ int real_main(int argc, char** argv) { return 1; if (options.tool && options.tool->when == Tool::RUN_AFTER_LOGS) - return (ninja.*options.tool->func)(argc, argv); + return (ninja.*options.tool->func)(&options, argc, argv); // Attempt to rebuild the manifest before building anything else if (ninja.RebuildManifest(options.input_file, &err)) { |