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

[SR-12075] Trying to depend on a package whose name doesn’t match the Git repository name gives sub-optimal error message #4618

Open
ahoppen opened this issue Jan 23, 2020 · 11 comments
Assignees

Comments

@ahoppen
Copy link
Contributor

ahoppen commented Jan 23, 2020

Previous ID SR-12075
Radar rdar://problem/59223047
Original Reporter @ahoppen
Type Improvement
Status Reopened
Resolution
Additional Detail from JIRA
Votes 0
Component/s Package Manager
Labels Improvement
Assignee @hartbit
Priority Medium

md5: 832567a75e77933899a45288f49e4e50

Issue Description:

If I try to depend on SwiftSyntax (package name `SwiftSyntax`, Git repository name `swift-syntax`), I used to write:

let package = Package(
  name: "testpackage",
  dependencies: [
    .package(url: "https://github.com/apple/swift-syntax.git", .branch("master")),
  ],
  targets: [
    .target(name: "testpackage", dependencies: ["SwiftSyntax"]),
  ]
) 

Doing the same with Swift 5.2 gives me the ambiguous error message

error: manifest parse error: target 'testpackage' depends on an unknown package 'SwiftSyntax' 

SwiftPM should tell me that I need to specify name: "SwiftSyntax" in the declaration of the dependency.

@ankitspd
Copy link
Member

cc @hartbit

@hartbit
Copy link
Collaborator

hartbit commented Jan 24, 2020

What do you think of the following diagnostics?

error: target 'testpackage' depends on an unknown package 'SwiftSyntax'; if the package is named differently from the product, either use '.product(name: "SwiftSyntax", package: <package-name>)' to specify the package name or give the package the 'SwiftSyntax' name using '.package(name: "SwiftSyntax", ...)'

@beccadax
Copy link
Contributor

@swift-ci create

@ahoppen
Copy link
Contributor Author

ahoppen commented Jan 24, 2020

I don’t know if that’s possible but could you, if you can’t find the package name based on the Git repository name, look into all packages and scan their package names for the name that was used in `dependencies`? That way you could provide a nice fix-it that specifies the package name.

Or, different strategy: If there’s a Git repository listed whose name doesn’t match the package name you can’t use it as a dependency AFAICT. So you could just offer a fixit adding `name: <the package name>`.

@hartbit
Copy link
Collaborator

hartbit commented Jan 25, 2020

I don’t know if that’s possible but could you, if you can’t find the package name based on the Git repository name, look into all packages and scan their package names for the name that was used in `dependencies`? That way you could provide a nice fix-it that specifies the package name.

That's something we could (and probably should) do in the long run, but it requires a fair amount of work. I think we should start by improving the diagnostic. What do you think of the one I suggested?

@ankitspd
Copy link
Member

I agree with David, let's start by improving the diagnostics without automatically looking up the package name from the repository.

@ahoppen
Copy link
Contributor Author

ahoppen commented Jan 28, 2020

OK, sounds good to me. The improved diagnostic definitely gives a lot better idea of what’s going on.

@ankitspd
Copy link
Member

ankitspd commented Feb 6, 2020

Reopening because we should also fill in package name in the diagnostic.

@sharplet
Copy link

I just ran into this issue testing out https://github.com/apple/swift-crypto/. Interestingly, this works in tools version 5.1, but gives the "unknown package error" in 5.2:

    .target(name: "foo", dependencies: ["Crypto"]),

@ankitspd
Copy link
Member

Can you try with the latest snapshot? You should see a much better error.

@sharplet
Copy link

@aciidb0mb3r Just confirming that I do see the improved error message on a recent toolchain. Thanks.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants