File tree Expand file tree Collapse file tree 1 file changed +9
-18
lines changed Expand file tree Collapse file tree 1 file changed +9
-18
lines changed Original file line number Diff line number Diff line change @@ -85,33 +85,24 @@ public func lookupExecutablePath(
85
85
return nil
86
86
}
87
87
88
- let path : AbsolutePath
88
+ var paths : [ AbsolutePath ] = [ ]
89
+
89
90
if let cwd = currentWorkingDirectory {
90
91
// We have a value, but it could be an absolute or a relative path.
91
- path = AbsolutePath ( value, relativeTo: cwd)
92
+ paths . append ( AbsolutePath ( value, relativeTo: cwd) )
92
93
} else if let absPath = try ? AbsolutePath ( validating: value) {
93
94
// Current directory not being available is not a problem
94
95
// for the absolute-specified paths.
95
- path = absPath
96
- } else {
97
- return nil
96
+ paths. append ( absPath)
98
97
}
99
98
100
- if localFileSystem. isExecutableFile ( path) {
101
- return path
102
- }
103
99
// Ensure the value is not a path.
104
- guard !value. contains ( " / " ) else {
105
- return nil
100
+ if !value. contains ( " / " ) {
101
+ // Try to locate in search paths.
102
+ paths. append ( contentsOf: searchPaths. map ( { $0. appending ( component: value) } ) )
106
103
}
107
- // Try to locate in search paths.
108
- for path in searchPaths {
109
- let exec = path. appending ( component: value)
110
- if localFileSystem. isExecutableFile ( exec) {
111
- return exec
112
- }
113
- }
114
- return nil
104
+
105
+ return paths. first ( where: { localFileSystem. isExecutableFile ( $0) } )
115
106
}
116
107
117
108
/// A wrapper for Range to make it Codable.
You can’t perform that action at this time.
0 commit comments