From d0646326435bea789db0b583c0a01f33009ee564 Mon Sep 17 00:00:00 2001 From: Tristan Labelle Date: Sat, 21 Sep 2024 08:05:12 -0400 Subject: [PATCH] Rename --support to --spm-support-package and improve format of url references (#311) --- .../SwiftWinRT/CommandLineArguments.swift | 4 +-- .../SwiftWinRT/Writing/SwiftPackageFile.swift | 33 +++++++++++-------- Generator/Sources/SwiftWinRT/main.swift | 2 +- .../Build-WinRTComponentProjection.ps1 | 2 +- InteropTests/CMakeLists.txt | 2 +- InteropTests/GenerateProjection.cmake | 14 ++++---- 6 files changed, 32 insertions(+), 25 deletions(-) diff --git a/Generator/Sources/SwiftWinRT/CommandLineArguments.swift b/Generator/Sources/SwiftWinRT/CommandLineArguments.swift index 7500f24..51f35ef 100644 --- a/Generator/Sources/SwiftWinRT/CommandLineArguments.swift +++ b/Generator/Sources/SwiftWinRT/CommandLineArguments.swift @@ -28,8 +28,8 @@ struct CommandLineArguments: ParsableCommand { @Flag(name: .customLong("spm"), help: "Generate a package.swift file for building with SPM.") var generatePackageDotSwift: Bool = false - @Option(name: .customLong("support"), help: .init("The directory path or url:branch or url@revision of the support package to use.", valueName: "dir-or-url")) - var supportPackageLocation: String = "https://github.com/tristanlabelle/swift-winrt.git:main" + @Option(name: .customLong("spm-support-package"), help: .init("The directory path or '#branch=' of the support package to reference.", valueName: "dir-or-url")) + var spmSupportPackageReference: String = "https://github.com/tristanlabelle/swift-winrt.git#branch=main" @Flag(name: .customLong("cmakelists"), help: "Generate a CMakeLists.txt files for building with CMake.") var generateCMakeLists: Bool = false diff --git a/Generator/Sources/SwiftWinRT/Writing/SwiftPackageFile.swift b/Generator/Sources/SwiftWinRT/Writing/SwiftPackageFile.swift index 3e6999c..a5da516 100644 --- a/Generator/Sources/SwiftWinRT/Writing/SwiftPackageFile.swift +++ b/Generator/Sources/SwiftWinRT/Writing/SwiftPackageFile.swift @@ -6,12 +6,12 @@ import struct Foundation.URL func writeSwiftPackageFile( _ projection: Projection, - supportPackageLocation: String, + supportPackageReference: String, excludeCMakeLists: Bool, dynamicLibraries: Bool, toPath path: String) { var package = SwiftPackage(name: "Projection") - package.dependencies.append(getSupportPackageDependency(location: supportPackageLocation)) + package.dependencies.append(getSupportPackageDependency(reference: supportPackageReference)) for module in projection.modulesByName.values { guard !module.isEmpty else { continue } @@ -77,19 +77,26 @@ func writeSwiftPackageFile( package.write(version: "5.10", to: FileTextOutputStream(path: path, directoryCreation: .ancestors)) } -fileprivate func getSupportPackageDependency(location: String) -> SwiftPackage.Dependency { - if location.starts(with: "https://") { - if let separatorIndex = location.lastIndex(of: ":"), - let lastSlashIndex = location.lastIndex(of: "/"), - separatorIndex > lastSlashIndex { - let url = String(location[.. SwiftPackage.Dependency { + if reference.starts(with: "https://") { + guard let fragmentSeparatorIndex = reference.lastIndex(of: "#") else { + fatalError("Package URL reference should include # fragment: \(reference)") } - else { - fatalError("Unexpected support package location format: \(location)") + + let url = reference[..