Skip to content

Commit 793b409

Browse files
laszlocsomorbuchgr
authored andcommitted
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 837e1b3 Change-Id: Id8331cdcf58adb31ed2b60ebbc57022a0bf32438 PiperOrigin-RevId: 164436539
1 parent 242a434 commit 793b409

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

src/test/py/bazel/launcher_test.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ def testJavaBinaryLauncher(self):
7676
if self.IsWindows():
7777
self.assertRegexpMatches(stdout[1], r'java_runfiles=.*foo\\foo.runfiles')
7878
self.assertEqual(stdout[2], 'runfiles_manifest_only=1')
79-
self.assertRegexpMatches(stdout[3], r'^runfiles_manifest_file.*MANIFEST$')
79+
self.assertRegexpMatches(
80+
stdout[3], r'^runfiles_manifest_file=[a-zA-Z]:[/\\].*MANIFEST$')
8081
else:
8182
self.assertRegexpMatches(stdout[1], r'java_runfiles=.*/foo/foo.runfiles')
8283
self.assertEqual(stdout[2], 'runfiles_manifest_only=')
@@ -150,7 +151,9 @@ def _buildShBinaryTargets(self, bazel_bin, launcher_flag, bin1_suffix):
150151
self.assertEqual(stdout[0], 'hello shell')
151152
if self.IsWindows():
152153
self.assertEqual(stdout[1], 'runfiles_manifest_only=1')
153-
self.assertRegexpMatches(stdout[2], r'^runfiles_manifest_file.*MANIFEST$')
154+
self.assertRegexpMatches(stdout[2],
155+
(r'^runfiles_manifest_file='
156+
r'[a-zA-Z]:/.*/foo/bin1.sh.runfiles/MANIFEST$'))
154157
else:
155158
# TODO(laszlocsomor): Find out whether the runfiles-related envvars should
156159
# be set on Linux (e.g. $RUNFILES, $RUNFILES_MANIFEST_FILE). Currently

src/tools/launcher/launcher.cc

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
// limitations under the License.
1414

1515
#include <windows.h>
16+
#include <algorithm>
1617
#include <fstream>
1718
#include <iostream>
1819
#include <sstream>
@@ -47,8 +48,12 @@ string BinaryLauncherBase::FindManifestFile(const char* argv0) {
4748
// Get the name of the binary
4849
string binary = GetBinaryPathWithoutExtension(argv0);
4950

51+
// The path will be set as the RUNFILES_MANIFEST_FILE envvar and used by the
52+
// shell script, so let's convert backslashes to forward slashes.
53+
std::replace(binary.begin(), binary.end(), '\\', '/');
54+
5055
// Try to find <path to binary>.runfiles/MANIFEST
51-
string manifest_file = binary + ".runfiles\\MANIFEST";
56+
string manifest_file = binary + ".runfiles/MANIFEST";
5257
if (DoesFilePathExist(manifest_file.c_str())) {
5358
return manifest_file;
5459
}
@@ -64,6 +69,9 @@ string BinaryLauncherBase::FindManifestFile(const char* argv0) {
6469

6570
void BinaryLauncherBase::ParseManifestFile(ManifestFileMap* manifest_file_map,
6671
const string& manifest_path) {
72+
// TODO(laszlocsomor): prefix manifest_path with the longpath prefix.
73+
// std::ifstream supports long paths, but only if they are in the correct
74+
// format, e.g. "\\\\?\\c:\\imagine\\some\\very\\long\\path.txt".
6775
ifstream manifest_file(manifest_path.c_str());
6876

6977
if (!manifest_file) {

src/tools/launcher/util/launcher_util.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ void PrintError(const char* format, ...) {
6868
}
6969

7070
bool DoesFilePathExist(const char* path) {
71-
DWORD dwAttrib = GetFileAttributes(path);
71+
// TODO(laszlocsomor): convert `path` to (const wchar_t*), add longpath-prefix
72+
// and use GetFileAttributesW.
73+
DWORD dwAttrib = GetFileAttributesA(path);
7274

7375
return (dwAttrib != INVALID_FILE_ATTRIBUTES &&
7476
!(dwAttrib & FILE_ATTRIBUTE_DIRECTORY));

0 commit comments

Comments
 (0)