@@ -10,7 +10,16 @@ import func Foundation.exit
10
10
let projectRoot = URL ( fileURLWithPath: #filePath) . deletingLastPathComponent ( ) . deletingLastPathComponent ( )
11
11
12
12
/// Returns the path to the executable if it is found in the PATH environment variable.
13
- func which( _ executable: String ) -> String ? {
13
+ func which( _ executable: String ) -> URL ? {
14
+ do {
15
+ // Check overriding environment variable
16
+ let envVariable = executable. uppercased ( ) . replacingOccurrences ( of: " - " , with: " _ " ) + " _PATH "
17
+ if let path = ProcessInfo . processInfo. environment [ envVariable] {
18
+ if FileManager . default. isExecutableFile ( atPath: path) {
19
+ return URL ( fileURLWithPath: path)
20
+ }
21
+ }
22
+ }
14
23
let pathSeparator : Character
15
24
#if os(Windows)
16
25
pathSeparator = " ; "
@@ -21,7 +30,7 @@ func which(_ executable: String) -> String? {
21
30
for path in paths {
22
31
let url = URL ( fileURLWithPath: String ( path) ) . appendingPathComponent ( executable)
23
32
if FileManager . default. isExecutableFile ( atPath: url. path) {
24
- return url. path
33
+ return url
25
34
}
26
35
}
27
36
return nil
@@ -33,8 +42,9 @@ func swiftFormat(_ arguments: [String]) throws {
33
42
print ( " swift-format not found in PATH " )
34
43
exit ( 1 )
35
44
}
45
+ print ( " [Utilities/format.swift] Running \( swiftFormat. path) " )
36
46
let task = Process ( )
37
- task. executableURL = URL ( fileURLWithPath : swiftFormat)
47
+ task. executableURL = swiftFormat
38
48
task. arguments = arguments
39
49
task. currentDirectoryURL = projectRoot
40
50
try task. run ( )
@@ -43,6 +53,7 @@ func swiftFormat(_ arguments: [String]) throws {
43
53
print ( " swift-format failed with status \( task. terminationStatus) " )
44
54
exit ( 1 )
45
55
}
56
+ print ( " [Utilities/format.swift] Done " )
46
57
}
47
58
48
59
/// Patterns to exclude from formatting.
0 commit comments