1

多年来,我一直在使用服务器端 Swift 进行服务器端开发,并使用 Xcode 作为方便的编辑工具。现在 Xcode 已经支持 Swift 包,情况总体上有所改善。我没有针对任何传统的 Apple 硬件,所以这可能是我的问题的根源,但鉴于这个问题最近才开始出现,我正在报告它以防其他人也遇到它。

使用我的一个包: http: //github.com/SyncServerII/ServerDropboxAccount.git 我不能再用 Xcode 构建它。

我的意图主要是编辑和消除语法错误——即,我使用 Xcode 作为编辑器。在某些情况下,使用这些服务器端包,我可以在 Xcode 中运行单元测试。在某些情况下,我必须在我的 Ubuntu 目标平台上运行测试。

就在过去的几天里,我不能再在 Xcode 中构建这个特定的包,也不能在 Mac OS 的命令行中构建。

我收到这样的错误:

/Users/chris/Desktop/NewSyncServer/ServerDropboxAccount/Sources/ServerDropboxAccount/DropboxCreds+CloudStorage.swift:140:37: Cannot find type 'APICallResult' in scope
/Users/chris/Desktop/NewSyncServer/ServerDropboxAccount/Sources/ServerDropboxAccount/DropboxCreds.swift:16:29: Cannot find type 'AccountAPICall' in scope
/Users/chris/Desktop/NewSyncServer/ServerDropboxAccount/Sources/ServerDropboxAccount/DropboxCreds.swift:16:45: Cannot find type 'Account' in scope
/Users/chris/Desktop/NewSyncServer/ServerDropboxAccount/Sources/ServerDropboxAccount/DropboxCreds+CloudStorage.swift:49:14: Value of type 'DropboxCreds' has no member 'apiCall'
/Users/chris/Desktop/NewSyncServer/ServerDropboxAccount/Sources/ServerDropboxAccount/DropboxCreds+CloudStorage.swift:49:111: Cannot infer contextual base in reference to member 'string'
/Users/chris/Desktop/NewSyncServer/ServerDropboxAccount/Sources/ServerDropboxAccount/DropboxCreds+CloudStorage.swift:49:147: Cannot infer contextual base in reference to member 'json'
/Users/chris/Desktop/NewSyncServer/ServerDropboxAccount/Sources/ServerDropboxAccount/DropboxCreds+CloudStorage.swift:106:14: Value of type 'DropboxCreds' has no member 'apiCall'
/Users/chris/Desktop/NewSyncServer/ServerDropboxAccount/Sources/ServerDropboxAccount/DropboxCreds+CloudStorage.swift:106:133: Cannot infer contextual base in reference to member 'data'
/Users/chris/Desktop/NewSyncServer/ServerDropboxAccount/Sources/ServerDropboxAccount/DropboxCreds+CloudStorage.swift:106:167: Cannot infer contextual base in reference to member 'json'
/Users/chris/Desktop/NewSyncServer/ServerDropboxAccount/Sources/ServerDropboxAccount/DropboxCreds+CloudStorage.swift:106:190: Unable to infer type of a closure parameter 'apiResult' in the current context
/Users/chris/Desktop/NewSyncServer/ServerDropboxAccount/Sources/ServerDropboxAccount/DropboxCreds+CloudStorage.swift:106:201: Unable to infer type of a closure parameter 'statusCode' in the current context

swift build当我在 Mac OS 的命令行中使用时,我得到了同样的错误。但是,当我swift build在 Ubuntu 上使用时,我没有收到任何错误 - 包构建得很干净。

在 Mac 操作系统上:

MacBook-Pro-4:ServerDropboxAccount chris$ swift --version
Apple Swift version 5.3.2 (swiftlang-1200.0.45 clang-1200.0.32.28)
Target: x86_64-apple-darwin19.6.0

在 Ubuntu 上:

root@7b763a0a0a3f:~/Apps/ServerDropboxAccount# swift --version
Swift version 5.3.1 (swift-5.3.1-RELEASE)
Target: x86_64-unknown-linux-gnu

这可能是一个边缘用例,但在我完全放弃使用 Xcode 之前,我想了解为什么会发生这种情况。想法受到赞赏。谢谢!

我在这个问题中包含了一个标签,Kitura因为我的服务器是基于 Kitura 的。而且因为 Kitura 最近经历了一些转变,从 IBM 转移到社区支持。

4

1 回答 1

1

嗯,我现在觉得很傻。我在依赖库中的一个文件中有一个条件,它排除了一些代码。

#if os(Linux) || SERVER

// Code

#endif

我将留下这个问题只是为了显示修复。我需要SERVER在 Package.swift 中为该依赖库添加一个定义:

        .target(
            name: "ServerAccount",
            dependencies: [
                "ServerShared",
                // For new condition feature, see https://forums.swift.org/t/package-manager-conditional-target-dependencies/31306/26
                .product(name: "Kitura", package: "Kitura", condition: .when(platforms: [.linux, .macOS])),
                .product(name: "HeliumLogger", package: "HeliumLogger", condition: .when(platforms: [.linux, .macOS])),
                .product(name: "Credentials", package: "Kitura-Credentials", condition: .when(platforms: [.linux, .macOS])),
            ],
            swiftSettings: [
                // So I can do basic development and editing with this on Mac OS. Otherwise if some dependent library uses this it will not get Account related code. See Account.swift.
                .define("SERVER", .when(platforms: [.macOS], configuration: .debug)),
            ]),

哎呀。:)。

于 2020-12-26T04:36:50.770 回答