diff options
-rw-r--r-- | doc/manual.asciidoc | 17 | ||||
-rw-r--r-- | src/ninja.cc | 37 |
2 files changed, 23 insertions, 31 deletions
diff --git a/doc/manual.asciidoc b/doc/manual.asciidoc index 7e7063b..ff197b1 100644 --- a/doc/manual.asciidoc +++ b/doc/manual.asciidoc @@ -383,15 +383,14 @@ one. It can be used to know which rule name to pass to +ninja -t targets rule _name_+. `clean`:: remove built files. If used like this +ninja -t clean+ it removes -all the built files, except for those created by the generator. If used like -this +ninja -t clean -g+ it also removes built files created by the generator. -If used like this +ninja -t clean _targets..._+ or like this +ninja -t clean -target _targets..._+ it removes the given targets and recursively all files -built for it. If used like this +ninja -t clean rule _rules_+ it removes -all files built using the given rules. The depfiles are not removed. Files -created but not referenced in the graph are not removed. This tool takes -in account the +-v+ and the +-n+ options (note that +-n+ implies +-v+). -It returns non-zero if an error occurs. +all the built files, except for those created by the generator. If used +like this +ninja -t clean -g+ it also removes built files created by the +generator. If used like this +ninja -t clean _targets..._+ it removes the +given targets and recursively all files built for it. If used like this ++ninja -t clean -r _rules_+ it removes all files built using the given +rules. The depfiles are not removed. Files created but not referenced in +the graph are not removed. This tool takes in account the +-v+ and the +-n+ +options (note that +-n+ implies +-v+). It returns non-zero if an error occurs. Ninja file reference -------------------- diff --git a/src/ninja.cc b/src/ninja.cc index 5b96ca1..a058e95 100644 --- a/src/ninja.cc +++ b/src/ninja.cc @@ -359,14 +359,18 @@ int CmdRules(State* state, int argc, char* argv[]) { int CmdClean(State* state, int argc, char* argv[], const BuildConfig& config) { bool generator = false; + bool clean_rules = false; optind = 1; int opt; - while ((opt = getopt(argc, argv, "g")) != -1) { + while ((opt = getopt(argc, argv, "gr")) != -1) { switch (opt) { case 'g': generator = true; break; + case 'r': + clean_rules = true; + break; default: Usage(config); return 1; @@ -375,29 +379,18 @@ int CmdClean(State* state, int argc, char* argv[], const BuildConfig& config) { argv += optind; argc -= optind; + if (clean_rules && argc == 0) { + Error("expected a rule to clean"); + return 1; + } + Cleaner cleaner(state, config); - if (argc >= 1) - { - string mode = argv[0]; - if (mode == "target") { - if (argc >= 2) { - return cleaner.CleanTargets(argc - 1, &argv[1]); - } else { - Error("expected a target to clean"); - return 1; - } - } else if (mode == "rule") { - if (argc >= 2) { - return cleaner.CleanRules(argc - 1, &argv[1]); - } else { - Error("expected a rule to clean"); - return 1; - } - } else { + if (argc >= 1) { + if (clean_rules) + return cleaner.CleanRules(argc, argv); + else return cleaner.CleanTargets(argc, argv); - } - } - else { + } else { return cleaner.CleanAll(generator); } } |