如何解决 Swift Package Manager 目标重叠源错误 [英] How to resolve Swift Package Manager target overlapping sources error

查看:75
本文介绍了如何解决 Swift Package Manager 目标重叠源错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 GitHub 存储库,它是一个 Objective-C 项目,它定义了多个目标(每个目标操作系统一个:macOS、iOS、tvOS 等).这些目标共享项目的大部分源代码文件.

I have a GitHub repo that is an Objective-C project that defines multiple targets (one per each targeted OS: macOS, iOS, tvOS, etc.). These targets share most of the source code files of the project.

我正在尝试向项目添加 SPM 支持,并在 Package.swift 文件中定义匹配目标,源 path 引用包含跨目标共享的那些源代码文件的同一文件夹.

I am trying to add SPM support to the project and in the Package.swift file I define matching targets with source path referring to the same folder containing those source code files shared across the targets.

当我将此 SPM-启用"项目/包添加到尝试通过 SPM 将其用作依赖项的测试项目时,我收到一条错误消息,指出依赖项包中的第二个目标与另一个目标具有重叠源(第一个使用相同的共享源代码文件).

When I add this SPM-"enabled" project/package to a test project that is trying to use it as a dependency via SPM, I get an error saying that the second target in the dependency package having overlapping sources with another target (the first one that uses the same shared source code files).

关于如何解决问题的任何想法?我假设我在共享源代码文件上的多目标配置不是那么独特...

Any ideas about how to fix the problem? I would assume my multi-target configuration over the shared source code files is not that uniqueue...

推荐答案

我终于弄清楚问题出在哪里以及应该如何解决.

I finally figured out what was the problem and what should be a solution to it.

我的错误是认为 SPM 目标与 Xcode 的想法相同.实际上,SPM 目标本质上是命名文件夹,其中包含需要构建以生成一个或多个产品的源代码文件.他们不假设有关如何构建的配方定义(Xcode 目标的方式).但是,依赖于给定 SPM 包的代码库确实会应用其 Xcode 目标来构建自身和依赖项(在构建自己的代码库之前).SPM 目标与目标设备完全无关.

My mistake was to think of SPM targets the same way Xcode thinks of them. In reality, SPM targets are essentially named folder containing source code files that need to be built to produce a product or products. They do not assume a definition of a recipe regarding how to build (the way Xcode targets do). However, a codebase that depends on a given SPM package does apply its Xcode targets to build itself and the dependency (prior to building its own codebase). The SPM targets are completely agnostic to the targeted device.

因此,当我尝试将我的所有 Xcode 目标映射为类似的 SPM 目标(同时引用来自多个 SPM 目标的相同源代码文件)时,从 SPM 的角度来看这是错误的.

Hence, when I tried to map all my Xcode targets as similar SPM targets (at the same time referring to the same source code files from multiple SPM targets) it was wrong from the SPM point of view.

正确的解决方案是在单个代码库位置(路径)上定义单个 SPM 目标,然后一切顺利.

The correct solution anded up to be a definition of a single SPM target over a single codebase location (path) and everything went well from there.

这是一个很好的视频,它很好地解释了 SPM 概念,随后引导我找到了可行的解决方案:创建 Swift 包

Here is a good video that explains the SPM concepts well and that subsequently led me towards the working solution: Creating Swift Packages

这篇关于如何解决 Swift Package Manager 目标重叠源错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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