Skip to content

Commit

Permalink
Windows, native launcher: Rlocation knows external
Browse files Browse the repository at this point in the history
The native launcher's own Rlocation()
implementation correctly handles runfile paths
that start with "external/".

Fixes #7809

This PR subsumes #7853.
That PR changed the launcher to use the C++
runfiles library. Alas that broke some tests.

Closes #7873.

PiperOrigin-RevId: 240782949
  • Loading branch information
laszlocsomor authored and copybara-github committed Mar 28, 2019
1 parent d4f51b9 commit 7e3cfd8
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 29 deletions.
2 changes: 1 addition & 1 deletion src/tools/launcher/java_launcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ ExitCode JavaBinaryLauncher::Launch() {

// Print Java binary path if needed
wstring java_bin = this->Rlocation(this->GetLaunchInfoByKey(JAVA_BIN_PATH),
/*need_workspace_name =*/false);
/*has_workspace_name =*/true);
if (this->print_javabin ||
this->GetLaunchInfoByKey(JAVA_START_CLASS) == L"--print_javabin") {
wprintf(L"%s\n", java_bin.c_str());
Expand Down
33 changes: 13 additions & 20 deletions src/tools/launcher/launcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -139,42 +139,35 @@ void BinaryLauncherBase::ParseManifestFile(ManifestFileMap* manifest_file_map,
}
}

wstring BinaryLauncherBase::Rlocation(const wstring& path,
bool need_workspace_name) const {
wstring BinaryLauncherBase::Rlocation(wstring path,
bool has_workspace_name) const {
// No need to do rlocation if the path is absolute.
if (blaze_util::IsAbsolute(path)) {
return path;
}

if (path.find(L"external/") == 0) {
// Ignore 'has_workspace_name' when the path is under "external/". Such
// paths already have a workspace name in the next path component.
path = path.substr(9);
} else if (!has_workspace_name) {
path = this->workspace_name + L"/" + path;
}

// If the manifest file map is empty, then we're using the runfiles directory
// instead.
if (manifest_file_map.empty()) {
wstring query_path = runfiles_dir;
if (need_workspace_name) {
query_path += L"/" + this->workspace_name;
}
query_path += L"/" + path;
return query_path;
return runfiles_dir + L"/" + path;
}

wstring query_path = path;
if (need_workspace_name) {
query_path = this->workspace_name + L"/" + path;
}
auto entry = manifest_file_map.find(query_path);
auto entry = manifest_file_map.find(path);
if (entry == manifest_file_map.end()) {
die(L"Rlocation failed on %s, path doesn't exist in MANIFEST file",
query_path.c_str());
path.c_str());
}
return entry->second;
}

wstring BinaryLauncherBase::Rlocation(const string& path,
bool need_workspace_name) const {
return this->Rlocation(blaze_util::CstringToWstring(path),
need_workspace_name);
}

wstring BinaryLauncherBase::GetLaunchInfoByKey(const string& key) {
auto item = launch_info.find(key);
if (item == launch_info.end()) {
Expand Down
15 changes: 7 additions & 8 deletions src/tools/launcher/launcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,13 @@ class BinaryLauncherBase {

// Map a runfile path to its absolute path.
//
// If need_workspace_name is true, then this method prepend workspace name to
// path before doing rlocation.
// If need_workspace_name is false, then this method uses path directly.
// The default value of need_workspace_name is true.
std::wstring Rlocation(const std::wstring& path,
bool need_workspace_name = true) const;
std::wstring Rlocation(const std::string& path,
bool need_workspace_name = true) const;
// 'has_workspace_name' indicates whether 'path' already starts with the
// runfile's workspace name. (This is implicitly true when 'path' is under
// "external/".) If the path does not have a workspace name (and does not
// start with "external/"), this method prepends the main repository's name to
// it before looking up the runfile.
std::wstring Rlocation(std::wstring path,
bool has_workspace_name = false) const;

// Lauch a process with given executable and command line arguments.
// If --print_launcher_command exists in arguments, then we print the full
Expand Down

0 comments on commit 7e3cfd8

Please sign in to comment.