[PATCH] D135284: RFC: [Driver] select alternative target containing . in executable name
Dan McGregor via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Oct 5 10:19:16 PDT 2022
dankm created this revision.
Herald added subscribers: pengfei, krytarowski, arichardson, emaste.
Herald added a project: All.
dankm added reviewers: echristo, zarko.
dankm added a comment.
dankm published this revision for review.
Herald added subscribers: cfe-commits, MaskRay.
Herald added a project: clang.
I'd like comments on this approach to handle target names with a . in them. My assumption is that the way it was done (by finding the filename stem) was to strip any ".exe" string on Windows, but there may be other reasons.
The gcc compatible driver has support for selecting an alternative
target based on the driver's executable name, for instance
x86_64-unknown-linux-gnu-clang will set the target to linux on x86_64.
Previously, this failed when the target contains a minor version, for
example x86_64-unknown-freebsd13.1, so instead of finding the file's
stem, use the whole file name, but strip off any '.exe' from the tail.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D135284
Files:
clang/lib/Driver/ToolChain.cpp
Index: clang/lib/Driver/ToolChain.cpp
===================================================================
--- clang/lib/Driver/ToolChain.cpp
+++ clang/lib/Driver/ToolChain.cpp
@@ -198,7 +198,7 @@
/// Normalize the program name from argv[0] by stripping the file extension if
/// present and lower-casing the string on Windows.
static std::string normalizeProgramName(llvm::StringRef Argv0) {
- std::string ProgName = std::string(llvm::sys::path::stem(Argv0));
+ std::string ProgName = std::string(llvm::sys::path::filename(Argv0));
if (is_style_windows(llvm::sys::path::Style::native)) {
// Transform to lowercase for case insensitive file systems.
std::transform(ProgName.begin(), ProgName.end(), ProgName.begin(),
@@ -217,6 +217,13 @@
// added via -target as implicit first argument.
const DriverSuffix *DS = FindDriverSuffix(ProgName, Pos);
+ if (!DS && ProgName.endswith(".exe")) {
+ // Try again after stripping the executable suffix:
+ // clang++.exe -> clang++
+ ProgName = ProgName.drop_back(StringRef(".exe").size());
+ DS = FindDriverSuffix(ProgName, Pos);
+ }
+
if (!DS) {
// Try again after stripping any trailing version number:
// clang++3.5 -> clang++
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D135284.465445.patch
Type: text/x-patch
Size: 1220 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20221005/ecb5e3ea/attachment-0001.bin>
More information about the cfe-commits
mailing list