Skip to content

Conversation

@karwa
Copy link
Contributor

@karwa karwa commented Jul 21, 2021

Improve the diagnostics added in #3625 and add tests for more file URLs with hostnames.

CC @neonichu

Motivation:

Previous diagnostic was not entirely clear - the change in the previous patch ensures that all file URLs with hostnames are now rejected. That's a good thing.

  • On POSIX systems, remote filesystems are typically mounted within the local filesystem, so there's no obvious interpretation of a file URL with a hostname.
  • On Windows, they require UNC paths - even for localhost - which is non-trivial kind of path that SwiftPM seems to not support right now.

This patch doesn't change the functionality from the previous patch; it only makes clear what the limitation is.

Modifications:

Reworded diagnostic, added tests.

Result:

Clearer diagnostic, more tests.

@neonichu
Copy link
Contributor

Thanks for the PR, @karwa.

I had indeed not considered the other failure cases, but I think we should also still represent the relative URL case with its own diagnostic, at least in its most simple form of the hostname component being ... Could you add a special case for that?

@abertelrud
Copy link
Contributor

@karwa do you need more information to finalize this?

@karwa karwa force-pushed the file-url-hostnames branch from a537ae3 to 728ca96 Compare August 9, 2021 14:49
@karwa
Copy link
Contributor Author

karwa commented Aug 9, 2021

@abertelrud @neonichu Sorry, I just totally forgot about it! 😓 I've added the relative path diagnostic back if the hostname is ".."

guard hostnameComponent.isEmpty else {
if hostnameComponent == ".." {
throw ManifestParseError.invalidManifestFormat(
"file:// URLs cannot be relative, did you mean to use `.package(path:)`?", diagnosticFile: nil
Copy link
Contributor

Choose a reason for hiding this comment

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

nitpick:

Suggested change
"file:// URLs cannot be relative, did you mean to use `.package(path:)`?", diagnosticFile: nil
"file:// URLs cannot be relative, did you mean to use '.package(path:)'?", diagnosticFile: nil

I think it should be single quotes instead of back ticks for consistency.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

#3625 uses backticks, so I kept them as they were. I don't mind changing it if the maintainers agree.

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 backpacks are probably not correct and we should update everywhere

"""
switch expectedError {
case .relativePath:
XCTAssertManifestLoadThrows(ManifestParseError.invalidManifestFormat("file:// URLs cannot be relative, did you mean to use `.package(path:)`?", diagnosticFile: nil), stream.bytes)
Copy link
Contributor

Choose a reason for hiding this comment

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

same nitpick as the previous comment:

Suggested change
XCTAssertManifestLoadThrows(ManifestParseError.invalidManifestFormat("file:// URLs cannot be relative, did you mean to use `.package(path:)`?", diagnosticFile: nil), stream.bytes)
XCTAssertManifestLoadThrows(ManifestParseError.invalidManifestFormat("file:// URLs cannot be relative, did you mean to use '.package(path:)'?", diagnosticFile: nil), stream.bytes)

@tomerd
Copy link
Contributor

tomerd commented Aug 25, 2021

@karwa @WowbaggersLiquidLunch do you feel this is ready?

@WowbaggersLiquidLunch
Copy link
Contributor

@tomerd I didn't look very closely at the code, so I don't really have an opinion. The only thing I reviewed was the back tick vs single quote in diagnostics messages. They've not been updated yet, but my review was just a nitpick, so I think it's fine.

@karwa karwa force-pushed the file-url-hostnames branch from 728ca96 to 8aa03c7 Compare August 25, 2021 12:46
@karwa
Copy link
Contributor Author

karwa commented Aug 25, 2021

@tomerd Yes. I was waiting for the project maintainers' input on @WowbaggersLiquidLunch's suggestion to use single quotes rather than backticks. Since you commented that you agree, I'll take that as confirmation.

So I've made that change and rebased the patch.

@neonichu
Copy link
Contributor

@swift-ci please smoke test

@tomerd tomerd merged commit 40f9df2 into swiftlang:main Aug 27, 2021
@tomerd
Copy link
Contributor

tomerd commented Aug 27, 2021

thanks @karwa

@karwa karwa deleted the file-url-hostnames branch August 27, 2021 21:52
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.

5 participants