Skip to content

Commit 9c5e0c6

Browse files
committed
Minor behavioral fixes
1 parent 56ef883 commit 9c5e0c6

File tree

3 files changed

+14
-13
lines changed

3 files changed

+14
-13
lines changed

Sources/TSCBasic/Process.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,10 @@ public final class Process {
360360
searchPaths.append(AbsolutePath(String(decodingCString: buffer, as: UTF16.self)))
361361

362362
// The 16-bit Windows system directory
363-
searchPaths.append(AbsolutePath("\(ProcessEnv.vars["systemdrive"] ?? "C:")\\System"))
363+
if let systemDrive = ProcessEnv.vars["systemdrive"],
364+
let systemPath = try? AbsolutePath(validating: "\(systemDrive))\\System") {
365+
searchPaths.append(systemPath)
366+
}
364367

365368
// The Windows directory
366369
GetWindowsDirectoryW(&buffer, .init(MAX_PATH + 1))

Sources/TSCBasic/misc.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public func lookupExecutablePath(
9898
guard var value = value, !value.isEmpty else {
9999
return nil
100100
}
101-
let isPath = value.contains("\\")
101+
let isPath = value.contains("\\") || value.contains("/")
102102
if !isPath && !value.contains(".") {
103103
value.append(executableFileSuffix)
104104
}

Tests/TSCBasicTests/ProcessTests.swift

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -140,31 +140,29 @@ class ProcessTests: XCTestCase {
140140
XCTAssertNil(Process.findExecutable("nonExistantProgram"))
141141
XCTAssertNil(Process.findExecutable(""))
142142

143-
// Create a bat file to test.
144-
let tempExecutable = tmpdir.appending(component: "program.bat")
145-
try localFileSystem.writeFileContents(tempExecutable, bytes: """
146-
@echo off
147-
exit
148-
149-
""")
143+
// Copy an executable file to test.
144+
let tempExecutable = tmpdir.appending(component: "executableProgram.exe")
145+
try localFileSystem.copy(from: Process.findExecutable("cmd")!, to: tempExecutable)
150146

151147
// Create a non-executable file to test.
152-
let tempNonExecutable = tmpdir.appending(component: "program.bc")
148+
let tempNonExecutable = tmpdir.appending(component: "program.bat")
153149
try localFileSystem.writeFileContents(tempNonExecutable, bytes: """
154150
@echo off
155151
exit
156152
157153
""")
158154

159155
try withCustomEnv(["PATH": tmpdir.pathString]) {
160-
XCTAssertNotNil(Process.findExecutable("program.bat"))
161-
XCTAssertNil(Process.findExecutable("program.bc"))
156+
XCTAssertNotNil(Process.findExecutable("executableProgram.exe"))
157+
XCTAssertNotNil(Process.findExecutable("executableProgram"))
158+
// Currently, Foundation treats all readable files as executable on Windows.
159+
// XCTAssertNil(Process.findExecutable("program.bat"))
162160
}
163161
}
164162
#endif
165163
}
166164

167-
#if !os(Windows) // Foundation treats all readable files as executable on Windows.
165+
#if !os(Windows) // Foundation treats all readable files as executable on Windows
168166
func testNonExecutableLaunch() throws {
169167
try testWithTemporaryDirectory { tmpdir in
170168
// Create a local nonexecutable file to test.

0 commit comments

Comments
 (0)