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.
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"
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
);
33 " When run with no arguments \"gn gen\" is assumed.\n"
35 "Common switches:\n");
37 "--args: Specifies build args overrides. See \"gn help buildargs\".");
39 "--no-exec: Skips exec_script calls (for performance testing).");
41 "-q: Quiet mode, don't print anything on success.");
43 "--output: Directory for build output (relative to source root).");
45 "--root: Specifies source root (overrides .gn file).");
47 "--secondary: Specifies secondary source root (overrides .gn file).");
49 "--time: Outputs a summary of how long everything took.");
51 "--tracelog: Writes a Chrome-compatible trace log to the given file.");
53 "-v: Verbose mode, print lots of logging.");
56 OutputString("\nBuildfile functions (type \"gn help <function>\" for more "
58 const functions::FunctionInfoMap
& function_map
= functions::GetFunctions();
59 std::vector
<std::string
> sorted_functions
;
60 for (functions::FunctionInfoMap::const_iterator i
= function_map
.begin();
61 i
!= function_map
.end(); ++i
)
62 sorted_functions
.push_back(i
->first
.as_string());
63 std::sort(sorted_functions
.begin(), sorted_functions
.end());
64 for (size_t i
= 0; i
< sorted_functions
.size(); i
++)
65 OutputString(" " + sorted_functions
[i
] + "\n", DECORATION_YELLOW
);
67 // Built-in variables.
68 OutputString("\nBuilt-in predefined variables (type \"gn help <variable>\" "
69 "for more details):\n");
70 const variables::VariableInfoMap
& builtin_vars
=
71 variables::GetBuiltinVariables();
72 for (variables::VariableInfoMap::const_iterator i
= builtin_vars
.begin();
73 i
!= builtin_vars
.end(); ++i
)
74 PrintShortHelp(i
->second
.help_short
);
77 OutputString("\nVariables you set in targets (type \"gn help <variable>\" "
78 "for more details):\n");
79 const variables::VariableInfoMap
& target_vars
=
80 variables::GetTargetVariables();
81 for (variables::VariableInfoMap::const_iterator i
= target_vars
.begin();
82 i
!= target_vars
.end(); ++i
)
83 PrintShortHelp(i
->second
.help_short
);
85 OutputString("\nOther help topics:\n");
86 PrintShortHelp("buildargs: How build arguments work.");
87 PrintShortHelp("dotfile: Info about the toplevel .gn file.");
89 "input_conversion: Processing input from exec_script and read_file.");
90 PrintShortHelp("patterns: How to use patterns.");
91 PrintShortHelp("source_expansion: Map sources to outputs for scripts.");
96 const char kHelp
[] = "help";
97 const char kHelp_HelpShort
[] =
98 "help: Does what you think.";
99 const char kHelp_Help
[] =
100 "gn help <anything>\n"
101 " Yo dawg, I heard you like help on your help so I put help on the help\n"
104 int RunHelp(const std::vector
<std::string
>& args
) {
105 if (args
.size() == 0) {
111 const commands::CommandInfoMap
& command_map
= commands::GetCommands();
112 commands::CommandInfoMap::const_iterator found_command
=
113 command_map
.find(args
[0]);
114 if (found_command
!= command_map
.end()) {
115 PrintLongHelp(found_command
->second
.help
);
120 const functions::FunctionInfoMap
& function_map
= functions::GetFunctions();
121 functions::FunctionInfoMap::const_iterator found_function
=
122 function_map
.find(args
[0]);
123 if (found_function
!= function_map
.end()) {
124 PrintLongHelp(found_function
->second
.help
);
128 // Builtin variables.
129 const variables::VariableInfoMap
& builtin_vars
=
130 variables::GetBuiltinVariables();
131 variables::VariableInfoMap::const_iterator found_builtin_var
=
132 builtin_vars
.find(args
[0]);
133 if (found_builtin_var
!= builtin_vars
.end()) {
134 PrintLongHelp(found_builtin_var
->second
.help
);
139 const variables::VariableInfoMap
& target_vars
=
140 variables::GetTargetVariables();
141 variables::VariableInfoMap::const_iterator found_target_var
=
142 target_vars
.find(args
[0]);
143 if (found_target_var
!= target_vars
.end()) {
144 PrintLongHelp(found_target_var
->second
.help
);
148 // Random other topics.
149 if (args
[0] == "buildargs") {
150 PrintLongHelp(kBuildArgs_Help
);
153 if (args
[0] == "dotfile") {
154 PrintLongHelp(kDotfile_Help
);
157 if (args
[0] == "input_conversion") {
158 PrintLongHelp(kInputConversion_Help
);
161 if (args
[0] == "patterns") {
162 PrintLongHelp(kPattern_Help
);
165 if (args
[0] == "source_expansion") {
166 PrintLongHelp(kSourceExpansion_Help
);
171 Err(Location(), "No help on \"" + args
[0] + "\".").PrintToStdout();
172 RunHelp(std::vector
<std::string
>());
176 } // namespace commands