Skip to content

Replace package manifest parsing with PackageManifestKit #204

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ let package = Package(
from: "4.0.1"),
.package(url: "https://github.com/giginet/scipio-cache-storage.git",
from: "1.0.0"),
.package(url: "https://github.com/giginet/PackageManifestKit",
from: "0.1.0")
],
targets: [
.executableTarget(
Expand All @@ -63,6 +65,7 @@ let package = Package(
.product(name: "Algorithms", package: "swift-algorithms"),
.product(name: "Rainbow", package: "Rainbow"),
.product(name: "ScipioStorage", package: "scipio-cache-storage"),
.product(name: "PackageManifestKit", package: "PackageManifestKit")
],
swiftSettings: swiftSettings,
plugins: [
Expand Down
38 changes: 31 additions & 7 deletions Sources/ScipioKit/DescriptionPackage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@ import PackageModel
import PackageLoading
// We may drop this annotation in SwiftPM's future release
@preconcurrency import PackageGraph
import PackageManifestKit

struct DescriptionPackage: PackageLocator {
let mode: Runner.Mode
let packageDirectory: TSCAbsolutePath
private let toolchain: UserToolchain
let workspace: Workspace
let graph: ModulesGraph
let manifest: Manifest
let manifest: PackageManifestKit.Manifest
let jsonDecoder = JSONDecoder()

enum Error: LocalizedError {
case packageNotDefined
Expand All @@ -31,11 +33,11 @@ struct DescriptionPackage: PackageLocator {
// MARK: Properties

var name: String {
manifest.displayName
manifest.name
}

var supportedSDKs: Set<SDK> {
Set(manifest.platforms.map(\.platformName).compactMap(SDK.init(platformName:)))
Set(manifest.platforms?.map(\.platformName).compactMap(SDK.init(platformName:)) ?? [])
}

// MARK: Initializer
Expand All @@ -58,6 +60,26 @@ struct DescriptionPackage: PackageLocator {
return workspace
}

private static func makeManifest(
packageDirectory: TSCAbsolutePath,
jsonDecoder: JSONDecoder,
executor: some Executor
) async throws -> PackageManifestKit.Manifest {
let commands = [
"/usr/bin/xcrun",
"swift",
"package",
"dump-package",
"--package-path",
packageDirectory.pathString,
]

let manifestString = try await executor.execute(commands).unwrapOutput()
let manifest = try jsonDecoder.decode(PackageManifestKit.Manifest.self, from: manifestString)

return manifest
}

/// Make DescriptionPackage from a passed package directory
/// - Parameter packageDirectory: A path for the Swift package to build
/// - Parameter mode: A Scipio running mode
Expand All @@ -69,7 +91,8 @@ struct DescriptionPackage: PackageLocator {
packageDirectory: TSCAbsolutePath,
mode: Runner.Mode,
onlyUseVersionsFromResolvedFile: Bool,
toolchainEnvironment: ToolchainEnvironment? = nil
toolchainEnvironment: ToolchainEnvironment? = nil,
executor: some Executor = ProcessExecutor(decoder: StandardOutputDecoder())
) async throws {
self.packageDirectory = packageDirectory
self.mode = mode
Expand Down Expand Up @@ -100,9 +123,10 @@ struct DescriptionPackage: PackageLocator {
observabilityScope: scope
)
#endif
self.manifest = try await workspace.loadRootManifest(
at: packageDirectory.spmAbsolutePath,
observabilityScope: scope
self.manifest = try await Self.makeManifest(
packageDirectory: packageDirectory,
jsonDecoder: jsonDecoder,
executor: executor
)
self.workspace = workspace
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/ScipioKitTests/CacheSystemTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ final class CacheSystemTests: XCTestCase {
let testingPackage = descriptionPackage
.graph
.packages
.first { $0.manifest.displayName == descriptionPackage.manifest.displayName }!
.first { $0.manifest.displayName == descriptionPackage.manifest.name }!

let myTarget = testingPackage.modules.first { $0.name == "MyTarget" }!
let cacheTarget = CacheSystem.CacheTarget(
Expand Down
4 changes: 2 additions & 2 deletions Tests/ScipioKitTests/RunnerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ final class RunnerTests: XCTestCase {
outputDirectory: frameworkOutputDir
)
let packages = descriptionPackage.graph.packages
.filter { $0.manifest.displayName != descriptionPackage.manifest.displayName }
.filter { $0.manifest.displayName != descriptionPackage.manifest.name }

let allTargets = packages
.flatMap { package in
Expand Down Expand Up @@ -508,7 +508,7 @@ final class RunnerTests: XCTestCase {
outputDirectory: frameworkOutputDir
)
let packages = descriptionPackage.graph.packages
.filter { $0.manifest.displayName != descriptionPackage.manifest.displayName }
.filter { $0.manifest.displayName != descriptionPackage.manifest.name }

let allTargets = packages
.flatMap { package in
Expand Down