[llvm-branch-commits] [llvm] da76a22 - [llvm-rc] Continue to use Argv[0] to resolve executable path
Tobias Hieta via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Mon Aug 28 23:12:38 PDT 2023
Author: Amy Huang
Date: 2023-08-29T08:10:31+02:00
New Revision: da76a22ae9ff984a2038940b17e0322219bce25f
URL: https://github.com/llvm/llvm-project/commit/da76a22ae9ff984a2038940b17e0322219bce25f
DIFF: https://github.com/llvm/llvm-project/commit/da76a22ae9ff984a2038940b17e0322219bce25f.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
(cherry picked from commit e4eb8d97e8afcb879dc5cd0da7a937dbb26fbf12)
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 4a77f4bd88cce0..233b888546a81e 100644
--- a/llvm/tools/llvm-rc/llvm-rc.cpp
+++ b/llvm/tools/llvm-rc/llvm-rc.cpp
@@ -142,20 +142,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-branch-commits
mailing list