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");
25 for (const auto& cmd
: commands::GetCommands())
26 PrintShortHelp(cmd
.second
.help_short
);
30 "Common switches:\n");
32 "--args: Specifies build arguments overrides. "
33 "See \"gn help buildargs\".");
35 "--[no]color: Forces colored output on or off (rather than autodetect).");
37 "--dotfile: Specifies an alternate .gn file. See \"gn help dotfile\".");
39 "--no-exec: Skips exec_script calls (for performance testing).");
41 "-q: Quiet mode, don't print anything on success.");
43 "--root: Specifies source root (overrides .gn file).");
45 "--time: Outputs a summary of how long everything took.");
47 "--tracelog: Writes a Chrome-compatible trace log to the given file.");
49 "-v: Verbose mode, print lots of logging.");
51 "--version: Print the GN binary's version and exit.");
53 // Target declarations.
54 OutputString("\nTarget declarations (type \"gn help <function>\" for more "
56 for (const auto& func
: functions::GetFunctions()) {
57 if (func
.second
.is_target
)
58 PrintShortHelp(func
.second
.help_short
);
62 OutputString("\nBuildfile functions (type \"gn help <function>\" for more "
64 for (const auto& func
: functions::GetFunctions()) {
65 if (!func
.second
.is_target
)
66 PrintShortHelp(func
.second
.help_short
);
69 // Built-in variables.
70 OutputString("\nBuilt-in predefined variables (type \"gn help <variable>\" "
71 "for more details):\n");
72 for (const auto& builtin
: variables::GetBuiltinVariables())
73 PrintShortHelp(builtin
.second
.help_short
);
76 OutputString("\nVariables you set in targets (type \"gn help <variable>\" "
77 "for more details):\n");
78 for (const auto& target
: variables::GetTargetVariables())
79 PrintShortHelp(target
.second
.help_short
);
81 OutputString("\nOther help topics:\n");
82 PrintShortHelp("buildargs: How build arguments work.");
83 PrintShortHelp("dotfile: Info about the toplevel .gn file.");
84 PrintShortHelp("label_pattern: Matching more than one label.");
86 "input_conversion: Processing input from exec_script and read_file.");
87 PrintShortHelp("source_expansion: Map sources to outputs for scripts.");
92 const char kHelp
[] = "help";
93 const char kHelp_HelpShort
[] =
94 "help: Does what you think.";
95 const char kHelp_Help
[] =
96 "gn help <anything>\n"
97 " Yo dawg, I heard you like help on your help so I put help on the help\n"
100 int RunHelp(const std::vector
<std::string
>& args
) {
101 if (args
.size() == 0) {
107 const commands::CommandInfoMap
& command_map
= commands::GetCommands();
108 commands::CommandInfoMap::const_iterator found_command
=
109 command_map
.find(args
[0]);
110 if (found_command
!= command_map
.end()) {
111 PrintLongHelp(found_command
->second
.help
);
116 const functions::FunctionInfoMap
& function_map
= functions::GetFunctions();
117 functions::FunctionInfoMap::const_iterator found_function
=
118 function_map
.find(args
[0]);
119 if (found_function
!= function_map
.end()) {
120 PrintLongHelp(found_function
->second
.help
);
124 // Builtin variables.
125 const variables::VariableInfoMap
& builtin_vars
=
126 variables::GetBuiltinVariables();
127 variables::VariableInfoMap::const_iterator found_builtin_var
=
128 builtin_vars
.find(args
[0]);
129 if (found_builtin_var
!= builtin_vars
.end()) {
130 PrintLongHelp(found_builtin_var
->second
.help
);
135 const variables::VariableInfoMap
& target_vars
=
136 variables::GetTargetVariables();
137 variables::VariableInfoMap::const_iterator found_target_var
=
138 target_vars
.find(args
[0]);
139 if (found_target_var
!= target_vars
.end()) {
140 PrintLongHelp(found_target_var
->second
.help
);
144 // Random other topics.
145 if (args
[0] == "buildargs") {
146 PrintLongHelp(kBuildArgs_Help
);
149 if (args
[0] == "dotfile") {
150 PrintLongHelp(kDotfile_Help
);
153 if (args
[0] == "input_conversion") {
154 PrintLongHelp(kInputConversion_Help
);
157 if (args
[0] == "label_pattern") {
158 PrintLongHelp(kLabelPattern_Help
);
161 if (args
[0] == "source_expansion") {
162 PrintLongHelp(kSourceExpansion_Help
);
167 Err(Location(), "No help on \"" + args
[0] + "\".").PrintToStdout();
168 RunHelp(std::vector
<std::string
>());
172 } // namespace commands