aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/cpp/blaze.cc
diff options
context:
space:
mode:
authorGravatar Laszlo Csomor <laszlocsomor@google.com>2016-11-10 13:31:27 +0000
committerGravatar Klaus Aehlig <aehlig@google.com>2016-11-10 16:17:29 +0000
commit9c95196bf21e42bf46df9436a84d263c26e972d2 (patch)
tree5960e30273a63b95c5f16ca458d9b3511f3d7092 /src/main/cpp/blaze.cc
parentbff767a0e24be19c6535214abb69f3d5d1d24210 (diff)
Bazel client: wrap some POSIX functions
This change: - starts using blaze_util::CanAccess and blaze_util::PathExists instead of access(2) - implements and starts using blaze_util::GetCwd instead of getcwd(2) - implements and starts using blaze_util::ChangeDirectory instead of chdir(2) - adds tests for the new wrapper methods -- MOS_MIGRATED_REVID=138750297
Diffstat (limited to 'src/main/cpp/blaze.cc')
-rw-r--r--src/main/cpp/blaze.cc13
1 files changed, 5 insertions, 8 deletions
diff --git a/src/main/cpp/blaze.cc b/src/main/cpp/blaze.cc
index 39215a51be..b69586012a 100644
--- a/src/main/cpp/blaze.cc
+++ b/src/main/cpp/blaze.cc
@@ -75,6 +75,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/file_platform.h"
#include "src/main/cpp/util/md5.h"
#include "src/main/cpp/util/numbers.h"
#include "src/main/cpp/util/port.h"
@@ -614,9 +615,9 @@ static string GetArgumentString(const vector<string>& argument_array) {
// Do a chdir into the workspace, and die if it fails.
static void GoToWorkspace() {
if (WorkspaceLayout::InWorkspace(globals->workspace) &&
- chdir(globals->workspace.c_str()) != 0) {
+ !blaze_util::ChangeDirectory(globals->workspace)) {
pdie(blaze_exit_code::INTERNAL_ERROR,
- "chdir() into %s failed", globals->workspace.c_str());
+ "changing directory into %s failed", globals->workspace.c_str());
}
}
@@ -1334,11 +1335,7 @@ static string MakeCanonical(const char *path) {
// Compute the globals globals->cwd and globals->workspace.
static void ComputeWorkspace() {
- char cwdbuf[PATH_MAX];
- if (getcwd(cwdbuf, sizeof cwdbuf) == NULL) {
- pdie(blaze_exit_code::INTERNAL_ERROR, "getcwd() failed");
- }
- globals->cwd = MakeCanonical(cwdbuf);
+ globals->cwd = MakeCanonical(blaze_util::GetCwd().c_str());
globals->workspace = WorkspaceLayout::GetWorkspace(globals->cwd);
}
@@ -1392,7 +1389,7 @@ static void ComputeBaseDirectories(const string &self_path) {
output_base);
}
}
- if (access(output_base, R_OK | W_OK | X_OK) != 0) {
+ if (!blaze_util::CanAccess(globals->options->output_base, true, true, true)) {
die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR,
"Error: Output base directory '%s' must be readable and writable.",
output_base);