| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <algorithm> | 5 #include <algorithm> |
| 6 #include <iostream> | 6 #include <iostream> |
| 7 | 7 |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "tools/gn/args.h" | 9 #include "tools/gn/args.h" |
| 10 #include "tools/gn/commands.h" | 10 #include "tools/gn/commands.h" |
| 11 #include "tools/gn/err.h" | 11 #include "tools/gn/err.h" |
| 12 #include "tools/gn/functions.h" | 12 #include "tools/gn/functions.h" |
| 13 #include "tools/gn/input_conversion.h" | 13 #include "tools/gn/input_conversion.h" |
| 14 #include "tools/gn/label.h" |
| 14 #include "tools/gn/label_pattern.h" | 15 #include "tools/gn/label_pattern.h" |
| 16 #include "tools/gn/ninja_build_writer.h" |
| 15 #include "tools/gn/parser.h" | 17 #include "tools/gn/parser.h" |
| 16 #include "tools/gn/runtime_deps.h" | 18 #include "tools/gn/runtime_deps.h" |
| 17 #include "tools/gn/setup.h" | 19 #include "tools/gn/setup.h" |
| 18 #include "tools/gn/standard_out.h" | 20 #include "tools/gn/standard_out.h" |
| 19 #include "tools/gn/string_utils.h" | 21 #include "tools/gn/string_utils.h" |
| 20 #include "tools/gn/substitution_writer.h" | 22 #include "tools/gn/substitution_writer.h" |
| 21 #include "tools/gn/switches.h" | 23 #include "tools/gn/switches.h" |
| 24 #include "tools/gn/target.h" |
| 22 #include "tools/gn/variables.h" | 25 #include "tools/gn/variables.h" |
| 23 | 26 |
| 24 namespace commands { | 27 namespace commands { |
| 25 | 28 |
| 26 namespace { | 29 namespace { |
| 27 | 30 |
| 28 void PrintToplevelHelp() { | 31 void PrintToplevelHelp() { |
| 29 OutputString("Commands (type \"gn help <command>\" for more details):\n"); | 32 OutputString("Commands (type \"gn help <command>\" for more details):\n"); |
| 30 for (const auto& cmd : commands::GetCommands()) | 33 for (const auto& cmd : commands::GetCommands()) |
| 31 PrintShortHelp(cmd.second.help_short); | 34 PrintShortHelp(cmd.second.help_short); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 55 // Target variables. | 58 // Target variables. |
| 56 OutputString("\nVariables you set in targets (type \"gn help <variable>\" " | 59 OutputString("\nVariables you set in targets (type \"gn help <variable>\" " |
| 57 "for more details):\n"); | 60 "for more details):\n"); |
| 58 for (const auto& target : variables::GetTargetVariables()) | 61 for (const auto& target : variables::GetTargetVariables()) |
| 59 PrintShortHelp(target.second.help_short); | 62 PrintShortHelp(target.second.help_short); |
| 60 | 63 |
| 61 OutputString("\nOther help topics:\n"); | 64 OutputString("\nOther help topics:\n"); |
| 62 PrintShortHelp("all: Print all the help at once"); | 65 PrintShortHelp("all: Print all the help at once"); |
| 63 PrintShortHelp("buildargs: How build arguments work."); | 66 PrintShortHelp("buildargs: How build arguments work."); |
| 64 PrintShortHelp("dotfile: Info about the toplevel .gn file."); | 67 PrintShortHelp("dotfile: Info about the toplevel .gn file."); |
| 68 PrintShortHelp("execution: Build graph and execution overview."); |
| 65 PrintShortHelp("grammar: Language and grammar for GN build files."); | 69 PrintShortHelp("grammar: Language and grammar for GN build files."); |
| 66 PrintShortHelp( | 70 PrintShortHelp( |
| 67 "input_conversion: Processing input from exec_script and read_file."); | 71 "input_conversion: Processing input from exec_script and read_file."); |
| 68 PrintShortHelp("label_pattern: Matching more than one label."); | 72 PrintShortHelp("label_pattern: Matching more than one label."); |
| 73 PrintShortHelp("labels: About labels."); |
| 74 PrintShortHelp("ninja_rules: How Ninja build rules and named."); |
| 69 PrintShortHelp("nogncheck: Annotating includes for checking."); | 75 PrintShortHelp("nogncheck: Annotating includes for checking."); |
| 70 PrintShortHelp("runtime_deps: How runtime dependency computation works."); | 76 PrintShortHelp("runtime_deps: How runtime dependency computation works."); |
| 71 PrintShortHelp("source_expansion: Map sources to outputs for scripts."); | 77 PrintShortHelp("source_expansion: Map sources to outputs for scripts."); |
| 72 PrintShortHelp("switches: Show available command-line switches."); | 78 PrintShortHelp("switches: Show available command-line switches."); |
| 73 } | 79 } |
| 74 | 80 |
| 75 void PrintSwitchHelp() { | 81 void PrintSwitchHelp() { |
| 76 const base::CommandLine* cmdline = base::CommandLine::ForCurrentProcess(); | 82 const base::CommandLine* cmdline = base::CommandLine::ForCurrentProcess(); |
| 77 bool use_markdown = cmdline->HasSwitch(switches::kMarkdown); | 83 bool use_markdown = cmdline->HasSwitch(switches::kMarkdown); |
| 78 | 84 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 PrintLongHelp(f.second.help); | 123 PrintLongHelp(f.second.help); |
| 118 | 124 |
| 119 for (const auto& v: variables::GetBuiltinVariables()) | 125 for (const auto& v: variables::GetBuiltinVariables()) |
| 120 PrintLongHelp(v.second.help); | 126 PrintLongHelp(v.second.help); |
| 121 | 127 |
| 122 for (const auto& v: variables::GetTargetVariables()) | 128 for (const auto& v: variables::GetTargetVariables()) |
| 123 PrintLongHelp(v.second.help); | 129 PrintLongHelp(v.second.help); |
| 124 | 130 |
| 125 PrintLongHelp(kBuildArgs_Help); | 131 PrintLongHelp(kBuildArgs_Help); |
| 126 PrintLongHelp(kDotfile_Help); | 132 PrintLongHelp(kDotfile_Help); |
| 133 PrintLongHelp(kExecution_Help); |
| 127 PrintLongHelp(kGrammar_Help); | 134 PrintLongHelp(kGrammar_Help); |
| 128 PrintLongHelp(kInputConversion_Help); | 135 PrintLongHelp(kInputConversion_Help); |
| 129 PrintLongHelp(kLabelPattern_Help); | 136 PrintLongHelp(kLabelPattern_Help); |
| 137 PrintLongHelp(kLabels_Help); |
| 138 PrintLongHelp(kNinjaRules_Help); |
| 130 PrintLongHelp(kNoGnCheck_Help); | 139 PrintLongHelp(kNoGnCheck_Help); |
| 131 PrintLongHelp(kRuntimeDeps_Help); | 140 PrintLongHelp(kRuntimeDeps_Help); |
| 132 PrintLongHelp(kSourceExpansion_Help); | 141 PrintLongHelp(kSourceExpansion_Help); |
| 133 PrintSwitchHelp(); | 142 PrintSwitchHelp(); |
| 134 } | 143 } |
| 135 | 144 |
| 136 // Prints help on the given switch. There should be no leading hyphens. Returns | 145 // Prints help on the given switch. There should be no leading hyphens. Returns |
| 137 // true if the switch was found and help was printed. False means the switch is | 146 // true if the switch was found and help was printed. False means the switch is |
| 138 // unknown. | 147 // unknown. |
| 139 bool PrintHelpOnSwitch(const std::string& what) { | 148 bool PrintHelpOnSwitch(const std::string& what) { |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 if (found_target_var != target_vars.end()) { | 242 if (found_target_var != target_vars.end()) { |
| 234 PrintLongHelp(found_target_var->second.help); | 243 PrintLongHelp(found_target_var->second.help); |
| 235 return 0; | 244 return 0; |
| 236 } | 245 } |
| 237 for (const auto& entry : target_vars) | 246 for (const auto& entry : target_vars) |
| 238 all_help_topics.push_back(entry.first); | 247 all_help_topics.push_back(entry.first); |
| 239 | 248 |
| 240 // Random other topics. | 249 // Random other topics. |
| 241 std::map<std::string, void(*)()> random_topics; | 250 std::map<std::string, void(*)()> random_topics; |
| 242 random_topics["all"] = PrintAllHelp; | 251 random_topics["all"] = PrintAllHelp; |
| 252 random_topics["execution"] = []() { PrintLongHelp(kExecution_Help); }; |
| 243 random_topics["buildargs"] = []() { PrintLongHelp(kBuildArgs_Help); }; | 253 random_topics["buildargs"] = []() { PrintLongHelp(kBuildArgs_Help); }; |
| 244 random_topics["dotfile"] = []() { PrintLongHelp(kDotfile_Help); }; | 254 random_topics["dotfile"] = []() { PrintLongHelp(kDotfile_Help); }; |
| 245 random_topics["grammar"] = []() { PrintLongHelp(kGrammar_Help); }; | 255 random_topics["grammar"] = []() { PrintLongHelp(kGrammar_Help); }; |
| 246 random_topics["input_conversion"] = []() { | 256 random_topics["input_conversion"] = []() { |
| 247 PrintLongHelp(kInputConversion_Help); | 257 PrintLongHelp(kInputConversion_Help); |
| 248 }; | 258 }; |
| 249 random_topics["label_pattern"] = []() { PrintLongHelp(kLabelPattern_Help); }; | 259 random_topics["label_pattern"] = []() { PrintLongHelp(kLabelPattern_Help); }; |
| 260 random_topics["labels"] = []() { PrintLongHelp(kLabels_Help); }; |
| 261 random_topics["ninja_rules"] = []() { PrintLongHelp(kNinjaRules_Help); }; |
| 250 random_topics["nogncheck"] = []() { PrintLongHelp(kNoGnCheck_Help); }; | 262 random_topics["nogncheck"] = []() { PrintLongHelp(kNoGnCheck_Help); }; |
| 251 random_topics["runtime_deps"] = []() { PrintLongHelp(kRuntimeDeps_Help); }; | 263 random_topics["runtime_deps"] = []() { PrintLongHelp(kRuntimeDeps_Help); }; |
| 252 random_topics["source_expansion"] = []() { | 264 random_topics["source_expansion"] = []() { |
| 253 PrintLongHelp(kSourceExpansion_Help); | 265 PrintLongHelp(kSourceExpansion_Help); |
| 254 }; | 266 }; |
| 255 random_topics["switches"] = PrintSwitchHelp; | 267 random_topics["switches"] = PrintSwitchHelp; |
| 256 auto found_random_topic = random_topics.find(what); | 268 auto found_random_topic = random_topics.find(what); |
| 257 if (found_random_topic != random_topics.end()) { | 269 if (found_random_topic != random_topics.end()) { |
| 258 found_random_topic->second(); | 270 found_random_topic->second(); |
| 259 return 0; | 271 return 0; |
| 260 } | 272 } |
| 261 for (const auto& entry : random_topics) | 273 for (const auto& entry : random_topics) |
| 262 all_help_topics.push_back(entry.first); | 274 all_help_topics.push_back(entry.first); |
| 263 | 275 |
| 264 // No help on this. | 276 // No help on this. |
| 265 Err(Location(), "No help on \"" + what + "\".").PrintToStdout(); | 277 Err(Location(), "No help on \"" + what + "\".").PrintToStdout(); |
| 266 base::StringPiece suggestion = SpellcheckString(what, all_help_topics); | 278 base::StringPiece suggestion = SpellcheckString(what, all_help_topics); |
| 267 if (suggestion.empty()) { | 279 if (suggestion.empty()) { |
| 268 OutputString("Run `gn help` for a list of available topics.\n", | 280 OutputString("Run `gn help` for a list of available topics.\n", |
| 269 DECORATION_NONE); | 281 DECORATION_NONE); |
| 270 } else { | 282 } else { |
| 271 OutputString("Did you mean `gn help " + suggestion.as_string() + "`?\n", | 283 OutputString("Did you mean `gn help " + suggestion.as_string() + "`?\n", |
| 272 DECORATION_NONE); | 284 DECORATION_NONE); |
| 273 } | 285 } |
| 274 return 1; | 286 return 1; |
| 275 } | 287 } |
| 276 | 288 |
| 277 } // namespace commands | 289 } // namespace commands |
| OLD | NEW |