aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar Nathan Harmata <nharmata@google.com>2016-01-07 22:58:29 +0000
committerGravatar Damien Martin-Guillerez <dmarting@google.com>2016-01-08 07:27:20 +0000
commitbf98f39d5d69d14d74dad79e705f76966f348766 (patch)
tree7afb1efdb2774ab71c1da35b7c73da64206f58ea /src
parent3df1728fdb9b5a5784b21c1d73f124f3eb01fe18 (diff)
Add the ability to customize the bazel client's exit code used when the bazel server exits abruptly.
-- MOS_MIGRATED_REVID=111641619
Diffstat (limited to 'src')
-rw-r--r--src/main/cpp/BUILD15
-rw-r--r--src/main/cpp/blaze.cc68
-rw-r--r--src/main/cpp/blaze_abrupt_exit.cc23
-rw-r--r--src/main/cpp/blaze_abrupt_exit.h29
-rw-r--r--src/main/cpp/blaze_globals.h97
-rw-r--r--src/main/cpp/blaze_util.cc8
-rw-r--r--src/main/cpp/blaze_util.h4
-rw-r--r--src/main/java/com/google/devtools/build/lib/skyframe/SkyframeExecutor.java3
-rw-r--r--src/main/java/com/google/devtools/build/skyframe/BuildDriver.java3
9 files changed, 182 insertions, 68 deletions
diff --git a/src/main/cpp/BUILD b/src/main/cpp/BUILD
index e6b3c74f80..3fb6719b93 100644
--- a/src/main/cpp/BUILD
+++ b/src/main/cpp/BUILD
@@ -51,10 +51,24 @@ cc_library(
],
)
+cc_library(
+ name = "blaze_abrupt_exit",
+ srcs = [
+ "blaze_abrupt_exit.cc",
+ ],
+ hdrs = [
+ "blaze_abrupt_exit.h",
+ ],
+ deps = [
+ "//src/main/cpp/util:blaze_exit_code",
+ ],
+)
+
cc_binary(
name = "client",
srcs = [
"blaze.cc",
+ "blaze_globals.h",
"blaze_startup_options.cc",
"blaze_startup_options.h",
"blaze_startup_options_common.cc",
@@ -80,6 +94,7 @@ cc_binary(
}),
visibility = ["//src:__pkg__"],
deps = [
+ ":blaze_abrupt_exit",
":blaze_util",
"//src/main/cpp/util",
"//src/main/cpp/util:md5",
diff --git a/src/main/cpp/blaze.cc b/src/main/cpp/blaze.cc
index 0651351ff6..7548c89340 100644
--- a/src/main/cpp/blaze.cc
+++ b/src/main/cpp/blaze.cc
@@ -54,6 +54,8 @@
#include <utility>
#include <vector>
+#include "src/main/cpp/blaze_abrupt_exit.h"
+#include "src/main/cpp/blaze_globals.h"
#include "src/main/cpp/blaze_startup_options.h"
#include "src/main/cpp/blaze_util.h"
#include "src/main/cpp/blaze_util_platform.h"
@@ -82,70 +84,6 @@ namespace blaze {
////////////////////////////////////////////////////////////////////////
// Global Variables
-
-// The reason for a blaze server restart.
-// Keep in sync with logging.proto
-enum RestartReason {
- NO_RESTART = 0,
- NO_DAEMON,
- NEW_VERSION,
- NEW_OPTIONS
-};
-
-struct GlobalVariables {
- // Used to make concurrent invocations of this program safe.
- string lockfile; // = <output_base>/lock
- int lockfd;
-
- string jvm_log_file; // = <output_base>/server/jvm.out
-
- string cwd;
-
- // The nearest enclosing workspace directory, starting from cwd.
- // If not under a workspace directory, this is equal to cwd.
- string workspace;
-
- // Option processor responsible for parsing RC files and converting them into
- // the argument list passed on to the server.
- OptionProcessor option_processor;
-
- pid_t server_pid;
-
- volatile sig_atomic_t sigint_count;
-
- // The number of the last received signal that should cause the client
- // to shutdown. This is saved so that the client's WTERMSIG can be set
- // correctly. (Currently only SIGPIPE uses this mechanism.)
- volatile sig_atomic_t received_signal;
-
- // Contains the relative paths of all the files in the attached zip, and is
- // populated during GetInstallDir().
- vector<string> extracted_binaries;
-
- // Parsed startup options
- BlazeStartupOptions options;
-
- // The time in ms the launcher spends before sending the request to the Blaze
- uint64_t startup_time;
-
- // The time spent on extracting the new blaze version
- // This is part of startup_time
- uint64_t extract_data_time;
-
- // The time in ms if a command had to wait on a busy Blaze server process
- // This is part of startup_time
- uint64_t command_wait_time;
-
- RestartReason restart_reason;
-
- // Absolute path of the blaze binary
- 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;
-};
-
static GlobalVariables *globals;
static void InitGlobals() {
@@ -1178,7 +1116,7 @@ static char read_server_char(FILE *fp) {
"Contents of '%s':\n", globals->options.GetProductName().c_str(),
globals->jvm_log_file.c_str());
WriteFileToStreamOrDie(stderr, globals->jvm_log_file.c_str());
- exit(blaze_exit_code::INTERNAL_ERROR);
+ exit(GetExitCodeForAbruptExit(*globals));
}
return static_cast<char>(c);
}
diff --git a/src/main/cpp/blaze_abrupt_exit.cc b/src/main/cpp/blaze_abrupt_exit.cc
new file mode 100644
index 0000000000..e0b5b172e4
--- /dev/null
+++ b/src/main/cpp/blaze_abrupt_exit.cc
@@ -0,0 +1,23 @@
+// 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/blaze_abrupt_exit.h"
+#include "src/main/cpp/util/exit_code.h"
+
+namespace blaze {
+
+int GetExitCodeForAbruptExit(const GlobalVariables& globals) {
+ return blaze_exit_code::INTERNAL_ERROR;
+}
+
+} // namespace blaze
diff --git a/src/main/cpp/blaze_abrupt_exit.h b/src/main/cpp/blaze_abrupt_exit.h
new file mode 100644
index 0000000000..15b9fed641
--- /dev/null
+++ b/src/main/cpp/blaze_abrupt_exit.h
@@ -0,0 +1,29 @@
+// 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.
+//
+//
+// blaze_abrupt_exit.h: Deals with abrupt exits of the Blaze server.
+//
+#ifndef THIRD_PARTY_BAZEL_SRC_MAIN_CPP_BLAZE_ABRUPT_EXIT_H_
+#define THIRD_PARTY_BAZEL_SRC_MAIN_CPP_BLAZE_ABRUPT_EXIT_H_
+
+namespace blaze {
+
+class GlobalVariables;
+
+// Returns the exit code to use for when the Blaze server exits abruptly.
+int GetExitCodeForAbruptExit(const GlobalVariables& globals);
+
+} // namespace blaze
+#endif // THIRD_PARTY_BAZEL_SRC_MAIN_CPP_BLAZE_ABRUPT_EXIT_H_
diff --git a/src/main/cpp/blaze_globals.h b/src/main/cpp/blaze_globals.h
new file mode 100644
index 0000000000..71242c3324
--- /dev/null
+++ b/src/main/cpp/blaze_globals.h
@@ -0,0 +1,97 @@
+// 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.
+//
+// blaze_globals.h: The global state in the blaze.cc Blaze client.
+//
+
+#ifndef THIRD_PARTY_BAZEL_SRC_MAIN_CPP_BLAZE_H_
+#define THIRD_PARTY_BAZEL_SRC_MAIN_CPP_BLAZE_H_
+
+#include <signal.h>
+#include <sys/types.h>
+#include <string>
+#include <vector>
+
+#include "src/main/cpp/blaze_startup_options.h"
+#include "src/main/cpp/option_processor.h"
+
+using std::vector;
+
+namespace blaze {
+
+// The reason for a blaze server restart.
+// Keep in sync with logging.proto
+enum RestartReason {
+ NO_RESTART = 0,
+ NO_DAEMON,
+ NEW_VERSION,
+ NEW_OPTIONS
+};
+
+struct GlobalVariables {
+ // Used to make concurrent invocations of this program safe.
+ string lockfile; // = <output_base>/lock
+ int lockfd;
+
+ string jvm_log_file; // = <output_base>/server/jvm.out
+
+ string cwd;
+
+ // The nearest enclosing workspace directory, starting from cwd.
+ // If not under a workspace directory, this is equal to cwd.
+ string workspace;
+
+ // Option processor responsible for parsing RC files and converting them into
+ // the argument list passed on to the server.
+ OptionProcessor option_processor;
+
+ pid_t server_pid;
+
+ volatile sig_atomic_t sigint_count;
+
+ // The number of the last received signal that should cause the client
+ // to shutdown. This is saved so that the client's WTERMSIG can be set
+ // correctly. (Currently only SIGPIPE uses this mechanism.)
+ volatile sig_atomic_t received_signal;
+
+ // Contains the relative paths of all the files in the attached zip, and is
+ // populated during GetInstallDir().
+ vector<string> extracted_binaries;
+
+ // Parsed startup options
+ BlazeStartupOptions options;
+
+ // The time in ms the launcher spends before sending the request to the Blaze
+ uint64_t startup_time;
+
+ // The time spent on extracting the new blaze version
+ // This is part of startup_time
+ uint64_t extract_data_time;
+
+ // The time in ms if a command had to wait on a busy Blaze server process
+ // This is part of startup_time
+ uint64_t command_wait_time;
+
+ RestartReason restart_reason;
+
+ // Absolute path of the blaze binary
+ 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;
+};
+
+} // namespace blaze
+#endif // THIRD_PARTY_BAZEL_SRC_MAIN_CPP_BLAZE_H_
diff --git a/src/main/cpp/blaze_util.cc b/src/main/cpp/blaze_util.cc
index cde7523ff5..f8d9c7a245 100644
--- a/src/main/cpp/blaze_util.cc
+++ b/src/main/cpp/blaze_util.cc
@@ -201,7 +201,7 @@ bool ReadFile(const string &filename, string *content) {
// Writes 'content' into file 'filename', and makes it executable.
// Returns false on failure, sets errno.
bool WriteFile(const string &content, const string &filename) {
- unlink(filename.c_str());
+ DeleteFile(filename); // We don't care about the success of this.
int fd = open(filename.c_str(), O_CREAT|O_WRONLY|O_TRUNC, 0755); // chmod +x
if (fd == -1) {
return false;
@@ -218,6 +218,12 @@ bool WriteFile(const string &content, const string &filename) {
return static_cast<uint>(r) == content.size();
}
+// Deletes the file 'filename'.
+// Returns false on failure, sets errno.
+bool DeleteFile(const string &filename) {
+ return unlink(filename.c_str()) == 0;
+}
+
// Returns true iff both stdout and stderr are connected to a
// terminal, and it can support color and cursor movement
// (this is computed heuristically based on the values of
diff --git a/src/main/cpp/blaze_util.h b/src/main/cpp/blaze_util.h
index 67e1b328e7..5cf81822f6 100644
--- a/src/main/cpp/blaze_util.h
+++ b/src/main/cpp/blaze_util.h
@@ -55,6 +55,10 @@ bool ReadFileDescriptor(int fd, string *content);
// Returns false on failure, sets errno.
bool WriteFile(const string &content, const string &filename);
+// Deletes the file 'filename'.
+// Returns false on failure, sets errno.
+bool DeleteFile(const string &filename);
+
// Returns true iff the current terminal can support color and cursor movement.
bool IsStandardTerminal();
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeExecutor.java b/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeExecutor.java
index f142e75863..20b3777fe2 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeExecutor.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeExecutor.java
@@ -1459,7 +1459,8 @@ public abstract class SkyframeExecutor implements WalkableGraphFactory {
* Get metadata related to the prepareAndGet() lookup. Resulting data is specific to the
* underlying evaluation implementation.
*/
- public String prepareAndGetMetadata(Collection<String> patterns, String offset) {
+ public String prepareAndGetMetadata(Collection<String> patterns, String offset)
+ throws AbruptExitException, InterruptedException {
return buildDriver.meta(ImmutableList.of(getUniverseKey(patterns, offset)));
}
diff --git a/src/main/java/com/google/devtools/build/skyframe/BuildDriver.java b/src/main/java/com/google/devtools/build/skyframe/BuildDriver.java
index 129238b4d9..a63afc71d8 100644
--- a/src/main/java/com/google/devtools/build/skyframe/BuildDriver.java
+++ b/src/main/java/com/google/devtools/build/skyframe/BuildDriver.java
@@ -15,6 +15,7 @@
package com.google.devtools.build.skyframe;
import com.google.devtools.build.lib.events.EventHandler;
+import com.google.devtools.build.lib.util.AbruptExitException;
import javax.annotation.Nullable;
@@ -34,7 +35,7 @@ public interface BuildDriver {
* Retrieve metadata about the computation over the given roots. Data returned is specific to the
* underlying evaluator implementation.
*/
- String meta(Iterable<SkyKey> roots);
+ String meta(Iterable<SkyKey> roots) throws AbruptExitException, InterruptedException;
MemoizingEvaluator getGraphForTesting();