Skip to content
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

POSIX is not portable, remove it #2045

Closed
wants to merge 16 commits into from

Conversation

compnerd
Copy link
Collaborator

This prepares swift-package-manager to adopt more functionality in Foundation. The implementation in swift-package-manager is EXTREMELY unfriendly to porting due to the highly POSIX/UNIX specific implementation. Rather than trying to implement a POSIX/UNIX layer for Windows, it is preferable to use Foundation where ever possible and generalizing the implementation otherwise to permit the use of Windows semantics.

@aciidgh
Copy link
Member

aciidgh commented Mar 19, 2019

Thanks. These were written before Foundation on linux was complete. I am a little afraid of the fallout here so maybe start doing this one at a time so it can be reviewed and merged independently?

@compnerd
Copy link
Collaborator Author

@aciidb0mb3r - sure, would you mind looking through the changes individually? I can split it up into a single PR for each of the changes, but, if you can take a preliminary look through this, I can change them before splitting them up into individual PRs.

@aciidgh
Copy link
Member

aciidgh commented Mar 21, 2019

I took a preliminary look, they look great in general. I probably will have minor comments on some individual changes but go ahead and break them up. It probably makes the most sense to break them according to the API (symlink, createdir, contents of dir, getenv, etc). For getting the environment, use Basic.Process.env instead of ProcessInfo except in the manifest file. We should also move the existing POSIX tests over to Basic and use the new APIs.

Remove some of the custom error messages that were in use previously.
We can forward along the NSError from Foundation to relay the necessary
diagnostic information.
var process: Process = Process()
process.executableURL = path
process.arguments = args
try process.run()
Copy link
Member

Choose a reason for hiding this comment

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

Two notes:

  1. This API is for replacing the current process with a new one so we shouldn't just run it as a subprocess.
  2. Don't use Foundation's Process. We have our own implementation for various reasons. It is one of the thing that we'll want to implement for all platforms instead of using Foundation's.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That isn't a great idea ... there is a bunch of complexity that is involved for process execution, particularly on Windows. On Windows, CreateProcess is the closest equivalent to exec.

Copy link
Member

Choose a reason for hiding this comment

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

We should conditionalize it then..

@@ -21,64 +21,10 @@ import SPMLibc
import POSIX
Copy link

Choose a reason for hiding this comment

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

Does this need to be removed as well?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Probably, but, can't as of yet, I'm just mechanically removing the items so that we can split this up and merge it piecemeal. It's easier to review this an API at a time rather than everything at once.

// Otherwise, we failed due to some other error. Report it.
do {
try FileManager.default.createDirectory(atPath: path.pathString, withIntermediateDirectories: recursive)
} catch {
throw FileSystemError(errno: errno)
}
Copy link

Choose a reason for hiding this comment

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

You should be able to catch an _NSErrorWithErrno and extract the errno from that as it may be overwritten in between.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, however, it seems that there is no real reason to keep the custom error wrappers around, so, Im going to change towards letting the NSError propagate through which makes things simpler and less likely to introduce errors like that.

@aciidgh
Copy link
Member

aciidgh commented Mar 24, 2019

I am starting to do the work of landing these changes in smaller chunks.
First PR: #2052
Second: #2053
Third: #2055

@aciidgh
Copy link
Member

aciidgh commented Mar 25, 2019

I've removed the POSIX module. There are now less things requires conversion (in Basic) but that can happen overtime: #2055

@compnerd compnerd closed this Mar 26, 2019
@compnerd compnerd deleted the posix-is-not-portable branch March 26, 2019 17:58
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.

None yet

3 participants