diff --git a/src/tools/launcher/java_launcher.cc b/src/tools/launcher/java_launcher.cc index 6e99cca4f813dd..353b5d20170505 100644 --- a/src/tools/launcher/java_launcher.cc +++ b/src/tools/launcher/java_launcher.cc @@ -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()); diff --git a/src/tools/launcher/launcher.cc b/src/tools/launcher/launcher.cc index dfd23952aece33..f666657dad6df3 100644 --- a/src/tools/launcher/launcher.cc +++ b/src/tools/launcher/launcher.cc @@ -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()) { diff --git a/src/tools/launcher/launcher.h b/src/tools/launcher/launcher.h index 911e8a031f1939..c2e8cf16417986 100644 --- a/src/tools/launcher/launcher.h +++ b/src/tools/launcher/launcher.h @@ -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