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/functions.h"
12 #include "tools/gn/input_conversion.h"
13 #include "tools/gn/label_pattern.h"
14 #include "tools/gn/setup.h"
15 #include "tools/gn/standard_out.h"
16 #include "tools/gn/substitution_writer.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]color: Forces colored output on or off (rather than autodetect).");
40 "--dotfile: Specifies an alternate .gn file. See \"gn help dotfile\".");
42 "--no-exec: Skips exec_script calls (for performance testing).");
44 "-q: Quiet mode, don't print anything on success.");
46 "--root: Specifies 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.");
56 // Target declarations.
57 OutputString("\nTarget declarations (type \"gn help <function>\" for more "
59 const functions::FunctionInfoMap
& function_map
= functions::GetFunctions();
60 for (functions::FunctionInfoMap::const_iterator i
= function_map
.begin();
61 i
!= function_map
.end(); ++i
) {
62 if (i
->second
.is_target
)
63 PrintShortHelp(i
->second
.help_short
);
67 OutputString("\nBuildfile functions (type \"gn help <function>\" for more "
69 for (functions::FunctionInfoMap::const_iterator i
= function_map
.begin();
70 i
!= function_map
.end(); ++i
) {
71 if (!i
->second
.is_target
)
72 PrintShortHelp(i
->second
.help_short
);
75 // Built-in variables.
76 OutputString("\nBuilt-in predefined variables (type \"gn help <variable>\" "
77 "for more details):\n");
78 const variables::VariableInfoMap
& builtin_vars
=
79 variables::GetBuiltinVariables();
80 for (variables::VariableInfoMap::const_iterator i
= builtin_vars
.begin();
81 i
!= builtin_vars
.end(); ++i
)
82 PrintShortHelp(i
->second
.help_short
);
85 OutputString("\nVariables you set in targets (type \"gn help <variable>\" "
86 "for more details):\n");
87 const variables::VariableInfoMap
& target_vars
=
88 variables::GetTargetVariables();
89 for (variables::VariableInfoMap::const_iterator i
= target_vars
.begin();
90 i
!= target_vars
.end(); ++i
)
91 PrintShortHelp(i
->second
.help_short
);
93 OutputString("\nOther help topics:\n");
94 PrintShortHelp("buildargs: How build arguments work.");
95 PrintShortHelp("dotfile: Info about the toplevel .gn file.");
96 PrintShortHelp("label_pattern: Matching more than one label.");
98 "input_conversion: Processing input from exec_script and read_file.");
99 PrintShortHelp("source_expansion: Map sources to outputs for scripts.");
104 const char kHelp
[] = "help";
105 const char kHelp_HelpShort
[] =
106 "help: Does what you think.";
107 const char kHelp_Help
[] =
108 "gn help <anything>\n"
109 " Yo dawg, I heard you like help on your help so I put help on the help\n"
112 int RunHelp(const std::vector
<std::string
>& args
) {
113 if (args
.size() == 0) {
119 const commands::CommandInfoMap
& command_map
= commands::GetCommands();
120 commands::CommandInfoMap::const_iterator found_command
=
121 command_map
.find(args
[0]);
122 if (found_command
!= command_map
.end()) {
123 PrintLongHelp(found_command
->second
.help
);
128 const functions::FunctionInfoMap
& function_map
= functions::GetFunctions();
129 functions::FunctionInfoMap::const_iterator found_function
=
130 function_map
.find(args
[0]);
131 if (found_function
!= function_map
.end()) {
132 PrintLongHelp(found_function
->second
.help
);
136 // Builtin variables.
137 const variables::VariableInfoMap
& builtin_vars
=
138 variables::GetBuiltinVariables();
139 variables::VariableInfoMap::const_iterator found_builtin_var
=
140 builtin_vars
.find(args
[0]);
141 if (found_builtin_var
!= builtin_vars
.end()) {
142 PrintLongHelp(found_builtin_var
->second
.help
);
147 const variables::VariableInfoMap
& target_vars
=
148 variables::GetTargetVariables();
149 variables::VariableInfoMap::const_iterator found_target_var
=
150 target_vars
.find(args
[0]);
151 if (found_target_var
!= target_vars
.end()) {
152 PrintLongHelp(found_target_var
->second
.help
);
156 // Random other topics.
157 if (args
[0] == "buildargs") {
158 PrintLongHelp(kBuildArgs_Help
);
161 if (args
[0] == "dotfile") {
162 PrintLongHelp(kDotfile_Help
);
165 if (args
[0] == "input_conversion") {
166 PrintLongHelp(kInputConversion_Help
);
169 if (args
[0] == "label_pattern") {
170 PrintLongHelp(kLabelPattern_Help
);
173 if (args
[0] == "source_expansion") {
174 PrintLongHelp(kSourceExpansion_Help
);
179 Err(Location(), "No help on \"" + args
[0] + "\".").PrintToStdout();
180 RunHelp(std::vector
<std::string
>());
184 } // namespace commands