Having Very Strange Package Manager Dependency Chain Issues

UPDATE: I gave it a couple of days, with no answers, so I will be starting to modify the repos, in an effort to fix the problem (I'll get it, eventually).

I am absolutely sure that "I'm not holding it right," but there's no way for me to diagnose the issue.

I have also asked this question on Stack Overflow.

I have this package[0], which is consumed by this package[1], which is, in turn, consumed by this app[2]. The first package[0] is also consumed by this package[3], which is also consumed by the app[2]. That chain works fine, but is also a great deal simpler.

The issue is that I get an error inside the RVS_BlueThoth package[1] during the BlueVanClef[2] build.

The error is consistent with the RVS_Generic_Swift_Toolbox[0] package not building in the RVS_BlueThoth package[1] build (the module is not available), but I can't figure out why. There is nothing but a blank serialized diagnostics file for one of the files that consumes the RVS_Generic_Swift_Toolbox[0] module, and no other errors, other than the file isn't there.

If I build the RVS_BlueThoth package[1] independently, I have no issues, but including it in the BlueVanClef app[2] consistently reports this error.

Here is a visual map of the dependency relationships:

Note the dotted line between RVS_BlueThoth and RVS_Persistent_Prefs. That's because the dependency is only for test harnesses, and is not used by Blue Van Clef.

Like I said, I am sure that the problem is mine. I just can't figure out how to get to it.

Thanks for any help!

(For example, is there any diagnostic utility available for SPM?)

Here are the Package.swift files:

RVS_Generic_Swift_Toolbox:

// swift-tools-version:5.2

import PackageDescription

let package = Package(
    name: "RVS_Generic_Swift_Toolbox",
    platforms: [
        .iOS(.v11),
        .tvOS(.v11),
        .macOS(.v10_14),
        .watchOS(.v5)
    ],
    products: [
        .library(
            name: "RVS-Generic-Swift-Toolbox",
            type: .dynamic,
            targets: ["RVS_Generic_Swift_Toolbox"])
    ],
    targets: [
        .target(
            name: "RVS_Generic_Swift_Toolbox",
            path: "./src")
    ]
)

RVS_Peristent_Prefs (This one works):

// swift-tools-version:5.2
import PackageDescription

let package = Package(
    name: "RVS_Persistent_Prefs",
    platforms: [
        .iOS(.v11),
        .tvOS(.v11),
        .macOS(.v10_14),
        .watchOS(.v5)
    ],
    products: [
        .library(
            name: "RVS-Persistent-Prefs",
            type: .dynamic,
            targets: ["RVS_Persistent_Prefs"])
    ],
    dependencies: [
        .package(
            url: "git@github.com:RiftValleySoftware/RVS_Generic_Swift_Toolbox.git",
            from: "1.2.1"
        )
    ],
    targets: [
        .target(
            name: "RVS_Persistent_Prefs",
            path: "./src")
    ]
)

RVS_BlueThoth (This one does not work):

// swift-tools-version:5.2
import PackageDescription

let package = Package(
    name: "RVS_BlueThoth",
    platforms: [
        .iOS(.v11),
        .tvOS(.v11),
        .macOS(.v10_14),
        .watchOS(.v5)
    ],
    products: [
        .library(
            name: "RVS-BlueThoth",
            type: .dynamic,
            targets: ["RVS_BlueThoth"]
        )
    ],
    dependencies: [
        .package(
            url: "git@github.com:RiftValleySoftware/RVS_Generic_Swift_Toolbox.git",
            from: "1.2.1"
        ),
        .package(
            url: "git@github.com:RiftValleySoftware/RVS_PersistentPrefs.git",
            from: "1.1.1"
        )
    ],
    targets: [
        .target(
            name: "RVS_BlueThoth",
            path: "./src/Source"
        )
    ]
)

Because I am not allowed to have more than five links, here goes:

[0]
[1]
[2]
[3]

OK. Solved. Finally.

I was, indeed, "holding it wrong," but it was not easy to tell.

The best way to debug was to cd to the package directory, and do a swift build. That helped me to see the errors as they happened (They were not reflected in the Xcode logs).

The issue was that I needed to do the dependency in TWO places. I had it only in one. Now that I look back on it, it was a fairly natural structure, but was complicated by the fact that I needed to rename the product of the dependency to use dashes, instead of underscores.

This was fixed by changing the RVS_BlueThoth Package.swift file to like so:

// swift-tools-version:5.2

import PackageDescription

let package = Package(
    name: "RVS_BlueThoth",
    platforms: [
        .iOS(.v11),
        .tvOS(.v11),
        .macOS(.v10_14),
        .watchOS(.v5)
    ],
    products: [
        .library(name: "RVS-BlueThoth", type: .dynamic, targets: ["RVS_BlueThoth"])
    ],
    dependencies: [
        .package(name: "RVS_Generic_Swift_Toolbox", url: "git@github.com:RiftValleySoftware/RVS_Generic_Swift_Toolbox.git", from: "1.2.1")
    ],
    targets: [
        .target(
            name: "RVS_BlueThoth",
            dependencies: [.product(name: "RVS-Generic-Swift-Toolbox", package: "RVS_Generic_Swift_Toolbox")],
            path: "./src/Source"
        )
    ]
)

The money shot was this line:

dependencies: [.product(name: "RVS-Generic-Swift-Toolbox", package: "RVS_Generic_Swift_Toolbox")]

Note that the name argument is "RVS-Generic-Swift-Toolbox", NOT "RVS_Generic_Swift_Toolbox", but the package name had the underscores (I probably could do without the name argument in the global dependency list).

That is because I had to swap underscores for dashes in order to get the app to be accepted by the App Store.

UPDATE: I wanted to mention that the thing that made it for me, was the error response from the swift build command. It was awesome. It actually had the code that I needed to use. It was that response that showed me that I need to use dashes, mixed with underscores. That was not something that I was understanding.

1 Like

Just FYI. I have written up a fairly comprehensive series on implementing the SPM.

It draws from my experience converting a significant number of my projects to Swift Package Manager.

If I got anything wrong, I'd be grateful for any feedback.

Thanks!

2 Likes