Damien Martin-Guillerez | f88f4d8 | 2015-09-25 13:56:55 +0000 | [diff] [blame] | 1 | // Copyright 2014 The Bazel Authors. All rights reserved. |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 2 | // |
| 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. |
| 14 | package com.google.devtools.build.lib.runtime; |
| 15 | |
| 16 | import com.google.devtools.build.lib.util.OptionsUtils; |
| 17 | import com.google.devtools.build.lib.vfs.PathFragment; |
| 18 | import com.google.devtools.common.options.Converter; |
| 19 | import com.google.devtools.common.options.Converters; |
| 20 | import com.google.devtools.common.options.Option; |
| 21 | import com.google.devtools.common.options.OptionsBase; |
ccalvarin | 2eaa02e | 2017-04-17 23:37:46 +0200 | [diff] [blame] | 22 | import com.google.devtools.common.options.OptionsParser.OptionUsageRestrictions; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 23 | import com.google.devtools.common.options.OptionsParsingException; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 24 | import java.util.List; |
| 25 | import java.util.Map; |
| 26 | import java.util.logging.Level; |
| 27 | |
| 28 | /** |
| 29 | * Options common to all commands. |
| 30 | */ |
| 31 | public 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 | |
brandjon | 9426175 | 2017-03-31 20:05:26 +0000 | [diff] [blame] | 101 | // 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 | |
ccalvarin | 2eaa02e | 2017-04-17 23:37:46 +0200 | [diff] [blame] | 113 | @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 Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 126 | public List<String> configs; |
| 127 | |
ccalvarin | 2eaa02e | 2017-04-17 23:37:46 +0200 | [diff] [blame] | 128 | @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 Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 135 | public Level verbosity; |
| 136 | |
ccalvarin | 2eaa02e | 2017-04-17 23:37:46 +0200 | [diff] [blame] | 137 | @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 Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 145 | public List<Map.Entry<String, String>> clientEnv; |
| 146 | |
ccalvarin | 2eaa02e | 2017-04-17 23:37:46 +0200 | [diff] [blame] | 147 | @Option( |
| 148 | name = "ignore_client_env", |
| 149 | defaultValue = "false", |
| 150 | optionUsageRestrictions = OptionUsageRestrictions.HIDDEN, |
| 151 | deprecationWarning = "Deprecated, no-op.", |
| 152 | help = "Deprecated, no-op." |
Dmitry Lomov | 31fab29 | 2017-03-07 18:33:08 +0000 | [diff] [blame] | 153 | ) |
| 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 Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 156 | public boolean ignoreClientEnv; |
| 157 | |
ccalvarin | 2eaa02e | 2017-04-17 23:37:46 +0200 | [diff] [blame] | 158 | @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 Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 165 | public PathFragment clientCwd; |
| 166 | |
ccalvarin | 2eaa02e | 2017-04-17 23:37:46 +0200 | [diff] [blame] | 167 | @Option( |
| 168 | name = "announce_rc", |
| 169 | defaultValue = "false", |
| 170 | category = "verbosity", |
| 171 | help = "Whether to announce rc options." |
| 172 | ) |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 173 | public boolean announceRcOptions; |
| 174 | |
| 175 | /** |
ccalvarin | 2eaa02e | 2017-04-17 23:37:46 +0200 | [diff] [blame] | 176 | * These are the actual default overrides. Each value is a pair of (command name, value). |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 177 | * |
ccalvarin | 2eaa02e | 2017-04-17 23:37:46 +0200 | [diff] [blame] | 178 | * <p>For example: "--default_override=build=--cpu=piii" |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 179 | */ |
ccalvarin | 2eaa02e | 2017-04-17 23:37:46 +0200 | [diff] [blame] | 180 | @Option( |
| 181 | name = "default_override", |
| 182 | defaultValue = "", |
| 183 | allowMultiple = true, |
| 184 | optionUsageRestrictions = OptionUsageRestrictions.HIDDEN, |
| 185 | converter = OptionOverrideConverter.class, |
| 186 | help = "" |
| 187 | ) |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 188 | public List<OptionOverride> optionsOverrides; |
| 189 | |
ccalvarin | 2eaa02e | 2017-04-17 23:37:46 +0200 | [diff] [blame] | 190 | /** 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 Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 198 | public List<String> rcSource; |
| 199 | |
ccalvarin | 2eaa02e | 2017-04-17 23:37:46 +0200 | [diff] [blame] | 200 | @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 Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 206 | public boolean alwaysProfileSlowOperations; |
| 207 | |
ccalvarin | 2eaa02e | 2017-04-17 23:37:46 +0200 | [diff] [blame] | 208 | @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 Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 217 | public PathFragment profilePath; |
| 218 | |
ccalvarin | 2eaa02e | 2017-04-17 23:37:46 +0200 | [diff] [blame] | 219 | @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 Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 229 | public boolean recordFullProfilerData; |
| 230 | |
ccalvarin | 2eaa02e | 2017-04-17 23:37:46 +0200 | [diff] [blame] | 231 | @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 Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 238 | public PathFragment memoryProfilePath; |
| 239 | |
ccalvarin | 2eaa02e | 2017-04-17 23:37:46 +0200 | [diff] [blame] | 240 | @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 Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 247 | public boolean gcWatchdog; |
| 248 | |
ccalvarin | 2eaa02e | 2017-04-17 23:37:46 +0200 | [diff] [blame] | 249 | @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 Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 255 | public long startupTime; |
| 256 | |
Thiago Farina | 36c1d15 | 2016-05-04 14:24:14 +0000 | [diff] [blame] | 257 | @Option( |
| 258 | name = "extract_data_time", |
| 259 | defaultValue = "0", |
ccalvarin | 2eaa02e | 2017-04-17 23:37:46 +0200 | [diff] [blame] | 260 | optionUsageRestrictions = OptionUsageRestrictions.HIDDEN, |
Thiago Farina | 36c1d15 | 2016-05-04 14:24:14 +0000 | [diff] [blame] | 261 | help = "The time in ms spent on extracting the new blaze version." |
| 262 | ) |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 263 | public long extractDataTime; |
| 264 | |
ccalvarin | 2eaa02e | 2017-04-17 23:37:46 +0200 | [diff] [blame] | 265 | @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 Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 271 | public long waitTime; |
| 272 | |
ccalvarin | 2eaa02e | 2017-04-17 23:37:46 +0200 | [diff] [blame] | 273 | @Option( |
| 274 | name = "tool_tag", |
| 275 | defaultValue = "", |
| 276 | category = "misc", |
| 277 | help = "A tool name to attribute this Blaze invocation to." |
| 278 | ) |
Googler | 88e3104 | 2015-07-08 19:16:57 +0000 | [diff] [blame] | 279 | public String toolTag; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 280 | |
ccalvarin | 2eaa02e | 2017-04-17 23:37:46 +0200 | [diff] [blame] | 281 | @Option( |
| 282 | name = "restart_reason", |
| 283 | defaultValue = "no_restart", |
| 284 | optionUsageRestrictions = OptionUsageRestrictions.HIDDEN, |
| 285 | help = "The reason for the server restart." |
| 286 | ) |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 287 | public String restartReason; |
| 288 | |
ccalvarin | 2eaa02e | 2017-04-17 23:37:46 +0200 | [diff] [blame] | 289 | @Option( |
| 290 | name = "binary_path", |
| 291 | defaultValue = "", |
| 292 | optionUsageRestrictions = OptionUsageRestrictions.HIDDEN, |
| 293 | help = "The absolute path of the blaze binary." |
| 294 | ) |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 295 | public String binaryPath; |
| 296 | |
ccalvarin | 2eaa02e | 2017-04-17 23:37:46 +0200 | [diff] [blame] | 297 | @Option( |
| 298 | name = "experimental_allow_project_files", |
| 299 | defaultValue = "false", |
| 300 | optionUsageRestrictions = OptionUsageRestrictions.HIDDEN, |
| 301 | help = "Enable processing of +<file> parameters." |
| 302 | ) |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 303 | public boolean allowProjectFiles; |
Lukacs Berki | ce1445f | 2016-04-19 15:52:55 +0000 | [diff] [blame] | 304 | |
ccalvarin | 2eaa02e | 2017-04-17 23:37:46 +0200 | [diff] [blame] | 305 | @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 Berki | ce1445f | 2016-04-19 15:52:55 +0000 | [diff] [blame] | 313 | public boolean blockForLock; |
| 314 | |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 315 | } |