[llvm] e4eb8d9 - [llvm-rc] Continue to use Argv[0] to resolve executable path
Amy Huang via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 28 14:40:29 PDT 2023
Author: Amy Huang
Date: 2023-08-28T14:40:19-07:00
New Revision: e4eb8d97e8afcb879dc5cd0da7a937dbb26fbf12
URL: https://github.com/llvm/llvm-project/commit/e4eb8d97e8afcb879dc5cd0da7a937dbb26fbf12
DIFF: https://github.com/llvm/llvm-project/commit/e4eb8d97e8afcb879dc5cd0da7a937dbb26fbf12.diff
LOG: [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
Added:
Modified:
llvm/tools/llvm-rc/llvm-rc.cpp
Removed:
################################################################################
diff --git a/llvm/tools/llvm-rc/llvm-rc.cpp b/llvm/tools/llvm-rc/llvm-rc.cpp
index ec1cdae27cf62b..e5bf623f9a73b7 100644
--- a/llvm/tools/llvm-rc/llvm-rc.cpp
+++ b/llvm/tools/llvm-rc/llvm-rc.cpp
@@ -130,20 +130,24 @@ ErrorOr<std::string> findClang(const char *Argv0, StringRef Triple) {
if (MainExecPath.empty())
MainExecPath = Argv0;
- StringRef Parent = llvm::sys::path::parent_path(MainExecPath);
ErrorOr<std::string> Path = std::error_code();
std::string TargetClang = (Triple + "-clang").str();
std::string VersionedClang = ("clang-" + Twine(LLVM_VERSION_MAJOR)).str();
- if (!Parent.empty()) {
- // First look for the tool with all potential names in the specific
- // directory of Argv0, if known
- for (const auto *Name :
- {TargetClang.c_str(), VersionedClang.c_str(), "clang", "clang-cl"}) {
+ for (const auto *Name :
+ {TargetClang.c_str(), VersionedClang.c_str(), "clang", "clang-cl"}) {
+ for (const StringRef Parent :
+ {llvm::sys::path::parent_path(MainExecPath),
+ llvm::sys::path::parent_path(Argv0)}) {
+ // Look for various versions of "clang" first in the MainExecPath parent
+ // directory and then in the argv[0] parent directory.
+ // On Windows (but not Unix) argv[0] is overwritten with the eqiuvalent
+ // of MainExecPath by InitLLVM.
Path = sys::findProgramByName(Name, Parent);
if (Path)
return Path;
}
}
+
// If no parent directory known, or not found there, look everywhere in PATH
for (const auto *Name : {"clang", "clang-cl"}) {
Path = sys::findProgramByName(Name);
More information about the llvm-commits
mailing list