Skip to content

Commit

Permalink
Make sure runfiles dir is calculated as normlized absolute path
Browse files Browse the repository at this point in the history
Fixes: bazelbuild#13484

Closes bazelbuild#13559.

PiperOrigin-RevId: 378604795
  • Loading branch information
meteorcloudy authored and copybara-github committed Jun 10, 2021
1 parent 517951a commit a48937f
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/tools/launcher/launcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <string>
#include <vector>

#include "src/main/cpp/util/file_platform.h"
#include "src/main/cpp/util/path_platform.h"
#include "src/main/cpp/util/strings.h"
#include "src/tools/launcher/util/data_parser.h"
Expand All @@ -45,12 +46,20 @@ static wstring GetRunfilesDir(const wchar_t* argv0) {
wstring runfiles_dir;
// If RUNFILES_DIR is already set (probably we are either in a test or in a
// data dependency) then use it.
if (GetEnv(L"RUNFILES_DIR", &runfiles_dir)) {
return runfiles_dir;
if (!GetEnv(L"RUNFILES_DIR", &runfiles_dir)) {
// Otherwise this is probably a top-level non-test binary (e.g. a genrule
// tool) and should look for its runfiles beside the executable.
runfiles_dir = GetBinaryPathWithExtension(argv0) + L".runfiles";
}
// Otherwise this is probably a top-level non-test binary (e.g. a genrule
// tool) and should look for its runfiles beside the executable.
return GetBinaryPathWithExtension(argv0) + L".runfiles";
// Make sure we return a normalized absolute path.
if (!blaze_util::IsAbsolute(runfiles_dir)) {
runfiles_dir = blaze_util::GetCwdW() + L"\\" + runfiles_dir;
}
wstring result;
if (!NormalizePath(runfiles_dir, &result)) {
die(L"GetRunfilesDir Failed");
}
return result;
}

BinaryLauncherBase::BinaryLauncherBase(
Expand Down

0 comments on commit a48937f

Please sign in to comment.