Last active
July 10, 2017 02:26
-
-
Save tonisuter/1734db055a56ce81bd9f4a69f0e49b01 to your computer and use it in GitHub Desktop.
Testing libSwiftPM
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Basic | |
import PackageGraph | |
import PackageLoading | |
import Workspace | |
class MyWorkspaceDelegate: WorkspaceDelegate { | |
func packageGraphWillLoad(currentGraph: PackageGraph, dependencies: AnySequence<ManagedDependency>, missingURLs: Set<String>) { | |
print("packageGraphWillLoad") | |
} | |
func fetching(repository: String) { | |
print("fetching \(repository)") | |
} | |
func cloning(repository: String) { | |
print("cloning \(repository)") | |
} | |
func checkingOut(repository: String, at reference: String) { | |
print("checking out \(repository)") | |
} | |
func removing(repository: String) { | |
print("removing \(repository)") | |
} | |
func warning(message: String) { | |
print("warning \(message)") | |
} | |
func managedDependenciesDidUpdate(_ dependencies: AnySequence<ManagedDependency>) { | |
print("managedDependenciesDidUpdate") | |
} | |
} | |
struct MyManifestResourceProvider: ManifestResourceProvider { | |
var swiftCompiler = AbsolutePath("/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift") | |
var libDir = AbsolutePath("/Users/tonisuter/Projects/swift-package-manager/.build/lib/swift/pm") | |
} | |
func printManifest(pkgPath: AbsolutePath) { | |
let manifestLoader = ManifestLoader(resources: MyManifestResourceProvider()) | |
let workspace = Workspace( | |
dataPath: pkgPath.appending(component: ".build"), | |
editablesPath: pkgPath.appending(component: "Packages"), | |
pinsFile: pkgPath.appending(component: "Package.pins"), | |
manifestLoader: manifestLoader, | |
delegate: MyWorkspaceDelegate() | |
) | |
let diagnosticsEngine = DiagnosticsEngine() | |
let manifests = workspace.loadRootManifests(packages: [pkgPath], diagnostics: diagnosticsEngine) | |
if let manifest = manifests.first { | |
print(manifest) | |
} else { | |
for diagnostic in diagnosticsEngine.diagnostics { | |
print(diagnostic.localizedDescription) | |
} | |
} | |
} | |
printManifest(pkgPath: AbsolutePath("/Users/tonisuter/Downloads/MyProj")) |
The problem was that I used the libSwiftPM
library from the master branch, but the libDir
path was set to /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/pm
(i.e., the folder that contains the libPackageDescription.dylib
of the current version of Xcode). Instead, I had to execute the following command in the Swift Package Manager repository:
<Path-To-SwiftPM-Repository>/Utilities/bootstrap --libswiftpm-library-dir "/tmp/libSwiftPM/install/dir/include" --libswiftpm-modules-dir "/tmp/libSwiftPM/install/dir/lib"
Finally, the libDir
path needs to be set to <Path-To-SwiftPM-Repository>/.build/lib/swift/pm
.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
My file structure looks like this and additionally, there's a regular, empty SwiftPM project at the path
/Users/tonisuter/Downloads/MyProj
:And I am using the following command to compile and run
main.swift
:However, when I run the command I get the following error: