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