diff options
author | Nicolas Despres <nicolas.despres@gmail.com> | 2011-04-09 17:45:24 (GMT) |
---|---|---|
committer | Nicolas Despres <nicolas.despres@gmail.com> | 2011-04-26 11:20:23 (GMT) |
commit | f10afb9d402b33710bd0b93f0c9c42f438347171 (patch) | |
tree | 233ec72820601b2b61e0b909e3240de0d111b003 /src/ninja.cc | |
parent | 8c7e87bb0801e07c6c4d8499be965901b917a207 (diff) | |
download | Ninja-f10afb9d402b33710bd0b93f0c9c42f438347171.zip Ninja-f10afb9d402b33710bd0b93f0c9c42f438347171.tar.gz Ninja-f10afb9d402b33710bd0b93f0c9c42f438347171.tar.bz2 |
Add -C DIR option.
Can be useful when calling ninja from a script or a code editor or in many
other occasions. It costs nothing and does not bring more complexity, so
I think we can afford it.
Diffstat (limited to 'src/ninja.cc')
-rw-r--r-- | src/ninja.cc | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/src/ninja.cc b/src/ninja.cc index 6359aaf..dbbf05e 100644 --- a/src/ninja.cc +++ b/src/ninja.cc @@ -53,6 +53,7 @@ void usage(const BuildConfig& config) { " -j N run N jobs in parallel [default=%d]\n" " -n dry run (don't run commands but pretend they succeeded)\n" " -v show all command lines\n" +" -C DIR change to DIR before doing anything else\n" "\n" " -t TOOL run a subtool. tools are:\n" " browse browse dependency graph in a web browser\n" @@ -163,12 +164,13 @@ int CmdBrowse(State* state, int argc, char* argv[]) { int main(int argc, char** argv) { BuildConfig config; const char* input_file = "build.ninja"; + const char* working_dir = 0; string tool; config.parallelism = GuessParallelism(); int opt; - while ((opt = getopt_long(argc, argv, "f:hj:nt:v", options, NULL)) != -1) { + while ((opt = getopt_long(argc, argv, "f:hj:nt:vC:", options, NULL)) != -1) { switch (opt) { case 'f': input_file = optarg; @@ -185,6 +187,9 @@ int main(int argc, char** argv) { case 't': tool = optarg; break; + case 'C': + working_dir = optarg; + break; case 'h': default: usage(config); @@ -199,6 +204,12 @@ int main(int argc, char** argv) { argv += optind; argc -= optind; + if (working_dir) { + if (chdir(working_dir) < 0) { + Fatal("chdir to '%s' - %s", working_dir, strerror(errno)); + } + } + State state; RealFileReader file_reader; ManifestParser parser(&state, &file_reader); |