简体   繁体   English

Swift Package 管理器的奇怪依赖问题

[英]Strange Dependency Issue With Swift Package Manager

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 made a similar post on the Swift Forums. 我也在 Swift 论坛上发表了类似的帖子。

I havethis package , which is consumed by this package , which is, in turn, consumed by this app .我有这个 package ,它被这个 package消耗,而它又被这个应用消耗。 The first package is also consumed by this package , which is also consumed by the app . 第一个 package也被这个 package消耗,它也被应用程序消耗。 That chain works fine, but is also a great deal simpler.该链工作正常,但也简单得多。

The issue is that I get an error inside the RVS_BlueThoth package during the BlueVanClef build.问题是在BlueVanClef构建期间,我在 RVS_BlueThoth package中遇到错误。

The error is consistent withthe RVS_Generic_Swift_Toolbox package not building in the RVS_BlueThoth package build (the module is not available), but I can't figure out why.该错误与未在RVS_BlueThoth package 构建中构建的 RVS_Generic_Swift_Toolbox package 一致(该模块不可用),但我不知道为什么。 There is nothing but a blank serialized diagnostics file for one of the files that consumesthe RVS_Generic_Swift_Toolbox module, and no other errors, other than the file isn't there.对于使用 RVS_Generic_Swift_Toolbox模块的文件之一,只有一个空白的序列化诊断文件,除了文件不存在之外,没有其他错误。

If I build the RVS_BlueThoth package independently, I have no issues, but including it in the BlueVanClef app consistently reports this error.如果我独立构建RVS_BlueThoth package ,我没有问题,但将它包含在BlueVanClef 应用程序中始终会报告此错误。

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?) (例如,是否有任何可用于 SPM 的诊断实用程序?)

Here's a diagram of the dependencies:下面是依赖关系图:

包层次结构图

Note the dotted line between RVS_BlueThoth and RVS_Persistent_Prefs.请注意 RVS_BlueThoth 和 RVS_Persistent_Prefs 之间的虚线。 That's because the dependency is only for test harnesses, and is not used by Blue Van Clef.这是因为依赖项仅适用于测试工具,Blue Van Clef 不使用该依赖项。

Here are the various Package.swift Files:以下是各种 Package.swift 文件:

RVS_Generic_Swift_Toolbox : 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_Persistent_Prefs (This one works): RVS_Persistent_Prefs (这个有效):

// 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): RVS_BlueThoth (这个不行):

// 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"
        )
    ]
)

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 .最好的调试方法是cd到 package 目录,然后执行swift build That helped me to see the errors as they happened (They were not reflected in the Xcode logs).这帮助我看到了发生的错误(它们没有反映在 Xcode 日志中)。

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:这已通过将 RVS_BlueThoth Package.swift 文件更改为如下方式修复:

// 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).请注意, name参数是"RVS-Generic-Swift-Toolbox" ,而不是"RVS_Generic_Swift_Toolbox" ,但 package 名称有下划线(我可能可以在全局依赖项列表中不使用name参数)。

That is because I had to swap underscores for dashes in order to get the app to be accepted by the App Store .那是因为我必须将下划线换成破折号才能让应用程序被 App Store 接受

I was also able to simplify the dependency chain a bit, because some dependencies were only required for test harnesses.我还能够稍微简化依赖链,因为某些依赖关系只需要测试工具。

UPDATE: I wanted to mention that the thing that made it for me, was the error response from the swift build command.更新:我想提一下,为我做的事情是来自swift build命令的错误响应。 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.那不是我所理解的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM