Skip to content

Conversation

mstokercricut
Copy link

Adds Windows support to swsh, while trying to avoid the most grievous of sins.

cobbal and others added 30 commits June 19, 2023 14:01
…rn the string instead of the empty string. Refined windows tests (some still fail)
…o process struct. Removed some debug printing
…ods from libuv for quoting command arguments and searching the execution path. Used the quoting method to quote arguments.
… changing the environment. Failed tests early that were blocking on Windows. Test suite now runs to completion
…to restrict handles inherited by the child process
…ends FileManager as that type already posesses a 'nullDevice' property, but lacks its path.
let pipe = FDPipe()
_ = async(fdMap: [ .stdout: pipe.fileHandleForWriting.fileDescriptor ])
pipe.fileHandleForWriting.close()
// TODO: Previously, this returned a FileHandle, but the test using it fails without returning an FDFileHandle, because otherwise, on return, the FDFileHandle is deallocate and calls close(). Can maintain liveness of the FDFileHandle in some way without changing the interface of this call?
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To do that, just duplicate the handle

throw InvalidString(data: data, encoding: encoding)
}
guard let trimStop = string.lastIndex(where: { $0 != "\n" }) else {
// TODO: Shoudn't this return `string`?
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, the string is all newlines and should be completely trimmed.

self.spawner = PosixSpawn()
#elseif canImport(Glibc)
self.spawner = LinuxSpawn()
#elseif canImport(ucrt)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is mismatched with the import statement at the top of the file. They should both have the same #condition.

}

static let NtSuspendProcess: (ProcessInformation) -> Int32 = {
// TODO: Tie into (undocumented) NtSuspendProcess() syscall
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't be a noop

} else if signal == SIGSTOP {
// Method borrowed from https://github.com/giampaolo/psutil/blob/a7e70bb66d5823f2cdcdf0f950bdbf26875058b4/psutil/arch/windows/proc.c#L539
// See also https://ntopcode.wordpress.com/2018/01/16/anatomy-of-the-thread-suspension-mechanism-in-windows-windows-internals/
_ = Self.NtSuspendProcess(process)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These errors shouldn't be ignored

let parentFDMax = fdMap.keys.max() ?? -1
var childHandleArray = Array<HANDLE?>(repeating: nil, count: Int(parentFDMax + 1))
for (parentFD, childFD) in fdMap {
childHandleArray[Int(parentFD)] = Self.osHandle(for: childFD)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
childHandleArray[Int(parentFD)] = Self.osHandle(for: childFD)
childHandleArray[Int(parentFD)] = osHandle(for: childFD)

}

private init?(_ handles: [HANDLE?]) {
let handles = !shouldDuplicate ? handles : handles.map { Self.duplicate($0) }
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Self shouldn't be used in classes unless you're absolutely sure you want to dispatch based on the dynamic type.


func testAbsPath() {
#if os(Windows)
XCTAssertEqual(try? cmd("C:\\Windows\\System32\\cmd.exe", "/C", "ECHO 1").runString(), "1\r\n")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the wrong answer. runString is supposed to remove the newline

let cProgramExecutable = "writer-\(id)"
#endif

try cmd("cat").input(cProgram).output(overwritingFile: cProgramFile).run()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be put in the temp directory, not the current folder

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This script has been made non-executable

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants