blob: ca9b00e619fe2f3bdfed73965240442f0db8531a [file] [log] [blame]
Nathan Harmatabf98f392016-01-07 22:58:29 +00001// 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 Farina676cb9f2016-10-06 11:00:43 +000015// global_variables.h: The global state in the blaze.cc Blaze client.
Nathan Harmatabf98f392016-01-07 22:58:29 +000016//
17
Thiago Farina676cb9f2016-10-06 11:00:43 +000018#ifndef BAZEL_SRC_MAIN_CPP_GLOBAL_VARIABLES_H_
19#define BAZEL_SRC_MAIN_CPP_GLOBAL_VARIABLES_H_
Nathan Harmatabf98f392016-01-07 22:58:29 +000020
Nathan Harmatabf98f392016-01-07 22:58:29 +000021#include <sys/types.h>
22#include <string>
23#include <vector>
24
Laszlo Csomor3b89d2d2016-11-28 14:04:27 +000025#include "src/main/cpp/util/port.h" // pid_t on Windows/MSVC
26
Nathan Harmatabf98f392016-01-07 22:58:29 +000027namespace blaze {
28
Thiago Farina676cb9f2016-10-06 11:00:43 +000029class OptionProcessor;
30class StartupOptions;
31
Nathan Harmatabf98f392016-01-07 22:58:29 +000032// The reason for a blaze server restart.
Thiago Farina36c1d152016-05-04 14:24:14 +000033// Keep in sync with logging.proto.
janakrfaa9dcf2017-05-17 07:10:41 +020034enum RestartReason {
35 NO_RESTART = 0,
36 NO_DAEMON,
37 NEW_VERSION,
38 NEW_OPTIONS,
39 PID_FILE_BUT_NO_SERVER,
40 SERVER_VANISHED,
41 SERVER_UNRESPONSIVE
42};
Nathan Harmatabf98f392016-01-07 22:58:29 +000043
44struct GlobalVariables {
Thiago Farina676cb9f2016-10-06 11:00:43 +000045 GlobalVariables(OptionProcessor *option_processor);
46
László Csomor41627ad2017-06-07 04:06:44 -040047 std::string ServerJarPath() const {
48 // The server jar is called "A-server.jar" so it's the first binary we
49 // extracted.
50 return extracted_binaries.empty() ? "" : extracted_binaries[0];
51 }
52
Nathan Harmatabf98f392016-01-07 22:58:29 +000053 // Used to make concurrent invocations of this program safe.
Thiago Farina676cb9f2016-10-06 11:00:43 +000054 std::string lockfile; // = <output_base>/lock
Nathan Harmatabf98f392016-01-07 22:58:29 +000055
michajlof74f9fe2018-01-29 09:06:44 -080056 // Whrere to write the server's JVM's output. Default value is
57 // <output_base>/server/jvm.out.
58 std::string jvm_log_file;
59
60 // Whether or not the jvm_log_file should be opened with O_APPEND.
61 bool jvm_log_file_append;
Nathan Harmatabf98f392016-01-07 22:58:29 +000062
Thiago Farina676cb9f2016-10-06 11:00:43 +000063 std::string cwd;
Nathan Harmatabf98f392016-01-07 22:58:29 +000064
65 // The nearest enclosing workspace directory, starting from cwd.
66 // If not under a workspace directory, this is equal to cwd.
Thiago Farina676cb9f2016-10-06 11:00:43 +000067 std::string workspace;
Nathan Harmatabf98f392016-01-07 22:58:29 +000068
69 // Option processor responsible for parsing RC files and converting them into
70 // the argument list passed on to the server.
Julio Merino28774852016-09-14 16:59:46 +000071 OptionProcessor *option_processor;
Nathan Harmatabf98f392016-01-07 22:58:29 +000072
Eric Fellheimer3a695f32016-05-11 17:26:30 +000073 // The path of the JVM executable that should be used to launch Blaze.
Thiago Farina676cb9f2016-10-06 11:00:43 +000074 std::string jvm_path;
Eric Fellheimer3a695f32016-05-11 17:26:30 +000075
jingwen68c57f02018-11-21 16:17:17 -080076 // TODO(laszlocsomor) 2016-11-28: move pid_t usage out of here and wherever
Laszlo Csomor3b89d2d2016-11-28 14:04:27 +000077 // else it appears. Find some way to not have to declare a pid_t here, either
78 // by making PID handling platform-independent or some other idea.
Nathan Harmatabf98f392016-01-07 22:58:29 +000079 pid_t server_pid;
80
Nathan Harmatabf98f392016-01-07 22:58:29 +000081 // Contains the relative paths of all the files in the attached zip, and is
Thiago Farina3820e8d2016-04-05 23:52:40 +000082 // populated during GetInstallBase().
Thiago Farina676cb9f2016-10-06 11:00:43 +000083 std::vector<std::string> extracted_binaries;
Nathan Harmatabf98f392016-01-07 22:58:29 +000084
Thiago Farina36c1d152016-05-04 14:24:14 +000085 // Parsed startup options.
Julio Merino28774852016-09-14 16:59:46 +000086 StartupOptions *options; // TODO(jmmv): This should really be const.
Nathan Harmatabf98f392016-01-07 22:58:29 +000087
Thiago Farina36c1d152016-05-04 14:24:14 +000088 // The time in ms the launcher spends before sending the request to the blaze
89 // server.
Nathan Harmatabf98f392016-01-07 22:58:29 +000090 uint64_t startup_time;
91
Thiago Farina36c1d152016-05-04 14:24:14 +000092 // The time in ms spent on extracting the new blaze version.
93 // This is part of startup_time.
Nathan Harmatabf98f392016-01-07 22:58:29 +000094 uint64_t extract_data_time;
95
Thiago Farina36c1d152016-05-04 14:24:14 +000096 // The time in ms a command had to wait on a busy Blaze server process.
97 // This is part of startup_time.
Nathan Harmatabf98f392016-01-07 22:58:29 +000098 uint64_t command_wait_time;
99
Thiago Farina36c1d152016-05-04 14:24:14 +0000100 // The reason for the server restart.
Nathan Harmatabf98f392016-01-07 22:58:29 +0000101 RestartReason restart_reason;
102
Thiago Farina36c1d152016-05-04 14:24:14 +0000103 // The absolute path of the blaze binary.
Thiago Farina676cb9f2016-10-06 11:00:43 +0000104 std::string binary_path;
Nathan Harmatabf98f392016-01-07 22:58:29 +0000105
106 // MD5 hash of the Blaze binary (includes deploy.jar, extracted binaries, and
107 // anything else that ends up under the install_base).
Thiago Farina676cb9f2016-10-06 11:00:43 +0000108 std::string install_md5;
Nathan Harmatabf98f392016-01-07 22:58:29 +0000109};
110
111} // namespace blaze
Thiago Farina319fd3a2016-01-14 19:42:24 +0000112
Thiago Farina676cb9f2016-10-06 11:00:43 +0000113#endif // BAZEL_SRC_MAIN_CPP_GLOBAL_VARIABLES_H_