blob: 76d97151e27dbd789d8c85fe18797d7029d37e81 [file] [log] [blame]
Damien Martin-Guillerezf88f4d82015-09-25 13:56:55 +00001// Copyright 2014 The Bazel Authors. All rights reserved.
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +01002//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14package com.google.devtools.build.lib.runtime;
15
16import com.google.devtools.build.lib.util.OptionsUtils;
17import com.google.devtools.build.lib.vfs.PathFragment;
18import com.google.devtools.common.options.Converter;
19import com.google.devtools.common.options.Converters;
20import com.google.devtools.common.options.Option;
21import com.google.devtools.common.options.OptionsBase;
ccalvarin2eaa02e2017-04-17 23:37:46 +020022import com.google.devtools.common.options.OptionsParser.OptionUsageRestrictions;
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010023import com.google.devtools.common.options.OptionsParsingException;
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010024import java.util.List;
25import java.util.Map;
26import java.util.logging.Level;
27
28/**
29 * Options common to all commands.
30 */
31public class CommonCommandOptions extends OptionsBase {
32 /**
33 * A class representing a blazerc option. blazeRc is serial number of the rc
34 * file this option came from, option is the name of the option and value is
35 * its value (or null if not specified).
36 */
37 public static class OptionOverride {
38 final int blazeRc;
39 final String command;
40 final String option;
41
42 public OptionOverride(int blazeRc, String command, String option) {
43 this.blazeRc = blazeRc;
44 this.command = command;
45 this.option = option;
46 }
47
48 @Override
49 public String toString() {
50 return String.format("%d:%s=%s", blazeRc, command, option);
51 }
52 }
53
54 /**
55 * Converter for --default_override. The format is:
56 * --default_override=blazerc:command=option.
57 */
58 public static class OptionOverrideConverter implements Converter<OptionOverride> {
59 static final String ERROR_MESSAGE = "option overrides must be in form "
60 + " rcfile:command=option, where rcfile is a nonzero integer";
61
62 public OptionOverrideConverter() {}
63
64 @Override
65 public OptionOverride convert(String input) throws OptionsParsingException {
66 int colonPos = input.indexOf(':');
67 int assignmentPos = input.indexOf('=');
68
69 if (colonPos < 0) {
70 throw new OptionsParsingException(ERROR_MESSAGE);
71 }
72
73 if (assignmentPos <= colonPos + 1) {
74 throw new OptionsParsingException(ERROR_MESSAGE);
75 }
76
77 int blazeRc;
78 try {
79 blazeRc = Integer.valueOf(input.substring(0, colonPos));
80 } catch (NumberFormatException e) {
81 throw new OptionsParsingException(ERROR_MESSAGE);
82 }
83
84 if (blazeRc < 0) {
85 throw new OptionsParsingException(ERROR_MESSAGE);
86 }
87
88 String command = input.substring(colonPos + 1, assignmentPos);
89 String option = input.substring(assignmentPos + 1);
90
91 return new OptionOverride(blazeRc, command, option);
92 }
93
94 @Override
95 public String getTypeDescription() {
96 return "blazerc option override";
97 }
98 }
99
100
brandjon94261752017-03-31 20:05:26 +0000101 // To create a new incompatible change, see the javadoc for AllIncompatibleChangesExpansion.
102 @Option(
103 name = "all_incompatible_changes",
104 defaultValue = "null",
105 category = "misc",
106 expansionFunction = AllIncompatibleChangesExpansion.class,
107 help =
108 "Enables all options of the form --incompatible_*. Use this option to find places where "
109 + "your build may break in the future due to deprecations or other changes."
110 )
111 public Void allIncompatibleChanges;
112
ccalvarin2eaa02e2017-04-17 23:37:46 +0200113 @Option(
114 name = "config",
115 defaultValue = "",
116 category = "misc",
117 allowMultiple = true,
118 help =
119 "Selects additional config sections from the rc files; for every <command>, it "
120 + "also pulls in the options from <command>:<config> if such a section exists; "
121 + "if the section does not exist, this flag is ignored. "
122 + "Note that it is currently only possible to provide these options on the "
123 + "command line, not in the rc files. The config sections and flag combinations "
124 + "they are equivalent to are located in the tools/*.blazerc config files."
125 )
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100126 public List<String> configs;
127
ccalvarin2eaa02e2017-04-17 23:37:46 +0200128 @Option(
129 name = "logging",
130 defaultValue = "3", // Level.INFO
131 category = "verbosity",
132 converter = Converters.LogLevelConverter.class,
133 help = "The logging level."
134 )
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100135 public Level verbosity;
136
ccalvarin2eaa02e2017-04-17 23:37:46 +0200137 @Option(
138 name = "client_env",
139 defaultValue = "",
140 optionUsageRestrictions = OptionUsageRestrictions.HIDDEN,
141 converter = Converters.AssignmentConverter.class,
142 allowMultiple = true,
143 help = "A system-generated parameter which specifies the client's environment"
144 )
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100145 public List<Map.Entry<String, String>> clientEnv;
146
ccalvarin2eaa02e2017-04-17 23:37:46 +0200147 @Option(
148 name = "ignore_client_env",
149 defaultValue = "false",
150 optionUsageRestrictions = OptionUsageRestrictions.HIDDEN,
151 deprecationWarning = "Deprecated, no-op.",
152 help = "Deprecated, no-op."
Dmitry Lomov31fab292017-03-07 18:33:08 +0000153 )
154 // TODO(laszlocsomor, dslomov) 2017-03-07: remove this flag after 2017-06-01 (~3 months from now)
155 // and all of its occurrences.
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100156 public boolean ignoreClientEnv;
157
ccalvarin2eaa02e2017-04-17 23:37:46 +0200158 @Option(
159 name = "client_cwd",
160 defaultValue = "",
161 optionUsageRestrictions = OptionUsageRestrictions.HIDDEN,
162 converter = OptionsUtils.PathFragmentConverter.class,
163 help = "A system-generated parameter which specifies the client's working directory"
164 )
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100165 public PathFragment clientCwd;
166
ccalvarin2eaa02e2017-04-17 23:37:46 +0200167 @Option(
168 name = "announce_rc",
169 defaultValue = "false",
170 category = "verbosity",
171 help = "Whether to announce rc options."
172 )
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100173 public boolean announceRcOptions;
174
175 /**
ccalvarin2eaa02e2017-04-17 23:37:46 +0200176 * These are the actual default overrides. Each value is a pair of (command name, value).
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100177 *
ccalvarin2eaa02e2017-04-17 23:37:46 +0200178 * <p>For example: "--default_override=build=--cpu=piii"
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100179 */
ccalvarin2eaa02e2017-04-17 23:37:46 +0200180 @Option(
181 name = "default_override",
182 defaultValue = "",
183 allowMultiple = true,
184 optionUsageRestrictions = OptionUsageRestrictions.HIDDEN,
185 converter = OptionOverrideConverter.class,
186 help = ""
187 )
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100188 public List<OptionOverride> optionsOverrides;
189
ccalvarin2eaa02e2017-04-17 23:37:46 +0200190 /** This is the filename that the Blaze client parsed. */
191 @Option(
192 name = "rc_source",
193 defaultValue = "",
194 allowMultiple = true,
195 optionUsageRestrictions = OptionUsageRestrictions.HIDDEN,
196 help = ""
197 )
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100198 public List<String> rcSource;
199
ccalvarin2eaa02e2017-04-17 23:37:46 +0200200 @Option(
201 name = "always_profile_slow_operations",
202 defaultValue = "true",
203 optionUsageRestrictions = OptionUsageRestrictions.UNDOCUMENTED,
204 help = "Whether profiling slow operations is always turned on"
205 )
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100206 public boolean alwaysProfileSlowOperations;
207
ccalvarin2eaa02e2017-04-17 23:37:46 +0200208 @Option(
209 name = "profile",
210 defaultValue = "null",
211 category = "misc",
212 converter = OptionsUtils.PathFragmentConverter.class,
213 help =
214 "If set, profile Blaze and write data to the specified "
215 + "file. Use blaze analyze-profile to analyze the profile."
216 )
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100217 public PathFragment profilePath;
218
ccalvarin2eaa02e2017-04-17 23:37:46 +0200219 @Option(
220 name = "record_full_profiler_data",
221 defaultValue = "false",
222 optionUsageRestrictions = OptionUsageRestrictions.UNDOCUMENTED,
223 help =
224 "By default, Blaze profiler will record only aggregated data for fast but numerous "
225 + "events (such as statting the file). If this option is enabled, profiler will record "
226 + "each event - resulting in more precise profiling data but LARGE performance "
227 + "hit. Option only has effect if --profile used as well."
228 )
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100229 public boolean recordFullProfilerData;
230
ccalvarin2eaa02e2017-04-17 23:37:46 +0200231 @Option(
232 name = "memory_profile",
233 defaultValue = "null",
234 optionUsageRestrictions = OptionUsageRestrictions.UNDOCUMENTED,
235 converter = OptionsUtils.PathFragmentConverter.class,
236 help = "If set, write memory usage data to the specified " + "file at phase ends."
237 )
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100238 public PathFragment memoryProfilePath;
239
ccalvarin2eaa02e2017-04-17 23:37:46 +0200240 @Option(
241 name = "gc_watchdog",
242 defaultValue = "false",
243 optionUsageRestrictions = OptionUsageRestrictions.UNDOCUMENTED,
244 deprecationWarning = "Ignoring: this option is no longer supported",
245 help = "Deprecated."
246 )
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100247 public boolean gcWatchdog;
248
ccalvarin2eaa02e2017-04-17 23:37:46 +0200249 @Option(
250 name = "startup_time",
251 defaultValue = "0",
252 optionUsageRestrictions = OptionUsageRestrictions.HIDDEN,
253 help = "The time in ms the launcher spends before sending the request to the blaze server."
254 )
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100255 public long startupTime;
256
Thiago Farina36c1d152016-05-04 14:24:14 +0000257 @Option(
258 name = "extract_data_time",
259 defaultValue = "0",
ccalvarin2eaa02e2017-04-17 23:37:46 +0200260 optionUsageRestrictions = OptionUsageRestrictions.HIDDEN,
Thiago Farina36c1d152016-05-04 14:24:14 +0000261 help = "The time in ms spent on extracting the new blaze version."
262 )
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100263 public long extractDataTime;
264
ccalvarin2eaa02e2017-04-17 23:37:46 +0200265 @Option(
266 name = "command_wait_time",
267 defaultValue = "0",
268 optionUsageRestrictions = OptionUsageRestrictions.HIDDEN,
269 help = "The time in ms a command had to wait on a busy Blaze server process."
270 )
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100271 public long waitTime;
272
ccalvarin2eaa02e2017-04-17 23:37:46 +0200273 @Option(
274 name = "tool_tag",
275 defaultValue = "",
276 category = "misc",
277 help = "A tool name to attribute this Blaze invocation to."
278 )
Googler88e31042015-07-08 19:16:57 +0000279 public String toolTag;
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100280
ccalvarin2eaa02e2017-04-17 23:37:46 +0200281 @Option(
282 name = "restart_reason",
283 defaultValue = "no_restart",
284 optionUsageRestrictions = OptionUsageRestrictions.HIDDEN,
285 help = "The reason for the server restart."
286 )
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100287 public String restartReason;
288
ccalvarin2eaa02e2017-04-17 23:37:46 +0200289 @Option(
290 name = "binary_path",
291 defaultValue = "",
292 optionUsageRestrictions = OptionUsageRestrictions.HIDDEN,
293 help = "The absolute path of the blaze binary."
294 )
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100295 public String binaryPath;
296
ccalvarin2eaa02e2017-04-17 23:37:46 +0200297 @Option(
298 name = "experimental_allow_project_files",
299 defaultValue = "false",
300 optionUsageRestrictions = OptionUsageRestrictions.HIDDEN,
301 help = "Enable processing of +<file> parameters."
302 )
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100303 public boolean allowProjectFiles;
Lukacs Berkice1445f2016-04-19 15:52:55 +0000304
ccalvarin2eaa02e2017-04-17 23:37:46 +0200305 @Option(
306 name = "block_for_lock",
307 defaultValue = "true",
308 optionUsageRestrictions = OptionUsageRestrictions.HIDDEN,
309 help =
310 "If set (the default), a command will block if there is another one running. If "
311 + "unset, these commands will immediately return with an error."
312 )
Lukacs Berkice1445f2016-04-19 15:52:55 +0000313 public boolean blockForLock;
314
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100315}