aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main
diff options
context:
space:
mode:
authorGravatar Laszlo Csomor <laszlocsomor@google.com>2016-12-21 12:47:40 +0000
committerGravatar Klaus Aehlig <aehlig@google.com>2016-12-21 12:59:45 +0000
commit48513d71e552e590d71c6f4337d07c52ff799d55 (patch)
tree957906c61776d1f48db5dc25be7f6bd5325d75dc /src/main
parent25a8c8e9175cc4f7104a1a82f63ab4b8b089b1bd (diff)
Bazel client: remove blaze_util::Which
This is only used in blaze_util_linux so move the method there. -- PiperOrigin-RevId: 142652521 MOS_MIGRATED_REVID=142652521
Diffstat (limited to 'src/main')
-rw-r--r--src/main/cpp/blaze_util_linux.cc27
-rw-r--r--src/main/cpp/util/file_platform.h5
-rw-r--r--src/main/cpp/util/file_posix.cc25
-rw-r--r--src/main/cpp/util/file_windows.cc8
4 files changed, 26 insertions, 39 deletions
diff --git a/src/main/cpp/blaze_util_linux.cc b/src/main/cpp/blaze_util_linux.cc
index 4d2ebfecbb..6e416448f9 100644
--- a/src/main/cpp/blaze_util_linux.cc
+++ b/src/main/cpp/blaze_util_linux.cc
@@ -21,6 +21,7 @@
#include <stdlib.h>
#include <string.h> // strerror
#include <sys/socket.h>
+#include <sys/stat.h>
#include <sys/statfs.h>
#include <sys/types.h>
#include <unistd.h>
@@ -143,6 +144,30 @@ bool IsSharedLibrary(const string &filename) {
return blaze_util::ends_with(filename, ".so");
}
+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());
+ }
+
+ std::vector<std::string> pieces = blaze_util::Split(path, ':');
+ for (auto piece : pieces) {
+ if (piece.empty()) {
+ piece = ".";
+ }
+
+ struct stat file_stat;
+ string candidate = blaze_util::JoinPath(piece, executable);
+ if (access(candidate.c_str(), X_OK) == 0 &&
+ stat(candidate.c_str(), &file_stat) == 0 &&
+ S_ISREG(file_stat.st_mode)) {
+ return candidate;
+ }
+ }
+ return "";
+}
+
string GetDefaultHostJavabase() {
// if JAVA_HOME is defined, then use it as default.
const char *javahome = getenv("JAVA_HOME");
@@ -151,7 +176,7 @@ string GetDefaultHostJavabase() {
}
// which javac
- string javac_dir = blaze_util::Which("javac");
+ string javac_dir = Which("javac");
if (javac_dir.empty()) {
die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR, "Could not find javac");
}
diff --git a/src/main/cpp/util/file_platform.h b/src/main/cpp/util/file_platform.h
index 15bfd5d737..daed1998d5 100644
--- a/src/main/cpp/util/file_platform.h
+++ b/src/main/cpp/util/file_platform.h
@@ -44,11 +44,6 @@ bool WriteFile(const std::string &content, const std::string &filename);
// Returns true on success. In case of failure sets errno.
bool UnlinkPath(const std::string &file_path);
-// Checks each element of the PATH variable for executable. If none is found, ""
-// is returned. Otherwise, the full path to executable is returned. Can die if
-// looking up PATH fails.
-std::string Which(const std::string &executable);
-
// Returns true if this path exists.
bool PathExists(const std::string& path);
diff --git a/src/main/cpp/util/file_posix.cc b/src/main/cpp/util/file_posix.cc
index 81e9bd65c3..c5568a4c3e 100644
--- a/src/main/cpp/util/file_posix.cc
+++ b/src/main/cpp/util/file_posix.cc
@@ -213,31 +213,6 @@ bool UnlinkPath(const string &file_path) {
return unlink(file_path.c_str()) == 0;
}
-string Which(const string &executable) {
- char *path_cstr = getenv("PATH");
- if (path_cstr == NULL || path_cstr[0] == '\0') {
- die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR,
- "Could not get PATH to find %s", executable.c_str());
- }
-
- string path(path_cstr);
- std::vector<std::string> pieces = blaze_util::Split(path, ':');
- for (auto piece : pieces) {
- if (piece.empty()) {
- piece = ".";
- }
-
- struct stat file_stat;
- string candidate = blaze_util::JoinPath(piece, executable);
- if (access(candidate.c_str(), X_OK) == 0 &&
- stat(candidate.c_str(), &file_stat) == 0 &&
- S_ISREG(file_stat.st_mode)) {
- return candidate;
- }
- }
- return "";
-}
-
bool PathExists(const string& path) {
return access(path.c_str(), F_OK) == 0;
}
diff --git a/src/main/cpp/util/file_windows.cc b/src/main/cpp/util/file_windows.cc
index 021e96d9a9..78cb331185 100644
--- a/src/main/cpp/util/file_windows.cc
+++ b/src/main/cpp/util/file_windows.cc
@@ -245,14 +245,6 @@ bool UnlinkPath(const string& file_path) {
#endif // COMPILER_MSVC
#ifdef COMPILER_MSVC
-string Which(const string &executable) {
- pdie(255, "blaze_util::Which is not implemented on Windows");
- return "";
-}
-#else // not COMPILER_MSVC
-#endif // COMPILER_MSVC
-
-#ifdef COMPILER_MSVC
bool PathExists(const string& path) {
// TODO(bazel-team): implement this.
pdie(255, "blaze_util::PathExists is not implemented on Windows");