Nathan Harmata | bf98f39 | 2016-01-07 22:58:29 +0000 | [diff] [blame] | 1 | // Copyright 2016 The Bazel Authors. All rights reserved. |
| 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 | // |
Thiago Farina | 676cb9f | 2016-10-06 11:00:43 +0000 | [diff] [blame] | 15 | // global_variables.h: The global state in the blaze.cc Blaze client. |
Nathan Harmata | bf98f39 | 2016-01-07 22:58:29 +0000 | [diff] [blame] | 16 | // |
| 17 | |
Thiago Farina | 676cb9f | 2016-10-06 11:00:43 +0000 | [diff] [blame] | 18 | #ifndef BAZEL_SRC_MAIN_CPP_GLOBAL_VARIABLES_H_ |
| 19 | #define BAZEL_SRC_MAIN_CPP_GLOBAL_VARIABLES_H_ |
Nathan Harmata | bf98f39 | 2016-01-07 22:58:29 +0000 | [diff] [blame] | 20 | |
Nathan Harmata | bf98f39 | 2016-01-07 22:58:29 +0000 | [diff] [blame] | 21 | #include <sys/types.h> |
| 22 | #include <string> |
| 23 | #include <vector> |
| 24 | |
Laszlo Csomor | 3b89d2d | 2016-11-28 14:04:27 +0000 | [diff] [blame] | 25 | #include "src/main/cpp/util/port.h" // pid_t on Windows/MSVC |
| 26 | |
Nathan Harmata | bf98f39 | 2016-01-07 22:58:29 +0000 | [diff] [blame] | 27 | namespace blaze { |
| 28 | |
Thiago Farina | 676cb9f | 2016-10-06 11:00:43 +0000 | [diff] [blame] | 29 | class StartupOptions; |
| 30 | |
Nathan Harmata | bf98f39 | 2016-01-07 22:58:29 +0000 | [diff] [blame] | 31 | // The reason for a blaze server restart. |
Thiago Farina | 36c1d15 | 2016-05-04 14:24:14 +0000 | [diff] [blame] | 32 | // Keep in sync with logging.proto. |
janakr | faa9dcf | 2017-05-17 07:10:41 +0200 | [diff] [blame] | 33 | enum RestartReason { |
| 34 | NO_RESTART = 0, |
| 35 | NO_DAEMON, |
| 36 | NEW_VERSION, |
| 37 | NEW_OPTIONS, |
| 38 | PID_FILE_BUT_NO_SERVER, |
| 39 | SERVER_VANISHED, |
| 40 | SERVER_UNRESPONSIVE |
| 41 | }; |
Nathan Harmata | bf98f39 | 2016-01-07 22:58:29 +0000 | [diff] [blame] | 42 | |
| 43 | struct GlobalVariables { |
michajlo | ce5e718 | 2019-06-03 13:16:41 -0700 | [diff] [blame^] | 44 | GlobalVariables(); |
Thiago Farina | 676cb9f | 2016-10-06 11:00:43 +0000 | [diff] [blame] | 45 | |
László Csomor | 41627ad | 2017-06-07 04:06:44 -0400 | [diff] [blame] | 46 | std::string ServerJarPath() const { |
| 47 | // The server jar is called "A-server.jar" so it's the first binary we |
| 48 | // extracted. |
| 49 | return extracted_binaries.empty() ? "" : extracted_binaries[0]; |
| 50 | } |
| 51 | |
michajlo | f74f9fe | 2018-01-29 09:06:44 -0800 | [diff] [blame] | 52 | // Whrere to write the server's JVM's output. Default value is |
| 53 | // <output_base>/server/jvm.out. |
| 54 | std::string jvm_log_file; |
| 55 | |
| 56 | // Whether or not the jvm_log_file should be opened with O_APPEND. |
| 57 | bool jvm_log_file_append; |
Nathan Harmata | bf98f39 | 2016-01-07 22:58:29 +0000 | [diff] [blame] | 58 | |
Nathan Harmata | bf98f39 | 2016-01-07 22:58:29 +0000 | [diff] [blame] | 59 | // The nearest enclosing workspace directory, starting from cwd. |
| 60 | // If not under a workspace directory, this is equal to cwd. |
Thiago Farina | 676cb9f | 2016-10-06 11:00:43 +0000 | [diff] [blame] | 61 | std::string workspace; |
Nathan Harmata | bf98f39 | 2016-01-07 22:58:29 +0000 | [diff] [blame] | 62 | |
Eric Fellheimer | 3a695f3 | 2016-05-11 17:26:30 +0000 | [diff] [blame] | 63 | // The path of the JVM executable that should be used to launch Blaze. |
Thiago Farina | 676cb9f | 2016-10-06 11:00:43 +0000 | [diff] [blame] | 64 | std::string jvm_path; |
Eric Fellheimer | 3a695f3 | 2016-05-11 17:26:30 +0000 | [diff] [blame] | 65 | |
jingwen | 68c57f0 | 2018-11-21 16:17:17 -0800 | [diff] [blame] | 66 | // TODO(laszlocsomor) 2016-11-28: move pid_t usage out of here and wherever |
Laszlo Csomor | 3b89d2d | 2016-11-28 14:04:27 +0000 | [diff] [blame] | 67 | // else it appears. Find some way to not have to declare a pid_t here, either |
| 68 | // by making PID handling platform-independent or some other idea. |
Nathan Harmata | bf98f39 | 2016-01-07 22:58:29 +0000 | [diff] [blame] | 69 | pid_t server_pid; |
| 70 | |
Nathan Harmata | bf98f39 | 2016-01-07 22:58:29 +0000 | [diff] [blame] | 71 | // Contains the relative paths of all the files in the attached zip, and is |
Thiago Farina | 3820e8d | 2016-04-05 23:52:40 +0000 | [diff] [blame] | 72 | // populated during GetInstallBase(). |
Thiago Farina | 676cb9f | 2016-10-06 11:00:43 +0000 | [diff] [blame] | 73 | std::vector<std::string> extracted_binaries; |
Nathan Harmata | bf98f39 | 2016-01-07 22:58:29 +0000 | [diff] [blame] | 74 | |
Thiago Farina | 36c1d15 | 2016-05-04 14:24:14 +0000 | [diff] [blame] | 75 | // Parsed startup options. |
Julio Merino | 2877485 | 2016-09-14 16:59:46 +0000 | [diff] [blame] | 76 | StartupOptions *options; // TODO(jmmv): This should really be const. |
Nathan Harmata | bf98f39 | 2016-01-07 22:58:29 +0000 | [diff] [blame] | 77 | |
Thiago Farina | 36c1d15 | 2016-05-04 14:24:14 +0000 | [diff] [blame] | 78 | // The time in ms the launcher spends before sending the request to the blaze |
| 79 | // server. |
Nathan Harmata | bf98f39 | 2016-01-07 22:58:29 +0000 | [diff] [blame] | 80 | uint64_t startup_time; |
| 81 | |
Thiago Farina | 36c1d15 | 2016-05-04 14:24:14 +0000 | [diff] [blame] | 82 | // The time in ms spent on extracting the new blaze version. |
| 83 | // This is part of startup_time. |
Nathan Harmata | bf98f39 | 2016-01-07 22:58:29 +0000 | [diff] [blame] | 84 | uint64_t extract_data_time; |
| 85 | |
Thiago Farina | 36c1d15 | 2016-05-04 14:24:14 +0000 | [diff] [blame] | 86 | // The time in ms a command had to wait on a busy Blaze server process. |
| 87 | // This is part of startup_time. |
Nathan Harmata | bf98f39 | 2016-01-07 22:58:29 +0000 | [diff] [blame] | 88 | uint64_t command_wait_time; |
| 89 | |
Thiago Farina | 36c1d15 | 2016-05-04 14:24:14 +0000 | [diff] [blame] | 90 | // The reason for the server restart. |
Nathan Harmata | bf98f39 | 2016-01-07 22:58:29 +0000 | [diff] [blame] | 91 | RestartReason restart_reason; |
| 92 | |
Thiago Farina | 36c1d15 | 2016-05-04 14:24:14 +0000 | [diff] [blame] | 93 | // The absolute path of the blaze binary. |
Thiago Farina | 676cb9f | 2016-10-06 11:00:43 +0000 | [diff] [blame] | 94 | std::string binary_path; |
Nathan Harmata | bf98f39 | 2016-01-07 22:58:29 +0000 | [diff] [blame] | 95 | |
| 96 | // MD5 hash of the Blaze binary (includes deploy.jar, extracted binaries, and |
| 97 | // anything else that ends up under the install_base). |
Thiago Farina | 676cb9f | 2016-10-06 11:00:43 +0000 | [diff] [blame] | 98 | std::string install_md5; |
Nathan Harmata | bf98f39 | 2016-01-07 22:58:29 +0000 | [diff] [blame] | 99 | }; |
| 100 | |
| 101 | } // namespace blaze |
Thiago Farina | 319fd3a | 2016-01-14 19:42:24 +0000 | [diff] [blame] | 102 | |
Thiago Farina | 676cb9f | 2016-10-06 11:00:43 +0000 | [diff] [blame] | 103 | #endif // BAZEL_SRC_MAIN_CPP_GLOBAL_VARIABLES_H_ |