aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Laszlo Csomor <laszlocsomor@google.com>2017-08-07 11:10:07 +0200
committerGravatar Jakob Buchgraber <buchgr@google.com>2017-08-07 11:22:30 +0200
commit793b409eeae2b42be7fed58251afa87b5733ca4d (patch)
treee931d576f8bfc7b766c69bf3202dad5de2adf0a7
parent242a43449dd44a22857f6ce95f7cc6a7e134d298 (diff)
Windows, sh_bin. launcher: fix manifest path
Fix the path we set in the exe launcher for the RUNFILES_MANIFEST_FILE path. It now uses forward slashes because it's to be consumed by the shell script. This is a follow-up to commit 837e1b3d4859140d29aaa6bbab8fbb008e6d701e Change-Id: Id8331cdcf58adb31ed2b60ebbc57022a0bf32438 PiperOrigin-RevId: 164436539
-rw-r--r--src/test/py/bazel/launcher_test.py7
-rw-r--r--src/tools/launcher/launcher.cc10
-rw-r--r--src/tools/launcher/util/launcher_util.cc4
3 files changed, 17 insertions, 4 deletions
diff --git a/src/test/py/bazel/launcher_test.py b/src/test/py/bazel/launcher_test.py
index 3487545820..92f93e552e 100644
--- a/src/test/py/bazel/launcher_test.py
+++ b/src/test/py/bazel/launcher_test.py
@@ -76,7 +76,8 @@ class LauncherTest(test_base.TestBase):
if self.IsWindows():
self.assertRegexpMatches(stdout[1], r'java_runfiles=.*foo\\foo.runfiles')
self.assertEqual(stdout[2], 'runfiles_manifest_only=1')
- self.assertRegexpMatches(stdout[3], r'^runfiles_manifest_file.*MANIFEST$')
+ self.assertRegexpMatches(
+ stdout[3], r'^runfiles_manifest_file=[a-zA-Z]:[/\\].*MANIFEST$')
else:
self.assertRegexpMatches(stdout[1], r'java_runfiles=.*/foo/foo.runfiles')
self.assertEqual(stdout[2], 'runfiles_manifest_only=')
@@ -150,7 +151,9 @@ class LauncherTest(test_base.TestBase):
self.assertEqual(stdout[0], 'hello shell')
if self.IsWindows():
self.assertEqual(stdout[1], 'runfiles_manifest_only=1')
- self.assertRegexpMatches(stdout[2], r'^runfiles_manifest_file.*MANIFEST$')
+ self.assertRegexpMatches(stdout[2],
+ (r'^runfiles_manifest_file='
+ r'[a-zA-Z]:/.*/foo/bin1.sh.runfiles/MANIFEST$'))
else:
# TODO(laszlocsomor): Find out whether the runfiles-related envvars should
# be set on Linux (e.g. $RUNFILES, $RUNFILES_MANIFEST_FILE). Currently
diff --git a/src/tools/launcher/launcher.cc b/src/tools/launcher/launcher.cc
index d3a023eb8b..9aaa8a5924 100644
--- a/src/tools/launcher/launcher.cc
+++ b/src/tools/launcher/launcher.cc
@@ -13,6 +13,7 @@
// limitations under the License.
#include <windows.h>
+#include <algorithm>
#include <fstream>
#include <iostream>
#include <sstream>
@@ -47,8 +48,12 @@ string BinaryLauncherBase::FindManifestFile(const char* argv0) {
// Get the name of the binary
string binary = GetBinaryPathWithoutExtension(argv0);
+ // The path will be set as the RUNFILES_MANIFEST_FILE envvar and used by the
+ // shell script, so let's convert backslashes to forward slashes.
+ std::replace(binary.begin(), binary.end(), '\\', '/');
+
// Try to find <path to binary>.runfiles/MANIFEST
- string manifest_file = binary + ".runfiles\\MANIFEST";
+ string manifest_file = binary + ".runfiles/MANIFEST";
if (DoesFilePathExist(manifest_file.c_str())) {
return manifest_file;
}
@@ -64,6 +69,9 @@ string BinaryLauncherBase::FindManifestFile(const char* argv0) {
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());
if (!manifest_file) {
diff --git a/src/tools/launcher/util/launcher_util.cc b/src/tools/launcher/util/launcher_util.cc
index 610516bcc3..247c7050c5 100644
--- a/src/tools/launcher/util/launcher_util.cc
+++ b/src/tools/launcher/util/launcher_util.cc
@@ -68,7 +68,9 @@ void PrintError(const char* format, ...) {
}
bool DoesFilePathExist(const char* path) {
- DWORD dwAttrib = GetFileAttributes(path);
+ // TODO(laszlocsomor): convert `path` to (const wchar_t*), add longpath-prefix
+ // and use GetFileAttributesW.
+ DWORD dwAttrib = GetFileAttributesA(path);
return (dwAttrib != INVALID_FILE_ATTRIBUTES &&
!(dwAttrib & FILE_ATTRIBUTE_DIRECTORY));