How to resolve Swift Package Manager target overlapping sources error

萝らか妹 提交于 2020-08-09 06:58:19

问题


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.

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.

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...


回答1:


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

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.

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.

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.

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



来源:https://stackoverflow.com/questions/60067701/how-to-resolve-swift-package-manager-target-overlapping-sources-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!