aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/tools/launcher
diff options
context:
space:
mode:
authorGravatar Yun Peng <pcloudy@google.com>2017-08-29 10:19:51 +0200
committerGravatar Vladimir Moskva <vladmos@google.com>2017-08-29 13:33:09 +0200
commit5fa338a0f6c81ffe8e5dffb872b800e6d37e9cee (patch)
treecb5874bf27bc2eff693b0f3039aea3eefebb2676 /src/tools/launcher
parent69ef625b464093aaefd3d8af9e947832d4385211 (diff)
Make Windows C++ launcher support long path
Change-Id: I25795c748fa98b9275ae34ead17fce02a57dc8e4 PiperOrigin-RevId: 166816800
Diffstat (limited to 'src/tools/launcher')
-rw-r--r--src/tools/launcher/launcher.cc5
-rw-r--r--src/tools/launcher/util/BUILD1
-rw-r--r--src/tools/launcher/util/launcher_util.cc18
-rw-r--r--src/tools/launcher/util/launcher_util.h4
4 files changed, 18 insertions, 10 deletions
diff --git a/src/tools/launcher/launcher.cc b/src/tools/launcher/launcher.cc
index b981761da6..eec963e4eb 100644
--- a/src/tools/launcher/launcher.cc
+++ b/src/tools/launcher/launcher.cc
@@ -76,10 +76,7 @@ string BinaryLauncherBase::GetRunfilesPath() const {
void BinaryLauncherBase::ParseManifestFile(ManifestFileMap* manifest_file_map,
const string& manifest_path) {
- // TODO(laszlocsomor): prefix manifest_path with the longpath prefix.
- // std::ifstream supports long paths, but only if they are in the correct
- // format, e.g. "\\\\?\\c:\\imagine\\some\\very\\long\\path.txt".
- ifstream manifest_file(manifest_path.c_str());
+ ifstream manifest_file(AsAbsoluteWindowsPath(manifest_path.c_str()).c_str());
if (!manifest_file) {
die("Couldn't open MANIFEST file: %s", manifest_path.c_str());
diff --git a/src/tools/launcher/util/BUILD b/src/tools/launcher/util/BUILD
index 7ecee600b6..b326e6a125 100644
--- a/src/tools/launcher/util/BUILD
+++ b/src/tools/launcher/util/BUILD
@@ -17,6 +17,7 @@ cc_library(
name = "util",
srcs = ["launcher_util.cc"],
hdrs = ["launcher_util.h"],
+ deps = ["//src/main/cpp/util:file"],
)
cc_test(
diff --git a/src/tools/launcher/util/launcher_util.cc b/src/tools/launcher/util/launcher_util.cc
index bc3eddb284..149c5f3242 100644
--- a/src/tools/launcher/util/launcher_util.cc
+++ b/src/tools/launcher/util/launcher_util.cc
@@ -20,6 +20,7 @@
#include <sstream>
#include <string>
+#include "src/main/cpp/util/file_platform.h"
#include "src/tools/launcher/util/launcher_util.h"
namespace bazel {
@@ -27,6 +28,7 @@ namespace launcher {
using std::ostringstream;
using std::string;
+using std::wstring;
using std::stringstream;
string GetLastErrorString() {
@@ -67,19 +69,23 @@ void PrintError(const char* format, ...) {
fputc('\n', stderr);
}
+wstring AsAbsoluteWindowsPath(const char* path) {
+ wstring wpath;
+ if (!blaze_util::AsAbsoluteWindowsPath(path, &wpath)) {
+ die("Couldn't convert %s to absoulte Windows path.", path);
+ }
+ return wpath;
+}
+
bool DoesFilePathExist(const char* path) {
- // TODO(laszlocsomor): convert `path` to (const wchar_t*), add longpath-prefix
- // and use GetFileAttributesW.
- DWORD dwAttrib = GetFileAttributesA(path);
+ DWORD dwAttrib = GetFileAttributesW(AsAbsoluteWindowsPath(path).c_str());
return (dwAttrib != INVALID_FILE_ATTRIBUTES &&
!(dwAttrib & FILE_ATTRIBUTE_DIRECTORY));
}
bool DoesDirectoryPathExist(const char* path) {
- // TODO(laszlocsomor): convert `path` to (const wchar_t*), add longpath-prefix
- // and use GetFileAttributesW.
- DWORD dwAttrib = GetFileAttributesA(path);
+ DWORD dwAttrib = GetFileAttributesW(AsAbsoluteWindowsPath(path).c_str());
return (dwAttrib != INVALID_FILE_ATTRIBUTES &&
(dwAttrib & FILE_ATTRIBUTE_DIRECTORY));
diff --git a/src/tools/launcher/util/launcher_util.h b/src/tools/launcher/util/launcher_util.h
index e5583006c0..6ae57828b3 100644
--- a/src/tools/launcher/util/launcher_util.h
+++ b/src/tools/launcher/util/launcher_util.h
@@ -47,6 +47,10 @@ std::string GetBinaryPathWithExtension(const std::string& binary);
// Escape " to \"
std::string GetEscapedArgument(const std::string& argument);
+// Convert a path to an absolute Windows path with \\?\ prefix.
+// This method will print an error and exit if it cannot convert the path.
+std::wstring AsAbsoluteWindowsPath(const char* path);
+
// Check if a file exists at a given path.
bool DoesFilePathExist(const char* path);