I'm trying to learn SPM by making a simple standalone Swift Package with Xcode 11. So far so good
I'm now trying to add a Build Phase script to execute SwiftLint when I run my Package's unit-tests locally in Xcode.
While reading the SPM documentation, i found that many of the Xcode concepts I'm familiar with can be described in the
Package.swift manifest (e.g. targets, products, build-settings, build-configurations...).
I found nothing about Schemes in the documentation, but I noticed that Xcode automatically creates a hidden
.swiftpm directory which can then contain my Schemes .
But I still haven't found an easy way to run a Build-Phase script, like in my other Xcode projects.
I tried creating a dummy Xcode project inside my Package's root directory, which would then reference the Package itself and add a Build-Phase script here. But with this kind of circular reference, it feels like I'm doing it wrong. Also my dummy project would get included in every App that depends on my Package.
I also thought about creating a dummy project inside another Git repository that then depends on my Package. But having to create 2 repositories for every Package also feels wrong.
Some tutorials suggest running scripts as a Git pre-commit hook, or maybe as a Scheme pre-action, but I would lose the nice integration of SwiftLint with Xcode's source code editor.
Has anyone found an elegant solution to this problem? Ideally a solution that would also work nicely if I decide to add my Package to a CI system. Am I missing something obvious?