Skip to content

[Commands] Migrate: Group manifest update errors per target #8677

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
34 changes: 16 additions & 18 deletions Sources/Commands/PackageCommands/Migrate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,12 @@ extension SwiftPackageCommand {

print("> Updating manifest.")
for module in modules.map(\.module) {
print("> Adding feature(s) to '\(module.name)'.")
for feature in features {
self.updateManifest(
for: module.name,
add: feature,
using: swiftCommandState
)
}
swiftCommandState.observabilityScope.emit(debug: "Adding feature(s) to '\(module.name)'.")
self.updateManifest(
for: module.name,
add: features,
using: swiftCommandState
)
}
}

Expand Down Expand Up @@ -179,28 +177,28 @@ extension SwiftPackageCommand {

private func updateManifest(
for target: String,
add feature: SwiftCompilerFeature,
add features: [SwiftCompilerFeature],
using swiftCommandState: SwiftCommandState
) {
typealias SwiftSetting = SwiftPackageCommand.AddSetting.SwiftSetting

let setting: (SwiftSetting, String) = switch feature {
case .upcoming(name: let name, migratable: _, enabledIn: _):
(.upcomingFeature, "\(name)")
case .experimental(name: let name, migratable: _):
(.experimentalFeature, "\(name)")
let settings: [(SwiftSetting, String)] = features.map {
switch $0 {
case .upcoming(name: let name, migratable: _, enabledIn: _):
(.upcomingFeature, "\(name)")
case .experimental(name: let name, migratable: _):
(.experimentalFeature, "\(name)")
}
}

do {
try SwiftPackageCommand.AddSetting.editSwiftSettings(
of: target,
using: swiftCommandState,
[setting]
settings
)
} catch {
print(
"! Couldn't update manifest due to - \(error); Please add '.enable\(feature.upcoming ? "Upcoming" : "Experimental")Feature(\"\(feature.name)\")' to target '\(target)' settings manually."
)
swiftCommandState.observabilityScope.emit(error: "Could not update manifest for '\(target)' (\(error)). Please enable '\(features.map(\.name).joined(separator: ", "))' features manually.")
}
}

Expand Down