ScanDirForExecutable on Windows fails to find executables with the "exe" extension...
authorReid Kleckner <rnk@google.com>
Thu, 10 Sep 2015 23:28:06 +0000 (23:28 +0000)
committerReid Kleckner <rnk@google.com>
Thu, 10 Sep 2015 23:28:06 +0000 (23:28 +0000)
When the driver tries to locate a program by its name, e.g. a linker, it
scans the paths provided by the toolchain using the ScanDirForExecutable
function. If the lookup fails, the driver uses
llvm::sys::findProgramByName. Unlike llvm::sys::findProgramByName,
ScanDirForExecutable is not aware of file extensions. If the program has
the "exe" extension in its name, which is very common on Windows,
ScanDirForExecutable won't find it under the toolchain-provided paths.

This patch changes the Windows version of the "`can_execute`" function
called by ScanDirForExecutable to respect file extensions, similarly to
llvm::sys::findProgramByName.

Patch by Oleg Ranevskyy

Reviewers: rnk

Differential Revision: http://reviews.llvm.org/D12711

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@247358 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Support/FileSystem.h
lib/Support/Unix/Path.inc
lib/Support/Windows/Path.inc

index f0b74da3ad6f3f8d9b679c4cde3d5ee8379e771b..48a2f0a748bcd5dd3f9d001da1f92469c3fd23f0 100644 (file)
@@ -378,9 +378,7 @@ inline bool exists(const Twine &Path) {
 ///
 /// @param Path Input path.
 /// @returns True if we can execute it, false otherwise.
-inline bool can_execute(const Twine &Path) {
-  return !access(Path, AccessMode::Execute);
-}
+bool can_execute(const Twine &Path);
 
 /// @brief Can we write this file?
 ///
index a77efcca8f56aef1f62730717899a98630d9442a..93e5654f28472df026e198cbb4ad92086706b386 100644 (file)
@@ -325,6 +325,10 @@ std::error_code access(const Twine &Path, AccessMode Mode) {
   return std::error_code();
 }
 
+bool can_execute(const Twine &Path) {
+  return !access(Path, AccessMode::Execute);
+}
+
 bool equivalent(file_status A, file_status B) {
   assert(status_known(A) && status_known(B));
   return A.fs_st_dev == B.fs_st_dev &&
index 3033149980c1e1dd7eac9f5bc7633dc987097002..1ee45c6f362779d934181b88d22e03ff616eb2c2 100644 (file)
@@ -302,6 +302,11 @@ std::error_code access(const Twine &Path, AccessMode Mode) {
   return std::error_code();
 }
 
+bool can_execute(const Twine &Path) {
+  return !access(Path, AccessMode::Execute) ||
+         !access(Path + ".exe", AccessMode::Execute);
+}
+
 bool equivalent(file_status A, file_status B) {
   assert(status_known(A) && status_known(B));
   return A.FileIndexHigh      == B.FileIndexHigh &&