Skip to content

Unify argument formatting for add setting and migrate #8800

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
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
2 changes: 1 addition & 1 deletion Sources/Commands/PackageCommands/AddSetting.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
30 changes: 16 additions & 14 deletions Sources/Commands/PackageCommands/Migrate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import CoreCommands

import Foundation

import OrderedCollections

import PackageGraph
import PackageModel

Expand All @@ -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<String>? {
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]
Expand Down Expand Up @@ -85,18 +84,20 @@ 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
)

// Next, let's build all of the individual targets or the
// 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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -176,7 +178,7 @@ extension SwiftPackageCommand {

private func createBuildSystem(
_ swiftCommandState: SwiftCommandState,
targets: Set<String>? = .none,
targets: OrderedSet<String>,
features: [SwiftCompilerFeature]
) async throws -> BuildSystem {
let toolsBuildParameters = try swiftCommandState.toolsBuildParameters
Expand All @@ -190,7 +192,7 @@ extension SwiftPackageCommand {
}
}

if let targets {
if !targets.isEmpty {
targets.lazy.compactMap {
modulesGraph.module(for: $0)
}.forEach(addFeaturesToModule)
Expand Down