Skip to content

Commit e4eb8d9

Browse files
committed
[llvm-rc] Continue to use Argv[0] to resolve executable path
In internal google builds, MainExecPath doesn't go to the directory with `clang`. Fall back to using Argv0 if MainExecPath doesn't find any clangs. Differential Revision: https://reviews.llvm.org/D158901
1 parent ed5acb1 commit e4eb8d9

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

llvm/tools/llvm-rc/llvm-rc.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -130,20 +130,24 @@ ErrorOr<std::string> findClang(const char *Argv0, StringRef Triple) {
130130
if (MainExecPath.empty())
131131
MainExecPath = Argv0;
132132

133-
StringRef Parent = llvm::sys::path::parent_path(MainExecPath);
134133
ErrorOr<std::string> Path = std::error_code();
135134
std::string TargetClang = (Triple + "-clang").str();
136135
std::string VersionedClang = ("clang-" + Twine(LLVM_VERSION_MAJOR)).str();
137-
if (!Parent.empty()) {
138-
// First look for the tool with all potential names in the specific
139-
// directory of Argv0, if known
140-
for (const auto *Name :
141-
{TargetClang.c_str(), VersionedClang.c_str(), "clang", "clang-cl"}) {
136+
for (const auto *Name :
137+
{TargetClang.c_str(), VersionedClang.c_str(), "clang", "clang-cl"}) {
138+
for (const StringRef Parent :
139+
{llvm::sys::path::parent_path(MainExecPath),
140+
llvm::sys::path::parent_path(Argv0)}) {
141+
// Look for various versions of "clang" first in the MainExecPath parent
142+
// directory and then in the argv[0] parent directory.
143+
// On Windows (but not Unix) argv[0] is overwritten with the eqiuvalent
144+
// of MainExecPath by InitLLVM.
142145
Path = sys::findProgramByName(Name, Parent);
143146
if (Path)
144147
return Path;
145148
}
146149
}
150+
147151
// If no parent directory known, or not found there, look everywhere in PATH
148152
for (const auto *Name : {"clang", "clang-cl"}) {
149153
Path = sys::findProgramByName(Name);

0 commit comments

Comments
 (0)