blob: e11ea1a43b6323ef0e6eef30c4c9c2903854c11c [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
Nathan Harmatabf98f392016-01-07 22:58:29 +000025namespace blaze {
26
Thiago Farina676cb9f2016-10-06 11:00:43 +000027class OptionProcessor;
28class StartupOptions;
29
Nathan Harmatabf98f392016-01-07 22:58:29 +000030// The reason for a blaze server restart.
Thiago Farina36c1d152016-05-04 14:24:14 +000031// Keep in sync with logging.proto.
Thiago Farina676cb9f2016-10-06 11:00:43 +000032enum RestartReason { NO_RESTART = 0, NO_DAEMON, NEW_VERSION, NEW_OPTIONS };
Nathan Harmatabf98f392016-01-07 22:58:29 +000033
34struct GlobalVariables {
Thiago Farina676cb9f2016-10-06 11:00:43 +000035 GlobalVariables(OptionProcessor *option_processor);
36
Nathan Harmatabf98f392016-01-07 22:58:29 +000037 // Used to make concurrent invocations of this program safe.
Thiago Farina676cb9f2016-10-06 11:00:43 +000038 std::string lockfile; // = <output_base>/lock
Nathan Harmatabf98f392016-01-07 22:58:29 +000039
Thiago Farina676cb9f2016-10-06 11:00:43 +000040 std::string jvm_log_file; // = <output_base>/server/jvm.out
Nathan Harmatabf98f392016-01-07 22:58:29 +000041
Thiago Farina676cb9f2016-10-06 11:00:43 +000042 std::string cwd;
Nathan Harmatabf98f392016-01-07 22:58:29 +000043
44 // The nearest enclosing workspace directory, starting from cwd.
45 // If not under a workspace directory, this is equal to cwd.
Thiago Farina676cb9f2016-10-06 11:00:43 +000046 std::string workspace;
Nathan Harmatabf98f392016-01-07 22:58:29 +000047
48 // Option processor responsible for parsing RC files and converting them into
49 // the argument list passed on to the server.
Julio Merino28774852016-09-14 16:59:46 +000050 OptionProcessor *option_processor;
Nathan Harmatabf98f392016-01-07 22:58:29 +000051
Eric Fellheimer3a695f32016-05-11 17:26:30 +000052 // The path of the JVM executable that should be used to launch Blaze.
Thiago Farina676cb9f2016-10-06 11:00:43 +000053 std::string jvm_path;
Eric Fellheimer3a695f32016-05-11 17:26:30 +000054
Nathan Harmatabf98f392016-01-07 22:58:29 +000055 pid_t server_pid;
56
Nathan Harmatabf98f392016-01-07 22:58:29 +000057 // Contains the relative paths of all the files in the attached zip, and is
Thiago Farina3820e8d2016-04-05 23:52:40 +000058 // populated during GetInstallBase().
Thiago Farina676cb9f2016-10-06 11:00:43 +000059 std::vector<std::string> extracted_binaries;
Nathan Harmatabf98f392016-01-07 22:58:29 +000060
Thiago Farina36c1d152016-05-04 14:24:14 +000061 // Parsed startup options.
Julio Merino28774852016-09-14 16:59:46 +000062 StartupOptions *options; // TODO(jmmv): This should really be const.
Nathan Harmatabf98f392016-01-07 22:58:29 +000063
Thiago Farina36c1d152016-05-04 14:24:14 +000064 // The time in ms the launcher spends before sending the request to the blaze
65 // server.
Nathan Harmatabf98f392016-01-07 22:58:29 +000066 uint64_t startup_time;
67
Thiago Farina36c1d152016-05-04 14:24:14 +000068 // The time in ms spent on extracting the new blaze version.
69 // This is part of startup_time.
Nathan Harmatabf98f392016-01-07 22:58:29 +000070 uint64_t extract_data_time;
71
Thiago Farina36c1d152016-05-04 14:24:14 +000072 // The time in ms a command had to wait on a busy Blaze server process.
73 // This is part of startup_time.
Nathan Harmatabf98f392016-01-07 22:58:29 +000074 uint64_t command_wait_time;
75
Thiago Farina36c1d152016-05-04 14:24:14 +000076 // The reason for the server restart.
Nathan Harmatabf98f392016-01-07 22:58:29 +000077 RestartReason restart_reason;
78
Thiago Farina36c1d152016-05-04 14:24:14 +000079 // The absolute path of the blaze binary.
Thiago Farina676cb9f2016-10-06 11:00:43 +000080 std::string binary_path;
Nathan Harmatabf98f392016-01-07 22:58:29 +000081
82 // MD5 hash of the Blaze binary (includes deploy.jar, extracted binaries, and
83 // anything else that ends up under the install_base).
Thiago Farina676cb9f2016-10-06 11:00:43 +000084 std::string install_md5;
Nathan Harmatabf98f392016-01-07 22:58:29 +000085};
86
87} // namespace blaze
Thiago Farina319fd3a2016-01-14 19:42:24 +000088
Thiago Farina676cb9f2016-10-06 11:00:43 +000089#endif // BAZEL_SRC_MAIN_CPP_GLOBAL_VARIABLES_H_