-
Notifications
You must be signed in to change notification settings - Fork 1.4k
SR-1005: [Foundation] Replace posix_spawn by NSTask #303
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@swift-ci Please test |
The failing OS X build doesn't appear to be related. Regarding the failing Linux build, this PR is dependent on a change in Foundation (PR). |
When testing this on Linux, most build-related tests fail. What I've found so far is that BEFORE:
AFTER:
|
NSTask does not run inside a shell, so no automatic PATH lookups are performed for binaries. Also referencing binaries by an absolute path is not desirable, so for relative paths a shell is opened and the absolute path is looked up through `which`.
No memoization has a performance penalty of ~6%.
Previous implementation used a temporary file, however NSTask doesn't allow child process to access parent's file descriptors. So stdout is used to communicate the toml output. See also: http://www.cocoabuilder.com/archive/cocoa/292758-sharing-file-descriptors-to-an-nstask.html
I've rebased the PR and tested against OSX and Ubuntu. Please retest. |
|
||
var environment = environment | ||
#if Xcode | ||
let keys = ["SWIFT_EXEC", "HOME", "PATH"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This lost the change to add: "TOOLCHAINS",
here that I made in the past couple of days.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I missed that, I've restored those changes.
|
||
private var memoized = [String: String]() | ||
private let PATH = [POSIX.getcwd()] + (getenv("PATH") ?? "").components(separatedBy: ":") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We shouldn't default to looking in the cwd
, that can be a security issue.
I'm closing this out... per my email to swift-build-dev I'm not longer convinced we should try to move all of our infrastructure onto the Foundation APIs. I think instead we should do it on a case by case basis, and in this case (posix_spawn) my feeling is that our needs match using the POSIX API directly, and I am fine with us needing to maintain the infrastructure for that (at least until there is a standard POSIX module for Swift itself). I think some of the cleanups on this branch make sense, but it didn't look like I could easily cherry pick them out. |
Currently this cannot be merged as builds fail on Linux;
NSTask.standardOutput
), so no output can be captured (PR).NSFileHandle.availableData
) (PR).argv[0]
and stderr [NSTask] Change argv[0] to full path + fixes combining stdout+stderr swift-corelibs-foundation#353