Replace command buffer FlushSync with WaitForTokenInRange and WaitForGetOffsetInRange
[chromium-blink-merge.git] / tools / gn / command_help.cc
blob14defea8261f1c4a17c7d8d5f4321b377392a061
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
3 // found in the LICENSE file.
5 #include <algorithm>
6 #include <iostream>
8 #include "tools/gn/args.h"
9 #include "tools/gn/commands.h"
10 #include "tools/gn/err.h"
11 #include "tools/gn/file_template.h"
12 #include "tools/gn/functions.h"
13 #include "tools/gn/input_conversion.h"
14 #include "tools/gn/pattern.h"
15 #include "tools/gn/setup.h"
16 #include "tools/gn/standard_out.h"
17 #include "tools/gn/variables.h"
19 namespace commands {
21 namespace {
23 void PrintToplevelHelp() {
24 OutputString("Commands (type \"gn help <command>\" for more details):\n");
26 const commands::CommandInfoMap& command_map = commands::GetCommands();
27 for (commands::CommandInfoMap::const_iterator i = command_map.begin();
28 i != command_map.end(); ++i)
29 PrintShortHelp(i->second.help_short);
31 OutputString(
32 "\n"
33 "Common switches:\n");
34 PrintShortHelp(
35 "--args: Specifies build arguments overrides. "
36 "See \"gn help buildargs\".");
37 PrintShortHelp(
38 "--no-exec: Skips exec_script calls (for performance testing).");
39 PrintShortHelp(
40 "-q: Quiet mode, don't print anything on success.");
41 PrintShortHelp(
42 "--output: Directory for build output (relative to source root).");
43 PrintShortHelp(
44 "--root: Specifies source root (overrides .gn file).");
45 PrintShortHelp(
46 "--secondary: Specifies secondary source root (overrides .gn file).");
47 PrintShortHelp(
48 "--time: Outputs a summary of how long everything took.");
49 PrintShortHelp(
50 "--tracelog: Writes a Chrome-compatible trace log to the given file.");
51 PrintShortHelp(
52 "-v: Verbose mode, print lots of logging.");
53 PrintShortHelp(
54 "--version: Print the GN binary's version and exit.");
56 // Functions.
57 OutputString("\nBuildfile functions (type \"gn help <function>\" for more "
58 "details):\n");
59 const functions::FunctionInfoMap& function_map = functions::GetFunctions();
60 std::vector<std::string> sorted_functions;
61 for (functions::FunctionInfoMap::const_iterator i = function_map.begin();
62 i != function_map.end(); ++i)
63 sorted_functions.push_back(i->first.as_string());
64 std::sort(sorted_functions.begin(), sorted_functions.end());
65 for (size_t i = 0; i < sorted_functions.size(); i++)
66 OutputString(" " + sorted_functions[i] + "\n", DECORATION_YELLOW);
68 // Built-in variables.
69 OutputString("\nBuilt-in predefined variables (type \"gn help <variable>\" "
70 "for more details):\n");
71 const variables::VariableInfoMap& builtin_vars =
72 variables::GetBuiltinVariables();
73 for (variables::VariableInfoMap::const_iterator i = builtin_vars.begin();
74 i != builtin_vars.end(); ++i)
75 PrintShortHelp(i->second.help_short);
77 // Target variables.
78 OutputString("\nVariables you set in targets (type \"gn help <variable>\" "
79 "for more details):\n");
80 const variables::VariableInfoMap& target_vars =
81 variables::GetTargetVariables();
82 for (variables::VariableInfoMap::const_iterator i = target_vars.begin();
83 i != target_vars.end(); ++i)
84 PrintShortHelp(i->second.help_short);
86 OutputString("\nOther help topics:\n");
87 PrintShortHelp("buildargs: How build arguments work.");
88 PrintShortHelp("dotfile: Info about the toplevel .gn file.");
89 PrintShortHelp(
90 "input_conversion: Processing input from exec_script and read_file.");
91 PrintShortHelp("patterns: How to use patterns.");
92 PrintShortHelp("source_expansion: Map sources to outputs for scripts.");
95 } // namespace
97 const char kHelp[] = "help";
98 const char kHelp_HelpShort[] =
99 "help: Does what you think.";
100 const char kHelp_Help[] =
101 "gn help <anything>\n"
102 " Yo dawg, I heard you like help on your help so I put help on the help\n"
103 " in the help.\n";
105 int RunHelp(const std::vector<std::string>& args) {
106 if (args.size() == 0) {
107 PrintToplevelHelp();
108 return 0;
111 // Check commands.
112 const commands::CommandInfoMap& command_map = commands::GetCommands();
113 commands::CommandInfoMap::const_iterator found_command =
114 command_map.find(args[0]);
115 if (found_command != command_map.end()) {
116 PrintLongHelp(found_command->second.help);
117 return 0;
120 // Check functions.
121 const functions::FunctionInfoMap& function_map = functions::GetFunctions();
122 functions::FunctionInfoMap::const_iterator found_function =
123 function_map.find(args[0]);
124 if (found_function != function_map.end()) {
125 PrintLongHelp(found_function->second.help);
126 return 0;
129 // Builtin variables.
130 const variables::VariableInfoMap& builtin_vars =
131 variables::GetBuiltinVariables();
132 variables::VariableInfoMap::const_iterator found_builtin_var =
133 builtin_vars.find(args[0]);
134 if (found_builtin_var != builtin_vars.end()) {
135 PrintLongHelp(found_builtin_var->second.help);
136 return 0;
139 // Target variables.
140 const variables::VariableInfoMap& target_vars =
141 variables::GetTargetVariables();
142 variables::VariableInfoMap::const_iterator found_target_var =
143 target_vars.find(args[0]);
144 if (found_target_var != target_vars.end()) {
145 PrintLongHelp(found_target_var->second.help);
146 return 0;
149 // Random other topics.
150 if (args[0] == "buildargs") {
151 PrintLongHelp(kBuildArgs_Help);
152 return 0;
154 if (args[0] == "dotfile") {
155 PrintLongHelp(kDotfile_Help);
156 return 0;
158 if (args[0] == "input_conversion") {
159 PrintLongHelp(kInputConversion_Help);
160 return 0;
162 if (args[0] == "patterns") {
163 PrintLongHelp(kPattern_Help);
164 return 0;
166 if (args[0] == "source_expansion") {
167 PrintLongHelp(kSourceExpansion_Help);
168 return 0;
171 // No help on this.
172 Err(Location(), "No help on \"" + args[0] + "\".").PrintToStdout();
173 RunHelp(std::vector<std::string>());
174 return 1;
177 } // namespace commands