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. |
Julio Merino | 2877485 | 2016-09-14 16:59:46 +0000 | [diff] [blame] | 14 | #ifndef BAZEL_SRC_MAIN_CPP_STARTUP_OPTIONS_H_ |
| 15 | #define BAZEL_SRC_MAIN_CPP_STARTUP_OPTIONS_H_ |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 16 | |
| 17 | #include <map> |
Kristina Chodorow | 9ce9b0f | 2015-10-06 03:54:45 +0000 | [diff] [blame] | 18 | #include <memory> |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 19 | #include <string> |
| 20 | #include <vector> |
| 21 | |
Thiago Farina | 7f9357f | 2015-04-23 13:57:43 +0000 | [diff] [blame] | 22 | #include "src/main/cpp/util/exit_code.h" |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 23 | |
| 24 | namespace blaze { |
| 25 | |
Julio Merino | e3e3bfa | 2016-12-08 22:22:12 +0000 | [diff] [blame] | 26 | class WorkspaceLayout; |
| 27 | |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 28 | // This class holds the parsed startup options for Blaze. |
Thiago Farina | 9bc5c34 | 2016-03-21 08:39:48 +0000 | [diff] [blame] | 29 | // These options and their defaults must be kept in sync with those in |
| 30 | // src/main/java/com/google/devtools/build/lib/runtime/BlazeServerStartupOptions.java. |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 31 | // The latter are purely decorative (they affect the help message, |
| 32 | // which displays the defaults). The actual defaults are defined |
| 33 | // in the constructor. |
| 34 | // |
| 35 | // TODO(bazel-team): The encapsulation is not quite right -- there are some |
| 36 | // places in blaze.cc where some of these fields are explicitly modified. Their |
| 37 | // names also don't conform to the style guide. |
Julio Merino | 2877485 | 2016-09-14 16:59:46 +0000 | [diff] [blame] | 38 | class StartupOptions { |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 39 | public: |
Julio Merino | e3e3bfa | 2016-12-08 22:22:12 +0000 | [diff] [blame] | 40 | explicit StartupOptions(const WorkspaceLayout* workspace_layout); |
Julio Merino | 2877485 | 2016-09-14 16:59:46 +0000 | [diff] [blame] | 41 | virtual ~StartupOptions(); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 42 | |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 43 | // Parses a single argument, either from the command line or from the .blazerc |
| 44 | // "startup" options. |
| 45 | // |
| 46 | // rcfile should be an empty string if the option being parsed does not come |
| 47 | // from a blazerc. |
| 48 | // |
Thiago Farina | 124c0b6 | 2015-05-08 12:00:12 +0000 | [diff] [blame] | 49 | // Sets "is_space_separated" true if arg is unary and uses the "--foo bar" |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 50 | // style, so its value is in next_arg. |
| 51 | // |
Thiago Farina | 124c0b6 | 2015-05-08 12:00:12 +0000 | [diff] [blame] | 52 | // Sets "is_space_separated" false if arg is either nullary |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 53 | // (e.g. "--[no]batch") or is unary but uses the "--foo=bar" style. |
| 54 | // |
| 55 | // Returns the exit code after processing the argument. "error" will contain |
| 56 | // a descriptive string for any return value other than |
| 57 | // blaze_exit_code::SUCCESS. |
Thiago Farina | 80bb0f2 | 2016-10-17 15:57:13 +0000 | [diff] [blame] | 58 | blaze_exit_code::ExitCode ProcessArg(const std::string &arg, |
| 59 | const std::string &next_arg, |
| 60 | const std::string &rcfile, |
| 61 | bool *is_space_separated, |
| 62 | std::string *error); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 63 | |
| 64 | // Adds any other options needed to result. |
Julio Merino | 2877485 | 2016-09-14 16:59:46 +0000 | [diff] [blame] | 65 | // |
| 66 | // TODO(jmmv): Now that we support site-specific options via subclasses of |
| 67 | // StartupOptions, the "ExtraOptions" concept makes no sense; remove it. |
Thiago Farina | 80bb0f2 | 2016-10-17 15:57:13 +0000 | [diff] [blame] | 68 | virtual void AddExtraOptions(std::vector<std::string> *result) const; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 69 | |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 70 | // Checks extra fields when processing arg. |
| 71 | // |
| 72 | // Returns the exit code after processing the argument. "error" will contain |
| 73 | // a descriptive string for any return value other than |
| 74 | // blaze_exit_code::SUCCESS. |
Julio Merino | 2877485 | 2016-09-14 16:59:46 +0000 | [diff] [blame] | 75 | // |
| 76 | // TODO(jmmv): Now that we support site-specific options via subclasses of |
| 77 | // StartupOptions, the "ExtraOptions" concept makes no sense; remove it. |
| 78 | virtual blaze_exit_code::ExitCode ProcessArgExtra( |
Thiago Farina | 80bb0f2 | 2016-10-17 15:57:13 +0000 | [diff] [blame] | 79 | const char *arg, const char *next_arg, const std::string &rcfile, |
| 80 | const char **value, bool *is_processed, std::string *error); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 81 | |
| 82 | // Return the default path to the JDK used to run Blaze itself |
| 83 | // (must be an absolute directory). |
Thiago Farina | 80bb0f2 | 2016-10-17 15:57:13 +0000 | [diff] [blame] | 84 | virtual std::string GetDefaultHostJavabase() const; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 85 | |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 86 | // Returns the path to the JVM. This should be called after parsing |
| 87 | // the startup options. |
Thiago Farina | 80bb0f2 | 2016-10-17 15:57:13 +0000 | [diff] [blame] | 88 | virtual std::string GetJvm(); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 89 | |
Eric Fellheimer | 3a695f3 | 2016-05-11 17:26:30 +0000 | [diff] [blame] | 90 | // Returns the executable used to start the Blaze server, typically the given |
| 91 | // JVM. |
Thiago Farina | 80bb0f2 | 2016-10-17 15:57:13 +0000 | [diff] [blame] | 92 | virtual std::string GetExe(const std::string &jvm, |
| 93 | const std::string &jar_path); |
Eric Fellheimer | 3a695f3 | 2016-05-11 17:26:30 +0000 | [diff] [blame] | 94 | |
| 95 | // Adds JVM prefix flags to be set. These will be added before all other |
| 96 | // JVM flags. |
Thiago Farina | 80bb0f2 | 2016-10-17 15:57:13 +0000 | [diff] [blame] | 97 | virtual void AddJVMArgumentPrefix(const std::string &javabase, |
| 98 | std::vector<std::string> *result) const; |
Eric Fellheimer | 3a695f3 | 2016-05-11 17:26:30 +0000 | [diff] [blame] | 99 | |
| 100 | // Adds JVM suffix flags. These will be added after all other JVM flags, and |
| 101 | // just before the Blaze server startup flags. |
Thiago Farina | 80bb0f2 | 2016-10-17 15:57:13 +0000 | [diff] [blame] | 102 | virtual void AddJVMArgumentSuffix(const std::string &real_install_dir, |
| 103 | const std::string &jar_path, |
| 104 | std::vector<std::string> *result) const; |
Eric Fellheimer | 3a695f3 | 2016-05-11 17:26:30 +0000 | [diff] [blame] | 105 | |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 106 | // Adds JVM tuning flags for Blaze. |
| 107 | // |
| 108 | // Returns the exit code after this operation. "error" will be set to a |
| 109 | // descriptive string for any value other than blaze_exit_code::SUCCESS. |
Julio Merino | 2877485 | 2016-09-14 16:59:46 +0000 | [diff] [blame] | 110 | virtual blaze_exit_code::ExitCode AddJVMArguments( |
Thiago Farina | 80bb0f2 | 2016-10-17 15:57:13 +0000 | [diff] [blame] | 111 | const std::string &host_javabase, std::vector<std::string> *result, |
| 112 | const std::vector<std::string> &user_options, std::string *error) const; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 113 | |
Luis Fernando Pino Duque | 8949c07 | 2016-10-28 15:17:22 +0000 | [diff] [blame] | 114 | // Checks whether the argument is a valid nullary option. |
| 115 | // E.g. --master_bazelrc, --nomaster_bazelrc. |
Luis Fernando Pino Duque | 0311fc5 | 2016-11-21 13:20:50 +0000 | [diff] [blame] | 116 | bool IsNullary(const std::string& arg) const; |
Luis Fernando Pino Duque | 8949c07 | 2016-10-28 15:17:22 +0000 | [diff] [blame] | 117 | |
| 118 | // Checks whether the argument is a valid unary option. |
| 119 | // E.g. --blazerc=foo, --blazerc foo. |
Luis Fernando Pino Duque | 0311fc5 | 2016-11-21 13:20:50 +0000 | [diff] [blame] | 120 | bool IsUnary(const std::string& arg) const; |
| 121 | |
| 122 | std::string GetLowercaseProductName() const; |
Luis Fernando Pino Duque | 8949c07 | 2016-10-28 15:17:22 +0000 | [diff] [blame] | 123 | |
Luis Fernando Pino Duque | 928a49c | 2016-06-24 09:43:20 +0000 | [diff] [blame] | 124 | // The capitalized name of this binary. |
Thiago Farina | 80bb0f2 | 2016-10-17 15:57:13 +0000 | [diff] [blame] | 125 | const std::string product_name; |
Luis Fernando Pino Duque | 928a49c | 2016-06-24 09:43:20 +0000 | [diff] [blame] | 126 | |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 127 | // Blaze's output base. Everything is relative to this. See |
| 128 | // the BlazeDirectories Java class for details. |
Thiago Farina | 80bb0f2 | 2016-10-17 15:57:13 +0000 | [diff] [blame] | 129 | std::string output_base; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 130 | |
| 131 | // Installation base for a specific release installation. |
Thiago Farina | 80bb0f2 | 2016-10-17 15:57:13 +0000 | [diff] [blame] | 132 | std::string install_base; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 133 | |
| 134 | // The toplevel directory containing Blaze's output. When Blaze is |
| 135 | // run by a test, we use TEST_TMPDIR, simplifying the correct |
| 136 | // hermetic invocation of Blaze from tests. |
Thiago Farina | 80bb0f2 | 2016-10-17 15:57:13 +0000 | [diff] [blame] | 137 | std::string output_root; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 138 | |
| 139 | // Blaze's output_user_root. Used only for computing install_base and |
| 140 | // output_base. |
Thiago Farina | 80bb0f2 | 2016-10-17 15:57:13 +0000 | [diff] [blame] | 141 | std::string output_user_root; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 142 | |
Lukacs Berki | 5fb98d1 | 2015-12-09 15:29:46 +0000 | [diff] [blame] | 143 | // Whether to put the execroot at $OUTPUT_BASE/$WORKSPACE_NAME (if false) or |
| 144 | // $OUTPUT_BASE/execroot/$WORKSPACE_NAME (if true). |
| 145 | bool deep_execroot; |
| 146 | |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 147 | // Block for the Blaze server lock. Otherwise, |
| 148 | // quit with non-0 exit code if lock can't |
| 149 | // be acquired immediately. |
| 150 | bool block_for_lock; |
| 151 | |
| 152 | bool host_jvm_debug; |
| 153 | |
Thiago Farina | 80bb0f2 | 2016-10-17 15:57:13 +0000 | [diff] [blame] | 154 | std::string host_jvm_profile; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 155 | |
Thiago Farina | 80bb0f2 | 2016-10-17 15:57:13 +0000 | [diff] [blame] | 156 | std::vector<std::string> host_jvm_args; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 157 | |
| 158 | bool batch; |
| 159 | |
| 160 | // From the man page: "This policy is useful for workloads that are |
| 161 | // non-interactive, but do not want to lower their nice value, and for |
| 162 | // workloads that want a deterministic scheduling policy without |
| 163 | // interactivity causing extra preemptions (between the workload's tasks)." |
| 164 | bool batch_cpu_scheduling; |
| 165 | |
| 166 | // If negative, don't mess with ionice. Otherwise, set a level from 0-7 |
| 167 | // for best-effort scheduling. 0 is highest priority, 7 is lowest. |
| 168 | int io_nice_level; |
| 169 | |
| 170 | int max_idle_secs; |
| 171 | |
Janak Ramakrishnan | adc706f | 2016-03-07 19:12:48 +0000 | [diff] [blame] | 172 | bool oom_more_eagerly; |
| 173 | |
Janak Ramakrishnan | 8cc772e | 2016-03-23 17:26:12 +0000 | [diff] [blame] | 174 | int oom_more_eagerly_threshold; |
| 175 | |
Michajlo Matijkiw | af79a32 | 2016-09-16 15:44:35 +0000 | [diff] [blame] | 176 | bool write_command_log; |
| 177 | |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 178 | // If true, Blaze will listen to OS-level file change notifications. |
| 179 | bool watchfs; |
| 180 | |
| 181 | // Temporary experimental flag that permits configurable attribute syntax |
| 182 | // in BUILD files. This will be removed when configurable attributes is |
| 183 | // a more stable feature. |
| 184 | bool allow_configurable_attributes; |
| 185 | |
| 186 | // Temporary flag for enabling EventBus exceptions to be fatal. |
| 187 | bool fatal_event_bus_exceptions; |
| 188 | |
| 189 | // A string to string map specifying where each option comes from. If the |
| 190 | // value is empty, it was on the command line, if it is a string, it comes |
| 191 | // from a blazerc file, if a key is not present, it is the default. |
Thiago Farina | 80bb0f2 | 2016-10-17 15:57:13 +0000 | [diff] [blame] | 192 | std::map<std::string, std::string> option_sources; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 193 | |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 194 | // Returns the GetHostJavabase. This should be called after parsing |
| 195 | // the --host_javabase option. |
Thiago Farina | 80bb0f2 | 2016-10-17 15:57:13 +0000 | [diff] [blame] | 196 | std::string GetHostJavabase(); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 197 | |
Lukacs Berki | bfd9aa3 | 2017-03-06 11:21:35 +0000 | [diff] [blame] | 198 | // Returns the explicit value of the --host_javabase startup option or the |
| 199 | // empty string if it was not specified on the command line. |
| 200 | std::string GetExplicitHostJavabase() const; |
| 201 | |
Lukacs Berki | 8b3b918 | 2016-04-14 08:29:05 +0000 | [diff] [blame] | 202 | // Port for gRPC command server. 0 means let the kernel choose, -1 means no |
| 203 | // gRPC command server. |
Lukacs Berki | 7e0249e | 2016-04-21 08:14:08 +0000 | [diff] [blame] | 204 | int command_port; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 205 | |
Lukacs Berki | 71675a5 | 2016-11-08 09:48:27 +0000 | [diff] [blame] | 206 | // Connection timeout for each gRPC connection attempt. |
| 207 | int connect_timeout_secs; |
| 208 | |
Alex Humesky | 2f3f4cf | 2015-09-29 01:42:00 +0000 | [diff] [blame] | 209 | // Invocation policy proto. May be NULL. |
Thiago Farina | 80bb0f2 | 2016-10-17 15:57:13 +0000 | [diff] [blame] | 210 | const char *invocation_policy; |
Alex Humesky | 2f3f4cf | 2015-09-29 01:42:00 +0000 | [diff] [blame] | 211 | |
Lukacs Berki | 71675a5 | 2016-11-08 09:48:27 +0000 | [diff] [blame] | 212 | // Whether to output addition debugging information in the client. |
| 213 | bool client_debug; |
| 214 | |
Chloe Calvarin | eaa3be7 | 2016-12-13 19:48:34 +0000 | [diff] [blame] | 215 | // Whether to check custom file for exit code when the Blaze Server exits |
| 216 | // abruptly without proper communication over gRPC. |
| 217 | bool use_custom_exit_code_on_abrupt_exit; |
| 218 | |
Julio Merino | 5a09804 | 2017-02-06 16:43:10 +0000 | [diff] [blame] | 219 | // Value of the java.util.logging.FileHandler.formatter Java property. |
| 220 | std::string java_logging_formatter; |
| 221 | |
Julio Merino | 41b5688 | 2016-09-15 13:48:10 +0000 | [diff] [blame] | 222 | protected: |
| 223 | // Constructor for subclasses only so that site-specific extensions of this |
| 224 | // class can override the product name. The product_name must be the |
| 225 | // capitalized version of the name, as in "Bazel". |
Julio Merino | e3e3bfa | 2016-12-08 22:22:12 +0000 | [diff] [blame] | 226 | explicit StartupOptions(const std::string &product_name, |
| 227 | const WorkspaceLayout* workspace_layout); |
Julio Merino | 41b5688 | 2016-09-15 13:48:10 +0000 | [diff] [blame] | 228 | |
Luis Fernando Pino Duque | 8949c07 | 2016-10-28 15:17:22 +0000 | [diff] [blame] | 229 | // Holds the valid nullary startup options. |
| 230 | std::vector<std::string> nullary_options; |
| 231 | |
| 232 | // Holds the valid unary startup options. |
| 233 | std::vector<std::string> unary_options; |
| 234 | |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 235 | private: |
Thiago Farina | 80bb0f2 | 2016-10-17 15:57:13 +0000 | [diff] [blame] | 236 | std::string host_javabase; |
Lukacs Berki | bfd9aa3 | 2017-03-06 11:21:35 +0000 | [diff] [blame] | 237 | std::string default_host_javabase; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 238 | }; |
| 239 | |
| 240 | } // namespace blaze |
Thiago Farina | c380dc4 | 2016-09-30 08:36:20 +0000 | [diff] [blame] | 241 | |
Julio Merino | 2877485 | 2016-09-14 16:59:46 +0000 | [diff] [blame] | 242 | #endif // BAZEL_SRC_MAIN_CPP_STARTUP_OPTIONS_H_ |