从CLI运行swift测试时可以指定平台目标吗? [英] Can I specify a platform target when running swift test from the CLI?

查看:48
本文介绍了从CLI运行swift测试时可以指定平台目标吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 Package.swift 看起来像

let package = Package(
  name: "MyPackage",
  platforms: [
    .iOS(.v13)
  ],
  products: [
    .library(
      name: "MyPackage",
      targets: ["MyPackage"])
  ],
  dependencies: [
    .package(url: "https://github.com/SnapKit/SnapKit.git", from: "5.0.0"),
  ],
  targets: [
    .target(
      name: "MyPackage",
      dependencies: [
        "SnapKit",
      ]),
    .testTarget(
      name: "MyPackageTests",
      dependencies: ["MyPackage"])
  ]
)

当我运行 swift test 时,我会得到

error: the library 'MyPackage' requires macos 10.10, but depends on the product 'SnapKit' \
which requires macos 10.12; consider changing the library 'SurfUIKit' to require macos 10.12 \
or later, or the product 'SnapKit' to require macos 10.10 or earlier.

为什么要快速运行未列出为受支持平台的macOS测试?我可以迅速运行iOS测试,理想情况下指定一些版本目标吗?在CLI中使用xcode有什么替代方法?

Why is swift running tests for macos that is not listed as a supported platform? Can I get swift to run the tests for iOS, ideally specifying some version target? What alternative do I have using xcode in the CLI?

推荐答案

诀窍是:

  • 您认为 .iOS(...)在这里将编译限制为仅一个平台

  • you think that .iOS(...) is here to restrict the compilation to only one platform

这实际上是用于精确化最低版本的行,您的产品将为此平台支持

while it actually is a line used to precised what minimum version is going to be supported by your product for this platform

它没有说:仅针对.iOS X.y 进行编译,但是 .iOS的最低版本为X.y

It does not say: only compile for .iOS X.y, but .iOS min version is X.y

SPM是用于 Swift first 的工具,因此想为 all〜平台构建,并且目前无法使用〜system only参数〜(我知道我伤心太).

SPM is a tool for Swift first, thus wants to build for all~ platforms, and has currently no way of using a ~system only parameter~ (I know me sad too).

现在,如果您只想拥有iOS软件包,仍然可以,但是

Now if you want to have an iOS only Package it's still possible but you'll have to compil through xcodebuild commands (and you don't need a xcodeproj file for that).

//在iOS模拟器上进行编译和测试

xcodebuild -list

xcodebuild -scheme< scheme>-destination'generic/platform = iOS'

xcodebuild -scheme< scheme>-sdk iphonesimulator-目标'platform = iOS Simulator,name = iPhone 11'

xcodebuild -scheme< scheme>测试-sdk iphonesimulator-目标'platform = iOS Simulator,name = iPhone 11'

SPM有关取决于Apple模块"的文档用法

根据我的经验,我还会说您可能具有以下文件夹层次结构(使用xCode 12):

From my experience I would also say that you could have a folder hierarchy as follow (with xCode 12):

|根项目文件夹/

  • 源代码///您的源代码文件夹
  • Example///在其中创建一个xcodeproj
  • Tests///您的测试文件〜
  • YourPackage.xcworkspace
    • 在其中添加 root文件夹,以便能够访问您的打包目标
    • 添加示例项目(并将Package添加到其依赖项中)
    • 最终创建一个新方案,在该方案中,选择包装的测试目标
    • Source/ // folder of your sources
    • Example/ // create an xcodeproj in it
    • Tests/ // Your tests files ~
    • YourPackage.xcworkspace
      • add the root folder in it to be able to access your Package targets
      • add your example project (and add your Package to its dependencies)
      • finally create a new scheme in which you select the Test target of your package

      现在,您已经准备就绪,可以与示例和测试并行地开发Package.

      Now you're all setup to develop your Package in parallele with your example and tests.

      请记住,Swift Package Manager当前(12/2020)没有参数只能在一个平台上构建.

      And remember that Swift Package Manager currently (12/2020) has no parameter to only build on one platform.

      希望很清楚.

      这篇关于从CLI运行swift测试时可以指定平台目标吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆