@@ -42,14 +42,14 @@ using std::vector;
42
42
using std::wostringstream;
43
43
using std::wstring;
44
44
45
- static wstring GetRunfilesDir (const wchar_t * argv0 ) {
45
+ static wstring GetRunfilesDir (const wchar_t * executable_file ) {
46
46
wstring runfiles_dir;
47
47
// If RUNFILES_DIR is already set (probably we are either in a test or in a
48
48
// data dependency) then use it.
49
49
if (!GetEnv (L" RUNFILES_DIR" , &runfiles_dir)) {
50
50
// Otherwise this is probably a top-level non-test binary (e.g. a genrule
51
51
// tool) and should look for its runfiles beside the executable.
52
- runfiles_dir = GetBinaryPathWithExtension (argv0 ) + L" .runfiles" ;
52
+ runfiles_dir = GetBinaryPathWithExtension (executable_file ) + L" .runfiles" ;
53
53
}
54
54
// Make sure we return a normalized absolute path.
55
55
if (!blaze_util::IsAbsolute (runfiles_dir)) {
@@ -63,10 +63,14 @@ static wstring GetRunfilesDir(const wchar_t* argv0) {
63
63
}
64
64
65
65
BinaryLauncherBase::BinaryLauncherBase (
66
- const LaunchDataParser::LaunchInfo& _launch_info, int argc, wchar_t * argv[])
67
- : launch_info(_launch_info),
68
- manifest_file (FindManifestFile(argv[0 ])),
69
- runfiles_dir(GetRunfilesDir(argv[0 ])),
66
+ const LaunchDataParser::LaunchInfo& _launch_info,
67
+ const std::wstring& executable_file,
68
+ int argc,
69
+ wchar_t * argv[])
70
+ : executable_file(executable_file),
71
+ launch_info (_launch_info),
72
+ manifest_file(FindManifestFile(executable_file.c_str())),
73
+ runfiles_dir(GetRunfilesDir(executable_file.c_str())),
70
74
workspace_name(GetLaunchInfoByKey(WORKSPACE_NAME)),
71
75
symlink_runfiles_enabled(GetLaunchInfoByKey(SYMLINK_RUNFILES_ENABLED) ==
72
76
L"1") {
@@ -81,7 +85,8 @@ BinaryLauncherBase::BinaryLauncherBase(
81
85
}
82
86
}
83
87
84
- static bool FindManifestFileImpl (const wchar_t * argv0, wstring* result) {
88
+ static bool FindManifestFileImpl (const wchar_t * executable_file,
89
+ wstring* result) {
85
90
// If this binary X runs as the data-dependency of some other binary Y, then
86
91
// X has no runfiles manifest/directory and should use Y's.
87
92
if (GetEnv (L" RUNFILES_MANIFEST_FILE" , result) &&
@@ -100,7 +105,7 @@ static bool FindManifestFileImpl(const wchar_t* argv0, wstring* result) {
100
105
// If this binary X runs by itself (not as a data-dependency of another
101
106
// binary), then look for the manifest in a runfiles directory next to the
102
107
// main binary, then look for it (the manifest) next to the main binary.
103
- directory = GetBinaryPathWithExtension (argv0 ) + L" .runfiles" ;
108
+ directory = GetBinaryPathWithExtension (executable_file ) + L" .runfiles" ;
104
109
*result = directory + L" /MANIFEST" ;
105
110
if (DoesFilePathExist (result->c_str ())) {
106
111
return true ;
@@ -114,9 +119,9 @@ static bool FindManifestFileImpl(const wchar_t* argv0, wstring* result) {
114
119
return false ;
115
120
}
116
121
117
- wstring BinaryLauncherBase::FindManifestFile (const wchar_t * argv0 ) {
122
+ wstring BinaryLauncherBase::FindManifestFile (const wchar_t * executable_file ) {
118
123
wstring manifest_file;
119
- if (!FindManifestFileImpl (argv0 , &manifest_file)) {
124
+ if (!FindManifestFileImpl (executable_file , &manifest_file)) {
120
125
return L" " ;
121
126
}
122
127
// The path will be set as the RUNFILES_MANIFEST_FILE envvar and used by the
@@ -125,9 +130,13 @@ wstring BinaryLauncherBase::FindManifestFile(const wchar_t* argv0) {
125
130
return manifest_file;
126
131
}
127
132
133
+ wstring BinaryLauncherBase::GetExecutableFile () const {
134
+ return executable_file;
135
+ }
136
+
128
137
wstring BinaryLauncherBase::GetRunfilesPath () const {
129
138
wstring runfiles_path =
130
- GetBinaryPathWithExtension (this -> commandline_arguments [ 0 ] ) + L" .runfiles" ;
139
+ GetBinaryPathWithExtension (executable_file ) + L" .runfiles" ;
131
140
std::replace (runfiles_path.begin (), runfiles_path.end (), L' /' , L' \\ ' );
132
141
return runfiles_path;
133
142
}
0 commit comments