rules_swift_package_manager icon indicating copy to clipboard operation
rules_swift_package_manager copied to clipboard

feat: Improve error message for duplicate entries in Package.swift

Open AttilaTheFun opened this issue 7 months ago • 1 comments
trafficstars

I just tried updating to RSPM 1.0.0-rc1 and I'm getting this error when trying to run bazel mod tidy:

logan@Mac app_engine % bazel mod tidy
ERROR: /private/var/tmp/_bazel_logan/a9bff835f203c9cd5cf94c66e6112ec0/external/rules_swift_package_manager+/swiftpkg/bzlmod/swift_deps.bzl:305:41: Traceback (most recent call last):
        File "/private/var/tmp/_bazel_logan/a9bff835f203c9cd5cf94c66e6112ec0/external/rules_swift_package_manager+/swiftpkg/bzlmod/swift_deps.bzl", line 305, column 41, in _swift_deps_impl
                return module_ctx.extension_metadata(
Error in extension_metadata: in root_module_direct_deps: duplicate entry 'swiftpkg_swift_collections'
ERROR: error evaluating module extension @@rules_swift_package_manager+//:extensions.bzl%swift_deps
ERROR: Failed to process 1 extension due to errors.
    Fetching module extension @@rules_swift_package_manager+//:extensions.bzl%swift_deps; starting

There is only a single entry for swiftpkg_swift_collections in MODULE.bazel, and this is the only reference to it in Package.resolved:

    {
      "identity" : "swift-collections",
      "kind" : "remoteSourceControl",
      "location" : "https://github.com/apple/swift-collections.git",
      "state" : {
        "revision" : "671108c96644956dddcd89dd59c203dcdb36cec7",
        "version" : "1.1.4"
      }
    },

Prior to attempting to update to 1.0.0-rc1 I was using e8211504ff68a22edfbe4442cc2cb2572b4b439d which was a version of my SwiftSettings PR from a few weeks ago. After I rebased it this started breaking.

@cgrindel @luispadron I think given the timing, it's likely this could be the result of one of the swift package registry PRs: https://github.com/cgrindel/rules_swift_package_manager/pull/1318 https://github.com/cgrindel/rules_swift_package_manager/pull/1521

My (truncated) Package.swift has:

// swift-tools-version: 5.9

import PackageDescription

let package = Package(
    name: "Packages",
    dependencies: [

        // MARK: GRPC Dependencies

        .package(url: "https://github.com/grpc/grpc-swift-extras", exact: "1.0.0"), // required for reflection client
        .package(url: "https://github.com/grpc/grpc-swift-nio-transport.git", exact: "1.0.1"), // compatible with grpc-swift from 2.0.0
        .package(url: "https://github.com/grpc/grpc-swift-protobuf.git", exact: "1.1.0"), // Required by grpc-swift-extras @ 1.0.0
        .package(url: "https://github.com/grpc/grpc-swift.git", exact: "2.1.0"), // Required by grpc-swift-extras @ 2.0.0, grpc-swift-protobuf @ 1.1.0
        .package(url: "https://github.com/apple/swift-collections.git", from: "1.1.3"), // Required by grpc-swift @ 2.1.0
        .package(url: "https://github.com/apple/swift-protobuf.git", from: "1.28.1"), // Required by grpc-swift @ 2.1.0
        .package(url: "https://github.com/apple/swift-collections.git", from: "1.1.3"), // Required by grpc-swift @ 2.1.0
        
        .package(url: "https://github.com/apple/swift-argument-parser.git", from: "1.5.0"), // Required by grpc-swift @ 2.0.0-beta.2
        .package(url: "https://github.com/apple/swift-async-algorithms.git", from: "1.0.0"),
    ]
)

AttilaTheFun avatar Mar 30 '25 16:03 AttilaTheFun

As @luispadron pointed out, I had a duplicate entry for swift-collections in my Package.swift. The swift package resolve command did not emit a warning and Package.resolved had only one entry for it so I missed it. It would be great if we could emit a better error message here, stating there are duplicate entries in Package.swift.

AttilaTheFun avatar Mar 30 '25 17:03 AttilaTheFun