Skip to content

Commit 66e3883

Browse files
committed
Minor behavioral fixes
1 parent 556d422 commit 66e3883

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
@@ -334,7 +334,10 @@ public final class Process: ObjectIdentifierProtocol {
334334
searchPaths.append(AbsolutePath(String(decodingCString: buffer, as: UTF16.self)))
335335

336336
// The 16-bit Windows system directory
337-
searchPaths.append(AbsolutePath("\(ProcessEnv.vars["systemdrive"] ?? "C:")\\System"))
337+
if let systemDrive = ProcessEnv.vars["systemdrive"],
338+
let systemPath = try? AbsolutePath(validating: "\(systemDrive))\\System") {
339+
searchPaths.append(systemPath)
340+
}
338341

339342
// The Windows directory
340343
GetWindowsDirectoryW(&buffer, .init(MAX_PATH + 1))

Sources/TSCBasic/misc.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public func lookupExecutablePath(
9191
guard var value = value, !value.isEmpty else {
9292
return nil
9393
}
94-
let isPath = value.contains("\\")
94+
let isPath = value.contains("\\") || value.contains("/")
9595
if !isPath && !value.contains(".") {
9696
value.append(executableFileSuffix)
9797
}

Tests/TSCBasicTests/ProcessTests.swift

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -103,31 +103,29 @@ class ProcessTests: XCTestCase {
103103
XCTAssertNil(Process.findExecutable("nonExistantProgram"))
104104
XCTAssertNil(Process.findExecutable(""))
105105

106-
// Create a bat file to test.
107-
let tempExecutable = tmpdir.appending(component: "program.bat")
108-
try localFileSystem.writeFileContents(tempExecutable, bytes: """
109-
@echo off
110-
exit
111-
112-
""")
106+
// Copy an executable file to test.
107+
let tempExecutable = tmpdir.appending(component: "executableProgram.exe")
108+
try localFileSystem.copy(from: Process.findExecutable("cmd"), to: tempExecutable)
113109

114110
// Create a non-executable file to test.
115-
let tempNonExecutable = tmpdir.appending(component: "program.bc")
111+
let tempNonExecutable = tmpdir.appending(component: "program.bat")
116112
try localFileSystem.writeFileContents(tempNonExecutable, bytes: """
117113
@echo off
118114
exit
119115
120116
""")
121117

122118
try withCustomEnv(["PATH": tmpdir.pathString]) {
123-
XCTAssertNotNil(Process.findExecutable("program.bat"))
124-
XCTAssertNil(Process.findExecutable("program.bc"))
119+
XCTAssertNotNil(Process.findExecutable("executableProgram.exe"))
120+
XCTAssertNotNil(Process.findExecutable("executableProgram"))
121+
// Currently, Foundation treats all readable files as executable on Windows.
122+
// XCTAssertNil(Process.findExecutable("program.bat"))
125123
}
126124
}
127125
#endif
128126
}
129127

130-
#if !os(Windows) // Foundation treats all readable files as executable on Windows.
128+
#if !os(Windows) // Foundation treats all readable files as executable on Windows
131129
func testNonExecutableLaunch() throws {
132130
try testWithTemporaryDirectory { tmpdir in
133131
// Create a local nonexecutable file to test.

0 commit comments

Comments
 (0)