aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/cpp')
-rw-r--r--src/main/cpp/BUILD5
-rw-r--r--src/main/cpp/blaze.cc3
-rw-r--r--src/main/cpp/blaze_util.cc22
-rw-r--r--src/main/cpp/blaze_util.h7
-rw-r--r--src/main/cpp/blaze_util_darwin.cc3
-rw-r--r--src/main/cpp/blaze_util_linux.cc3
-rw-r--r--src/main/cpp/blaze_util_mingw.cc3
-rw-r--r--src/main/cpp/util/errors.cc44
-rw-r--r--src/main/cpp/util/errors.h32
-rw-r--r--src/main/cpp/util/file.cc6
10 files changed, 98 insertions, 30 deletions
diff --git a/src/main/cpp/BUILD b/src/main/cpp/BUILD
index 2681792924..0e31cdbc0e 100644
--- a/src/main/cpp/BUILD
+++ b/src/main/cpp/BUILD
@@ -1,11 +1,15 @@
cc_library(
name = "util",
srcs = [
+ "util/errors.cc",
+ "util/file.cc",
"util/numbers.cc",
"util/port.cc",
"util/strings.cc",
],
hdrs = [
+ "util/errors.h",
+ "util/file.h",
"util/numbers.h",
"util/port.h",
"util/strings.h",
@@ -40,7 +44,6 @@ cc_binary(
"blaze_startup_options_common.cc",
"blaze_util.cc",
"option_processor.cc",
- "util/file.cc",
":blaze_util_os",
],
copts = [
diff --git a/src/main/cpp/blaze.cc b/src/main/cpp/blaze.cc
index 547a6a5683..f324c950fa 100644
--- a/src/main/cpp/blaze.cc
+++ b/src/main/cpp/blaze.cc
@@ -58,6 +58,7 @@
#include "blaze_util.h"
#include "blaze_util_platform.h"
#include "option_processor.h"
+#include "util/errors.h"
#include "util/file.h"
#include "util/md5.h"
#include "util/numbers.h"
@@ -67,6 +68,8 @@
#include "archive_entry.h"
using blaze_util::Md5Digest;
+using blaze_util::die;
+using blaze_util::pdie;
using std::set;
using std::vector;
diff --git a/src/main/cpp/blaze_util.cc b/src/main/cpp/blaze_util.cc
index 782c87a3e5..4f67533716 100644
--- a/src/main/cpp/blaze_util.cc
+++ b/src/main/cpp/blaze_util.cc
@@ -29,33 +29,17 @@
#include <unistd.h>
#include <sstream>
+#include "util/errors.h"
#include "util/file.h"
#include "util/numbers.h"
#include "util/strings.h"
+using blaze_util::die;
+using blaze_util::pdie;
using std::vector;
namespace blaze {
-void die(const int exit_status, const char *format, ...) {
- va_list ap;
- va_start(ap, format);
- vfprintf(stderr, format, ap);
- va_end(ap);
- fputc('\n', stderr);
- exit(exit_status);
-}
-
-void pdie(const int exit_status, const char *format, ...) {
- fprintf(stderr, "Error: ");
- va_list ap;
- va_start(ap, format);
- vfprintf(stderr, format, ap);
- va_end(ap);
- fprintf(stderr, ": %s\n", strerror(errno));
- exit(exit_status);
-}
-
string GetUserName() {
const char *user = getenv("USER");
if (user && user[0] != '\0') return user;
diff --git a/src/main/cpp/blaze_util.h b/src/main/cpp/blaze_util.h
index d4a84100a6..071200c6e8 100644
--- a/src/main/cpp/blaze_util.h
+++ b/src/main/cpp/blaze_util.h
@@ -36,13 +36,6 @@ namespace blaze {
using std::string;
-// Prints the specified error message and exits nonzero.
-void die(const int exit_status, const char *format, ...) ATTRIBUTE_NORETURN
- PRINTF_ATTRIBUTE(2, 3);
-// Prints "Error: <formatted-message>: <strerror(errno)>\n", and exits nonzero.
-void pdie(const int exit_status, const char *format, ...) ATTRIBUTE_NORETURN
- PRINTF_ATTRIBUTE(2, 3);
-
string GetUserName();
// Return the path to the JVM launcher.
diff --git a/src/main/cpp/blaze_util_darwin.cc b/src/main/cpp/blaze_util_darwin.cc
index da4036effd..30b1af578c 100644
--- a/src/main/cpp/blaze_util_darwin.cc
+++ b/src/main/cpp/blaze_util_darwin.cc
@@ -22,11 +22,14 @@
#include "blaze_exit_code.h"
#include "blaze_util.h"
#include "blaze_util_platform.h"
+#include "util/errors.h"
#include "util/file.h"
#include "util/strings.h"
namespace blaze {
+using blaze_util::die;
+using blaze_util::pdie;
using std::string;
string GetOutputRoot() {
diff --git a/src/main/cpp/blaze_util_linux.cc b/src/main/cpp/blaze_util_linux.cc
index 2e7bce6417..9945ebb37f 100644
--- a/src/main/cpp/blaze_util_linux.cc
+++ b/src/main/cpp/blaze_util_linux.cc
@@ -22,11 +22,14 @@
#include "blaze_exit_code.h"
#include "blaze_util_platform.h"
#include "blaze_util.h"
+#include "util/errors.h"
#include "util/file.h"
#include "util/strings.h"
namespace blaze {
+using blaze_util::die;
+using blaze_util::pdie;
using std::string;
string GetOutputRoot() {
diff --git a/src/main/cpp/blaze_util_mingw.cc b/src/main/cpp/blaze_util_mingw.cc
index dbe1731c34..972857c4f6 100644
--- a/src/main/cpp/blaze_util_mingw.cc
+++ b/src/main/cpp/blaze_util_mingw.cc
@@ -24,11 +24,14 @@
#include "blaze_exit_code.h"
#include "blaze_util_platform.h"
#include "blaze_util.h"
+#include "util/errors.h"
#include "util/file.h"
#include "util/strings.h"
namespace blaze {
+using blaze_util::die;
+using blaze_util::pdie;
using std::string;
void WarnFilesystemType(const string& output_base) {
diff --git a/src/main/cpp/util/errors.cc b/src/main/cpp/util/errors.cc
new file mode 100644
index 0000000000..ceaf93c5f6
--- /dev/null
+++ b/src/main/cpp/util/errors.cc
@@ -0,0 +1,44 @@
+// Copyright 2015 Google Inc. 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 "util/errors.h"
+
+#include <errno.h>
+#include <stdarg.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+namespace blaze_util {
+
+void die(const int exit_status, const char *format, ...) {
+ va_list ap;
+ va_start(ap, format);
+ vfprintf(stderr, format, ap);
+ va_end(ap);
+ fputc('\n', stderr);
+ exit(exit_status);
+}
+
+void pdie(const int exit_status, const char *format, ...) {
+ fprintf(stderr, "Error: ");
+ va_list ap;
+ va_start(ap, format);
+ vfprintf(stderr, format, ap);
+ va_end(ap);
+ fprintf(stderr, ": %s\n", strerror(errno));
+ exit(exit_status);
+}
+
+} // namespace blaze_util
diff --git a/src/main/cpp/util/errors.h b/src/main/cpp/util/errors.h
new file mode 100644
index 0000000000..718169fa9f
--- /dev/null
+++ b/src/main/cpp/util/errors.h
@@ -0,0 +1,32 @@
+// Copyright 2015 Google Inc. 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.
+//
+
+#ifndef DEVTOOLS_BLAZE_MAIN_UTIL_ERRORS_H_
+#define DEVTOOLS_BLAZE_MAIN_UTIL_ERRORS_H_
+
+#include "util/port.h"
+
+namespace blaze_util {
+
+// Prints the specified error message and exits nonzero.
+void die(const int exit_status, const char *format, ...) ATTRIBUTE_NORETURN
+ PRINTF_ATTRIBUTE(2, 3);
+// Prints "Error: <formatted-message>: <strerror(errno)>\n", and exits nonzero.
+void pdie(const int exit_status, const char *format, ...) ATTRIBUTE_NORETURN
+ PRINTF_ATTRIBUTE(2, 3);
+
+} // namespace blaze_util
+
+#endif // DEVTOOLS_BLAZE_MAIN_UTIL_ERRORS_H_
diff --git a/src/main/cpp/util/file.cc b/src/main/cpp/util/file.cc
index 581b71a6c6..86181196e5 100644
--- a/src/main/cpp/util/file.cc
+++ b/src/main/cpp/util/file.cc
@@ -21,7 +21,7 @@
#include <vector>
#include "blaze_exit_code.h"
-#include "blaze_util.h"
+#include "util/errors.h"
#include "util/strings.h"
using std::pair;
@@ -76,8 +76,8 @@ string JoinPath(const string &path1, const string &path2) {
string Which(const string &executable) {
string path(getenv("PATH"));
if (path.empty()) {
- blaze::die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR,
- "Could not get PATH to find %s", executable.c_str());
+ die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR,
+ "Could not get PATH to find %s", executable.c_str());
}
std::vector<std::string> pieces = blaze_util::Split(path, ':');