From cb37998118512bba2cc6dd3db134bcf336fdd1be Mon Sep 17 00:00:00 2001 From: Pavel Yaskevich Date: Tue, 10 Jun 2025 08:53:25 -0700 Subject: [PATCH 1/2] [Commands] Migrate: Make argument formatting consistent - Rename `--targets` to `--target` - Change `--target` and `--to-feature` to accept space separated argument lists --- .../Commands/PackageCommands/Migrate.swift | 30 ++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/Sources/Commands/PackageCommands/Migrate.swift b/Sources/Commands/PackageCommands/Migrate.swift index ff8aac0019b..d19f815bb6d 100644 --- a/Sources/Commands/PackageCommands/Migrate.swift +++ b/Sources/Commands/PackageCommands/Migrate.swift @@ -19,6 +19,8 @@ import CoreCommands import Foundation +import OrderedCollections + import PackageGraph import PackageModel @@ -29,18 +31,15 @@ import var TSCBasic.stdoutStream struct MigrateOptions: ParsableArguments { @Option( - name: .customLong("targets"), + name: .customLong("target"), + parsing: .upToNextOption, help: "The targets to migrate to specified set of features." ) - var _targets: String? - - var targets: Set? { - self._targets.flatMap { Set($0.components(separatedBy: ",")) } - } + var targets: [String] = [] @Option( name: .customLong("to-feature"), - parsing: .unconditionalSingleValue, + parsing: .upToNextOption, help: "The Swift language upcoming/experimental feature to migrate to." ) var features: [String] @@ -85,9 +84,11 @@ extension SwiftPackageCommand { features.append(feature) } + let uniqueTargets = OrderedSet(self.options.targets) + let buildSystem = try await createBuildSystem( swiftCommandState, - targets: self.options.targets, + targets: uniqueTargets, features: features ) @@ -95,8 +96,8 @@ extension SwiftPackageCommand { // whole project to get diagnostic files. print("> Starting the build") - if let targets = self.options.targets { - for target in targets { + if !uniqueTargets.isEmpty { + for target in uniqueTargets { try await buildSystem.build(subset: .target(target)) } } else { @@ -107,8 +108,9 @@ extension SwiftPackageCommand { let buildPlan = try buildSystem.buildPlan var modules: [any ModuleBuildDescription] = [] - if let targets = self.options.targets { - for buildDescription in buildPlan.buildModules where targets.contains(buildDescription.module.name) { + if !uniqueTargets.isEmpty { + for buildDescription in buildPlan.buildModules + where uniqueTargets.contains(buildDescription.module.name) { modules.append(buildDescription) } } else { @@ -176,7 +178,7 @@ extension SwiftPackageCommand { private func createBuildSystem( _ swiftCommandState: SwiftCommandState, - targets: Set? = .none, + targets: OrderedSet, features: [SwiftCompilerFeature] ) async throws -> BuildSystem { let toolsBuildParameters = try swiftCommandState.toolsBuildParameters @@ -190,7 +192,7 @@ extension SwiftPackageCommand { } } - if let targets { + if !targets.isEmpty { targets.lazy.compactMap { modulesGraph.module(for: $0) }.forEach(addFeaturesToModule) From e12717f84e9b6c7fb4ed198322033fb4bee22f81 Mon Sep 17 00:00:00 2001 From: Pavel Yaskevich Date: Tue, 10 Jun 2025 08:56:44 -0700 Subject: [PATCH 2/2] [Commands] AddSetting: Switch to `.upToNextOption` formatting Instead of `--swift A=B --swift C=D` switch to `--swift A=B C=D` to make the command shorter and consistent with `migrate` and in the future other commands. --- Sources/Commands/PackageCommands/AddSetting.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Commands/PackageCommands/AddSetting.swift b/Sources/Commands/PackageCommands/AddSetting.swift index b0bfc719946..e62388ff4bf 100644 --- a/Sources/Commands/PackageCommands/AddSetting.swift +++ b/Sources/Commands/PackageCommands/AddSetting.swift @@ -44,7 +44,7 @@ extension SwiftPackageCommand { @Option( name: .customLong("swift"), - parsing: .unconditionalSingleValue, + parsing: .upToNextOption, help: "The Swift language setting(s) to add. Supported settings: \(SwiftSetting.allCases.map(\.rawValue).joined(separator: ", "))." ) var _swiftSettings: [String]