Skip to content

Implement FileManager.url{s,}(for:…) and NSSearchPathForDirectoriesInDomains. #1456

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

Merged
merged 8 commits into from
Jun 12, 2018

Conversation

millenomi
Copy link
Contributor

@millenomi millenomi commented Feb 23, 2018

Implement urls(for:…) as the primitive directory method:

  • In Darwin, match paths with the Objective-C implementation wherever possible.
  • On platforms that use FHS/XDG, implement reading user-dirs.* files to determine XDG directories;

This patch also enables the @testable import syntax in TestFoundation in the Debug configuration.

@millenomi
Copy link
Contributor Author

@swift-ci Please test.

@millenomi millenomi requested a review from phausler February 27, 2018 23:26
@millenomi millenomi changed the title [WIP] Implement FileManager.url{s,}(for:…) and NSSearchPathForDirectoriesInDomains. Implement FileManager.url{s,}(for:…) and NSSearchPathForDirectoriesInDomains. Feb 27, 2018
@pushkarnk
Copy link
Member

@millenomi I'm not sure if @testable import Foundation would have the desired effect on Linux.

@pushkarnk
Copy link
Member

@millenomi Sorry, I noticed your changes to phases.py later. However, there's still a build failure
TestFoundation/TestFileManager.swift:11:22: error: module 'Foundation' was not compiled for testing

@millenomi
Copy link
Contributor Author

Looks like RelWithDebugInfo still builds Debug; I need to conditionalize these changes for Release.

@millenomi
Copy link
Contributor Author

Or, better, see if CI can build for @testable import. Stay tuned…

@millenomi
Copy link
Contributor Author

@swift-ci please test

1 similar comment
@shahmishal
Copy link
Member

@swift-ci please test

@millenomi
Copy link
Contributor Author

@shahmishal The build failed, but the Foundation tests compile and run, thank you!

@millenomi
Copy link
Contributor Author

@swift-ci please test and merge

return [ URL(fileURLWithPath: "/home", isDirectory: true) ]

case .moviesDirectory:
return []
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we use _XDGUserDirectory.videos.url here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch.

@shahmishal
Copy link
Member

We need to update swiftpm to be able to use --debug-foundation flag

/home/buildnode/jenkins/workspace/swift-corelibs-foundation-PR-Linux/Ninja-ReleaseAssert/swiftpm-linux-x86_64/x86_64-unknown-linux/release/swift-test: error while loading shared libraries: libswiftSwiftOnoneSupport.so: cannot open shared object file: No such file or directory
--- bootstrap: error: tests failed with exit status 127

@millenomi
Copy link
Contributor Author

I think we fixed that with #1495 — I built and tested locally and it seemed to go through. Trying again.

@millenomi
Copy link
Contributor Author

@swift-ci please test

@millenomi
Copy link
Contributor Author

The test has not passed but it's not related to this patch. A moment.

@millenomi
Copy link
Contributor Author

@swift-ci please test

@spevans
Copy link
Contributor

spevans commented Apr 3, 2018

@millenomi Does this PR need a rebase to resolve the conflict?

@millenomi
Copy link
Contributor Author

… oh. Yes, yes it does.

@millenomi
Copy link
Contributor Author

@swift-ci please test

1 similar comment
@alblue
Copy link
Contributor

alblue commented Apr 12, 2018

@swift-ci please test

@pvieito
Copy link
Contributor

pvieito commented May 27, 2018

What is the status of this PR? I would love to be able to use FileManager.url(for:…) across platforms :)

@millenomi
Copy link
Contributor Author

@swift-ci please test

@@ -28,7 +28,10 @@ class TestFileManager : XCTestCase {
("test_homedirectoryForUser", test_homedirectoryForUser),
("test_temporaryDirectoryForUser", test_temporaryDirectoryForUser),
("test_creatingDirectoryWithShortIntermediatePath", test_creatingDirectoryWithShortIntermediatePath),
("test_mountedVolumeURLs", test_mountedVolumeURLs),
("test_mountedVolumeURLs", test_mountedVolumeURLs)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you need a , at the end of this line

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Late night merge mistake. Thanks for the catch.

// Created by Lily Vulcano on 2/26/18.
// Copyright © 2018 Apple. All rights reserved.
//

Copy link
Contributor

Choose a reason for hiding this comment

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

This should probably be the standard swift.org file header

@millenomi
Copy link
Contributor Author

@swift-ci please test.

self = .user
}

return nil
Copy link
Contributor

Choose a reason for hiding this comment

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

Wont this failable initialiser always fail?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How so? It didn’t in local testing. (It will fail for bitmasks with more than one bit set and that’s intended.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh dear. Yeah, I see the problem.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This patch needs some care and attention.

@felix91gr
Copy link
Contributor

Thank you for working on this! The FileManager API is possibly the most commonly needed at projects in the community that wish to become cross-platform*. Thank you 🙏

* This includes SPM, which if it had access to the FileManager and FileHandle APIs it uses in Darwin, would be able to synthesize the LinuxMain.swift file (and actually wouldn't really need to create it at all!) in every platform that runs corelibs-foundation.

millenomi added 2 commits June 8, 2018 09:59
…ectoriesInDomains.

Implement urls(for:…) as the primitive directory method:
 - In Darwin, match paths with the Objective-C implementation wherever possible.
 - On platforms that use FHS/XDG, implement reading user-dirs.* files to determine XDG directories;

Implement url(for:in:…) and NSSearchPathForDirectoriesInDomains() in terms of urls(for:…).
@millenomi
Copy link
Contributor Author

@swift-ci please test

1 similar comment
@millenomi
Copy link
Contributor Author

@swift-ci please test

@millenomi
Copy link
Contributor Author

@swift-ci please test and merge

1 similar comment
@spevans
Copy link
Contributor

spevans commented Jun 12, 2018

@swift-ci please test and merge

@swift-ci swift-ci merged commit 233ce17 into swiftlang:master Jun 12, 2018
@rudkx
Copy link
Contributor

rudkx commented Jun 12, 2018

@millenomi It looks like this broke the build on the CI bots, despite having passed PR testing.

https://ci.swift.org/job/oss-swift-incremental-RA-linux-ubuntu-16_04/4410/

@rudkx
Copy link
Contributor

rudkx commented Jun 12, 2018

This is blocking PR testing as well, so I'm going to open a PR to revert. I don't understand how this passed PR testing unless there was a second PR being tested simultaneously and both are required to cause the failure (or perhaps a clean build was required and it didn't happen for the PR testing)?

@millenomi
Copy link
Contributor Author

On it.

@rudkx
Copy link
Contributor

rudkx commented Jun 12, 2018

@millenomi Thanks. Happy to hold off on reverting if we can get this resolved pretty quickly. We have another PR (swiftlang/swift#17140) we're trying to get through to fix another breakage on Linux, and I suspect this issue will block merging that PR.

@millenomi
Copy link
Contributor Author

@rudkx I will resolve it today, but it requires some work. Let's just revert for now.

@rudkx
Copy link
Contributor

rudkx commented Jun 12, 2018

@millenomi Okay, sounds good to me. Thanks!

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.

9 participants