Skip to content

[6.2][Commands] SE-0481: Align the arguments to --target and `--to-featu… #8841

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
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
26 changes: 16 additions & 10 deletions Sources/Commands/PackageCommands/Migrate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,23 @@ import var TSCBasic.stdoutStream
struct MigrateOptions: ParsableArguments {
@Option(
name: .customLong("target"),
parsing: .upToNextOption,
help: "The targets to migrate to specified set of features."
)
var targets: [String] = []
var _targets: String?

var targets: OrderedSet<String> {
self._targets.flatMap { OrderedSet($0.components(separatedBy: ",")) } ?? []
}

@Option(
name: .customLong("to-feature"),
parsing: .upToNextOption,
help: "The Swift language upcoming/experimental feature to migrate to."
)
var features: [String]
var _features: String

var features: Set<String> {
Set(self._features.components(separatedBy: ","))
}
}

extension SwiftPackageCommand {
Expand Down Expand Up @@ -84,20 +90,20 @@ extension SwiftPackageCommand {
features.append(feature)
}

let uniqueTargets = OrderedSet(self.options.targets)
let targets = self.options.targets

let buildSystem = try await createBuildSystem(
swiftCommandState,
targets: uniqueTargets,
targets: targets,
features: features
)

// Next, let's build all of the individual targets or the
// whole project to get diagnostic files.

print("> Starting the build")
if !uniqueTargets.isEmpty {
for target in uniqueTargets {
if !targets.isEmpty {
for target in targets {
try await buildSystem.build(subset: .target(target))
}
} else {
Expand All @@ -108,9 +114,9 @@ extension SwiftPackageCommand {
let buildPlan = try buildSystem.buildPlan

var modules: [any ModuleBuildDescription] = []
if !uniqueTargets.isEmpty {
if !targets.isEmpty {
for buildDescription in buildPlan.buildModules
where uniqueTargets.contains(buildDescription.module.name) {
where targets.contains(buildDescription.module.name) {
modules.append(buildDescription)
}
} else {
Expand Down