[PATCH] D158901: [llvm-rc] Continue to use Argv[0] to resolve executable path
Amy Huang via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 25 15:23:15 PDT 2023
akhuang created this revision.
akhuang added reviewers: mstorsjo, thieta.
Herald added a project: All.
akhuang requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
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.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D158901
Files:
llvm/tools/llvm-rc/llvm-rc.cpp
Index: llvm/tools/llvm-rc/llvm-rc.cpp
===================================================================
--- llvm/tools/llvm-rc/llvm-rc.cpp
+++ llvm/tools/llvm-rc/llvm-rc.cpp
@@ -130,20 +130,24 @@
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"}) {
- Path = sys::findProgramByName(Name, Parent);
- if (Path)
- return Path;
+ for (const StringRef Parent :
+ {llvm::sys::path::parent_path(MainExecPath),
+ llvm::sys::path::parent_path(Argv0)}) {
+ 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"}) {
+ 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);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D158901.553645.patch
Type: text/x-patch
Size: 1526 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230825/fef7e48b/attachment.bin>
More information about the llvm-commits
mailing list