aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Thiago Farina <tfarina@chromium.org>2016-10-06 11:00:43 +0000
committerGravatar Damien Martin-Guillerez <dmarting@google.com>2016-10-07 08:03:08 +0000
commit676cb9f96884c9d55cc4e2379aa6e95f2d174fe9 (patch)
tree7ba7e2b43db16a0735e120b4a28c846086885eef
parentffdc05d2278d7f9c6e299c923019f689cde5fe76 (diff)
cpp: refactoring blaze_globals.h
* drop "blaze_" prefix (like it was done with statup_options.h) * add a constructor to initalize the data members * rename the header file to global_variables.h to match the struct in there. -- Change-Id: I8c9f89f5d07c9a064bf1999c7bfb6d617d72818a Reviewed-on: https://bazel-review.googlesource.com/6370 MOS_MIGRATED_REVID=135342354
-rw-r--r--src/main/cpp/BUILD3
-rw-r--r--src/main/cpp/blaze.cc17
-rw-r--r--src/main/cpp/global_variables.cc30
-rw-r--r--src/main/cpp/global_variables.h (renamed from src/main/cpp/blaze_globals.h)41
4 files changed, 52 insertions, 39 deletions
diff --git a/src/main/cpp/BUILD b/src/main/cpp/BUILD
index c559673b03..921baef3f4 100644
--- a/src/main/cpp/BUILD
+++ b/src/main/cpp/BUILD
@@ -80,7 +80,8 @@ cc_binary(
srcs = [
"blaze.cc",
"blaze.h",
- "blaze_globals.h",
+ "global_variables.cc",
+ "global_variables.h",
"main.cc",
"option_processor.cc",
"option_processor.h",
diff --git a/src/main/cpp/blaze.cc b/src/main/cpp/blaze.cc
index e83f7dd7c1..57824ace54 100644
--- a/src/main/cpp/blaze.cc
+++ b/src/main/cpp/blaze.cc
@@ -67,9 +67,9 @@
#include "src/main/cpp/blaze_abrupt_exit.h"
-#include "src/main/cpp/blaze_globals.h"
#include "src/main/cpp/blaze_util.h"
#include "src/main/cpp/blaze_util_platform.h"
+#include "src/main/cpp/global_variables.h"
#include "src/main/cpp/option_processor.h"
#include "src/main/cpp/startup_options.h"
#include "src/main/cpp/util/errors.h"
@@ -226,19 +226,6 @@ class BlazeServer {
static GlobalVariables *globals;
static BlazeServer *blaze_server;
-static void InitGlobals(OptionProcessor *option_processor) {
- globals = new GlobalVariables;
- globals->server_pid = -1;
- globals->sigint_count = 0;
- globals->received_signal = 0;
- globals->startup_time = 0;
- globals->extract_data_time = 0;
- globals->command_wait_time = 0;
- globals->restart_reason = NO_RESTART;
- globals->option_processor = option_processor;
- globals->options = NULL; // Initialized after parsing with option_processor.
-}
-
uint64_t BlazeServer::AcquireLock() {
return blaze::AcquireLock(
globals->options->output_base, globals->options->batch,
@@ -1826,7 +1813,7 @@ static void CreateSecureOutputRoot() {
// unexpectedly (in a way that isn't already handled), we can observe the file,
// if it exists. (If it doesn't, then we know something went horribly wrong.)
int Main(int argc, const char *argv[], OptionProcessor *option_processor) {
- InitGlobals(option_processor);
+ globals = new GlobalVariables(option_processor);
SetupStreams();
// Must be done before command line parsing.
diff --git a/src/main/cpp/global_variables.cc b/src/main/cpp/global_variables.cc
new file mode 100644
index 0000000000..2387304a4d
--- /dev/null
+++ b/src/main/cpp/global_variables.cc
@@ -0,0 +1,30 @@
+// Copyright 2016 The Bazel Authors. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include "src/main/cpp/global_variables.h"
+
+namespace blaze {
+
+GlobalVariables::GlobalVariables(OptionProcessor* option_processor)
+ : option_processor(option_processor),
+ server_pid(-1),
+ sigint_count(0),
+ received_signal(0),
+ options(NULL), /* Initialized after parsing with option_processor. */
+ startup_time(0),
+ extract_data_time(0),
+ command_wait_time(0),
+ restart_reason(NO_RESTART) {}
+
+} // namespace blaze
diff --git a/src/main/cpp/blaze_globals.h b/src/main/cpp/global_variables.h
index eba73b00d0..8ea47be55d 100644
--- a/src/main/cpp/blaze_globals.h
+++ b/src/main/cpp/global_variables.h
@@ -12,51 +12,46 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//
-// blaze_globals.h: The global state in the blaze.cc Blaze client.
+// global_variables.h: The global state in the blaze.cc Blaze client.
//
-#ifndef BAZEL_SRC_MAIN_CPP_BLAZE_GLOBALS_H_
-#define BAZEL_SRC_MAIN_CPP_BLAZE_GLOBALS_H_
+#ifndef BAZEL_SRC_MAIN_CPP_GLOBAL_VARIABLES_H_
+#define BAZEL_SRC_MAIN_CPP_GLOBAL_VARIABLES_H_
#include <signal.h>
#include <sys/types.h>
#include <string>
#include <vector>
-#include "src/main/cpp/option_processor.h"
-#include "src/main/cpp/startup_options.h"
-
-using std::vector;
-
namespace blaze {
+class OptionProcessor;
+class StartupOptions;
+
// The reason for a blaze server restart.
// Keep in sync with logging.proto.
-enum RestartReason {
- NO_RESTART = 0,
- NO_DAEMON,
- NEW_VERSION,
- NEW_OPTIONS
-};
+enum RestartReason { NO_RESTART = 0, NO_DAEMON, NEW_VERSION, NEW_OPTIONS };
struct GlobalVariables {
+ GlobalVariables(OptionProcessor *option_processor);
+
// Used to make concurrent invocations of this program safe.
- string lockfile; // = <output_base>/lock
+ std::string lockfile; // = <output_base>/lock
- string jvm_log_file; // = <output_base>/server/jvm.out
+ std::string jvm_log_file; // = <output_base>/server/jvm.out
- string cwd;
+ std::string cwd;
// The nearest enclosing workspace directory, starting from cwd.
// If not under a workspace directory, this is equal to cwd.
- string workspace;
+ std::string workspace;
// Option processor responsible for parsing RC files and converting them into
// the argument list passed on to the server.
OptionProcessor *option_processor;
// The path of the JVM executable that should be used to launch Blaze.
- string jvm_path;
+ std::string jvm_path;
pid_t server_pid;
@@ -69,7 +64,7 @@ struct GlobalVariables {
// Contains the relative paths of all the files in the attached zip, and is
// populated during GetInstallBase().
- vector<string> extracted_binaries;
+ std::vector<std::string> extracted_binaries;
// Parsed startup options.
StartupOptions *options; // TODO(jmmv): This should really be const.
@@ -90,13 +85,13 @@ struct GlobalVariables {
RestartReason restart_reason;
// The absolute path of the blaze binary.
- string binary_path;
+ std::string binary_path;
// MD5 hash of the Blaze binary (includes deploy.jar, extracted binaries, and
// anything else that ends up under the install_base).
- string install_md5;
+ std::string install_md5;
};
} // namespace blaze
-#endif // BAZEL_SRC_MAIN_CPP_BLAZE_GLOBALS_H_
+#endif // BAZEL_SRC_MAIN_CPP_GLOBAL_VARIABLES_H_