简体   繁体   English

Swift Package 管理器依赖镜像

[英]Swift Package Manager Dependency Mirroring

I have a project and:我有一个项目,并且:

  • the company I'm working with is self-hosting their git我正在合作的公司是自托管他们的 git
  • the CI can communicate only with company's network CI 只能与公司的网络通信

That being said, if I want to install any dependency, I have to ask their dev ops to mirror the target repository and only then I can use it.话虽如此,如果我想安装任何依赖项,我必须让他们的开发人员镜像目标存储库,然后我才能使用它。

The problem arises when I want to implement Crashlytics which has a lot of dependencies.当我想实现具有很多依赖项的 Crashlytics 时,就会出现问题。 When I import the Firebase, it's fetched from the mirrored repo correctly, but it's dependencies are still being fetched from the original URLs (which makes perfect sense).当我导入 Firebase 时,它是从镜像仓库中正确获取的,但它的依赖项仍然是从原始 URL 中获取的(这很有意义)。

The question is - How do I tell Swift Package Manager to swap each URL with mirrors ?问题是 -我如何告诉 Swift Package 经理用镜子交换每个 URL I have all the dependencies mirrored.我已经镜像了所有依赖项。 I only need to tell SPM to use it.我只需要告诉 SPM 使用它。

I have found this proposal which was implemented in Swift 5, but when I go to root of my project and run:我发现这个提案是在 Swift 5 中实现的,但是当我将 go 放到我的项目的根目录并运行时:

$ swift package config set-mirror --package-url <original URL> --mirror-url <mirror URL>

I get this error:我收到此错误:

error: root manifest not found

Any ideas how to do this correctly?任何想法如何正确地做到这一点? Thank you谢谢

EDIT:编辑:

As Florian correctly pointed out, the proposal works from the package's repository, not my projects: So:正如弗洛里安正确指出的那样,该提案适用于包的存储库,而不是我的项目:所以:

  1. I do clone mirrored repo in my project's root我确实在项目的根目录中克隆了镜像仓库
  2. I run set of commands to set mirror url for each dependency:我运行一组命令为每个依赖项设置镜像 url:
swift package config set-mirror \
    --original-url https://github.com/google/GoogleAppMeasurement.git \
    --mirror-url <company's url>/mirrors/githubcom-google-GoogleAppMeasurement
  1. I go back to projects root and run:我 go 回到项目根目录并运行:
xcodebuild -resolvePackageDependencies -project MyProject.xcodeproj -scheme MyAppScheme

But it's still fetching from original urls, not the mirrors!但它仍然从原始网址获取,而不是从镜像中获取!

Having an Xcode project makes this task basically impossible.拥有 Xcode 项目使这项任务基本上不可能完成。 Xcode's integration with SPM works fine for most things, but is not (yet?) at par with what SPM can do in pure SPM packages. Xcode 与 SPM 的集成在大多数情况下都可以正常工作,但还不能(还没有?)与 SPM 在纯 SPM 包中的功能相提并论。

The problem is, that swift package config is alway only local to the package and does not have any effect on projects / packages that depend on the package. The problem is, that swift package config is alway only local to the package and does not have any effect on projects / packages that depend on the package. And with Xcode currently having no counterpart to swift package config , it's not possible to do this at the moment.并且由于 Xcode 目前没有对应于swift package config ,目前无法执行此操作。

What you could do, however, is to clone all your dependencies locally and then reference them as local packages from Xcode (simply dragging the package folder onto Xcode will do so).但是,您可以做的是在本地克隆所有依赖项,然后将它们作为本地包从 Xcode 引用(只需将 package 文件夹拖到 ZA3B5EBD8A1E9EBF44A172E80D5A7D3A 上即可)。 Xcode will be smart enough to take the dependencies from the local local checkout (or at least it was smart enough last time I tried this). Xcode 将足够聪明,可以从本地本地结帐中获取依赖项(或者至少在我上次尝试这个时它足够聪明)。

Let's hope for a future Xcode version with full SPM support!让我们期待未来的 Xcode 版本完全支持 SPM!

I second what Florian said - there seems not to be a straightforward way to set mirrors for SPM in Xcode projects yet.我赞同 Florian 所说的 - 在 Xcode 项目中,似乎还没有一种直接的方法来为 SPM 设置镜像。

Not sure if it's a bug, but following this proposal results in fetching dependencies from the original URL, not mirrored even though it's correctly updated inside the .swiftpm/config .不确定这是否是一个错误,但遵循这个建议会导致从原始 URL 获取依赖项,即使它在.swiftpm/config中正确更新,也没有镜像。

There is, however, a workaround for this.但是,有一个解决方法。 I will continue using Crashlytics as an example.我将继续以 Crashlytics 为例。 You have to clone the Firebase repository inside the root of your project (don't forget to add it in your .gitignore ) and edit its Package.swift file - replace the URL of each dependency with your mirror. You have to clone the Firebase repository inside the root of your project (don't forget to add it in your .gitignore ) and edit its Package.swift file - replace the URL of each dependency with your mirror. Copy this file somewhere in your project and commit it (CI will replace the cloned package file with the edited one).将此文件复制到项目中的某个位置并提交(CI 将用已编辑的文件替换克隆的 package 文件)。 Finally, run a command to resolve packages and you will see the mirrors gets fetched.最后,运行一个命令来解析包,你会看到镜像被获取。 Not very sophisticated, but works.不是很复杂,但很有效。

Script for the CI can look like this: CI 的脚本可能如下所示:

cd <path to root of the project>
git clone <mirrored repo>
rm ./firebase-mirror-repo/Package.swift
cp ./Resources/Package.swift ./firebase-mirror-repo/
xcodebuild -resolvePackageDependencies

I have decided not to use this hack, nor any dependency manager in this case.在这种情况下,我决定不使用这个 hack,也不使用任何依赖管理器。 I have all the dependencies as .xcframework s and store them in artifactory.我将所有依赖项作为.xcframework并将它们存储在工件中。 CI fetches all the dependencies including Crashlytics from artifactory in each run. CI 在每次运行中从工件中获取所有依赖项,包括 Crashlytics。 Frameworks are in .gitignore and I never commit them.框架在.gitignore中,我从不提交它们。

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

相关问题 Swift Package 管理器 - 排除依赖项 - Swift Package Manager - Exclude dependency 使用Swift Package Manager添加依赖项 - Adding a dependency using Swift Package Manager 如何使用 Swift package 管理器添加依赖项 - How to add dependency using Swift package manager 具有 Swift Package Manager 依赖项的项目的 Github Actions - Github Actions for project with Swift Package Manager dependency 使用 Swift Package 管理器为二进制目标添加 package 依赖项 - Add package dependency for a binary target with Swift Package Manager 使用 Swift Package Manager 时如何导入包的依赖? - How to import a package's dependency when using Swift Package Manager? Swift 包管理器 - 复制动态依赖项的文件构建阶段 - Swift Package Manager - copy files build phase for a dynamic dependency 如何在 Swift 包管理器中添加二进制框架作为依赖项? - How to add Binary framework in Swift Package Manager as dependency? Swift Package 管理器 - 将 package 依赖项添加到您的 Package.swift 以进行本机反应 - Swift Package Manager - add the package dependency to your Package.swift for react native Xcode 13 Swift Package 管理器依赖命令 CompileSwiftSources 失败,出现非零退出代码错误 - Xcode 13 Swift Package Manager Dependency Command CompileSwiftSources failed with a nonzero exit code Error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM