summaryrefslogtreecommitdiffstats
path: root/src/ninja.cc
diff options
context:
space:
mode:
authorHans Wennborg <hans@hanshq.net>2014-05-03 23:07:09 (GMT)
committerHans Wennborg <hans@hanshq.net>2014-05-03 23:07:09 (GMT)
commit86c4b0618bf714367096c8b7661bde068b02e8fa (patch)
treecf454effecdef3f65e5ce9a028f31aa810e23f93 /src/ninja.cc
parent9b156e4e026bfad25bb2684d2f4fb8862ec19752 (diff)
downloadNinja-86c4b0618bf714367096c8b7661bde068b02e8fa.zip
Ninja-86c4b0618bf714367096c8b7661bde068b02e8fa.tar.gz
Ninja-86c4b0618bf714367096c8b7661bde068b02e8fa.tar.bz2
Process the -C option before running RUN_AFTER_FLAGS tools.
This brings the flag more inline with its description: "change to DIR before doing anything else". The use case is to make it possible to use -C together with -t msvc. When debugging Windows builds, it's handy to be able to copy-paste the commands from "ninja -v" and make them run in the correct directory by adding this flag.
Diffstat (limited to 'src/ninja.cc')
-rw-r--r--src/ninja.cc17
1 files changed, 9 insertions, 8 deletions
diff --git a/src/ninja.cc b/src/ninja.cc
index 03ca83b..25eb3a5 100644
--- a/src/ninja.cc
+++ b/src/ninja.cc
@@ -161,7 +161,8 @@ struct Tool {
/// When to run the tool.
enum {
- /// Run after parsing the command-line flags (as early as possible).
+ /// Run after parsing the command-line flags and potentially changing
+ /// the current working directory (as early as possible).
RUN_AFTER_FLAGS,
/// Run after loading build.ninja.
@@ -1026,13 +1027,6 @@ int real_main(int argc, char** argv) {
if (exit_code >= 0)
return exit_code;
- if (options.tool && options.tool->when == Tool::RUN_AFTER_FLAGS) {
- // 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);
- }
-
if (options.working_dir) {
// The formatting of this string, complete with funny quotes, is
// so Emacs can properly identify that the cwd has changed for
@@ -1046,6 +1040,13 @@ int real_main(int argc, char** argv) {
}
}
+ if (options.tool && options.tool->when == Tool::RUN_AFTER_FLAGS) {
+ // 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);
+ }
+
// The build can take up to 2 passes: one to rebuild the manifest, then
// another to build the desired target.
for (int cycle = 0; cycle < 2; ++cycle) {