[clang] Support target names with dots in more utilities (PR #65812)

James Henderson via cfe-commits cfe-commits at lists.llvm.org
Tue Sep 19 01:03:48 PDT 2023


================
@@ -1696,6 +1696,40 @@ TEST(Support, ReplacePathPrefix) {
   EXPECT_EQ(Path, "C:\\old/foo\\bar");
 }
 
+TEST(Support, FindProgramName) {
+  StringRef WindowsProgName =
+      path::program_name("C:\\Test\\foo.exe", path::Style::windows);
+  EXPECT_EQ(WindowsProgName, "foo");
+
+  StringRef WindowsProgNameManyDots = path::program_name(
+      "C:\\Test.7\\x86_64-freebsd14.0-clang.exe", path::Style::windows);
+  EXPECT_EQ(WindowsProgNameManyDots, "x86_64-freebsd14.0-clang");
+
+  StringRef PosixProgName =
+      path::program_name("/var/empty/clang.exe", path::Style::posix);
+  EXPECT_EQ(PosixProgName, "clang");
+
+  StringRef PosixProgNameManyDotsExe = path::program_name(
+      "/llvm-test16.4/x86_64-portbld-freebsd13.2-llvm-ar.exe",
+      path::Style::posix);
+  EXPECT_EQ(PosixProgNameManyDotsExe, "x86_64-portbld-freebsd13.2-llvm-ar");
+
+  StringRef PosixProgNameManyDots = path::program_name(
+      "/llvm-test16.4/x86_64-portbld-freebsd13.2-llvm-ar", path::Style::posix);
+  EXPECT_EQ(PosixProgNameManyDots, "x86_64-portbld-freebsd13.2-llvm-ar");
+
+  StringRef PosixProgNameSh =
+      path::program_name("/llvm-test16.4/x86_64-portbld-freebsd13.2-llvm-ar.sh",
+                         path::Style::posix);
+  EXPECT_EQ(PosixProgNameSh, "x86_64-portbld-freebsd13.2-llvm-ar.sh");
+
+  // TODO: determine if this is correct. What happens on windows with an executable
+  // named ".exe"?
----------------
jh7370 wrote:

I just used the Windows UI to rename a file to ".exe" and it works fine (both renaming and susbequent execution of the file from the command-line). Meanwhile, the documented behaviour of `stem` is that something containing only a single dot will result in an empty string, which I think we should be mirroring here. I think the behaviour tested here is therefore correct and you can probably drop the TODO note.

https://github.com/llvm/llvm-project/pull/65812


More information about the cfe-commits mailing list