swiftlang / swift-package-manager

The Package Manager for the Swift Programming Language
Apache License 2.0
9.76k stars 1.35k forks source link

[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 4 years ago

ahoppen commented 4 years ago
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.

aciidgh commented 4 years ago

cc @hartbit

hartbit commented 4 years ago

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 commented 4 years ago

@swift-ci create

ahoppen commented 4 years ago

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 commented 4 years ago

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?

aciidgh commented 4 years ago

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

ahoppen commented 4 years ago

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

aciidgh commented 4 years ago

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

sharplet commented 4 years ago

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"]),
aciidgh commented 4 years ago

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

sharplet commented 4 years ago

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