• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 kScriptExecutable[] = "script-executable";
103 const char kScriptExecutable_HelpShort[] =
104     "--script-executable: Set the executable used to execute scripts.";
105 const char kScriptExecutable_Help[] =
106     R"(--script-executable: Set the executable used to execute scripts.
107 
108   Path to specific Python executable or other interpreter to use in
109   action targets and exec_script calls. By default GN searches the
110   PATH for Python to execute these scripts.
111 
112   If set to the empty string, the path specified in action targets
113   and exec_script calls will be executed directly.
114 )";
115 
116 const char kMetaDataKeys[] = "data";
117 const char kMetaDataKeys_HelpShort[] =
118     "--data: list of data keys to concatenate when collecting metadata.";
119 const char kMetaDataKeys_Help[] =
120     R"(--data: list of data keys to concatenate when collecting metadata.
121 
122   Data keys identify which variables in the given targets' `metadata`
123   scopes should be collected. At least one data key must be specified.
124 )";
125 
126 const char kMetaWalkKeys[] = "walk";
127 const char kMetaWalkKeys_HelpShort[] =
128     "--walk: list of walk keys to traverse when collecting metadata.";
129 const char kMetaWalkKeys_Help[] =
130     R"(--walk: list of walk keys to traverse when collecting metadata.
131 
132   Walk keys identify which variables in the given targets' `metadata`
133   scopes contain the list of dependencies to walk next. Absence of any
134   walk keys indicates that all deps and data_deps should be walked.
135 )";
136 
137 const char kMetaRebaseFiles[] = "rebase-files";
138 const char kMetaRebaseFiles_HelpShort[] =
139     "--rebase-files (boolean): whether to rebase the paths of the collected "
140     "metadata.";
141 const char kMetaRebaseFiles_Help[] =
142     R"(--rebase-files: whether to rebase the paths of the collected metadata.
143 
144   This flag indicates whether or not to rebase the collected results onto their
145   declaring source directory path. Note that this requires the data key(s) to
146   contain only lists of strings, which will be interpreted as file names.
147 )";
148 
149 const char kQuiet[] = "q";
150 const char kQuiet_HelpShort[] =
151     "-q: Quiet mode. Don't print output on success.";
152 const char kQuiet_Help[] =
153     R"(-q: Quiet mode. Don't print output on success.
154 
155   This is useful when running as a part of another script.
156 )";
157 
158 const char kRoot[] = "root";
159 const char kRoot_HelpShort[] = "--root: Explicitly specify source root.";
160 const char kRoot_Help[] =
161     R"(--root: Explicitly specify source root.
162 
163   Normally GN will look up in the directory tree from the current directory to
164   find a ".gn" file. The source root directory specifies the meaning of "//"
165   beginning with paths, and the BUILD.gn file in that directory will be the
166   first thing loaded.
167 
168   Specifying --root allows GN to do builds in a specific directory regardless
169   of the current directory.
170 
171 Examples
172 
173   gn gen //out/Default --root=/home/baracko/src
174 
175   gn desc //out/Default --root="C:\Users\BObama\My Documents\foo"
176 )";
177 
178 const char kRuntimeDepsListFile[] = "runtime-deps-list-file";
179 const char kRuntimeDepsListFile_HelpShort[] =
180     "--runtime-deps-list-file: Save runtime dependencies for targets in file.";
181 const char kRuntimeDepsListFile_Help[] =
182     R"(--runtime-deps-list-file: Save runtime dependencies for targets in file.
183 
184   --runtime-deps-list-file=<filename>
185 
186   Where <filename> is a text file consisting of the labels, one per line, of
187   the targets for which runtime dependencies are desired.
188 
189   See "gn help runtime_deps" for a description of how runtime dependencies are
190   computed.
191 
192 Runtime deps output file
193 
194   For each target requested, GN will write a separate runtime dependency file.
195   The runtime dependency file will be in the output directory alongside the
196   output file of the target, with a ".runtime_deps" extension. For example, if
197   the target "//foo:bar" is listed in the input file, and that target produces
198   an output file "bar.so", GN will create a file "bar.so.runtime_deps" in the
199   build directory.
200 
201   If a source set, action, copy, or group is listed, the runtime deps file will
202   correspond to the .stamp file corresponding to that target. This is probably
203   not useful; the use-case for this feature is generally executable targets.
204 
205   The runtime dependency file will list one file per line, with no escaping.
206   The files will be relative to the root_build_dir. The first line of the file
207   will be the main output file of the target itself (in the above example,
208   "bar.so").
209 )";
210 
211 const char kThreads[] = "threads";
212 const char kThreads_HelpShort[] =
213     "--threads: Specify number of worker threads.";
214 const char kThreads_Help[] =
215     R"(--threads: Specify number of worker threads.
216 
217   GN runs many threads to load and run build files. This can make debugging
218   challenging. Or you may want to experiment with different values to see how
219   it affects performance.
220 
221   The parameter is the number of worker threads. This does not count the main
222   thread (so there are always at least two).
223 
224 Examples
225 
226   gen gen out/Default --threads=1
227 )";
228 
229 const char kTime[] = "time";
230 const char kTime_HelpShort[] =
231     "--time: Outputs a summary of how long everything took.";
232 const char kTime_Help[] =
233     R"(--time: Outputs a summary of how long everything took.
234 
235   Hopefully self-explanatory.
236 
237 Examples
238 
239   gn gen out/Default --time
240 )";
241 
242 const char kTracelog[] = "tracelog";
243 const char kTracelog_HelpShort[] =
244     "--tracelog: Writes a Chrome-compatible trace log to the given file.";
245 const char kTracelog_Help[] =
246     R"(--tracelog: Writes a Chrome-compatible trace log to the given file.
247 
248   The trace log will show file loads, executions, scripts, and writes. This
249   allows performance analysis of the generation step.
250 
251   To view the trace, open Chrome and navigate to "chrome://tracing/", then
252   press "Load" and specify the file you passed to this parameter.
253 
254 Examples
255 
256   gn gen out/Default --tracelog=mytrace.trace
257 )";
258 
259 const char kVerbose[] = "v";
260 const char kVerbose_HelpShort[] = "-v: Verbose logging.";
261 const char kVerbose_Help[] =
262     R"(-v: Verbose logging.
263 
264   This will spew logging events to the console for debugging issues.
265 
266   Good luck!
267 )";
268 
269 const char kVersion[] = "version";
270 const char kVersion_HelpShort[] =
271     "--version: Prints the GN version number and exits.";
272 // It's impossible to see this since gn_main prints the version and exits
273 // immediately if this switch is used.
274 const char kVersion_Help[] = "";
275 
276 const char kAllToolchains[] = "all-toolchains";
277 
278 // -----------------------------------------------------------------------------
279 
SwitchInfo()280 SwitchInfo::SwitchInfo() : short_help(""), long_help("") {}
281 
282 SwitchInfo::SwitchInfo(const char* short_help, const char* long_help)
283     : short_help(short_help), long_help(long_help) {}
284 
285 #define INSERT_VARIABLE(var) \
286   info_map[k##var] = SwitchInfo(k##var##_HelpShort, k##var##_Help);
287 
288 const SwitchInfoMap& GetSwitches() {
289   static SwitchInfoMap info_map;
290   if (info_map.empty()) {
291     INSERT_VARIABLE(Args)
292     INSERT_VARIABLE(Color)
293     INSERT_VARIABLE(Dotfile)
294     INSERT_VARIABLE(FailOnUnusedArgs)
295     INSERT_VARIABLE(Markdown)
296     INSERT_VARIABLE(NoColor)
297     INSERT_VARIABLE(Root)
298     INSERT_VARIABLE(Quiet)
299     INSERT_VARIABLE(RuntimeDepsListFile)
300     INSERT_VARIABLE(ScriptExecutable)
301     INSERT_VARIABLE(Threads)
302     INSERT_VARIABLE(Time)
303     INSERT_VARIABLE(Tracelog)
304     INSERT_VARIABLE(Verbose)
305     INSERT_VARIABLE(Version)
306   }
307   return info_map;
308 }
309 
310 #undef INSERT_VARIABLE
311 
312 }  // namespace switches
313