I asked about mirroring and caching dependencies, over on the Swift forums, and I got an answer that I think might be helpful. It turns out that not too long ago, swift package manager added support for mirroring dependencies. It does this on a per-project basis, rather than being a global setting, which I can see how that’s probably a good thing. The proposal outlining how this works is described here.
So, it looks like the way to set up mirroring for a single project would be to do something like this:
- Resolve all the dependencies. Straightforwardly,
swift build
. - Go through the Package.resolved file (which is JSON) and for each dependency’s repositoryURL, do a git clone of that repository into a mirror directory on the local machine.
- After cloning, go to your project’s directory and do a swift package config set-mirror —original-url <repositoryURL> —mirror-url <file://absolute_path_to_cloned_repo>
Now, you should be able to disconnect from the network and still be able to build your project, even if you delete the project’s .build folder. To update the mirrors, you’d want to go through the local mirror directory and for each child directory, go in and do a git pull, to fetch any updates.
And all of *that* feels like the sort of thing that a shell script, or maybe Perl, could do. Hmmmm.