Skip to content

Commit

Permalink
Fix to compile & run with Swift 6+.
Browse files Browse the repository at this point in the history
Signed-off-by: furby™ <[email protected]>
  • Loading branch information
furby-tm committed Oct 31, 2024
1 parent a8beb04 commit d3cdfec
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ xcuserdata/
Package.resolved

.swift-version

.vscode
26 changes: 20 additions & 6 deletions Sources/PackageCollectionGenerator/PackageCollectionGenerate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import TSCUtility
import Utilities

@main
public struct PackageCollectionGenerate: ParsableCommand {
public struct PackageCollectionGenerate: AsyncParsableCommand {
public static let configuration = CommandConfiguration(
abstract: "Generate a package collection from the given list of packages."
)
Expand Down Expand Up @@ -65,7 +65,7 @@ public struct PackageCollectionGenerate: ParsableCommand {

public init() {}

public func run() throws {
public func run() async throws {
Backtrace.install()

// Parse auth tokens
Expand All @@ -91,9 +91,9 @@ public struct PackageCollectionGenerate: ParsableCommand {
let githubPackageMetadataProvider = GitHubPackageMetadataProvider(authTokens: authTokens)

// Generate metadata for each package
let packages: [Model.Collection.Package] = input.packages.compactMap { package in
let packages: [Model.Collection.Package] = await input.packages.asyncMap { package in
do {
let packageMetadata = try self.generateMetadata(for: package, metadataProvider: githubPackageMetadataProvider, jsonDecoder: jsonDecoder)
let packageMetadata = try await self.generateMetadata(for: package, metadataProvider: githubPackageMetadataProvider, jsonDecoder: jsonDecoder)
print("\(packageMetadata)", verbose: self.verbose)

guard !packageMetadata.versions.isEmpty else {
Expand Down Expand Up @@ -147,7 +147,7 @@ public struct PackageCollectionGenerate: ParsableCommand {

private func generateMetadata(for package: PackageCollectionGeneratorInput.Package,
metadataProvider: PackageMetadataProvider,
jsonDecoder: JSONDecoder) throws -> Model.Collection.Package {
jsonDecoder: JSONDecoder) async throws -> Model.Collection.Package {
print("Processing Package(\(package.url))", inColor: .cyan, verbose: self.verbose)

// Try to locate the directory where the repository might have been cloned to previously
Expand Down Expand Up @@ -207,7 +207,9 @@ public struct PackageCollectionGenerate: ParsableCommand {
jsonDecoder: JSONDecoder) throws -> Model.Collection.Package {
var additionalMetadata: PackageBasicMetadata?
do {
additionalMetadata = try temp_await { callback in metadataProvider.get(package.url, callback: callback) }
try metadataProvider.get(package.url) { callback in
additionalMetadata = callback.success
}
} catch {
printError("Failed to fetch additional metadata: \(error)")
}
Expand Down Expand Up @@ -419,3 +421,15 @@ extension PackageCollectionModel.V1.ProductType.LibraryType {
}
}
}

extension Sequence {
func asyncMap<T>( _ transform: (Element) async throws -> Optional<T> ) async rethrows -> [T] {
var values = [T]()
for element in self {
if let element = try await transform(element) {
try values.append(element)
}
}
return values
}
}

0 comments on commit d3cdfec

Please sign in to comment.