From f10afb9d402b33710bd0b93f0c9c42f438347171 Mon Sep 17 00:00:00 2001 From: Nicolas Despres Date: Sat, 9 Apr 2011 19:45:24 +0200 Subject: 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. --- src/ninja.cc | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) 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); -- cgit v0.12