diff options
Diffstat (limited to 'src/main/cpp/util')
-rw-r--r-- | src/main/cpp/util/BUILD | 10 | ||||
-rw-r--r-- | src/main/cpp/util/file_platform.h | 6 | ||||
-rw-r--r-- | src/main/cpp/util/file_posix.cc | 13 | ||||
-rw-r--r-- | src/main/cpp/util/file_windows.cc | 10 |
4 files changed, 37 insertions, 2 deletions
diff --git a/src/main/cpp/util/BUILD b/src/main/cpp/util/BUILD index 7537ac594d..600725f1c3 100644 --- a/src/main/cpp/util/BUILD +++ b/src/main/cpp/util/BUILD @@ -33,7 +33,10 @@ cc_library( ], }), hdrs = ["file_platform.h"], - visibility = ["//src/main/cpp:__pkg__"], + visibility = [ + "//src/main/cpp:__pkg__", + "//src/test/cpp:__pkg__", + ], deps = [ ":blaze_exit_code", ":errors", @@ -46,7 +49,10 @@ cc_library( name = "file", srcs = ["file.cc"], hdrs = ["file.h"], - visibility = ["//src/tools/singlejar:__pkg__"], + visibility = [ + "//src/test/cpp:__pkg__", + "//src/tools/singlejar:__pkg__", + ], deps = [ ":blaze_exit_code", ":errors", diff --git a/src/main/cpp/util/file_platform.h b/src/main/cpp/util/file_platform.h index 6d00daffff..b0df5ea18d 100644 --- a/src/main/cpp/util/file_platform.h +++ b/src/main/cpp/util/file_platform.h @@ -34,6 +34,12 @@ bool PathExists(const std::string& path); // openable. bool CanAccess(const std::string& path, bool read, bool write, bool exec); +// Returns the current working directory. +std::string GetCwd(); + +// Changes the current working directory to `path`, returns true upon success. +bool ChangeDirectory(const std::string& path); + } // namespace blaze_util #endif // BAZEL_SRC_MAIN_CPP_UTIL_FILE_PLATFORM_H_ diff --git a/src/main/cpp/util/file_posix.cc b/src/main/cpp/util/file_posix.cc index 11f5d1058b..90355b92ee 100644 --- a/src/main/cpp/util/file_posix.cc +++ b/src/main/cpp/util/file_posix.cc @@ -14,6 +14,7 @@ #include "src/main/cpp/util/file_platform.h" #include <sys/stat.h> +#include <limits.h> // PATH_MAX #include <stdlib.h> // getenv #include <unistd.h> // access #include <vector> @@ -71,4 +72,16 @@ bool CanAccess(const string& path, bool read, bool write, bool exec) { return access(path.c_str(), mode) == 0; } +string GetCwd() { + char cwdbuf[PATH_MAX]; + if (getcwd(cwdbuf, sizeof cwdbuf) == NULL) { + pdie(blaze_exit_code::INTERNAL_ERROR, "getcwd() failed"); + } + return string(cwdbuf); +} + +bool ChangeDirectory(const string& path) { + return chdir(path.c_str()) == 0; +} + } // namespace blaze_util diff --git a/src/main/cpp/util/file_windows.cc b/src/main/cpp/util/file_windows.cc index 34f8bcf7a2..5cf9987486 100644 --- a/src/main/cpp/util/file_windows.cc +++ b/src/main/cpp/util/file_windows.cc @@ -33,4 +33,14 @@ bool CanAccess(const string& path, bool read, bool write, bool exec) { pdie(255, "blaze_util::CanAccess is not implemented on Windows"); } +string GetCwd() { + // TODO(bazel-team): implement this. + pdie(255, "blaze_util::GetCwd is not implemented on Windows"); +} + +bool ChangeDirectory(const string& path) { + // TODO(bazel-team): implement this. + pdie(255, "blaze_util::ChangeDirectory is not implemented on Windows"); +} + } // namespace blaze_util |