aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/main/cpp/blaze.cc6
-rw-r--r--src/main/cpp/blaze_util_mingw.cc31
-rw-r--r--src/main/cpp/blaze_util_platform.h7
-rw-r--r--src/main/cpp/blaze_util_posix.cc4
4 files changed, 39 insertions, 9 deletions
diff --git a/src/main/cpp/blaze.cc b/src/main/cpp/blaze.cc
index 0c4fa76a79..336dbc2d8e 100644
--- a/src/main/cpp/blaze.cc
+++ b/src/main/cpp/blaze.cc
@@ -1009,6 +1009,8 @@ static void EnsureCorrectRunningVersion() {
// installation is running.
string installation_path = globals->options.output_base + "/install";
char prev_installation[PATH_MAX + 1] = ""; // NULs the whole array
+ // TODO(dslomov): On Windows, readlink always fails,
+ // so we do the linking every time.
if (readlink(installation_path.c_str(),
prev_installation, PATH_MAX) == -1 ||
prev_installation != globals->options.install_base) {
@@ -1016,8 +1018,8 @@ static void EnsureCorrectRunningVersion() {
globals->restart_reason = NEW_VERSION;
}
unlink(installation_path.c_str());
- if (symlink(globals->options.install_base.c_str(),
- installation_path.c_str())) {
+ if (!SymlinkDirectories(globals->options.install_base.c_str(),
+ installation_path.c_str())) {
pdie(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR,
"failed to create installation symlink '%s'",
installation_path.c_str());
diff --git a/src/main/cpp/blaze_util_mingw.cc b/src/main/cpp/blaze_util_mingw.cc
index d3ebfedaa1..c959f00f6d 100644
--- a/src/main/cpp/blaze_util_mingw.cc
+++ b/src/main/cpp/blaze_util_mingw.cc
@@ -115,12 +115,11 @@ void ReplaceAll(
pos += with.length();
}
}
-} // namespace
-// Replace the current process with the given program in the given working
-// directory, using the given argument vector.
-// This function does not return on success.
-void ExecuteProgram(const string& exe, const vector<string>& args_vector) {
+// Run the given program in the current working directory,
+// using the given argument vector.
+DWORD CreateProcessWrapper(
+ const string& exe, const vector<string>& args_vector) {
if (VerboseLogging()) {
string dbg;
for (const auto& s : args_vector) {
@@ -212,9 +211,16 @@ void ExecuteProgram(const string& exe, const vector<string>& args_vector) {
GetExitCodeProcess(pi.hProcess, &exit_code);
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
+ return exit_code;
+}
+} // namespace
+// Replace the current process with the given program in the current working
+// directory, using the given argument vector.
+// This function does not return on success.
+void ExecuteProgram(const string& exe, const vector<string>& args_vector) {
// Emulate execv.
- exit(exit_code);
+ exit(CreateProcessWrapper(exe, args_vector));
}
string ListSeparator() { return ";"; }
@@ -227,4 +233,17 @@ string ConvertPath(const string& path) {
return result;
}
+bool SymlinkDirectories(const string &target, const string &link) {
+ const string target_win = ConvertPath(target);
+ const string link_win = ConvertPath(link);
+ vector<string> args;
+ args.push_back("cmd");
+ args.push_back("/C");
+ args.push_back("mklink");
+ args.push_back("/J");
+ args.push_back(link_win);
+ args.push_back(target_win);
+ return CreateProcessWrapper("cmd", args) == 0;
+}
+
} // namespace blaze
diff --git a/src/main/cpp/blaze_util_platform.h b/src/main/cpp/blaze_util_platform.h
index a3b315c484..4aa462ed0b 100644
--- a/src/main/cpp/blaze_util_platform.h
+++ b/src/main/cpp/blaze_util_platform.h
@@ -54,7 +54,7 @@ bool IsSharedLibrary(const std::string& filename);
// (must be an absolute directory).
std::string GetDefaultHostJavabase();
-// Replace the current process with the given program in the given working
+// Replace the current process with the given program in the current working
// directory, using the given argument vector.
// This function does not return on success.
void ExecuteProgram(const string& exe, const std::vector<string>& args_vector);
@@ -68,6 +68,11 @@ std::string ConvertPath(const std::string& path);
// Return a string used to separate paths in a list.
std::string ListSeparator();
+// Create a symlink to directory ``target`` at location ``link``.
+// Returns true on success, false on failure.
+// Implemented via junctions on Windows.
+bool SymlinkDirectories(const string &target, const string &link);
+
} // namespace blaze
#endif // BAZEL_SRC_MAIN_CPP_BLAZE_UTIL_PLATFORM_H_
diff --git a/src/main/cpp/blaze_util_posix.cc b/src/main/cpp/blaze_util_posix.cc
index 3ac31a8573..44ad43cb17 100644
--- a/src/main/cpp/blaze_util_posix.cc
+++ b/src/main/cpp/blaze_util_posix.cc
@@ -60,4 +60,8 @@ void ExecuteProgram(const string &exe, const vector<string> &args_vector) {
std::string ConvertPath(const std::string &path) { return path; }
std::string ListSeparator() { return ":"; }
+
+bool SymlinkDirectories(const string &target, const string &link) {
+ return symlink(target.c_str(), link.c_str()) == 0;
+}
} // namespace blaze.