1 // Copyright 2014 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.
4
5 #include "gn/switches.h"
6
7 namespace switches {
8
9 const char kArgs[] = "args";
10 const char kArgs_HelpShort[] = "--args: Specifies build arguments overrides.";
11 const char kArgs_Help[] =
12 R"(--args: Specifies build arguments overrides.
13
14 See "gn help buildargs" for an overview of how build arguments work.
15
16 Most operations take a build directory. The build arguments are taken from
17 the previous build done in that directory. If a command specifies --args, it
18 will override the previous arguments stored in the build directory, and use
19 the specified ones.
20
21 The args specified will be saved to the build directory for subsequent
22 commands. Specifying --args="" will clear all build arguments.
23
24 Formatting
25
26 The value of the switch is interpreted in GN syntax. For typical usage of
27 string arguments, you will need to be careful about escaping of quotes.
28
29 Examples
30
31 gn gen out/Default --args="foo=\"bar\""
32
33 gn gen out/Default --args='foo="bar" enable=true blah=7'
34
35 gn check out/Default --args=""
36 Clears existing build args from the directory.
37
38 gn desc out/Default --args="some_list=[1, false, \"foo\"]"
39 )";
40
41 #define COLOR_HELP_LONG \
42 "--[no]color: Forces colored output on or off.\n" \
43 "\n" \
44 " Normally GN will try to detect whether it is outputting to a terminal\n" \
45 " and will enable or disable color accordingly. Use of these switches\n" \
46 " will override the default.\n" \
47 "\n" \
48 "Examples\n" \
49 "\n" \
50 " gn gen out/Default --color\n" \
51 "\n" \
52 " gn gen out/Default --nocolor\n"
53 const char kColor[] = "color";
54 const char kColor_HelpShort[] = "--color: Force colored output.";
55 const char kColor_Help[] = COLOR_HELP_LONG;
56
57 const char kDotfile[] = "dotfile";
58 const char kDotfile_HelpShort[] =
59 "--dotfile: Override the name of the \".gn\" file.";
60 const char kDotfile_Help[] =
61 R"(--dotfile: Override the name of the ".gn" file.
62
63 Normally GN loads the ".gn" file from the source root for some basic
64 configuration (see "gn help dotfile"). This flag allows you to
65 use a different file.
66 )";
67
68 const char kFailOnUnusedArgs[] = "fail-on-unused-args";
69 const char kFailOnUnusedArgs_HelpShort[] =
70 "--fail-on-unused-args: Treat unused build args as fatal errors.";
71 const char kFailOnUnusedArgs_Help[] =
72 R"(--fail-on-unused-args: Treat unused build args as fatal errors.
73
74 If you set a value in a build's "gn args" and never use it in the build (in
75 a declare_args() block), GN will normally print an error but not fail the
76 build.
77
78 In many cases engineers would use build args to enable or disable features
79 that would sometimes get removed. It would by annoying to block work for
80 typically benign problems. In Chrome in particular, flags might be configured
81 for build bots in a separate infrastructure repository, or a declare_args
82 block might be changed in a third party repository. Treating these errors as
83 blocking forced complex multi- way patches to land what would otherwise be
84 simple changes.
85
86 In some cases, such concerns are not as important, and a mismatch in build
87 flags between the invoker of the build and the build files represents a
88 critical mismatch that should be immediately fixed. Such users can set this
89 flag to force GN to fail in that case.
90 )";
91
92 const char kMarkdown[] = "markdown";
93 const char kMarkdown_HelpShort[] =
94 "--markdown: Write help output in the Markdown format.";
95 const char kMarkdown_Help[] =
96 "--markdown: Write help output in the Markdown format.\n";
97
98 const char kNoColor[] = "nocolor";
99 const char kNoColor_HelpShort[] = "--nocolor: Force non-colored output.";
100 const char kNoColor_Help[] = COLOR_HELP_LONG;
101
102 const char kNinjaExecutable[] = "ninja-executable";
103 const char kNinjaExecutable_HelpShort[] =
104 "--ninja-executable: Set the Ninja executable.";
105 const char kNinjaExecutable_Help[] =
106 R"(--ninja-executable: Set the Ninja executable.
107
108 When set specifies the Ninja executable that will be used to perform some
109 post-processing on the generated files for more consistent builds.
110 )";
111
112 const char kScriptExecutable[] = "script-executable";
113 const char kScriptExecutable_HelpShort[] =
114 "--script-executable: Set the executable used to execute scripts.";
115 const char kScriptExecutable_Help[] =
116 R"(--script-executable: Set the executable used to execute scripts.
117
118 Path to specific Python executable or other interpreter to use in
119 action targets and exec_script calls. By default GN searches the
120 PATH for Python to execute these scripts.
121
122 If set to the empty string, the path of scripts specified in action
123 targets and exec_script calls will be executed directly.
124 )";
125
126 const char kQuiet[] = "q";
127 const char kQuiet_HelpShort[] =
128 "-q: Quiet mode. Don't print output on success.";
129 const char kQuiet_Help[] =
130 R"(-q: Quiet mode. Don't print output on success.
131
132 This is useful when running as a part of another script.
133 )";
134
135 const char kRoot[] = "root";
136 const char kRoot_HelpShort[] = "--root: Explicitly specify source root.";
137 const char kRoot_Help[] =
138 R"(--root: Explicitly specify source root.
139
140 Normally GN will look up in the directory tree from the current directory to
141 find a ".gn" file. The source root directory specifies the meaning of "//"
142 beginning with paths, and the BUILD.gn file in that directory will be the
143 first thing loaded.
144
145 Specifying --root allows GN to do builds in a specific directory regardless
146 of the current directory.
147
148 Examples
149
150 gn gen //out/Default --root=/home/baracko/src
151
152 gn desc //out/Default --root="C:\Users\BObama\My Documents\foo"
153 )";
154
155 const char kRootTarget[] = "root-target";
156 const char kRootTarget_HelpShort[] =
157 "--root-target: Override the root target.";
158 const char kRootTarget_Help[] =
159 R"(--root-target: Override the root target.
160
161 The root target is the target initially loaded to begin population of the
162 build graph. It defaults to "//:" which normally causes the "//BUILD.gn" file
163 to be loaded. It can be specified in the .gn file via the "root" variable (see
164 "gn help dotfile").
165
166 If specified, the value of this switch will be take precedence over the value
167 in ".gn". The target name (after the colon) is ignored, only the directory
168 name is required. Relative paths will be resolved relative to the current "//"
169 directory.
170
171 Specifying a different initial BUILD.gn file does not change the meaning of
172 the source root (the "//" directory) which can be independently set via the
173 --root switch. It also does not prevent the build file located at "//BUILD.gn"
174 from being loaded if a target in the build references that directory.
175
176 One use-case of this feature is to load a different set of initial targets
177 from project that uses GN without modifying any files.
178
179 Examples
180
181 gn gen //out/Default --root-target="//third_party/icu"
182
183 gn gen //out/Default --root-target="//third_party/grpc"
184 )";
185
186 const char kRuntimeDepsListFile[] = "runtime-deps-list-file";
187 const char kRuntimeDepsListFile_HelpShort[] =
188 "--runtime-deps-list-file: Save runtime dependencies for targets in file.";
189 const char kRuntimeDepsListFile_Help[] =
190 R"(--runtime-deps-list-file: Save runtime dependencies for targets in file.
191
192 --runtime-deps-list-file=<filename>
193
194 Where <filename> is a text file consisting of the labels, one per line, of
195 the targets for which runtime dependencies are desired.
196
197 See "gn help runtime_deps" for a description of how runtime dependencies are
198 computed.
199
200 Runtime deps output file
201
202 For each target requested, GN will write a separate runtime dependency file.
203 The runtime dependency file will be in the output directory alongside the
204 output file of the target, with a ".runtime_deps" extension. For example, if
205 the target "//foo:bar" is listed in the input file, and that target produces
206 an output file "bar.so", GN will create a file "bar.so.runtime_deps" in the
207 build directory.
208
209 If a source set, action, copy, or group is listed, the runtime deps file will
210 correspond to the .stamp file corresponding to that target. This is probably
211 not useful; the use-case for this feature is generally executable targets.
212
213 The runtime dependency file will list one file per line, with no escaping.
214 The files will be relative to the root_build_dir. The first line of the file
215 will be the main output file of the target itself (in the above example,
216 "bar.so").
217 )";
218
219 const char kThreads[] = "threads";
220 const char kThreads_HelpShort[] =
221 "--threads: Specify number of worker threads.";
222 const char kThreads_Help[] =
223 R"(--threads: Specify number of worker threads.
224
225 GN runs many threads to load and run build files. This can make debugging
226 challenging. Or you may want to experiment with different values to see how
227 it affects performance.
228
229 The parameter is the number of worker threads. This does not count the main
230 thread (so there are always at least two).
231
232 Examples
233
234 gen gen out/Default --threads=1
235 )";
236
237 const char kTime[] = "time";
238 const char kTime_HelpShort[] =
239 "--time: Outputs a summary of how long everything took.";
240 const char kTime_Help[] =
241 R"(--time: Outputs a summary of how long everything took.
242
243 Hopefully self-explanatory.
244
245 Examples
246
247 gn gen out/Default --time
248 )";
249
250 const char kTracelog[] = "tracelog";
251 const char kTracelog_HelpShort[] =
252 "--tracelog: Writes a Chrome-compatible trace log to the given file.";
253 const char kTracelog_Help[] =
254 R"(--tracelog: Writes a Chrome-compatible trace log to the given file.
255
256 The trace log will show file loads, executions, scripts, and writes. This
257 allows performance analysis of the generation step.
258
259 To view the trace, open Chrome and navigate to "chrome://tracing/", then
260 press "Load" and specify the file you passed to this parameter.
261
262 Examples
263
264 gn gen out/Default --tracelog=mytrace.trace
265 )";
266
267 const char kVerbose[] = "v";
268 const char kVerbose_HelpShort[] = "-v: Verbose logging.";
269 const char kVerbose_Help[] =
270 R"(-v: Verbose logging.
271
272 This will spew logging events to the console for debugging issues.
273
274 Good luck!
275 )";
276
277 const char kVersion[] = "version";
278 const char kVersion_HelpShort[] =
279 "--version: Prints the GN version number and exits.";
280 // It's impossible to see this since gn_main prints the version and exits
281 // immediately if this switch is used.
282 const char kVersion_Help[] = "";
283
284 const char kDefaultToolchain[] = "default-toolchain";
285
286 const char kRegeneration[] = "regeneration";
287 // -----------------------------------------------------------------------------
288
SwitchInfo()289 SwitchInfo::SwitchInfo() : short_help(""), long_help("") {}
290
291 SwitchInfo::SwitchInfo(const char* short_help, const char* long_help)
292 : short_help(short_help), long_help(long_help) {}
293
294 #define INSERT_VARIABLE(var) \
295 info_map[k##var] = SwitchInfo(k##var##_HelpShort, k##var##_Help);
296
297 const SwitchInfoMap& GetSwitches() {
298 static SwitchInfoMap info_map;
299 if (info_map.empty()) {
300 INSERT_VARIABLE(Args)
301 INSERT_VARIABLE(Color)
302 INSERT_VARIABLE(Dotfile)
303 INSERT_VARIABLE(FailOnUnusedArgs)
304 INSERT_VARIABLE(Markdown)
305 INSERT_VARIABLE(NinjaExecutable)
306 INSERT_VARIABLE(NoColor)
307 INSERT_VARIABLE(Root)
308 INSERT_VARIABLE(RootTarget)
309 INSERT_VARIABLE(Quiet)
310 INSERT_VARIABLE(RuntimeDepsListFile)
311 INSERT_VARIABLE(ScriptExecutable)
312 INSERT_VARIABLE(Threads)
313 INSERT_VARIABLE(Time)
314 INSERT_VARIABLE(Tracelog)
315 INSERT_VARIABLE(Verbose)
316 INSERT_VARIABLE(Version)
317 }
318 return info_map;
319 }
320
321 #undef INSERT_VARIABLE
322
323 } // namespace switches
324