Skip to content

[5.5] Do not crash on relative file URLs in a dependency #3604

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 2 commits into from
Jul 23, 2021

Conversation

neonichu
Copy link
Contributor

5.5 cherry-pick of #3603

Currently, SwiftPM crashes when someone specifies the URL of a package dependency as a relative file URL. We should instead be able to just make it absolute based on the location of the package itself.

(cherry picked from commit d771063)
@neonichu neonichu requested a review from tomerd July 12, 2021 22:08
@neonichu
Copy link
Contributor Author

@swift-ci please test

@neonichu neonichu added the 5.5 label Jul 12, 2021
@neonichu neonichu self-assigned this Jul 12, 2021
@karwa
Copy link
Contributor

karwa commented Jul 16, 2021

I just happened to spot this by accident, but it doesn’t look correct - in the URL file://../best, the .. is in the host position, and is not part of the path.

Personally, I don’t agree that this syntax should be supported. Relative file URLs are not a thing. Even RFC-8089 says:

The path component represents the absolute path to the file in the
file system.

The reason is that, with the proper 3 slashes (file:///../best), the path would be /../best, which is an absolute path identical to /best on a POSIX system. Removing the leasing slash in the path doesn’t make it relative - it just breaks the URL by putting data in the wrong section.

@neonichu
Copy link
Contributor Author

Thanks, @karwa, looks like you're right and Foundation.URL also behaves exactly like that:

import Foundation

let url = URL(string: "file://../best")!
print("host: \(url.host ?? "<empty>")")
print("path: \(url.path)")

prints

host: ..
path: /best

Based on that, it seems appropriate to change this to checking whether there's a host component and rejecting the URL if that is the case.

neonichu added a commit that referenced this pull request Jul 20, 2021
It turns out that relative file URLs actually do not exist, see [here](#3604 (comment)) for more discussion. Instead we will now error and guide users to using a local package reference.
neonichu added a commit that referenced this pull request Jul 20, 2021
It turns out that relative file URLs actually do not exist, see [here](#3604 (comment)) for more discussion. Instead we will now error and guide users to using a local package reference.
neonichu added a commit that referenced this pull request Jul 21, 2021
It turns out that relative file URLs actually do not exist, see [here](#3604 (comment)) for more discussion. Instead we will now error and guide users to using a local package reference.
It turns out that relative file URLs actually do not exist, see [here](#3604 (comment)) for more discussion. Instead we will now error and guide users to using a local package reference.

rdar://80751251

(cherry picked from commit e6a7323)
@neonichu
Copy link
Contributor Author

Amended with cherry-pick of #3625

@neonichu
Copy link
Contributor Author

@swift-ci please test

@neonichu
Copy link
Contributor Author

:0: error: module file '/home/buildnode/jenkins/workspace/swift-package-manager-PR-Linux/build/buildbot_linux/foundation_static-linux-x86_64/module-cache/1O5EHM9AO5UP2/SwiftShims-5INC0PO62ITL.pcm' is out of date and needs to be rebuilt: signature mismatch

@neonichu
Copy link
Contributor Author

@swift-ci please test linux

@neonichu
Copy link
Contributor Author

Let's see how #3630 shakes out before merging this.

@neonichu
Copy link
Contributor Author

Actually, let's get this merged. We are getting closer to the 5.5 release and this diagnostic is already a big improvement over crashing. If there's time, we can make another cherry pick of a refined diagnostic.

@neonichu neonichu merged commit 14ff208 into release/5.5 Jul 23, 2021
@neonichu neonichu deleted the fix-relative-file-urls branch July 23, 2021 00:19
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.

4 participants