-
Notifications
You must be signed in to change notification settings - Fork 4.1k
/
Copy pathUiOptions.java
300 lines (264 loc) · 11.5 KB
/
UiOptions.java
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
// Copyright 2014 The Bazel Authors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.google.devtools.build.lib.runtime;
import com.google.devtools.build.lib.events.EventKind;
import com.google.devtools.common.options.Converter;
import com.google.devtools.common.options.Converters.CommaSeparatedOptionListConverter;
import com.google.devtools.common.options.Converters.RangeConverter;
import com.google.devtools.common.options.EnumConverter;
import com.google.devtools.common.options.Option;
import com.google.devtools.common.options.OptionDocumentationCategory;
import com.google.devtools.common.options.OptionEffectTag;
import com.google.devtools.common.options.OptionMetadataTag;
import com.google.devtools.common.options.OptionsBase;
import com.google.devtools.common.options.OptionsParsingException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
/** Command-line UI options. */
public class UiOptions extends OptionsBase {
/** Enum to select whether color output is enabled or not. */
public enum UseColor {
YES,
NO,
AUTO
}
/** Enum to select whether curses output is enabled or not. */
public enum UseCurses {
YES,
NO,
AUTO
}
/** Converter for {@link EventKind} filters * */
public static class EventFiltersConverter extends Converter.Contextless<List<EventKind>> {
/** A converter for event kinds. */
public static class EventKindConverter extends EnumConverter<EventKind> {
public EventKindConverter(String typeName) {
super(EventKind.class, typeName);
}
}
private final CommaSeparatedOptionListConverter delegate;
public EventFiltersConverter() {
this.delegate = new CommaSeparatedOptionListConverter();
}
@Override
public List<EventKind> convert(String input) throws OptionsParsingException {
if (input.isEmpty()) {
// This method is not called to convert the default value
// Empty list means that the user wants to filter all events
return new ArrayList<>(EventKind.ALL_EVENTS);
}
List<String> filters = this.delegate.convert(input, /*conversionContext=*/ null);
EnumConverter<EventKind> eventKindConverter = new EventKindConverter(input);
HashSet<EventKind> filteredEvents = new HashSet<>();
for (String filter : filters) {
if (!filter.startsWith("+") && !filter.startsWith("-")) {
filteredEvents.addAll(EventKind.ALL_EVENTS);
break;
}
}
for (String filter : filters) {
if (filter.startsWith("+")) {
filteredEvents.remove(
eventKindConverter.convert(filter.substring(1), /*conversionContext=*/ null));
} else if (filter.startsWith("-")) {
filteredEvents.add(
eventKindConverter.convert(filter.substring(1), /*conversionContext=*/ null));
} else {
filteredEvents.remove(eventKindConverter.convert(filter, /*conversionContext=*/ null));
}
}
return new ArrayList<>(filteredEvents);
}
@Override
public String getTypeDescription() {
return "Convert list of comma separated event kind to list of filters";
}
}
/** Converter for {@link UseColor}. */
public static class UseColorConverter extends EnumConverter<UseColor> {
public UseColorConverter() {
super(UseColor.class, "--color setting");
}
}
/** Converter for {@link UseCurses}. */
public static class UseCursesConverter extends EnumConverter<UseCurses> {
public UseCursesConverter() {
super(UseCurses.class, "--curses setting");
}
}
@Option(
name = "show_progress",
defaultValue = "true",
documentationCategory = OptionDocumentationCategory.UNCATEGORIZED,
effectTags = {OptionEffectTag.UNKNOWN},
help = "Display progress messages during a build.")
public boolean showProgress;
@Option(
name = "show_progress_rate_limit",
defaultValue = "0.2", // A nice middle ground; snappy but not too spammy in logs.
documentationCategory = OptionDocumentationCategory.UNCATEGORIZED,
effectTags = {OptionEffectTag.UNKNOWN},
help = "Minimum number of seconds between progress messages in the output.")
public double showProgressRateLimit;
@Option(
name = "color",
defaultValue = "auto",
converter = UseColorConverter.class,
documentationCategory = OptionDocumentationCategory.UNCATEGORIZED,
effectTags = {OptionEffectTag.UNKNOWN},
help = "Use terminal controls to colorize output.")
public UseColor useColorEnum;
@Option(
name = "curses",
defaultValue = "auto",
converter = UseCursesConverter.class,
documentationCategory = OptionDocumentationCategory.UNCATEGORIZED,
effectTags = {OptionEffectTag.UNKNOWN},
help = "Use terminal cursor controls to minimize scrolling output.")
public UseCurses useCursesEnum;
@Option(
name = "terminal_columns",
defaultValue = "80",
metadataTags = {OptionMetadataTag.HIDDEN},
documentationCategory = OptionDocumentationCategory.UNDOCUMENTED,
effectTags = {OptionEffectTag.UNKNOWN},
help = "A system-generated parameter which specifies the terminal width in columns.")
public int terminalColumns;
@Option(
name = "isatty",
defaultValue = "false",
metadataTags = {OptionMetadataTag.HIDDEN},
documentationCategory = OptionDocumentationCategory.UNDOCUMENTED,
effectTags = {OptionEffectTag.UNKNOWN},
help =
"A system-generated parameter which is used to notify the "
+ "server whether this client is running in a terminal. "
+ "If this is set to false, then '--color=auto' will be treated as '--color=no'. "
+ "If this is set to true, then '--color=auto' will be treated as '--color=yes'.")
public boolean isATty;
// This lives here (as opposed to the more logical BuildRequest.Options)
// because the client passes it to the server *always*. We don't want the
// client to have to figure out when it should or shouldn't to send it.
@Option(
name = "emacs",
defaultValue = "false",
documentationCategory = OptionDocumentationCategory.UNDOCUMENTED,
effectTags = {OptionEffectTag.UNKNOWN},
help =
"A system-generated parameter which is true iff EMACS=t or INSIDE_EMACS is set "
+ "in the environment of the client. This option controls certain display "
+ "features.")
public boolean runningInEmacs;
@Option(
name = "show_timestamps",
defaultValue = "false",
documentationCategory = OptionDocumentationCategory.UNCATEGORIZED,
effectTags = {OptionEffectTag.UNKNOWN},
help = "Include timestamps in messages")
public boolean showTimestamp;
@Option(
name = "progress_in_terminal_title",
defaultValue = "false",
documentationCategory = OptionDocumentationCategory.UNCATEGORIZED,
effectTags = {OptionEffectTag.UNKNOWN},
help =
"Show the command progress in the terminal title. "
+ "Useful to see what bazel is doing when having multiple terminal tabs.")
public boolean progressInTermTitle;
@Option(
name = "attempt_to_print_relative_paths",
oldName = "experimental_ui_attempt_to_print_relative_paths",
defaultValue = "false",
documentationCategory = OptionDocumentationCategory.LOGGING,
effectTags = {OptionEffectTag.TERMINAL_OUTPUT},
help =
"When printing the location part of messages, attempt to use a path relative to the "
+ "workspace directory or one of the directories specified by --package_path.")
public boolean attemptToPrintRelativePaths;
@Option(
name = "experimental_ui_debug_all_events",
defaultValue = "false",
metadataTags = {OptionMetadataTag.HIDDEN},
documentationCategory = OptionDocumentationCategory.UNDOCUMENTED,
effectTags = {OptionEffectTag.UNKNOWN},
help = "Report all events known to the Bazel UI.")
public boolean experimentalUiDebugAllEvents;
@Option(
name = "ui_event_filters",
converter = EventFiltersConverter.class,
defaultValue = "null",
documentationCategory = OptionDocumentationCategory.LOGGING,
effectTags = {OptionEffectTag.TERMINAL_OUTPUT},
help =
"Specifies which events to show in the UI. It is possible to add or remove events "
+ "to the default ones using leading +/-, or override the default "
+ "set completely with direct assignment. The set of supported event kinds "
+ "include INFO, DEBUG, ERROR and more.",
allowMultiple = true)
public List<EventKind> eventFilters;
@Option(
name = "ui_actions_shown",
oldName = "experimental_ui_actions_shown",
defaultValue = "8",
documentationCategory = OptionDocumentationCategory.UNCATEGORIZED,
effectTags = {OptionEffectTag.TERMINAL_OUTPUT},
help =
"Number of concurrent actions shown in the detailed progress bar; each "
+ "action is shown on a separate line. The progress bar always shows "
+ "at least one one, all numbers less than 1 are mapped to 1.")
public int uiActionsShown;
@Option(
name = "experimental_ui_max_stdouterr_bytes",
documentationCategory = OptionDocumentationCategory.EXECUTION_STRATEGY,
effectTags = {OptionEffectTag.EXECUTION},
defaultValue = "1048576",
converter = MaxStdoutErrBytesConverter.class,
help =
"The maximum size of the stdout / stderr files that will be printed to the console. "
+ "-1 implies no limit.")
public int maxStdoutErrBytes;
@Option(
name = "experimental_skymeld_ui",
defaultValue = "false",
documentationCategory = OptionDocumentationCategory.UNCATEGORIZED,
effectTags = {OptionEffectTag.TERMINAL_OUTPUT},
help =
"Displays both analysis and execution phase progress when both are running concurrently.")
public boolean skymeldUi;
public boolean useColor() {
return useColorEnum == UseColor.YES || (useColorEnum == UseColor.AUTO && isATty);
}
public boolean useCursorControl() {
return useCursesEnum == UseCurses.YES || (useCursesEnum == UseCurses.AUTO && isATty);
}
/** A converter for --experimental_ui_max_stdouterr_bytes. */
public static class MaxStdoutErrBytesConverter extends RangeConverter {
/**
* The maximum value of the flag must be limited to ensure conversions to UTF-8 do not trigger
* integer overflows. In JDK9+, if the message buffer contains a byte whose high bit is set, a
* UTF-8 decoding path is taken that allocates a new byte[] buffer twice as large as the message
* byte[] buffer.
*/
private static final int MAX_VALUE = (Integer.MAX_VALUE - 8) >> 1;
public MaxStdoutErrBytesConverter() {
super(-1, (Integer.MAX_VALUE - 8) >> 1);
}
@Override
public Integer convert(String input) throws OptionsParsingException {
Integer value = super.convert(input);
return value >= 0 ? value : MAX_VALUE;
}
}
}