aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/main/cpp/blaze.cc208
-rw-r--r--src/main/cpp/blaze_util.cc7
-rw-r--r--src/main/cpp/blaze_util_darwin.cc63
-rw-r--r--src/main/cpp/blaze_util_freebsd.cc17
-rw-r--r--src/main/cpp/blaze_util_linux.cc45
-rw-r--r--src/main/cpp/blaze_util_posix.cc112
-rw-r--r--src/main/cpp/blaze_util_windows.cc208
-rw-r--r--src/main/cpp/util/BUILD2
-rw-r--r--src/main/cpp/util/errors.cc37
-rw-r--r--src/main/cpp/util/errors.h7
-rw-r--r--src/main/cpp/util/file_posix.cc36
-rw-r--r--src/main/cpp/util/file_windows.cc146
-rw-r--r--src/main/cpp/util/strings.cc4
-rw-r--r--src/main/cpp/util/strings.h1
-rwxr-xr-xsrc/test/shell/integration/client_test.sh8
-rw-r--r--third_party/ijar/BUILD3
-rw-r--r--third_party/ijar/mapped_file_windows.cc88
-rw-r--r--third_party/ijar/platform_utils.cc5
18 files changed, 474 insertions, 523 deletions
diff --git a/src/main/cpp/blaze.cc b/src/main/cpp/blaze.cc
index f637dfa355..1e80b492ca 100644
--- a/src/main/cpp/blaze.cc
+++ b/src/main/cpp/blaze.cc
@@ -70,7 +70,6 @@
#include "src/main/protobuf/command_server.grpc.pb.h"
-using blaze_util::die;
using blaze_util::GetLastErrorString;
namespace blaze {
@@ -279,8 +278,8 @@ class NoteAllFilesZipProcessor : public PureZipExtractorProcessor {
void Process(const char *filename, const devtools_ijar::u4 attr,
const devtools_ijar::u1 *data, const size_t size) override {
- die(blaze_exit_code::INTERNAL_ERROR,
- "NoteAllFilesZipProcessor::Process shouldn't be called");
+ BAZEL_DIE(blaze_exit_code::INTERNAL_ERROR)
+ << "NoteAllFilesZipProcessor::Process shouldn't be called";
}
private:
std::vector<std::string>* files_;
@@ -339,10 +338,10 @@ class GetInstallKeyFileProcessor : public PureZipExtractorProcessor {
string str(reinterpret_cast<const char *>(data), size);
blaze_util::StripWhitespace(&str);
if (str.size() != 32) {
- die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR,
- "\nFailed to extract install_base_key: file size mismatch "
- "(should be 32, is %zd)",
- str.size());
+ BAZEL_DIE(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR)
+ << "Failed to extract install_base_key: file size mismatch "
+ "(should be 32, is "
+ << str.size() << ")";
}
*install_base_key_ = str;
}
@@ -362,18 +361,18 @@ static void ComputeInstallMd5AndNoteAllFiles(const string &self_path) {
std::unique_ptr<devtools_ijar::ZipExtractor> extractor(
devtools_ijar::ZipExtractor::Create(self_path.c_str(), &processor));
if (extractor.get() == NULL) {
- die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR,
- "Failed to open %s as a zip file: %s",
- globals->options->product_name.c_str(), GetLastErrorString().c_str());
+ BAZEL_DIE(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR)
+ << "Failed to open " << globals->options->product_name
+ << " as a zip file: " << GetLastErrorString();
}
if (extractor->ProcessAll() < 0) {
- die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR,
- "Failed to extract install_base_key: %s", extractor->GetError());
+ BAZEL_DIE(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR)
+ << "Failed to extract install_base_key: " << extractor->GetError();
}
if (globals->install_md5.empty()) {
- die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR,
- "Failed to find install_base_key's in zip file");
+ BAZEL_DIE(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR)
+ << "Failed to find install_base_key's in zip file";
}
}
@@ -426,7 +425,7 @@ static vector<string> GetArgumentArray(
globals->options->AddJVMArguments(globals->options->GetHostJavabase(),
&result, user_options, &error);
if (jvm_args_exit_code != blaze_exit_code::SUCCESS) {
- die(jvm_args_exit_code, "%s", error.c_str());
+ BAZEL_DIE(jvm_args_exit_code) << error;
}
// We put all directories on java.library.path that contain .so/.dll files.
@@ -640,9 +639,9 @@ static string GetArgumentString(const vector<string> &argument_array) {
static void GoToWorkspace(const WorkspaceLayout *workspace_layout) {
if (workspace_layout->InWorkspace(globals->workspace) &&
!blaze_util::ChangeDirectory(globals->workspace)) {
- die(blaze_exit_code::INTERNAL_ERROR,
- "changing directory into %s failed: %s", globals->workspace.c_str(),
- GetLastErrorString().c_str());
+ BAZEL_DIE(blaze_exit_code::INTERNAL_ERROR)
+ << "changing directory into " << globals->workspace
+ << " failed: " << GetLastErrorString();
}
}
@@ -723,23 +722,23 @@ static void StartStandalone(const WorkspaceLayout *workspace_layout,
string exe =
globals->options->GetExe(globals->jvm_path, globals->ServerJarPath());
ExecuteProgram(exe, jvm_args_vector);
- die(blaze_exit_code::INTERNAL_ERROR, "execv of '%s' failed: %s", exe.c_str(),
- GetLastErrorString().c_str());
+ BAZEL_DIE(blaze_exit_code::INTERNAL_ERROR)
+ << "execv of '" << exe << "' failed: " << GetLastErrorString();
}
static void WriteFileToStderrOrDie(const char *file_name) {
FILE *fp = fopen(file_name, "r");
if (fp == NULL) {
- die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR, "opening %s failed: %s",
- file_name, GetLastErrorString().c_str());
+ BAZEL_DIE(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR)
+ << "opening " << file_name << " failed: " << GetLastErrorString();
}
char buffer[255];
int num_read;
while ((num_read = fread(buffer, 1, sizeof buffer, fp)) > 0) {
if (ferror(fp)) {
- die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR,
- "failed to read from '%s': %s", file_name,
- GetLastErrorString().c_str());
+ BAZEL_DIE(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR)
+ << "failed to read from '" << file_name
+ << "': " << GetLastErrorString();
}
fwrite(buffer, 1, num_read, stderr);
}
@@ -777,9 +776,9 @@ static void StartServerAndConnect(const WorkspaceLayout *workspace_layout,
// The server dir has the socket, so we don't allow access by other
// users.
if (!blaze_util::MakeDirectories(server_dir, 0700)) {
- die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR,
- "server directory '%s' could not be created: %s", server_dir.c_str(),
- GetLastErrorString().c_str());
+ BAZEL_DIE(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR)
+ << "server directory '" << server_dir
+ << "' could not be created: " << GetLastErrorString();
}
// If we couldn't connect to the server check if there is still a PID file
@@ -848,8 +847,8 @@ static void StartServerAndConnect(const WorkspaceLayout *workspace_layout,
exit(blaze_exit_code::INTERNAL_ERROR);
}
}
- die(blaze_exit_code::INTERNAL_ERROR,
- "couldn't connect to server (%d) after 120 seconds.", server_pid);
+ BAZEL_DIE(blaze_exit_code::INTERNAL_ERROR)
+ << "couldn't connect to server (" << server_pid << ") after 120 seconds.";
}
// A PureZipExtractorProcessor to extract the files from the blaze zip.
@@ -871,14 +870,14 @@ class ExtractBlazeZipProcessor : public PureZipExtractorProcessor {
const devtools_ijar::u1 *data, const size_t size) override {
string path = blaze_util::JoinPath(embedded_binaries_, filename);
if (!blaze_util::MakeDirectories(blaze_util::Dirname(path), 0777)) {
- die(blaze_exit_code::INTERNAL_ERROR, "couldn't create '%s': %s",
- path.c_str(), GetLastErrorString().c_str());
+ BAZEL_DIE(blaze_exit_code::INTERNAL_ERROR)
+ << "couldn't create '" << path << "': " << GetLastErrorString();
}
if (!blaze_util::WriteFile(data, size, path, 0755)) {
- die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR,
- "Failed to write zipped file \"%s\": %s", path.c_str(),
- GetLastErrorString().c_str());
+ BAZEL_DIE(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR)
+ << "Failed to write zipped file '" << path
+ << "': " << GetLastErrorString();
}
}
@@ -896,8 +895,9 @@ static void ActuallyExtractData(const string &argv0,
CompoundZipProcessor processor({&extract_blaze_processor,
&install_key_processor});
if (!blaze_util::MakeDirectories(embedded_binaries, 0777)) {
- die(blaze_exit_code::INTERNAL_ERROR, "couldn't create '%s': %s",
- embedded_binaries.c_str(), GetLastErrorString().c_str());
+ BAZEL_DIE(blaze_exit_code::INTERNAL_ERROR)
+ << "couldn't create '" << embedded_binaries
+ << "': " << GetLastErrorString();
}
BAZEL_LOG(USER) << "Extracting " << globals->options->product_name
@@ -906,27 +906,25 @@ static void ActuallyExtractData(const string &argv0,
std::unique_ptr<devtools_ijar::ZipExtractor> extractor(
devtools_ijar::ZipExtractor::Create(argv0.c_str(), &processor));
if (extractor.get() == NULL) {
- die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR,
- "Failed to open %s as a zip file: %s",
- globals->options->product_name.c_str(), GetLastErrorString().c_str());
+ BAZEL_DIE(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR)
+ << "Failed to open " << globals->options->product_name
+ << " as a zip file: " << GetLastErrorString();
}
if (extractor->ProcessAll() < 0) {
- die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR,
- "Failed to extract %s as a zip file: %s",
- globals->options->product_name.c_str(), extractor->GetError());
+ BAZEL_DIE(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR)
+ << "Failed to extract " << globals->options->product_name
+ << " as a zip file: " << extractor->GetError();
}
if (install_md5 != globals->install_md5) {
- die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR,
- "The %s binary at %s was replaced during the client's self-extraction "
- "(old md5: %s new md5: %s). If you expected this then you should "
- "simply re-run %s in order to pick up the different version. If you "
- "didn't expect this then you should investigate what happened.",
- globals->options->product_name.c_str(),
- argv0.c_str(),
- globals->install_md5.c_str(),
- install_md5.c_str(),
- globals->options->product_name.c_str());
+ BAZEL_DIE(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR)
+ << "The " << globals->options->product_name << " binary at " << argv0
+ << " was replaced during the client's self-extraction (old md5: "
+ << globals->install_md5 << " new md5: " << install_md5
+ << "). If you expected this then you should simply re-run "
+ << globals->options->product_name
+ << " in order to pick up the different version. If you didn't expect "
+ "this then you should investigate what happened.";
}
// Set the timestamps of the extracted files to the future and make sure (or
@@ -951,9 +949,9 @@ static void ActuallyExtractData(const string &argv0,
// changed. This is essential for the correctness of actions that use
// embedded binaries as artifacts.
if (!mtime.get()->SetToDistantFuture(it)) {
- die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR,
- "failed to set timestamp on '%s': %s", extracted_path,
- GetLastErrorString().c_str());
+ BAZEL_DIE(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR)
+ << "failed to set timestamp on '" << extracted_path
+ << "': " << GetLastErrorString();
}
blaze_util::SyncFile(it);
@@ -1023,17 +1021,15 @@ static void ExtractData(const string &self_path) {
// Give up renaming after 120 failed attempts / 2 minutes.
if (attempts == 120) {
- die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR,
- "install base directory '%s' could not be renamed into place: "
- "%s",
- tmp_install.c_str(), GetLastErrorString().c_str());
+ BAZEL_DIE(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR)
+ << "install base directory '" << tmp_install
+ << "' could not be renamed into place: " << GetLastErrorString();
}
} else {
if (!blaze_util::IsDirectory(globals->options->install_base)) {
- die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR,
- "Install base directory '%s' could not be created. "
- "It exists but is not a directory.",
- globals->options->install_base.c_str());
+ BAZEL_DIE(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR)
+ << "Install base directory '" << globals->options->install_base
+ << "' could not be created. It exists but is not a directory.";
}
std::unique_ptr<blaze_util::IFileMtime> mtime(
@@ -1047,26 +1043,26 @@ static void ExtractData(const string &self_path) {
continue;
}
if (!blaze_util::CanReadFile(path)) {
- die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR,
- "corrupt installation: file '%s' missing."
- " Please remove '%s' and try again.",
- path.c_str(), globals->options->install_base.c_str());
+ BAZEL_DIE(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR)
+ << "corrupt installation: file '" << path
+ << "' missing. Please remove '" << globals->options->install_base
+ << "' and try again.";
}
// Check that the timestamp is in the future. A past timestamp would
// indicate that the file has been tampered with.
// See ActuallyExtractData().
bool is_in_future = false;
if (!mtime.get()->GetIfInDistantFuture(path, &is_in_future)) {
- die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR,
- "Error: could not retrieve mtime of file '%s'. "
- "Please remove '%s' and try again.",
- path.c_str(), globals->options->install_base.c_str());
+ BAZEL_DIE(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR)
+ << "Error: could not retrieve mtime of file '" << path
+ << "'. Please remove '" << globals->options->install_base
+ << "' and try again.";
}
if (!is_in_future) {
- die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR,
- "Error: corrupt installation: file '%s' "
- "modified. Please remove '%s' and try again.",
- path.c_str(), globals->options->install_base.c_str());
+ BAZEL_DIE(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR)
+ << "Error: corrupt installation: file '" << path
+ << "' modified. Please remove '" << globals->options->install_base
+ << "' and try again.";
}
}
}
@@ -1179,9 +1175,9 @@ static void EnsureCorrectRunningVersion(BlazeServer *server) {
blaze_util::UnlinkPath(installation_path);
if (!SymlinkDirectories(globals->options->install_base,
installation_path)) {
- die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR,
- "failed to create installation symlink '%s': %s",
- installation_path.c_str(), GetLastErrorString().c_str());
+ BAZEL_DIE(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR)
+ << "failed to create installation symlink '" << installation_path
+ << "': " << GetLastErrorString();
}
// Update the mtime of the install base so that cleanup tools can
@@ -1189,9 +1185,9 @@ static void EnsureCorrectRunningVersion(BlazeServer *server) {
std::unique_ptr<blaze_util::IFileMtime> mtime(
blaze_util::CreateFileMtime());
if (!mtime.get()->SetToNow(globals->options->install_base)) {
- die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR,
- "failed to set timestamp on '%s': %s",
- globals->options->install_base.c_str(), GetLastErrorString().c_str());
+ BAZEL_DIE(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR)
+ << "failed to set timestamp on '" << globals->options->install_base
+ << "': " << GetLastErrorString();
}
}
}
@@ -1256,7 +1252,7 @@ static void ParseOptions(int argc, const char *argv[]) {
if (parse_exit_code != blaze_exit_code::SUCCESS) {
globals->option_processor->PrintStartupOptionsProvenanceMessage();
- die(parse_exit_code, "%s", error.c_str());
+ BAZEL_DIE(parse_exit_code) << error;
}
globals->options = globals->option_processor->GetParsedStartupOptions();
}
@@ -1265,9 +1261,9 @@ static void ParseOptions(int argc, const char *argv[]) {
static void ComputeWorkspace(const WorkspaceLayout *workspace_layout) {
globals->cwd = blaze_util::MakeCanonical(blaze_util::GetCwd().c_str());
if (globals->cwd.empty()) {
- die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR,
- "blaze_util::MakeCanonical('%s') failed: %s",
- blaze_util::GetCwd().c_str(), GetLastErrorString().c_str());
+ BAZEL_DIE(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR)
+ << "blaze_util::MakeCanonical('" << blaze_util::GetCwd()
+ << "') failed: " << GetLastErrorString();
}
globals->workspace = workspace_layout->GetWorkspace(globals->cwd);
}
@@ -1307,30 +1303,29 @@ static void ComputeBaseDirectories(const WorkspaceLayout *workspace_layout,
const char *output_base = globals->options->output_base.c_str();
if (!blaze_util::PathExists(globals->options->output_base)) {
if (!blaze_util::MakeDirectories(globals->options->output_base, 0777)) {
- die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR,
- "Output base directory '%s' could not be created: %s", output_base,
- GetLastErrorString().c_str());
+ BAZEL_DIE(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR)
+ << "Output base directory '" << output_base
+ << "' could not be created: " << GetLastErrorString();
}
} else {
if (!blaze_util::IsDirectory(globals->options->output_base)) {
- die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR,
- "Output base directory '%s' could not be created. "
- "It exists but is not a directory.",
- output_base);
+ BAZEL_DIE(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR)
+ << "Output base directory '" << output_base
+ << "' could not be created. It exists but is not a directory.";
}
}
if (!blaze_util::CanAccessDirectory(globals->options->output_base)) {
- die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR,
- "Output base directory '%s' must be readable and writable.",
- output_base);
+ BAZEL_DIE(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR)
+ << "Output base directory '" << output_base
+ << "' must be readable and writable.";
}
ExcludePathFromBackup(output_base);
globals->options->output_base = blaze_util::MakeCanonical(output_base);
if (globals->options->output_base.empty()) {
- die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR,
- "blaze_util::MakeCanonical('%s') failed: %s", output_base,
- GetLastErrorString().c_str());
+ BAZEL_DIE(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR)
+ << "blaze_util::MakeCanonical('" << output_base
+ << "') failed: " << GetLastErrorString();
}
globals->lockfile =
@@ -1507,8 +1502,8 @@ GrpcBlazeServer::GrpcBlazeServer(int connect_timeout_secs) {
pipe_ = blaze_util::CreatePipe();
if (pipe_ == NULL) {
- die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR, "Couldn't create pipe: %s",
- GetLastErrorString().c_str());
+ BAZEL_DIE(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR)
+ << "Couldn't create pipe: " << GetLastErrorString();
}
}
@@ -1637,9 +1632,8 @@ void GrpcBlazeServer::CancelThread() {
if (bytes_read < 0 && error == blaze_util::IPipe::INTERRUPTED) {
continue;
} else if (bytes_read != 1) {
- die(blaze_exit_code::INTERNAL_ERROR,
- "Cannot communicate with cancel thread: %s",
- GetLastErrorString().c_str());
+ BAZEL_DIE(blaze_exit_code::INTERNAL_ERROR)
+ << "Cannot communicate with cancel thread: " << GetLastErrorString();
}
switch (buf) {
@@ -1866,9 +1860,9 @@ unsigned int GrpcBlazeServer::Communicate() {
}
if (!blaze_util::ChangeDirectory(request.working_directory())) {
- die(blaze_exit_code::INTERNAL_ERROR,
- "changing directory into %s failed: %s",
- request.working_directory().c_str(), GetLastErrorString().c_str());
+ BAZEL_DIE(blaze_exit_code::INTERNAL_ERROR)
+ << "changing directory into " << request.working_directory()
+ << " failed: " << GetLastErrorString();
}
ExecuteProgram(request.argv(0), argv);
}
diff --git a/src/main/cpp/blaze_util.cc b/src/main/cpp/blaze_util.cc
index a2a7d3f6f1..fd742e2392 100644
--- a/src/main/cpp/blaze_util.cc
+++ b/src/main/cpp/blaze_util.cc
@@ -30,8 +30,6 @@
#include "src/main/cpp/util/port.h"
#include "src/main/cpp/util/strings.h"
-using blaze_util::die;
-
namespace blaze {
using std::string;
@@ -75,8 +73,9 @@ bool GetNullaryOption(const char *arg, const char *key) {
if (value == NULL) {
return false;
} else if (value[0] == '=') {
- die(blaze_exit_code::BAD_ARGV,
- "In argument '%s': option '%s' does not take a value.", arg, key);
+ BAZEL_DIE(blaze_exit_code::BAD_ARGV)
+ << "In argument '" << arg << "': option '" << key
+ << "' does not take a value.";
} else if (value[0]) {
return false; // trailing garbage in key name
}
diff --git a/src/main/cpp/blaze_util_darwin.cc b/src/main/cpp/blaze_util_darwin.cc
index 76427f4c54..4bc3990eab 100644
--- a/src/main/cpp/blaze_util_darwin.cc
+++ b/src/main/cpp/blaze_util_darwin.cc
@@ -35,11 +35,11 @@
#include "src/main/cpp/util/errors.h"
#include "src/main/cpp/util/exit_code.h"
#include "src/main/cpp/util/file.h"
+#include "src/main/cpp/util/logging.h"
#include "src/main/cpp/util/strings.h"
namespace blaze {
-using blaze_util::die;
using blaze_util::GetLastErrorString;
using std::string;
using std::vector;
@@ -106,20 +106,16 @@ void WarnFilesystemType(const string& output_base) {
!CFURLCopyResourcePropertyForKey(cf_url, kCFURLVolumeIsLocalKey,
&cf_local, &cf_error)) {
CFScopedReleaser<CFErrorRef> cf_error_releaser(cf_error);
- string error_desc = DescriptionFromCFError(cf_error_releaser);
- fprintf(stderr, "Warning: couldn't get file system type information for "
- "'%s'", output_base.c_str());
- if (error_desc.length() > 0) {
- fprintf(stderr, " - '%s'", error_desc.c_str());
- }
- fprintf(stderr, "\n");
+ BAZEL_LOG(WARNING) << "couldn't get file system type information for '"
+ << output_base
+ << "': " << DescriptionFromCFError(cf_error_releaser);
return;
}
CFScopedReleaser<CFBooleanRef> cf_local_releaser(cf_local);
if (!CFBooleanGetValue(cf_local_releaser)) {
- fprintf(stderr, "Warning: Output base '%s' is on a non-local drive. This "
- "may lead to surprising failures and undetermined behavior.\n",
- output_base.c_str());
+ BAZEL_LOG(WARNING) << "Output base '" << output_base
+ << "' is on a non-local drive. This may lead to "
+ "surprising failures and undetermined behavior.";
}
}
@@ -127,8 +123,8 @@ string GetSelfPath() {
char pathbuf[PROC_PIDPATHINFO_MAXSIZE] = {};
int len = proc_pidpath(getpid(), pathbuf, sizeof(pathbuf));
if (len == 0) {
- die(blaze_exit_code::INTERNAL_ERROR, "error calling proc_pidpath: %s",
- GetLastErrorString().c_str());
+ BAZEL_DIE(blaze_exit_code::INTERNAL_ERROR)
+ << "error calling proc_pidpath: " << GetLastErrorString();
}
return string(pathbuf, len);
}
@@ -136,8 +132,8 @@ string GetSelfPath() {
uint64_t GetMillisecondsMonotonic() {
struct timeval ts = {};
if (gettimeofday(&ts, NULL) < 0) {
- die(blaze_exit_code::INTERNAL_ERROR, "error calling gettimeofday: %s",
- GetLastErrorString().c_str());
+ BAZEL_DIE(blaze_exit_code::INTERNAL_ERROR)
+ << "error calling gettimeofday: " << GetLastErrorString();
}
return ts.tv_sec * 1000LL + ts.tv_usec / 1000LL;
}
@@ -171,24 +167,23 @@ string GetDefaultHostJavabase() {
FILE *output = popen("/usr/libexec/java_home -v 1.7+", "r");
if (output == NULL) {
- die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR,
- "Could not run /usr/libexec/java_home: %s",
- GetLastErrorString().c_str());
+ BAZEL_DIE(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR)
+ << "Could not run /usr/libexec/java_home: " << GetLastErrorString();
}
char buf[512];
char *result = fgets(buf, sizeof(buf), output);
pclose(output);
if (result == NULL) {
- die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR,
- "No output from /usr/libexec/java_home");
+ BAZEL_DIE(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR)
+ << "No output from /usr/libexec/java_home";
}
string javabase = buf;
if (javabase.empty()) {
- die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR,
- "Empty output from /usr/libexec/java_home - "
- "install a JDK, or install a JRE and point your JAVA_HOME to it");
+ BAZEL_DIE(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR)
+ << "Empty output from /usr/libexec/java_home - install a JDK, or "
+ "install a JRE and point your JAVA_HOME to it";
}
// The output ends with a \n, trim it off.
@@ -213,21 +208,15 @@ void ExcludePathFromBackup(const string &path) {
kCFAllocatorDefault, reinterpret_cast<const UInt8 *>(path.c_str()),
path.length(), true));
if (!cf_url.isValid()) {
- fprintf(stderr, "Warning: unable to exclude '%s' from backups\n",
- path.c_str());
+ BAZEL_LOG(WARNING) << "unable to exclude '" << path << "' from backups";
return;
}
CFErrorRef cf_error = NULL;
if (!CFURLSetResourcePropertyForKey(cf_url, kCFURLIsExcludedFromBackupKey,
kCFBooleanTrue, &cf_error)) {
CFScopedReleaser<CFErrorRef> cf_error_releaser(cf_error);
- string error_desc = DescriptionFromCFError(cf_error_releaser);
- fprintf(stderr, "Warning: unable to exclude '%s' from backups",
- path.c_str());
- if (error_desc.length() > 0) {
- fprintf(stderr, " - '%s'", error_desc.c_str());
- }
- fprintf(stderr, "\n");
+ BAZEL_LOG(WARNING) << "unable to exclude '" << path << "' from backups: "
+ << DescriptionFromCFError(cf_error_releaser);
return;
}
}
@@ -248,14 +237,14 @@ int32_t GetExplicitSystemLimit(const int resource) {
int32_t limit;
size_t len = sizeof(limit);
if (sysctlbyname(sysctl_name, &limit, &len, nullptr, 0) == -1) {
- fprintf(stderr, "Warning: failed to get value of sysctl %s: %s\n",
- sysctl_name, std::strerror(errno));
+ BAZEL_LOG(WARNING) << "failed to get value of sysctl " << sysctl_name
+ << ": " << std::strerror(errno);
return 0;
}
if (len != sizeof(limit)) {
- fprintf(stderr, "Warning: failed to get value of sysctl %s: returned "
- "data length %zd did not match expected size %zd\n",
- sysctl_name, len, sizeof(limit));
+ BAZEL_LOG(WARNING) << "failed to get value of sysctl " << sysctl_name
+ << ": returned data length " << len
+ << " did not match expected size " << sizeof(limit);
return 0;
}
return limit;
diff --git a/src/main/cpp/blaze_util_freebsd.cc b/src/main/cpp/blaze_util_freebsd.cc
index e105e37ff3..4b27b4287d 100644
--- a/src/main/cpp/blaze_util_freebsd.cc
+++ b/src/main/cpp/blaze_util_freebsd.cc
@@ -38,7 +38,6 @@
namespace blaze {
-using blaze_util::die;
using blaze_util::GetLastErrorString;
using std::string;
@@ -79,14 +78,14 @@ string GetSelfPath() {
auto p = procstat_getprocs(procstat, KERN_PROC_PID, pid, &n);
if (p) {
if (n != 1) {
- die(blaze_exit_code::INTERNAL_ERROR,
- "expected exactly one process from procstat_getprocs, got %d: %s", n,
- GetLastErrorString().c_str());
+ BAZEL_DIE(blaze_exit_code::INTERNAL_ERROR)
+ << "expected exactly one process from procstat_getprocs, got " << n
+ << ": " << GetLastErrorString();
}
auto r = procstat_getpathname(procstat, p, buffer, PATH_MAX);
if (r != 0) {
- die(blaze_exit_code::INTERNAL_ERROR, "procstat_getpathname failed: %s",
- GetLastErrorString().c_str());
+ BAZEL_DIE(blaze_exit_code::INTERNAL_ERROR)
+ << "procstat_getpathname failed: " << GetLastErrorString();
}
procstat_freeprocs(procstat, p);
}
@@ -118,9 +117,9 @@ string GetProcessCWD(int pid) {
string cwd;
if (p) {
if (n != 1) {
- die(blaze_exit_code::INTERNAL_ERROR,
- "expected exactly one process from procstat_getprocs, got %d: %s", n,
- GetLastErrorString().c_str());
+ BAZEL_DIE(blaze_exit_code::INTERNAL_ERROR)
+ << "expected exactly one process from procstat_getprocs, got " << n
+ << ": " << GetLastErrorString();
}
auto files = procstat_getfiles(procstat, p, false);
filestat *entry;
diff --git a/src/main/cpp/blaze_util_linux.cc b/src/main/cpp/blaze_util_linux.cc
index 1682a65d39..ba0320d1c2 100644
--- a/src/main/cpp/blaze_util_linux.cc
+++ b/src/main/cpp/blaze_util_linux.cc
@@ -37,7 +37,6 @@
namespace blaze {
-using blaze_util::die;
using blaze_util::GetLastErrorString;
using std::string;
using std::vector;
@@ -89,8 +88,8 @@ string GetSelfPath() {
errno = ENAMETOOLONG;
}
if (bytes == -1) {
- die(blaze_exit_code::INTERNAL_ERROR, "error reading /proc/self/exe: %s",
- GetLastErrorString().c_str());
+ BAZEL_DIE(blaze_exit_code::INTERNAL_ERROR)
+ << "error reading /proc/self/exe: " << GetLastErrorString();
}
buffer[bytes] = '\0'; // readlink does not NUL-terminate
return string(buffer);
@@ -113,9 +112,8 @@ void SetScheduling(bool batch_cpu_scheduling, int io_nice_level) {
sched_param param = {};
param.sched_priority = 0;
if (sched_setscheduler(0, SCHED_BATCH, &param)) {
- die(blaze_exit_code::INTERNAL_ERROR,
- "sched_setscheduler(SCHED_BATCH) failed: %s",
- GetLastErrorString().c_str());
+ BAZEL_DIE(blaze_exit_code::INTERNAL_ERROR)
+ << "sched_setscheduler(SCHED_BATCH) failed: " << GetLastErrorString();
}
}
@@ -123,9 +121,9 @@ void SetScheduling(bool batch_cpu_scheduling, int io_nice_level) {
if (blaze_util::sys_ioprio_set(
IOPRIO_WHO_PROCESS, getpid(),
IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, io_nice_level)) < 0) {
- die(blaze_exit_code::INTERNAL_ERROR,
- "ioprio_set() with class %d and level %d failed: %s", IOPRIO_CLASS_BE,
- io_nice_level, GetLastErrorString().c_str());
+ BAZEL_DIE(blaze_exit_code::INTERNAL_ERROR)
+ << "ioprio_set() with class " << IOPRIO_CLASS_BE << " and level "
+ << io_nice_level << " failed: " << GetLastErrorString();
}
}
}
@@ -148,8 +146,8 @@ bool IsSharedLibrary(const string &filename) {
static string Which(const string &executable) {
string path(GetEnv("PATH"));
if (path.empty()) {
- die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR,
- "Could not get PATH to find %s", executable.c_str());
+ BAZEL_DIE(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR)
+ << "Could not get PATH to find " << executable;
}
vector<string> pieces = blaze_util::Split(path, ':');
@@ -179,14 +177,15 @@ string GetDefaultHostJavabase() {
// which javac
string javac_dir = Which("javac");
if (javac_dir.empty()) {
- die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR, "Could not find javac");
+ BAZEL_DIE(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR)
+ << "Could not find javac";
}
// Resolve all symlinks.
char resolved_path[PATH_MAX];
if (realpath(javac_dir.c_str(), resolved_path) == NULL) {
- die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR,
- "Could not resolve javac directory: %s", GetLastErrorString().c_str());
+ BAZEL_DIE(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR)
+ << "Could not resolve javac directory: " << GetLastErrorString();
}
javac_dir = resolved_path;
@@ -205,9 +204,9 @@ static bool GetStartTime(const string& pid, string* start_time) {
vector<string> stat_entries = blaze_util::Split(statline, ' ');
if (stat_entries.size() < 22) {
- die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR,
- "Format of stat file at %s is unknown: %s", statfile.c_str(),
- GetLastErrorString().c_str());
+ BAZEL_DIE(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR)
+ << "Format of stat file at " << statfile
+ << " is unknown: " << GetLastErrorString();
}
// Start time since startup in jiffies. This combined with the PID should be
@@ -222,16 +221,16 @@ void WriteSystemSpecificProcessIdentifier(
string start_time;
if (!GetStartTime(pid_string, &start_time)) {
- die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR,
- "Cannot get start time of process %s: %s", pid_string.c_str(),
- GetLastErrorString().c_str());
+ BAZEL_DIE(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR)
+ << "Cannot get start time of process " << pid_string << ": "
+ << GetLastErrorString();
}
string start_time_file = blaze_util::JoinPath(server_dir, "server.starttime");
if (!blaze_util::WriteFile(start_time, start_time_file)) {
- die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR,
- "Cannot write start time in server dir %s: %s", server_dir.c_str(),
- GetLastErrorString().c_str());
+ BAZEL_DIE(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR)
+ << "Cannot write start time in server dir " << server_dir << ": "
+ << GetLastErrorString();
}
}
diff --git a/src/main/cpp/blaze_util_posix.cc b/src/main/cpp/blaze_util_posix.cc
index 2a3fba22ce..74b6f0f7cb 100644
--- a/src/main/cpp/blaze_util_posix.cc
+++ b/src/main/cpp/blaze_util_posix.cc
@@ -49,7 +49,6 @@
namespace blaze {
using blaze_exit_code::INTERNAL_ERROR;
-using blaze_util::die;
using blaze_util::GetLastErrorString;
using std::string;
@@ -189,9 +188,9 @@ bool SymlinkDirectories(const string &target, const string &link) {
// change cwd, though.
static void Daemonize(const char* daemon_output,
const bool daemon_output_append) {
- // Don't call die() or exit() in this function; we're already in a
- // child process so it won't work as expected. Just don't do
- // anything that can possibly fail. :)
+ // Don't call BAZEL_DIE or exit() in this function; we're already in a child
+ // process so it won't work as expected. Just don't do anything that can
+ // possibly fail. :)
signal(SIGHUP, SIG_IGN);
if (fork() > 0) {
@@ -340,8 +339,8 @@ int ExecuteDaemon(const string& exe,
int fds[2];
if (socketpair(AF_UNIX, SOCK_STREAM, 0, fds)) {
- die(blaze_exit_code::INTERNAL_ERROR, "socket creation failed: %s",
- GetLastErrorString().c_str());
+ BAZEL_DIE(blaze_exit_code::INTERNAL_ERROR)
+ << "socket creation failed: " << GetLastErrorString();
}
const char* daemon_output_chars = daemon_output.c_str();
@@ -350,8 +349,8 @@ int ExecuteDaemon(const string& exe,
int child = fork();
if (child == -1) {
- die(blaze_exit_code::INTERNAL_ERROR, "fork() failed: %s",
- GetLastErrorString().c_str());
+ BAZEL_DIE(blaze_exit_code::INTERNAL_ERROR)
+ << "fork() failed: " << GetLastErrorString();
return -1;
} else if (child > 0) {
// Parent process (i.e. the client)
@@ -363,8 +362,8 @@ int ExecuteDaemon(const string& exe,
"cannot read server PID from server");
string pid_file = blaze_util::JoinPath(server_dir, kServerPidFile);
if (!blaze_util::WriteFile(ToString(server_pid), pid_file)) {
- die(blaze_exit_code::INTERNAL_ERROR, "cannot write PID file: %s",
- GetLastErrorString().c_str());
+ BAZEL_DIE(blaze_exit_code::INTERNAL_ERROR)
+ << "cannot write PID file: " << GetLastErrorString();
return -1;
}
@@ -405,8 +404,8 @@ static string RunProgram(const string& exe,
const std::vector<string>& args_vector) {
int fds[2];
if (pipe(fds)) {
- die(blaze_exit_code::INTERNAL_ERROR, "pipe creation failed: %s",
- GetLastErrorString().c_str());
+ BAZEL_DIE(blaze_exit_code::INTERNAL_ERROR)
+ << "pipe creation failed: " << GetLastErrorString();
}
int recv_socket = fds[0];
int send_socket = fds[1];
@@ -416,16 +415,16 @@ static string RunProgram(const string& exe,
int child = fork();
if (child == -1) {
- die(blaze_exit_code::INTERNAL_ERROR, "fork() failed: %s",
- GetLastErrorString().c_str());
+ BAZEL_DIE(blaze_exit_code::INTERNAL_ERROR)
+ << "fork() failed: " << GetLastErrorString();
} else if (child > 0) { // we're the parent
close(send_socket); // parent keeps only the reading side
string result;
bool success = blaze_util::ReadFrom(recv_socket, &result);
close(recv_socket);
if (!success) {
- die(blaze_exit_code::INTERNAL_ERROR, "Cannot read subprocess output: %s",
- GetLastErrorString().c_str());
+ BAZEL_DIE(blaze_exit_code::INTERNAL_ERROR)
+ << "Cannot read subprocess output: " << GetLastErrorString();
}
return result;
} else { // We're the child
@@ -460,40 +459,40 @@ void CreateSecureOutputRoot(const string& path) {
struct stat fileinfo = {};
if (!blaze_util::MakeDirectories(root, 0755)) {
- die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR, "mkdir('%s'): %s", root,
- GetLastErrorString().c_str());
+ BAZEL_DIE(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR)
+ << "mkdir('" << root << "'): " << GetLastErrorString();
}
// The path already exists.
// Check ownership and mode, and verify that it is a directory.
if (lstat(root, &fileinfo) < 0) {
- die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR, "lstat('%s'): %s", root,
- GetLastErrorString().c_str());
+ BAZEL_DIE(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR)
+ << "lstat('" << root << "'): " << GetLastErrorString();
}
if (fileinfo.st_uid != geteuid()) {
- die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR, "'%s' is not owned by me",
- root);
+ BAZEL_DIE(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR)
+ << "'" << root << "' is not owned by me";
}
if ((fileinfo.st_mode & 022) != 0) {
int new_mode = fileinfo.st_mode & (~022);
if (chmod(root, new_mode) < 0) {
- die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR,
- "'%s' has mode %o, chmod to %o failed", root,
- fileinfo.st_mode & 07777, new_mode);
+ BAZEL_DIE(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR)
+ << "'" << root << "' has mode " << (fileinfo.st_mode & 07777)
+ << ", chmod to " << new_mode << " failed";
}
}
if (stat(root, &fileinfo) < 0) {
- die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR, "stat('%s'): %s", root,
- GetLastErrorString().c_str());
+ BAZEL_DIE(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR)
+ << "stat('" << root << "'): " << GetLastErrorString();
}
if (!S_ISDIR(fileinfo.st_mode)) {
- die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR, "'%s' is not a directory",
- root);
+ BAZEL_DIE(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR)
+ << "'" << root << "' is not a directory";
}
ExcludePathFromBackup(root);
@@ -568,9 +567,8 @@ static int setlk(int fd, struct flock *lock) {
if (fcntl(fd, F_OFD_SETLK, lock) == 0) return 0;
if (errno != EINVAL) {
if (errno != EACCES && errno != EAGAIN) {
- die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR,
- "unexpected result from F_OFD_SETLK: %s",
- GetLastErrorString().c_str());
+ BAZEL_DIE(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR)
+ << "unexpected result from F_OFD_SETLK: " << GetLastErrorString();
}
return -1;
}
@@ -579,8 +577,8 @@ static int setlk(int fd, struct flock *lock) {
#endif
if (fcntl(fd, F_SETLK, lock) == 0) return 0;
if (errno != EACCES && errno != EAGAIN) {
- die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR,
- "unexpected result from F_SETLK: %s", GetLastErrorString().c_str());
+ BAZEL_DIE(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR)
+ << "unexpected result from F_SETLK: " << GetLastErrorString();
}
return -1;
}
@@ -591,17 +589,16 @@ uint64_t AcquireLock(const string& output_base, bool batch_mode, bool block,
int lockfd = open(lockfile.c_str(), O_CREAT|O_RDWR, 0644);
if (lockfd < 0) {
- die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR,
- "cannot open lockfile '%s' for writing: %s", lockfile.c_str(),
- GetLastErrorString().c_str());
+ BAZEL_DIE(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR)
+ << "cannot open lockfile '" << lockfile
+ << "' for writing: " << GetLastErrorString();
}
// Keep server from inheriting a useless fd if we are not in batch mode
if (!batch_mode) {
if (fcntl(lockfd, F_SETFD, FD_CLOEXEC) == -1) {
- die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR,
- "fcntl(F_SETFD) failed for lockfile: %s",
- GetLastErrorString().c_str());
+ BAZEL_DIE(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR)
+ << "fcntl(F_SETFD) failed for lockfile: " << GetLastErrorString();
}
}
@@ -630,24 +627,24 @@ uint64_t AcquireLock(const string& output_base, bool batch_mode, bool block,
string buffer(4096, 0);
ssize_t r = pread(lockfd, &buffer[0], buffer.size(), 0);
if (r < 0) {
- fprintf(stderr, "warning: pread() lock file: %s\n", strerror(errno));
+ BAZEL_LOG(WARNING) << "pread() lock file: " << strerror(errno);
r = 0;
}
buffer.resize(r);
if (owner != buffer) {
// Each time we learn a new lock owner, print it out.
owner = buffer;
- fprintf(stderr, "Another command holds the client lock: \n%s\n",
- owner.c_str());
+ BAZEL_LOG(USER) << "Another command holds the client lock: \n" << owner;
if (block) {
- fprintf(stderr, "Waiting for it to complete...\n");
+ BAZEL_LOG(USER) << "Waiting for it to complete...";
fflush(stderr);
}
}
if (!block) {
- die(blaze_exit_code::BAD_ARGV,
- "Exiting because the lock is held and --noblock_for_lock was given.");
+ BAZEL_DIE(blaze_exit_code::BAD_ARGV)
+ << "Exiting because the lock is held and --noblock_for_lock was "
+ "given.";
}
TrySleep(500);
@@ -688,10 +685,9 @@ bool KillServerProcess(int pid, const string& output_base) {
killpg(pid, SIGKILL);
if (!AwaitServerProcessTermination(pid, output_base,
kPostKillGracePeriodSeconds)) {
- die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR,
- "Attempted to kill stale server process (pid=%d) using "
- "SIGKILL, but it did not die in a timely fashion.",
- pid);
+ BAZEL_DIE(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR)
+ << "Attempted to kill stale server process (pid=" << pid
+ << ") using SIGKILL, but it did not die in a timely fashion.";
}
return true;
}
@@ -711,9 +707,9 @@ string GetUserName() {
errno = 0;
passwd *pwent = getpwuid(getuid()); // NOLINT (single-threaded)
if (pwent == NULL || pwent->pw_name == NULL) {
- die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR,
- "$USER is not set, and unable to look up name of current user: %s",
- GetLastErrorString().c_str());
+ BAZEL_DIE(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR)
+ << "$USER is not set, and unable to look up name of current user: "
+ << GetLastErrorString();
}
return pwent->pw_name;
}
@@ -772,8 +768,8 @@ int GetTerminalColumns() {
static bool UnlimitResource(const int resource) {
struct rlimit rl;
if (getrlimit(resource, &rl) == -1) {
- fprintf(stderr, "Warning: failed to get resource limit %d: %s\n", resource,
- strerror(errno));
+ BAZEL_LOG(WARNING) << "failed to get resource limit " << resource << ": "
+ << strerror(errno);
return false;
}
@@ -798,9 +794,9 @@ static bool UnlimitResource(const int resource) {
}
if (setrlimit(resource, &rl) == -1) {
- fprintf(stderr, "Warning: failed to raise resource limit %d to %" PRIdMAX
- ": %s\n", resource, static_cast<intmax_t>(rl.rlim_cur),
- strerror(errno));
+ BAZEL_LOG(WARNING) << "failed to raise resource limit " << resource
+ << " to " << static_cast<intmax_t>(rl.rlim_cur) << ": "
+ << strerror(errno);
return false;
}
diff --git a/src/main/cpp/blaze_util_windows.cc b/src/main/cpp/blaze_util_windows.cc
index 8097413309..418155c1c7 100644
--- a/src/main/cpp/blaze_util_windows.cc
+++ b/src/main/cpp/blaze_util_windows.cc
@@ -62,10 +62,10 @@ using bazel::windows::AutoAttributeList;
using bazel::windows::AutoHandle;
using bazel::windows::CreateJunction;
-// TODO(bazel-team): stop using die, handle errors on the caller side.
-// die calls exit(exitcode), which makes it difficult to follow the control flow
-// and does not call destructors on local variables on the call stack.
-using blaze_util::die;
+// TODO(bazel-team): stop using BAZEL_DIE, handle errors on the caller side.
+// BAZEL_DIE calls exit(exitcode), which makes it difficult to follow the
+// control flow and does not call destructors on local variables on the call
+// stack.
using blaze_util::GetLastErrorString;
using std::string;
@@ -195,8 +195,8 @@ string GetProcessIdAsString() {
string GetSelfPath() {
WCHAR buffer[kWindowsPathBufferSize] = {0};
if (!GetModuleFileNameW(0, buffer, kWindowsPathBufferSize)) {
- die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR,
- "GetSelfPath: GetModuleFileNameW: %s", GetLastErrorString().c_str());
+ BAZEL_DIE(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR)
+ << "GetSelfPath: GetModuleFileNameW: " << GetLastErrorString();
}
return string(blaze_util::WstringToCstring(buffer).get());
}
@@ -211,8 +211,8 @@ string GetOutputRoot() {
WCHAR buffer[kWindowsPathBufferSize] = {0};
if (!::GetTempPathW(kWindowsPathBufferSize, buffer)) {
- die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR,
- "GetOutputRoot: GetTempPathW: %s", GetLastErrorString().c_str());
+ BAZEL_DIE(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR)
+ << "GetOutputRoot: GetTempPathW: " << GetLastErrorString();
}
return string(blaze_util::WstringToCstring(buffer).get());
}
@@ -260,8 +260,8 @@ bool IsSharedLibrary(const string &filename) {
string GetDefaultHostJavabase() {
string javahome(GetEnv("JAVA_HOME"));
if (javahome.empty()) {
- die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR,
- "Error: JAVA_HOME not set.");
+ BAZEL_DIE(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR)
+ << "Error: JAVA_HOME not set.";
}
return javahome;
}
@@ -284,9 +284,9 @@ static void CreateCommandLine(CmdLine* result, const string& exe,
std::ostringstream cmdline;
string short_exe;
if (!blaze_util::AsShortWindowsPath(exe, &short_exe)) {
- die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR,
- "CreateCommandLine: AsShortWindowsPath(%s): %s", exe.c_str(),
- GetLastErrorString().c_str());
+ BAZEL_DIE(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR)
+ << "CreateCommandLine: AsShortWindowsPath(" << exe
+ << "): " << GetLastErrorString();
}
bool first = true;
for (const auto& s : args_vector) {
@@ -337,8 +337,9 @@ static void CreateCommandLine(CmdLine* result, const string& exe,
string cmdline_str = cmdline.str();
if (cmdline_str.size() >= MAX_CMDLINE_LENGTH) {
- die(blaze_exit_code::INTERNAL_ERROR, "Command line too long (%d > %d): %s",
- cmdline_str.size(), MAX_CMDLINE_LENGTH, cmdline_str.c_str());
+ BAZEL_DIE(blaze_exit_code::INTERNAL_ERROR)
+ << "Command line too long (" << cmdline_str.size() << " > "
+ << MAX_CMDLINE_LENGTH << "): " << cmdline_str;
}
// Copy command line into a mutable buffer.
@@ -364,17 +365,16 @@ static bool GetProcessStartupTime(HANDLE process, uint64_t* result) {
static void WriteProcessStartupTime(const string& server_dir, HANDLE process) {
uint64_t start_time = 0;
if (!GetProcessStartupTime(process, &start_time)) {
- die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR,
- "WriteProcessStartupTime(%s): GetProcessStartupTime failed: %s",
- server_dir.c_str(), GetLastErrorString().c_str());
+ BAZEL_DIE(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR)
+ << "WriteProcessStartupTime(" << server_dir
+ << "): GetProcessStartupTime failed: " << GetLastErrorString();
}
string start_time_file = blaze_util::JoinPath(server_dir, "server.starttime");
if (!blaze_util::WriteFile(ToString(start_time), start_time_file)) {
- die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR,
- "WriteProcessStartupTime(%s): WriteFile(%s) failed: %s",
- server_dir.c_str(), start_time_file.c_str(),
- GetLastErrorString().c_str());
+ BAZEL_DIE(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR)
+ << "WriteProcessStartupTime(" << server_dir << "): WriteFile("
+ << start_time_file << ") failed: " << GetLastErrorString();
}
}
@@ -445,9 +445,9 @@ int ExecuteDaemon(const string& exe, const std::vector<string>& args_vector,
BlazeServerStartup** server_startup) {
wstring wdaemon_output;
if (!blaze_util::AsAbsoluteWindowsPath(daemon_output, &wdaemon_output)) {
- die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR,
- "ExecuteDaemon(%s): AsAbsoluteWindowsPath(%s) failed: %s", exe.c_str(),
- daemon_output.c_str(), GetLastErrorString().c_str());
+ BAZEL_DIE(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR)
+ << "ExecuteDaemon(" << exe << "): AsAbsoluteWindowsPath("
+ << daemon_output << ") failed: " << GetLastErrorString();
}
SECURITY_ATTRIBUTES sa;
@@ -461,17 +461,18 @@ int ExecuteDaemon(const string& exe, const std::vector<string>& args_vector,
AutoHandle devnull(::CreateFileA("NUL", GENERIC_READ, FILE_SHARE_READ, NULL,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL));
if (!devnull.IsValid()) {
- die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR,
- "ExecuteDaemon(%s): CreateFileA(NUL) failed: %s", exe.c_str(),
- GetLastErrorString().c_str());
+ BAZEL_DIE(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR)
+ << "ExecuteDaemon(" << exe
+ << "): CreateFileA(NUL) failed: " << GetLastErrorString();
}
AutoHandle stdout_file(CreateJvmOutputFile(wdaemon_output.c_str(), &sa,
daemon_out_append));
if (!stdout_file.IsValid()) {
- die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR,
- "ExecuteDaemon(%s): CreateJvmOutputFile(%ls) failed: %s", exe.c_str(),
- wdaemon_output.c_str(), GetLastErrorString().c_str());
+ BAZEL_DIE(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR)
+ << "ExecuteDaemon(" << exe << "): CreateJvmOutputFile("
+ << blaze_util::WstringToString(wdaemon_output)
+ << ") failed: " << GetLastErrorString();
}
HANDLE stderr_handle;
// We must duplicate the handle to stdout, otherwise "bazel clean --expunge"
@@ -486,9 +487,10 @@ int ExecuteDaemon(const string& exe, const std::vector<string>& args_vector,
/* dwDesiredAccess */ 0,
/* bInheritHandle */ TRUE,
/* dwOptions */ DUPLICATE_SAME_ACCESS)) {
- die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR,
- "ExecuteDaemon(%s): DuplicateHandle(%ls) failed: %s", exe.c_str(),
- wdaemon_output.c_str(), GetLastErrorString().c_str());
+ BAZEL_DIE(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR)
+ << "ExecuteDaemon(" << exe << "): DuplicateHandle("
+ << blaze_util::WstringToString(wdaemon_output)
+ << ") failed: " << GetLastErrorString();
}
AutoHandle stderr_file(stderr_handle);
@@ -499,9 +501,9 @@ int ExecuteDaemon(const string& exe, const std::vector<string>& args_vector,
if (!UpdateProcThreadAttribute(
lpAttributeList, 0, PROC_THREAD_ATTRIBUTE_HANDLE_LIST,
handlesToInherit, 2 * sizeof(HANDLE), NULL, NULL)) {
- die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR,
- "ExecuteDaemon(%s): UpdateProcThreadAttribute failed: %s", exe.c_str(),
- GetLastErrorString().c_str());
+ BAZEL_DIE(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR)
+ << "ExecuteDaemon(" << exe
+ << "): UpdateProcThreadAttribute failed: " << GetLastErrorString();
}
PROCESS_INFORMATION processInfo = {0};
@@ -531,9 +533,9 @@ int ExecuteDaemon(const string& exe, const std::vector<string>& args_vector,
/* lpProcessInformation */ &processInfo);
if (!ok) {
- die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR,
- "ExecuteDaemon(%s): CreateProcess(%s) failed: %s", exe.c_str(),
- cmdline.cmdline, GetLastErrorString().c_str());
+ BAZEL_DIE(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR)
+ << "ExecuteDaemon(" << exe << "): CreateProcess(" << cmdline.cmdline
+ << ") failed: " << GetLastErrorString();
}
WriteProcessStartupTime(server_dir, processInfo.hProcess);
@@ -577,9 +579,9 @@ void ExecuteProgram(const string& exe, const std::vector<string>& args_vector) {
if (NestedJobsSupported()) {
job = CreateJobObject(NULL, NULL);
if (job == NULL) {
- die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR,
- "ExecuteProgram(%s): CreateJobObject failed: %s", exe.c_str(),
- GetLastErrorString().c_str());
+ BAZEL_DIE(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR)
+ << "ExecuteProgram(" << exe
+ << "): CreateJobObject failed: " << GetLastErrorString();
}
JOBOBJECT_EXTENDED_LIMIT_INFORMATION job_info = {0};
@@ -588,9 +590,9 @@ void ExecuteProgram(const string& exe, const std::vector<string>& args_vector) {
if (!SetInformationJobObject(job, JobObjectExtendedLimitInformation,
&job_info, sizeof(job_info))) {
- die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR,
- "ExecuteProgram(%s): SetInformationJobObject failed: %s", exe.c_str(),
- GetLastErrorString().c_str());
+ BAZEL_DIE(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR)
+ << "ExecuteProgram(" << exe
+ << "): SetInformationJobObject failed: " << GetLastErrorString();
}
}
@@ -607,9 +609,9 @@ void ExecuteProgram(const string& exe, const std::vector<string>& args_vector) {
/* lpProcessInformation */ &processInfo);
if (!success) {
- die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR,
- "ExecuteProgram(%s): CreateProcess(%s) failed: %s", exe.c_str(),
- cmdline.cmdline, GetLastErrorString().c_str());
+ BAZEL_DIE(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR)
+ << "ExecuteProgram(" << exe << "): CreateProcess(" << cmdline.cmdline
+ << ") failed: " << GetLastErrorString();
}
// On Windows versions that support nested jobs (Windows 8 and above), we
@@ -625,17 +627,17 @@ void ExecuteProgram(const string& exe, const std::vector<string>& args_vector) {
// subprocesses via the JNI library.
if (job != INVALID_HANDLE_VALUE) {
if (!AssignProcessToJobObject(job, processInfo.hProcess)) {
- die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR,
- "ExecuteProgram(%s): AssignProcessToJobObject failed: %s",
- exe.c_str(), GetLastErrorString().c_str());
+ BAZEL_DIE(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR)
+ << "ExecuteProgram(" << exe
+ << "): AssignProcessToJobObject failed: " << GetLastErrorString();
}
}
// Now that we potentially put the process into a new job object, we can start
// running it.
if (ResumeThread(processInfo.hThread) == -1) {
- die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR,
- "ExecuteProgram(%s): ResumeThread failed: %s", exe.c_str(),
- GetLastErrorString().c_str());
+ BAZEL_DIE(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR)
+ << "ExecuteProgram(" << exe
+ << "): ResumeThread failed: " << GetLastErrorString();
}
WaitForSingleObject(processInfo.hProcess, INFINITE);
@@ -651,9 +653,9 @@ const char kListSeparator = ';';
string PathAsJvmFlag(const string& path) {
string spath;
if (!blaze_util::AsShortWindowsPath(path, &spath)) {
- die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR,
- "PathAsJvmFlag(%s): AsShortWindowsPath failed: %s", path.c_str(),
- GetLastErrorString().c_str());
+ BAZEL_DIE(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR)
+ << "PathAsJvmFlag(" << path
+ << "): AsShortWindowsPath failed: " << GetLastErrorString();
}
// Convert backslashes to forward slashes, in order to avoid the JVM parsing
// Windows paths as if they contained escaped characters.
@@ -666,9 +668,9 @@ string ConvertPath(const string& path) {
// The path may not be Windows-style and may not be normalized, so convert it.
wstring wpath;
if (!blaze_util::AsAbsoluteWindowsPath(path, &wpath)) {
- die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR,
- "ConvertPath(%s): AsAbsoluteWindowsPath failed: %s", path.c_str(),
- GetLastErrorString().c_str());
+ BAZEL_DIE(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR)
+ << "ConvertPath(" << path
+ << "): AsAbsoluteWindowsPath failed: " << GetLastErrorString();
}
std::transform(wpath.begin(), wpath.end(), wpath.begin(), ::towlower);
return string(blaze_util::WstringToCstring(
@@ -680,17 +682,17 @@ bool SymlinkDirectories(const string &posix_target, const string &posix_name) {
wstring name;
wstring target;
if (!blaze_util::AsAbsoluteWindowsPath(posix_name, &name)) {
- die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR,
- "SymlinkDirectories(%s, %s): AsAbsoluteWindowsPath(%s) failed: %s",
- posix_target.c_str(), posix_name.c_str(), posix_target.c_str(),
- GetLastErrorString().c_str());
+ BAZEL_DIE(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR)
+ << "SymlinkDirectories(" << posix_target << ", " << posix_name
+ << "): AsAbsoluteWindowsPath(" << posix_target
+ << ") failed: " << GetLastErrorString();
return false;
}
if (!blaze_util::AsAbsoluteWindowsPath(posix_target, &target)) {
- die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR,
- "SymlinkDirectories(%s, %s): AsAbsoluteWindowsPath(%s) failed: %s",
- posix_target.c_str(), posix_name.c_str(), posix_name.c_str(),
- GetLastErrorString().c_str());
+ BAZEL_DIE(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR)
+ << "SymlinkDirectories(" << posix_target << ", " << posix_name
+ << "): AsAbsoluteWindowsPath(" << posix_name
+ << ") failed: " << GetLastErrorString();
return false;
}
wstring werror(CreateJunction(name, target));
@@ -755,9 +757,9 @@ bool KillServerProcess(int pid, const string& output_base) {
BOOL result = TerminateProcess(process, /*uExitCode*/ 0);
if (!result || !AwaitServerProcessTermination(pid, output_base,
kPostKillGracePeriodSeconds)) {
- die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR,
- "Cannot terminate server process with PID %d, output_base=(%s): %s",
- pid, output_base.c_str(), GetLastErrorString().c_str());
+ BAZEL_DIE(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR)
+ << "Cannot terminate server process with PID " << pid
+ << ", output_base=(" << output_base << "): " << GetLastErrorString();
}
return result;
}
@@ -798,13 +800,13 @@ void CreateSecureOutputRoot(const string& path) {
// implementation does.
const char* root = path.c_str();
if (!blaze_util::MakeDirectories(path, 0755)) {
- die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR,
- "MakeDirectories(%s) failed: %s", root, GetLastErrorString().c_str());
+ BAZEL_DIE(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR)
+ << "MakeDirectories(" << root << ") failed: " << GetLastErrorString();
}
if (!blaze_util::IsDirectory(path)) {
- die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR, "'%s' is not a directory",
- root);
+ BAZEL_DIE(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR)
+ << "'" << root << "' is not a directory";
}
ExcludePathFromBackup(root);
@@ -891,18 +893,18 @@ void SetupStdStreams() {
LARGE_INTEGER WindowsClock::GetFrequency() {
LARGE_INTEGER result;
if (!QueryPerformanceFrequency(&result)) {
- die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR,
- "WindowsClock::GetFrequency: QueryPerformanceFrequency failed: %s",
- GetLastErrorString().c_str());
+ BAZEL_DIE(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR)
+ << "WindowsClock::GetFrequency: QueryPerformanceFrequency failed: "
+ << GetLastErrorString();
}
// On ancient Windows versions (pre-XP) and specific hardware the result may
// be 0. Since this is pre-XP, we don't handle that, just error out.
if (result.QuadPart <= 0) {
- die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR,
- "WindowsClock::GetFrequency: QueryPerformanceFrequency returned "
- "invalid result (%llu): %s",
- result.QuadPart, GetLastErrorString().c_str());
+ BAZEL_DIE(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR)
+ << "WindowsClock::GetFrequency: QueryPerformanceFrequency returned "
+ "invalid result ("
+ << result.QuadPart << "): " << GetLastErrorString();
}
return result;
@@ -912,10 +914,10 @@ LARGE_INTEGER WindowsClock::GetMillisecondsAsLargeInt(
const LARGE_INTEGER& freq) {
LARGE_INTEGER counter;
if (!QueryPerformanceCounter(&counter)) {
- die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR,
- "WindowsClock::GetMillisecondsAsLargeInt: QueryPerformanceCounter "
- "failed: %s",
- GetLastErrorString().c_str());
+ BAZEL_DIE(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR)
+ << "WindowsClock::GetMillisecondsAsLargeInt: QueryPerformanceCounter "
+ "failed: "
+ << GetLastErrorString();
}
LARGE_INTEGER result;
@@ -947,9 +949,9 @@ uint64_t AcquireLock(const string& output_base, bool batch_mode, bool block,
string lockfile = blaze_util::JoinPath(output_base, "lock");
wstring wlockfile;
if (!blaze_util::AsAbsoluteWindowsPath(lockfile, &wlockfile)) {
- die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR,
- "AcquireLock(%s): AsAbsoluteWindowsPath(%s) failed: %s",
- output_base.c_str(), lockfile.c_str(), GetLastErrorString().c_str());
+ BAZEL_DIE(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR)
+ << "AcquireLock(" << output_base << "): AsAbsoluteWindowsPath("
+ << lockfile << ") failed: " << GetLastErrorString();
}
blaze_lock->handle = INVALID_HANDLE_VALUE;
@@ -971,20 +973,21 @@ uint64_t AcquireLock(const string& output_base, bool batch_mode, bool block,
if (GetLastError() == ERROR_SHARING_VIOLATION) {
// Someone else has the lock.
if (!block) {
- die(blaze_exit_code::BAD_ARGV,
- "Another command is running. Exiting immediately.");
+ BAZEL_DIE(blaze_exit_code::BAD_ARGV)
+ << "Another command is running. Exiting immediately.";
}
if (first_lock_attempt) {
first_lock_attempt = false;
- fprintf(stderr,
- "Another command is running. Waiting for it to complete...");
+ BAZEL_LOG(USER)
+ << "Another command is running. Waiting for it to complete...";
fflush(stderr);
}
Sleep(/* dwMilliseconds */ 200);
} else {
- die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR,
- "AcquireLock(%s): CreateFileW(%ls) failed: %s", lockfile.c_str(),
- wlockfile.c_str(), GetLastErrorString().c_str());
+ BAZEL_DIE(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR)
+ << "AcquireLock(" << lockfile << "): CreateFileW("
+ << blaze_util::WstringToString(wlockfile)
+ << ") failed: " << GetLastErrorString();
}
}
uint64_t wait_time = GetMillisecondsMonotonic() - st;
@@ -998,9 +1001,10 @@ uint64_t AcquireLock(const string& output_base, bool batch_mode, bool block,
/* nNumberOfBytesToLockLow */ 1,
/* nNumberOfBytesToLockHigh */ 0,
/* lpOverlapped */ &overlapped)) {
- die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR,
- "AcquireLock(%s): LockFileEx(%ls) failed: %s", lockfile.c_str(),
- wlockfile.c_str(), GetLastErrorString().c_str());
+ BAZEL_DIE(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR)
+ << "AcquireLock(" << lockfile << "): LockFileEx("
+ << blaze_util::WstringToString(wlockfile)
+ << ") failed: " << GetLastErrorString();
}
// On other platforms we write some info about this process into the lock file
// such as the server PID. On Windows we don't do that because the file is
@@ -1026,8 +1030,8 @@ string GetUserName() {
WCHAR buffer[UNLEN + 1];
DWORD len = UNLEN + 1;
if (!::GetUserNameW(buffer, &len)) {
- die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR, "GetUserNameW failed: %s",
- GetLastErrorString().c_str());
+ BAZEL_DIE(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR)
+ << "GetUserNameW failed: " << GetLastErrorString();
}
return string(blaze_util::WstringToCstring(buffer).get());
}
diff --git a/src/main/cpp/util/BUILD b/src/main/cpp/util/BUILD
index 66bd722dbc..be4a50f700 100644
--- a/src/main/cpp/util/BUILD
+++ b/src/main/cpp/util/BUILD
@@ -64,7 +64,7 @@ cc_library(
cc_library(
name = "errors",
- srcs = ["errors.cc"] + select({
+ srcs = select({
"//src/conditions:windows": ["errors_windows.cc"],
"//conditions:default": ["errors_posix.cc"],
}),
diff --git a/src/main/cpp/util/errors.cc b/src/main/cpp/util/errors.cc
deleted file mode 100644
index ec25de3b57..0000000000
--- a/src/main/cpp/util/errors.cc
+++ /dev/null
@@ -1,37 +0,0 @@
-// Copyright 2015 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/util/errors.h"
-
-#include <stdarg.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "src/main/cpp/util/logging.h"
-
-namespace blaze_util {
-
-// TODO(b/32967056) This should be a FATAL log statement
-void die(const int exit_status, const char *format, ...) {
- fprintf(stderr, "\nError: ");
- va_list ap;
- va_start(ap, format);
- vfprintf(stderr, format, ap);
- va_end(ap);
- fputc('\n', stderr);
- exit(exit_status);
-}
-
-} // namespace blaze_util
diff --git a/src/main/cpp/util/errors.h b/src/main/cpp/util/errors.h
index 4bea4228de..43892c3cbb 100644
--- a/src/main/cpp/util/errors.h
+++ b/src/main/cpp/util/errors.h
@@ -23,13 +23,6 @@
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);
-
// Returns the last error as a platform-specific error message.
// The string will also contain the platform-specific error code itself
// (which is `errno` on Linux/Darwin, and `GetLastError()` on Windows).
diff --git a/src/main/cpp/util/file_posix.cc b/src/main/cpp/util/file_posix.cc
index b04076ad95..f143ab125b 100644
--- a/src/main/cpp/util/file_posix.cc
+++ b/src/main/cpp/util/file_posix.cc
@@ -28,6 +28,7 @@
#include "src/main/cpp/util/errors.h"
#include "src/main/cpp/util/exit_code.h"
#include "src/main/cpp/util/file.h"
+#include "src/main/cpp/util/logging.h"
#include "src/main/cpp/util/strings.h"
namespace blaze_util {
@@ -160,18 +161,18 @@ class PosixPipe : public IPipe {
IPipe* CreatePipe() {
int fd[2];
if (pipe(fd) < 0) {
- die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR, "pipe() failed: %s",
- GetLastErrorString().c_str());
+ BAZEL_DIE(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR)
+ << "pipe() failed: " << GetLastErrorString();
}
if (fcntl(fd[0], F_SETFD, FD_CLOEXEC) == -1) {
- die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR,
- "fcntl(F_SETFD, FD_CLOEXEC) failed: %s", GetLastErrorString().c_str());
+ BAZEL_DIE(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR)
+ << "fcntl(F_SETFD, FD_CLOEXEC) failed: " << GetLastErrorString();
}
if (fcntl(fd[1], F_SETFD, FD_CLOEXEC) == -1) {
- die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR,
- "fcntl(F_SETFD, FD_CLOEXEC) failed: %s", GetLastErrorString().c_str());
+ BAZEL_DIE(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR)
+ << "fcntl(F_SETFD, FD_CLOEXEC) failed: " << GetLastErrorString();
}
return new PosixPipe(fd[0], fd[1]);
@@ -329,13 +330,13 @@ void SyncFile(const string& path) {
const char* file_path = path.c_str();
int fd = open(file_path, O_RDONLY);
if (fd < 0) {
- die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR,
- "failed to open '%s' for syncing: %s", file_path,
- GetLastErrorString().c_str());
+ BAZEL_DIE(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR)
+ << "failed to open '" << file_path
+ << "' for syncing: " << GetLastErrorString();
}
if (fsync(fd) < 0) {
- die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR, "failed to sync '%s': %s",
- file_path, GetLastErrorString().c_str());
+ BAZEL_DIE(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR)
+ << "failed to sync '" << file_path << "': " << GetLastErrorString();
}
close(fd);
}
@@ -392,8 +393,8 @@ bool PosixFileMtime::Set(const string &path, const struct utimbuf &mtime) {
time_t PosixFileMtime::GetNow() {
time_t result = time(NULL);
if (result == -1) {
- die(blaze_exit_code::INTERNAL_ERROR, "time(NULL) failed: %s",
- GetLastErrorString().c_str());
+ BAZEL_DIE(blaze_exit_code::INTERNAL_ERROR)
+ << "time(NULL) failed: " << GetLastErrorString();
}
return result;
}
@@ -417,8 +418,8 @@ bool MakeDirectories(const string &path, unsigned int mode) {
string GetCwd() {
char cwdbuf[PATH_MAX];
if (getcwd(cwdbuf, sizeof cwdbuf) == NULL) {
- die(blaze_exit_code::INTERNAL_ERROR, "getcwd() failed: %s",
- GetLastErrorString().c_str());
+ BAZEL_DIE(blaze_exit_code::INTERNAL_ERROR)
+ << "getcwd() failed: " << GetLastErrorString();
}
return string(cwdbuf);
}
@@ -447,8 +448,9 @@ void ForEachDirectoryEntry(const string &path,
if (ent->d_type == DT_UNKNOWN) {
struct stat buf;
if (lstat(filename.c_str(), &buf) == -1) {
- die(blaze_exit_code::INTERNAL_ERROR, "stat failed: %s",
- GetLastErrorString().c_str());
+ BAZEL_DIE(blaze_exit_code::INTERNAL_ERROR)
+ << "stat failed for filename '" << filename
+ << "': " << GetLastErrorString();
}
is_directory = S_ISDIR(buf.st_mode);
} else {
diff --git a/src/main/cpp/util/file_windows.cc b/src/main/cpp/util/file_windows.cc
index 2db123ec46..b495d8c268 100644
--- a/src/main/cpp/util/file_windows.cc
+++ b/src/main/cpp/util/file_windows.cc
@@ -149,8 +149,8 @@ IPipe* CreatePipe() {
HANDLE read_handle = INVALID_HANDLE_VALUE;
HANDLE write_handle = INVALID_HANDLE_VALUE;
if (!CreatePipe(&read_handle, &write_handle, &sa, 0)) {
- die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR, "CreatePipe: %s",
- GetLastErrorString().c_str());
+ BAZEL_DIE(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR)
+ << "CreatePipe failed: " << GetLastErrorString();
}
return new WindowsPipe(read_handle, write_handle);
}
@@ -185,10 +185,11 @@ bool WindowsFileMtime::GetIfInDistantFuture(const string& path, bool* result) {
}
wstring wpath;
if (!AsAbsoluteWindowsPath(path, &wpath)) {
- die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR,
- "WindowsFileMtime::GetIfInDistantFuture(%s): AsAbsoluteWindowsPath "
- "failed: %s",
- path.c_str(), GetLastErrorString().c_str());
+ BAZEL_DIE(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR)
+ << "WindowsFileMtime::GetIfInDistantFuture(" << path
+ << "): AsAbsoluteWindowsPath "
+ "failed: "
+ << GetLastErrorString();
}
AutoHandle handle(::CreateFileW(
@@ -238,9 +239,9 @@ bool WindowsFileMtime::Set(const string& path, const FILETIME& time) {
}
wstring wpath;
if (!AsAbsoluteWindowsPath(path, &wpath)) {
- die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR,
- "WindowsFileMtime::Set(%s): AsAbsoluteWindowsPath failed: %s",
- path.c_str(), GetLastErrorString().c_str());
+ BAZEL_DIE(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR)
+ << "WindowsFileMtime::Set(" << path
+ << "): AsAbsoluteWindowsPath failed: " << GetLastErrorString();
return false;
}
@@ -270,9 +271,9 @@ FILETIME WindowsFileMtime::GetNow() {
::GetSystemTime(&sys_time);
FILETIME file_time;
if (!::SystemTimeToFileTime(&sys_time, &file_time)) {
- die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR,
- "WindowsFileMtime::GetNow: SystemTimeToFileTime failed: %s",
- GetLastErrorString().c_str());
+ BAZEL_DIE(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR)
+ << "WindowsFileMtime::GetNow: SystemTimeToFileTime failed: "
+ << GetLastErrorString();
}
return file_time;
}
@@ -290,9 +291,9 @@ FILETIME WindowsFileMtime::GetFuture(WORD years) {
future_time.wMilliseconds = 0;
FILETIME file_time;
if (!::SystemTimeToFileTime(&future_time, &file_time)) {
- die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR,
- "WindowsFileMtime::GetFuture: SystemTimeToFileTime failed: %s",
- GetLastErrorString().c_str());
+ BAZEL_DIE(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR)
+ << "WindowsFileMtime::GetFuture: SystemTimeToFileTime failed: "
+ << GetLastErrorString();
}
return file_time;
}
@@ -557,9 +558,9 @@ bool AsShortWindowsPath(const string& path, string* result) {
wstring wpath;
wstring wsuffix;
if (!AsAbsoluteWindowsPath(path, &wpath)) {
- die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR,
- "AsShortWindowsPath(%s): AsAbsoluteWindowsPath failed: %s",
- path.c_str(), GetLastErrorString().c_str());
+ BAZEL_DIE(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR)
+ << "AsShortWindowsPath(" << path
+ << "): AsAbsoluteWindowsPath failed: " << GetLastErrorString();
return false;
}
DWORD size = ::GetShortPathNameW(wpath.c_str(), nullptr, 0);
@@ -599,9 +600,10 @@ bool AsShortWindowsPath(const string& path, string* result) {
unique_ptr<WCHAR[]> wshort(
new WCHAR[size]); // size includes null-terminator
if (size - 1 != ::GetShortPathNameW(wpath.c_str(), wshort.get(), size)) {
- die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR,
- "AsShortWindowsPath(%s): GetShortPathNameW(%S) failed: %s",
- path.c_str(), wpath.c_str(), GetLastErrorString().c_str());
+ BAZEL_DIE(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR)
+ << "AsShortWindowsPath(" << path << "): GetShortPathNameW("
+ << blaze_util::WstringToString(wpath)
+ << ") failed: " << GetLastErrorString();
}
// GetShortPathNameW may preserve the UNC prefix in the result, so strip it.
wresult = wstring(RemoveUncPrefixMaybe(wshort.get())) + wsuffix;
@@ -622,9 +624,9 @@ static bool OpenFileForReading(const string& filename, HANDLE* result) {
}
wstring wfilename;
if (!AsAbsoluteWindowsPath(filename, &wfilename)) {
- die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR,
- "OpenFileForReading(%s): AsAbsoluteWindowsPath failed: %s",
- filename.c_str(), GetLastErrorString().c_str());
+ BAZEL_DIE(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR)
+ << "OpenFileForReading(" << filename
+ << "): AsAbsoluteWindowsPath failed: " << GetLastErrorString();
}
*result = ::CreateFileW(
/* lpFileName */ wfilename.c_str(),
@@ -692,9 +694,9 @@ bool WriteFile(const void* data, size_t size, const string& filename,
}
wstring wpath;
if (!AsAbsoluteWindowsPath(filename, &wpath)) {
- die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR,
- "WriteFile(%s): AsAbsoluteWindowsPath failed: %s", filename.c_str(),
- GetLastErrorString().c_str());
+ BAZEL_DIE(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR)
+ << "WriteFile(" << filename
+ << "): AsAbsoluteWindowsPath failed: " << GetLastErrorString();
return false;
}
@@ -735,19 +737,19 @@ int WriteToStdOutErr(const void* data, size_t size, bool to_stdout) {
int RenameDirectory(const std::string& old_name, const std::string& new_name) {
wstring wold_name;
if (!AsAbsoluteWindowsPath(old_name, &wold_name)) {
- die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR,
- "RenameDirectory(%s, %s): AsAbsoluteWindowsPath(%s) failed: %s",
- old_name.c_str(), new_name.c_str(), old_name.c_str(),
- GetLastErrorString().c_str());
+ BAZEL_DIE(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR)
+ << "RenameDirectory(" << old_name << ", " << new_name
+ << "): AsAbsoluteWindowsPath(" << old_name
+ << ") failed: " << GetLastErrorString();
return kRenameDirectoryFailureOtherError;
}
wstring wnew_name;
if (!AsAbsoluteWindowsPath(new_name, &wnew_name)) {
- die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR,
- "RenameDirectory(%s, %s): AsAbsoluteWindowsPath(%s) failed: %s",
- old_name.c_str(), new_name.c_str(), new_name.c_str(),
- GetLastErrorString().c_str());
+ BAZEL_DIE(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR)
+ << "RenameDirectory(" << old_name << ", " << new_name
+ << "): AsAbsoluteWindowsPath(" << new_name
+ << ") failed: " << GetLastErrorString();
return kRenameDirectoryFailureOtherError;
}
@@ -787,9 +789,9 @@ bool UnlinkPath(const string& file_path) {
wstring wpath;
if (!AsAbsoluteWindowsPath(file_path, &wpath)) {
- die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR,
- "UnlinkPath(%s): AsAbsoluteWindowsPath failed: %s", file_path.c_str(),
- GetLastErrorString().c_str());
+ BAZEL_DIE(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR)
+ << "UnlinkPath(" << file_path
+ << "): AsAbsoluteWindowsPath failed: " << GetLastErrorString();
return false;
}
return UnlinkPathW(wpath);
@@ -920,9 +922,9 @@ bool JunctionResolver::Resolve(const WCHAR* path, unique_ptr<WCHAR[]>* result) {
bool ReadDirectorySymlink(const string& name, string* result) {
wstring wname;
if (!AsAbsoluteWindowsPath(name, &wname)) {
- die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR,
- "ReadDirectorySymlink(%s): AsAbsoluteWindowsPath failed: %s",
- name.c_str(), GetLastErrorString().c_str());
+ BAZEL_DIE(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR)
+ << "ReadDirectorySymlink(" << name
+ << "): AsAbsoluteWindowsPath failed: " << GetLastErrorString();
return false;
}
unique_ptr<WCHAR[]> result_ptr;
@@ -942,9 +944,9 @@ bool PathExists(const string& path) {
}
wstring wpath;
if (!AsAbsoluteWindowsPath(path, &wpath)) {
- die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR,
- "PathExists(%s): AsAbsoluteWindowsPath failed: %s", path.c_str(),
- GetLastErrorString().c_str());
+ BAZEL_DIE(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR)
+ << "PathExists(" << path
+ << "): AsAbsoluteWindowsPath failed: " << GetLastErrorString();
return false;
}
return JunctionResolver().Resolve(wpath.c_str(), nullptr);
@@ -959,9 +961,9 @@ string MakeCanonical(const char* path) {
return "";
}
if (!AsAbsoluteWindowsPath(path, &wpath)) {
- die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR,
- "MakeCanonical(%s): AsAbsoluteWindowsPath failed: %s", path,
- GetLastErrorString().c_str());
+ BAZEL_DIE(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR)
+ << "MakeCanonical(" << path
+ << "): AsAbsoluteWindowsPath failed: " << GetLastErrorString();
}
// Resolve all segments of the path. Do this from leaf to root, so we always
@@ -1066,9 +1068,9 @@ static bool CanReadFileW(const wstring& path) {
bool CanReadFile(const std::string& path) {
wstring wpath;
if (!AsAbsoluteWindowsPath(path, &wpath)) {
- die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR,
- "CanReadFile(%s): AsAbsoluteWindowsPath failed: %s", path.c_str(),
- GetLastErrorString().c_str());
+ BAZEL_DIE(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR)
+ << "CanReadFile(" << path
+ << "): AsAbsoluteWindowsPath failed: " << GetLastErrorString();
return false;
}
return CanReadFileW(wpath);
@@ -1077,9 +1079,9 @@ bool CanReadFile(const std::string& path) {
bool CanExecuteFile(const std::string& path) {
wstring wpath;
if (!AsAbsoluteWindowsPath(path, &wpath)) {
- die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR,
- "CanExecuteFile(%s): AsAbsoluteWindowsPath failed: %s", path.c_str(),
- GetLastErrorString().c_str());
+ BAZEL_DIE(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR)
+ << "CanExecuteFile(" << path
+ << "): AsAbsoluteWindowsPath failed: " << GetLastErrorString();
return false;
}
return CanReadFileW(wpath) && (ends_with(wpath, wstring(L".exe")) ||
@@ -1091,9 +1093,9 @@ bool CanExecuteFile(const std::string& path) {
bool CanAccessDirectory(const std::string& path) {
wstring wpath;
if (!AsAbsoluteWindowsPath(path, &wpath)) {
- die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR,
- "CanAccessDirectory(%s): AsAbsoluteWindowsPath failed: %s",
- path.c_str(), GetLastErrorString().c_str());
+ BAZEL_DIE(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR)
+ << "CanAccessDirectory(" << path
+ << "): AsAbsoluteWindowsPath failed: " << GetLastErrorString();
return false;
}
DWORD attr = ::GetFileAttributesW(wpath.c_str());
@@ -1159,9 +1161,9 @@ bool IsDirectory(const string& path) {
}
wstring wpath;
if (!AsAbsoluteWindowsPath(path, &wpath)) {
- die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR,
- "IsDirectory(%s): AsAbsoluteWindowsPath failed: %s", path.c_str(),
- GetLastErrorString().c_str());
+ BAZEL_DIE(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR)
+ << "IsDirectory(" << path
+ << "): AsAbsoluteWindowsPath failed: " << GetLastErrorString();
return false;
}
return IsDirectoryW(wpath);
@@ -1193,9 +1195,9 @@ static bool MakeDirectoriesW(const wstring& path) {
if (parent.empty()) {
// Since `path` is not a root directory, there should have been at least one
// directory above it.
- die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR,
- "MakeDirectoriesW(%S), could not find dirname: %s", path.c_str(),
- GetLastErrorString().c_str());
+ BAZEL_DIE(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR)
+ << "MakeDirectoriesW(" << blaze_util::WstringToString(path)
+ << ") could not find dirname: " << GetLastErrorString();
}
return MakeDirectoriesW(parent) &&
::CreateDirectoryW(path.c_str(), NULL) == TRUE;
@@ -1211,9 +1213,9 @@ bool MakeDirectories(const string& path, unsigned int mode) {
// According to MSDN, CreateDirectory's limit without the UNC prefix is
// 248 characters (so it could fit another filename before reaching MAX_PATH).
if (!AsAbsoluteWindowsPath(path, &wpath)) {
- die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR,
- "MakeDirectories(%s): AsAbsoluteWindowsPath failed: %s", path.c_str(),
- GetLastErrorString().c_str());
+ BAZEL_DIE(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR)
+ << "MakeDirectories(" << path
+ << "): AsAbsoluteWindowsPath failed: " << GetLastErrorString();
return false;
}
return MakeDirectoriesW(wpath);
@@ -1223,8 +1225,8 @@ static unique_ptr<WCHAR[]> GetCwdW() {
DWORD len = ::GetCurrentDirectoryW(0, nullptr);
unique_ptr<WCHAR[]> cwd(new WCHAR[len]);
if (!::GetCurrentDirectoryW(len, cwd.get())) {
- die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR,
- "GetCurrentDirectoryW failed: %s", GetLastErrorString().c_str());
+ BAZEL_DIE(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR)
+ << "GetCurrentDirectoryW failed: " << GetLastErrorString();
}
for (WCHAR* p = cwd.get(); *p != 0; ++p) {
*p = towlower(*p);
@@ -1256,9 +1258,9 @@ void ForEachDirectoryEntry(const string &path,
return;
}
if (!AsWindowsPath(path, &wpath)) {
- die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR,
- "ForEachDirectoryEntry(%s): AsWindowsPath failed: %s", path.c_str(),
- GetLastErrorString().c_str());
+ BAZEL_DIE(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR)
+ << "ForEachDirectoryEntry(" << path
+ << "): AsWindowsPath failed: " << GetLastErrorString();
}
static const wstring kUncPrefix(L"\\\\?\\");
@@ -1295,8 +1297,8 @@ string NormalizeWindowsPath(string path) {
}
if (path[0] == '/') {
// This is an absolute MSYS path, error out.
- die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR,
- "NormalizeWindowsPath(%s): expected a Windows path", path.c_str());
+ BAZEL_DIE(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR)
+ << "NormalizeWindowsPath(" << path << "): expected a Windows path";
}
if (path.size() >= 4 && HasUncPrefix(path.c_str())) {
path = path.substr(4);
diff --git a/src/main/cpp/util/strings.cc b/src/main/cpp/util/strings.cc
index 8bac35a958..e98b5d2483 100644
--- a/src/main/cpp/util/strings.cc
+++ b/src/main/cpp/util/strings.cc
@@ -300,6 +300,10 @@ unique_ptr<char[]> WstringToCstring(const wchar_t *input) {
return UstringToVstring<wchar_t, char>(input, wcstombs, "%ls");
}
+std::string WstringToString(const std::wstring &input) {
+ return string(WstringToCstring(input.c_str()).get());
+}
+
unique_ptr<wchar_t[]> CstringToWstring(const char *input) {
return UstringToVstring<char, wchar_t>(input, mbstowcs, "%s");
}
diff --git a/src/main/cpp/util/strings.h b/src/main/cpp/util/strings.h
index 943f6c6fd3..0a761e1726 100644
--- a/src/main/cpp/util/strings.h
+++ b/src/main/cpp/util/strings.h
@@ -110,6 +110,7 @@ std::string AsLower(const std::string &str);
// Convert a wchar_t string to a char string. Useful when consuming results of
// widechar Windows API functions.
std::unique_ptr<char[]> WstringToCstring(const wchar_t *input);
+std::string WstringToString(const std::wstring &input);
// Convert a char string to a wchar_t string. Useful when passing arguments to
// widechar Windows API functions.
diff --git a/src/test/shell/integration/client_test.sh b/src/test/shell/integration/client_test.sh
index 53f132a914..da0708e86d 100755
--- a/src/test/shell/integration/client_test.sh
+++ b/src/test/shell/integration/client_test.sh
@@ -93,17 +93,17 @@ function test_output_base() {
function test_output_base_is_file() {
bazel --output_base=/dev/null &>$TEST_log && fail "Expected non-zero exit"
- expect_log "Error: Output base directory '/dev/null' could not be created.*exists"
+ expect_log "FATAL: Output base directory '/dev/null' could not be created.*exists"
}
function test_cannot_create_output_base() {
bazel --output_base=/foo &>$TEST_log && fail "Expected non-zero exit"
- expect_log "Error: Output base directory '/foo' could not be created"
+ expect_log "FATAL: Output base directory '/foo' could not be created"
}
function test_nonwritable_output_base() {
bazel --output_base=/ &>$TEST_log && fail "Expected non-zero exit"
- expect_log "Output base directory '/' must be readable and writable."
+ expect_log "FATAL: Output base directory '/' must be readable and writable."
}
function test_no_arguments() {
@@ -124,7 +124,7 @@ function test_dashdash_before_command() {
bazel -- info &>$TEST_log && "Expected failure"
exitcode=$?
assert_equals 2 $exitcode
- expect_log "Unknown startup option: '--'."
+ expect_log "\\[bazel FATAL .*\\] Unknown startup option: '--'."
}
function test_dashdash_after_command() {
diff --git a/third_party/ijar/BUILD b/third_party/ijar/BUILD
index 90f74c5407..96f4066c01 100644
--- a/third_party/ijar/BUILD
+++ b/third_party/ijar/BUILD
@@ -31,6 +31,8 @@ cc_library(
"//src:windows": [
"//src/main/cpp/util:errors",
"//src/main/cpp/util:file",
+ "//src/main/cpp/util:logging",
+ "//src/main/cpp/util:strings",
],
"//conditions:default": [
],
@@ -58,6 +60,7 @@ cc_library(
deps = [
"//src/main/cpp/util:errors",
"//src/main/cpp/util:file",
+ "//src/main/cpp/util:logging",
],
)
diff --git a/third_party/ijar/mapped_file_windows.cc b/third_party/ijar/mapped_file_windows.cc
index 6292605e86..b3327ed89d 100644
--- a/third_party/ijar/mapped_file_windows.cc
+++ b/third_party/ijar/mapped_file_windows.cc
@@ -19,12 +19,15 @@
#include "src/main/cpp/util/errors.h"
#include "src/main/cpp/util/file_platform.h"
+#include "src/main/cpp/util/logging.h"
+#include "src/main/cpp/util/strings.h"
#include "third_party/ijar/mapped_file.h"
#define MAX_ERROR 2048
namespace devtools_ijar {
+using std::string;
using std::wstring;
static char errmsg[MAX_ERROR] = "";
@@ -46,36 +49,37 @@ MappedInputFile::MappedInputFile(const char* name) {
wstring wname;
if (!blaze_util::AsAbsoluteWindowsPath(name, &wname)) {
- blaze_util::die(255,
- "MappedInputFile(%s): AsAbsoluteWindowsPath failed: %s",
- name, blaze_util::GetLastErrorString().c_str());
+ BAZEL_DIE(255) << "MappedInputFile(" << name
+ << "): AsAbsoluteWindowsPath failed: "
+ << blaze_util::GetLastErrorString();
}
HANDLE file = CreateFileW(wname.c_str(), GENERIC_READ, FILE_SHARE_READ, NULL,
OPEN_EXISTING, 0, NULL);
if (file == INVALID_HANDLE_VALUE) {
- blaze_util::die(255, "MappedInputFile(%s): CreateFileW(%S) failed: %s",
- name, wname.c_str(),
- blaze_util::GetLastErrorString().c_str());
+ BAZEL_DIE(255) << "MappedInputFile(" << name << "): CreateFileW("
+ << blaze_util::WstringToString(wname)
+ << ") failed: " << blaze_util::GetLastErrorString();
}
LARGE_INTEGER size;
if (!GetFileSizeEx(file, &size)) {
- blaze_util::die(255, "MappedInputFile(%s): GetFileSizeEx failed: %s", name,
- blaze_util::GetLastErrorString().c_str());
+ BAZEL_DIE(255) << "MappedInputFile(" << name << "): GetFileSizeEx failed: "
+ << blaze_util::GetLastErrorString();
}
HANDLE mapping = CreateFileMapping(file, NULL, PAGE_READONLY,
size.HighPart, size.LowPart, NULL);
if (mapping == NULL || mapping == INVALID_HANDLE_VALUE) {
- blaze_util::die(255, "MappedInputFile(%s): CreateFileMapping failed: %s",
- name),
- blaze_util::GetLastErrorString().c_str();
+ BAZEL_DIE(255) << "MappedInputFile(" << name
+ << "): CreateFileMapping failed: "
+ << blaze_util::GetLastErrorString();
}
void *view = MapViewOfFileEx(mapping, FILE_MAP_READ, 0, 0, 0, NULL);
if (view == NULL) {
- blaze_util::die(255, "MappedInputFile(%s): MapViewOfFileEx failed: %s",
- name, blaze_util::GetLastErrorString().c_str());
+ BAZEL_DIE(255) << "MappedInputFile(" << name
+ << "): MapViewOfFileEx failed: "
+ << blaze_util::GetLastErrorString();
}
impl_ = new MappedInputFileImpl(file, mapping);
@@ -96,20 +100,18 @@ void MappedInputFile::Discard(size_t bytes) {
int MappedInputFile::Close() {
if (!UnmapViewOfFile(buffer_)) {
- blaze_util::die(255, "MappedInputFile::Close: UnmapViewOfFile failed: %s",
- blaze_util::GetLastErrorString().c_str());
+ BAZEL_DIE(255) << "MappedInputFile::Close: UnmapViewOfFile failed: "
+ << blaze_util::GetLastErrorString();
}
if (!CloseHandle(impl_->mapping_)) {
- blaze_util::die(
- 255, "MappedInputFile::Close: CloseHandle for mapping failed: %s",
- blaze_util::GetLastErrorString().c_str());
+ BAZEL_DIE(255) << "MappedInputFile::Close: CloseHandle for mapping failed: "
+ << blaze_util::GetLastErrorString();
}
if (!CloseHandle(impl_->file_)) {
- blaze_util::die(255,
- "MappedInputFile::Close: CloseHandle for file failed: %s",
- blaze_util::GetLastErrorString().c_str());
+ BAZEL_DIE(255) << "MappedInputFile::Close: CloseHandle for file failed: "
+ << blaze_util::GetLastErrorString();
}
return 0;
@@ -132,29 +134,30 @@ MappedOutputFile::MappedOutputFile(const char* name, size_t estimated_size) {
wstring wname;
if (!blaze_util::AsAbsoluteWindowsPath(name, &wname)) {
- blaze_util::die(255,
- "MappedOutputFile(%s): AsAbsoluteWindowsPath failed: %s",
- name, blaze_util::GetLastErrorString().c_str());
+ BAZEL_DIE(255) << "MappedOutputFile(" << name
+ << "): AsAbsoluteWindowsPath failed: "
+ << blaze_util::GetLastErrorString();
}
HANDLE file = CreateFileW(wname.c_str(), GENERIC_READ | GENERIC_WRITE, 0,
NULL, CREATE_ALWAYS, 0, NULL);
if (file == INVALID_HANDLE_VALUE) {
- blaze_util::die(255, "MappedOutputFile(%s): CreateFileW(%S) failed: %s",
- name, wname.c_str(),
- blaze_util::GetLastErrorString().c_str());
+ BAZEL_DIE(255) << "MappedOutputFile(" << name << "): CreateFileW("
+ << blaze_util::WstringToString(wname)
+ << ") failed: " << blaze_util::GetLastErrorString();
}
HANDLE mapping = CreateFileMapping(file, NULL, PAGE_READWRITE,
estimated_size >> 32, estimated_size & 0xffffffffUL, NULL);
if (mapping == NULL || mapping == INVALID_HANDLE_VALUE) {
- blaze_util::die(255, "MappedOutputFile(%s): CreateFileMapping failed: %s",
- name);
+ BAZEL_DIE(255) << "MappedOutputFile(" << name
+ << "): CreateFileMapping failed: ";
}
void *view = MapViewOfFileEx(mapping, FILE_MAP_ALL_ACCESS, 0, 0, 0, NULL);
if (view == NULL) {
- blaze_util::die(255, "MappedOutputFile(%s): MapViewOfFileEx failed: %s",
- name, blaze_util::GetLastErrorString().c_str());
+ BAZEL_DIE(255) << "MappedOutputFile(" << name
+ << "): MapViewOfFileEx failed: "
+ << blaze_util::GetLastErrorString();
CloseHandle(mapping);
CloseHandle(file);
return;
@@ -171,30 +174,29 @@ MappedOutputFile::~MappedOutputFile() {
int MappedOutputFile::Close(size_t size) {
if (!UnmapViewOfFile(buffer_)) {
- blaze_util::die(255, "MappedOutputFile::Close: UnmapViewOfFile failed: %s",
- blaze_util::GetLastErrorString().c_str());
+ BAZEL_DIE(255) << "MappedOutputFile::Close: UnmapViewOfFile failed: "
+ << blaze_util::GetLastErrorString();
}
if (!CloseHandle(impl_->mapping_)) {
- blaze_util::die(
- 255, "MappedOutputFile::Close: CloseHandle for mapping failed: %s",
- blaze_util::GetLastErrorString().c_str());
+ BAZEL_DIE(255)
+ << "MappedOutputFile::Close: CloseHandle for mapping failed: "
+ << blaze_util::GetLastErrorString();
}
if (!SetFilePointer(impl_->file_, size, NULL, FILE_BEGIN)) {
- blaze_util::die(255, "MappedOutputFile::Close: SetFilePointer failed: %s",
- blaze_util::GetLastErrorString().c_str());
+ BAZEL_DIE(255) << "MappedOutputFile::Close: SetFilePointer failed: "
+ << blaze_util::GetLastErrorString();
}
if (!SetEndOfFile(impl_->file_)) {
- blaze_util::die(255, "MappedOutputFile::Close: SetEndOfFile failed: %s",
- blaze_util::GetLastErrorString().c_str());
+ BAZEL_DIE(255) << "MappedOutputFile::Close: SetEndOfFile failed: "
+ << blaze_util::GetLastErrorString();
}
if (!CloseHandle(impl_->file_)) {
- blaze_util::die(255,
- "MappedOutputFile::Close: CloseHandle for file failed: %s",
- blaze_util::GetLastErrorString().c_str());
+ BAZEL_DIE(255) << "MappedOutputFile::Close: CloseHandle for file failed: "
+ << blaze_util::GetLastErrorString();
}
return 0;
diff --git a/third_party/ijar/platform_utils.cc b/third_party/ijar/platform_utils.cc
index 09818f7162..9633eb7cee 100644
--- a/third_party/ijar/platform_utils.cc
+++ b/third_party/ijar/platform_utils.cc
@@ -30,6 +30,7 @@
#include "src/main/cpp/util/errors.h"
#include "src/main/cpp/util/file.h"
#include "src/main/cpp/util/file_platform.h"
+#include "src/main/cpp/util/logging.h"
namespace devtools_ijar {
@@ -39,8 +40,8 @@ bool stat_file(const char* path, Stat* result) {
#if defined(COMPILER_MSVC) || defined(__CYGWIN__)
std::wstring wpath;
if (!blaze_util::AsAbsoluteWindowsPath(path, &wpath)) {
- blaze_util::die(255, "stat_file: AsAbsoluteWindowsPath(%s) failed: %s",
- path, blaze_util::GetLastErrorString().c_str());
+ BAZEL_DIE(255) << "stat_file: AsAbsoluteWindowsPath(" << path
+ << ") failed: " << blaze_util::GetLastErrorString();
}
bool success = false;
BY_HANDLE_FILE_INFORMATION info;