How to test a developing package with Swift Package Manager

Issue #525

Use macOS Command Line project

Example Puma

  • Create a new macOS project, select Command Line ToolScreenshot 2019-11-30 at 22 40 35
  • Drag Puma.xcodeproj as a sub project of our test project
  • Go to our TestPuma target, under Link Binary with Libraries, select Puma framework
Screenshot 2019-11-30 at 22 41 18
  • Puma has dependencies on PumaCore and PumaiOS, but in Xcode we only need to select Puma framework

  • In code, we need to explicitly import PumaiOS framework if we use any of its classes

1
2
3
4
5
6
7
8
9
10
11
import Foundation
import Puma
import PumaiOS

func testDrive() {
run {
SetVersionNumber {
$0.buildNumberForAllTarget("1.1")
}
}
}
  • As our Puma.xcodeproj is inside this test project, we can drill down into our Puma.xcodeproj and update the code.

Workspace

Instead of dragging Puma as a subproject of TestPuma, we can use workspace, and link Puma frameworks

Screenshot 2019-12-14 at 21 36 32

Troubleshooting

Code signing for frameworks

To avoid signing issue, we need to select a Team for all frameworks

not valid for use in process using Library Validation: mapped file has no Team ID and is not a platform binary (signed with custom identity or adhoc?

Library not loaded

Need to set runpath search path, read https://stackoverflow.com/questions/28577692/macos-command-line-tool-with-swift-cocoa-framework-library-not-loaded

Specify LD_RUNPATH_SEARCH_PATHS = @executable_path in Build Settings

missing required module ‘clibc’

Take a look at Puma -> SPMLibc, there’s header search path

1
$(SRCROOT)/.build/checkouts/swift-package-manager/Sources/clibc/include

which is at the .build folder inside root

Screenshot 2019-12-14 at 21 55 30

So for our TestPuma target, we need to add this header search path with the correct path

1
$(SRCROOT)/../../.build/checkouts/swift-package-manager/Sources/clibc/include
Screenshot 2019-12-14 at 21 55 55

Read more

Comments