Skip to content

Commit

Permalink
[llvm-rc] Look for "clang-<major>" when locating a suitable preprocessor
Browse files Browse the repository at this point in the history
In some cases, there's no adjacent executable named "clang" or
"clang-cl", but one name "clang-<major>". This logic doesn't
cover every possible deployment setup of course, but should
cover more fairly common/reasonable cases.

See
curl/curl-for-win@caaae17#commitcomment-105808524
for discussion about a case where this would have been helpful.

Differential Revision: https://reviews.llvm.org/D146794
  • Loading branch information
mstorsjo committed Mar 28, 2023
1 parent d2fa6b6 commit 282744a
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion llvm/tools/llvm-rc/llvm-rc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "ResourceScriptStmt.h"
#include "ResourceScriptToken.h"

#include "llvm/Config/llvm-config.h"
#include "llvm/Object/WindowsResource.h"
#include "llvm/Option/Arg.h"
#include "llvm/Option/ArgList.h"
Expand Down Expand Up @@ -138,10 +139,12 @@ ErrorOr<std::string> findClang(const char *Argv0, StringRef Triple) {
StringRef Parent = llvm::sys::path::parent_path(Argv0);
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(), "clang", "clang-cl"}) {
for (const auto *Name :
{TargetClang.c_str(), VersionedClang.c_str(), "clang", "clang-cl"}) {
Path = sys::findProgramByName(Name, Parent);
if (Path)
return Path;
Expand Down

0 comments on commit 282744a

Please sign in to comment.