# How to run a Build-Phase script when building a standalone Swift Package in Xcode?

**URL:** <https://forums.swift.org/t/how-to-run-a-build-phase-script-when-building-a-standalone-swift-package-in-xcode/40117>\
**Category:** Using Swift\
**Tags:** xcode, packagemanager\
**Created:** [September 8, 2020, 5:50pm UTC](https://forums.swift.org/t/how-to-run-a-build-phase-script-when-building-a-standalone-swift-package-in-xcode/40117 "2020-09-08T17:50:41Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![SDGGiesbrecht](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/sdggiesbrecht/32/4768_2.png) [@SDGGiesbrecht](https://forums.swift.org/u/SDGGiesbrecht)\
**Post date:** [September 8, 2020, 6:22pm UTC](https://forums.swift.org/t/how-to-run-a-build-phase-script-when-building-a-standalone-swift-package-in-xcode/40117/2 "2020-09-08T18:22:24Z")

</div>

(Disclaimer: This information relates to Xcode 11. I haven’t tried any of this in the Xcode 12 betas to know if any of it is out of date.)

The Xcode project will be completely ignored by any package clients.

SwiftPM has no equivalent of custom schemes. There is `--configuration debug` and `--configuration release` and that is all. (Well, you can add stuff to `.swiftpm` for some development time tweaks, but clients will not inherit it and you cannot inject build steps.)

External scripts are not supported. The feature you would need to do this “right” (known usually as “extensible build tools” been [much talked about](https://forums.swift.org/t/package-manager-extensible-build-tools/10900) but not implemented so far.

What I do for static analysis tools providing inline warnings is to script `swift package generate-xcodeproj` and the insertion of a build phase. Then I quickly run that when I want to find a bunch of warnings quickly. But I don’t keep the Xcode project around all the time.

If you have CI, just add it as a separate step outside of `swift test`.

Since SwiftLint is itself a package, an alternative workaround would be to add it as a dependency of your test target. Then you can use `#file` or other shenanigans to locate the produced executable and launch it with `Process` inside the tests. (But to be honest I don’t think static analysis belongs inside unit tests in the first place, although that is just my opinion.)

---

_[View the full topic](https://forums.swift.org/t/how-to-run-a-build-phase-script-when-building-a-standalone-swift-package-in-xcode/40117)._
