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 "Common switches:\n");
35 "--args: Specifies build arguments overrides. "
36 "See \"gn help buildargs\".");
38 "--no-exec: Skips exec_script calls (for performance testing).");
40 "-q: Quiet mode, don't print anything on success.");
42 "--output: Directory for build output (relative to source root).");
44 "--root: Specifies source root (overrides .gn file).");
46 "--secondary: Specifies secondary source root (overrides .gn file).");
48 "--time: Outputs a summary of how long everything took.");
50 "--tracelog: Writes a Chrome-compatible trace log to the given file.");
52 "-v: Verbose mode, print lots of logging.");
54 "--version: Print the GN binary's version and exit.");
57 OutputString("\nBuildfile functions (type \"gn help <function>\" for more "
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
);
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.");
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.");
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"
105 int RunHelp(const std::vector
<std::string
>& args
) {
106 if (args
.size() == 0) {
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
);
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
);
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
);
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
);
149 // Random other topics.
150 if (args
[0] == "buildargs") {
151 PrintLongHelp(kBuildArgs_Help
);
154 if (args
[0] == "dotfile") {
155 PrintLongHelp(kDotfile_Help
);
158 if (args
[0] == "input_conversion") {
159 PrintLongHelp(kInputConversion_Help
);
162 if (args
[0] == "patterns") {
163 PrintLongHelp(kPattern_Help
);
166 if (args
[0] == "source_expansion") {
167 PrintLongHelp(kSourceExpansion_Help
);
172 Err(Location(), "No help on \"" + args
[0] + "\".").PrintToStdout();
173 RunHelp(std::vector
<std::string
>());
177 } // namespace commands