Skip to content

Commit

Permalink
Add support of swift language mode SPM target build setting (tuist#6730)
Browse files Browse the repository at this point in the history
* bump tca dependency to include swift language mode build setting

* add swift language mode / swift version setting

See https://www.swift.org/migration/documentation/swift-6-concurrency-migration-guide/swift6mode/

* Run mise run lint-fix

* add TODO comment

* Rename SettingName swiftVersion case to swiftLanguageMode

* add some unit tests
  • Loading branch information
KaiOelfke authored Sep 18, 2024
1 parent 3572653 commit df61882
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 32 deletions.
7 changes: 7 additions & 0 deletions Sources/TuistLoader/Models/PackageInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,7 @@ extension PackageInfo.Target {

/// The name of the build setting.
public enum SettingName: String, Codable, Hashable {
case swiftLanguageMode
case headerSearchPath
case define
case linkedLibrary
Expand Down Expand Up @@ -419,6 +420,7 @@ extension PackageInfo.Target {

// Xcode 14 format
private enum Kind: Codable, Equatable {
case swiftLanguageMode(String)
case headerSearchPath(String)
case define(String)
case linkedLibrary(String)
Expand Down Expand Up @@ -456,6 +458,9 @@ extension PackageInfo.Target {
case let .enableExperimentalFeature(value):
name = .enableExperimentalFeature
self.value = [value]
case let .swiftLanguageMode(value):
name = .swiftLanguageMode
self.value = [value]
}
} else {
name = try container.decode(SettingName.self, forKey: .name)
Expand Down Expand Up @@ -483,6 +488,8 @@ extension PackageInfo.Target {
try container.encode(Kind.enableUpcomingFeature(value.first!), forKey: .kind)
case .enableExperimentalFeature:
try container.encode(Kind.enableExperimentalFeature(value.first!), forKey: .kind)
case .swiftLanguageMode:
try container.encode(Kind.swiftLanguageMode(value.first!), forKey: .kind)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ public final class PackageInfoMapper: PackageInfoMapping {
.linker,
.define
),
(.linker, .unsafeFlags), (_, .enableExperimentalFeature):
(.linker, .unsafeFlags), (_, .enableExperimentalFeature), (_, .swiftLanguageMode):
return nil
}
} catch {
Expand Down Expand Up @@ -971,7 +971,7 @@ extension ProjectDescription.TargetDependency {
.linker,
.define
),
(.linker, .unsafeFlags), (_, .enableExperimentalFeature):
(.linker, .unsafeFlags), (_, .enableExperimentalFeature), (_, .swiftLanguageMode):
return nil
}
} catch {
Expand Down
6 changes: 5 additions & 1 deletion Sources/TuistLoader/SwiftPackageManager/SettingsMapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ struct SettingsMapper {
swiftFlags.append("-enable-upcoming-feature \"\(setting.value[0])\"")
case (.swift, .enableExperimentalFeature):
swiftFlags.append("-enable-experimental-feature \"\(setting.value[0])\"")
case (.swift, .swiftLanguageMode):
// TODO: Use -language-mode instead of -swift-version when Xcode 15 support is removed.
// https://github.com/swiftlang/swift-evolution/blob/main/proposals/0441-formalize-language-mode-terminology.md#swift-compiler-option
swiftFlags.append("-swift-version \(setting.value[0])")
case (.linker, .unsafeFlags):
linkerFlags.append(contentsOf: setting.value)
case (.linker, .linkedFramework), (.linker, .linkedLibrary):
Expand All @@ -94,7 +98,7 @@ struct SettingsMapper {
case (.c, .linkedFramework), (.c, .linkedLibrary), (.cxx, .linkedFramework), (.cxx, .linkedLibrary),
(.swift, .headerSearchPath), (.swift, .linkedFramework), (.swift, .linkedLibrary),
(.linker, .headerSearchPath), (.linker, .define), (_, .enableUpcomingFeature),
(_, .enableExperimentalFeature):
(_, .enableExperimentalFeature), (_, .swiftLanguageMode):
throw PackageInfoMapperError.unsupportedSetting(setting.tool, setting.name)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2379,6 +2379,49 @@ final class PackageInfoMapperTests: TuistUnitTestCase {
)
}

func testMap_whenSettingsContainsSwiftLanguageMode_mapsToOtherSwiftFlags() throws {
let basePath = try temporaryPath()
let sourcesPath = basePath.appending(try RelativePath(validating: "Package/Sources/Target1"))
try fileHandler.createFolder(sourcesPath)
let project = try subject.map(
package: "Package",
basePath: basePath,
packageInfos: [
"Package": .init(
name: "Package",
products: [
.init(name: "Product1", type: .library(.automatic), targets: ["Target1"]),
],
targets: [
.test(
name: "Target1",
settings: [
.init(tool: .swift, name: .swiftLanguageMode, condition: nil, value: ["5"]),
]
),
],
platforms: [.ios],
cLanguageStandard: nil,
cxxLanguageStandard: nil,
swiftLanguageVersions: nil
),
]
)
XCTAssertBetterEqual(
project,
.testWithDefaultConfigs(
name: "Package",
targets: [
.test(
"Target1",
basePath: basePath,
customSettings: ["OTHER_SWIFT_FLAGS": ["$(inherited)", "-swift-version 5"]]
),
]
)
)
}

func testMap_whenSettingsContainsLinkerUnsafeFlags_mapsToOtherLdFlags() throws {
let basePath = try temporaryPath()
let sourcesPath = basePath.appending(try RelativePath(validating: "Package/Sources/Target1"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ final class SettingsMapperTests: XCTestCase {
.init(tool: .swift, name: .unsafeFlags, condition: nil, value: ["ArbitraryFlag"]),
.init(tool: .swift, name: .enableUpcomingFeature, condition: nil, value: ["NewFeature"]),
.init(tool: .swift, name: .enableExperimentalFeature, condition: nil, value: ["Experimental"]),
.init(tool: .swift, name: .swiftLanguageMode, condition: nil, value: ["5"]),
]

let mapper = SettingsMapper(
Expand All @@ -161,6 +162,7 @@ final class SettingsMapperTests: XCTestCase {
"ArbitraryFlag",
"-enable-upcoming-feature \"NewFeature\"",
"-enable-experimental-feature \"Experimental\"",
"-swift-version 5",
])
)
}
Expand Down
56 changes: 28 additions & 28 deletions fixtures/app_with_spm_dependencies/Tuist/Package.resolved
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"originHash" : "a18b44e37498cdc083fe1514666ea3bbc090f84d03b3b5888bf4d09314e4a1db",
"originHash" : "38140789c069d40cf43f4a55edc3a0c2ddd53bc53a8639441f41c99678e0f2e2",
"pins" : [
{
"identity" : "alamofire",
Expand Down Expand Up @@ -51,8 +51,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/combine-schedulers",
"state" : {
"revision" : "9dc9cbe4bc45c65164fa653a563d8d8db61b09bb",
"version" : "1.0.0"
"revision" : "9fa31f4403da54855f1e2aeaeff478f4f0e40b13",
"version" : "1.0.2"
}
},
{
Expand Down Expand Up @@ -222,17 +222,17 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-case-paths",
"state" : {
"revision" : "e593aba2c6222daad7c4f2732a431eed2c09bb07",
"version" : "1.3.0"
"revision" : "642e6aab8e03e5f992d9c83e38c5be98cfad5078",
"version" : "1.5.5"
}
},
{
"identity" : "swift-clocks",
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-clocks",
"state" : {
"revision" : "a8421d68068d8f45fbceb418fbf22c5dad4afd33",
"version" : "1.0.2"
"revision" : "b9b24b69e2adda099a1fa381cda1eeec272d5b53",
"version" : "1.0.5"
}
},
{
Expand All @@ -249,8 +249,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-composable-architecture",
"state" : {
"revision" : "115fe5af41d333b6156d4924d7c7058bc77fd580",
"version" : "1.9.2"
"revision" : "8013f1a72af8ccb2b1735d7aed831a8dc07c6fd0",
"version" : "1.15.0"
}
},
{
Expand All @@ -267,26 +267,26 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-custom-dump",
"state" : {
"revision" : "6ea3b1b6a4957806d72030a32360d4bcb155a0d2",
"version" : "1.2.0"
"revision" : "82645ec760917961cfa08c9c0c7104a57a0fa4b1",
"version" : "1.3.3"
}
},
{
"identity" : "swift-dependencies",
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-dependencies",
"state" : {
"revision" : "d3a5af3038a09add4d7682f66555d6212058a3c0",
"version" : "1.2.2"
"revision" : "fd1fb25b68fdb9756cd61d23dbd9e2614b340085",
"version" : "1.4.0"
}
},
{
"identity" : "swift-identified-collections",
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-identified-collections",
"state" : {
"revision" : "d1e45f3e1eee2c9193f5369fa9d70a6ddad635e8",
"version" : "1.0.0"
"revision" : "2f5ab6e091dd032b63dacbda052405756010dc3b",
"version" : "1.1.0"
}
},
{
Expand All @@ -307,6 +307,15 @@
"version" : "2.3.0"
}
},
{
"identity" : "swift-navigation",
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-navigation",
"state" : {
"revision" : "e834b3760731160d7d448509ee6a1408c8582a6b",
"version" : "2.2.0"
}
},
{
"identity" : "swift-package-manager-google-mobile-ads",
"kind" : "remoteSourceControl",
Expand All @@ -330,8 +339,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-perception",
"state" : {
"revision" : "83fc3d89676b33f1c3d49e9268e76ef62430339f",
"version" : "1.1.3"
"revision" : "bc67aa8e461351c97282c2419153757a446ae1c9",
"version" : "1.3.5"
}
},
{
Expand All @@ -352,15 +361,6 @@
"version" : "0.6.0"
}
},
{
"identity" : "swiftui-navigation",
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swiftui-navigation",
"state" : {
"revision" : "d9e72f3083c08375794afa216fb2f89c0114f303",
"version" : "1.2.1"
}
},
{
"identity" : "uickeychainstore",
"kind" : "remoteSourceControl",
Expand All @@ -375,8 +375,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/xctest-dynamic-overlay",
"state" : {
"revision" : "b58e6627149808b40634c4552fcf2f44d0b3ca87",
"version" : "1.1.0"
"revision" : "bc2a151366f2cd0e347274544933bc2acb00c9fe",
"version" : "1.4.0"
}
},
{
Expand Down
2 changes: 1 addition & 1 deletion fixtures/app_with_spm_dependencies/Tuist/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ let package = Package(
name: "PackageName",
dependencies: [
.package(url: "https://github.com/Alamofire/Alamofire", exact: "5.8.0"),
.package(url: "https://github.com/pointfreeco/swift-composable-architecture", .upToNextMinor(from: "1.9.2")),
.package(url: "https://github.com/pointfreeco/swift-composable-architecture", .upToNextMinor(from: "1.15.0")),
.package(url: "https://github.com/ZipArchive/ZipArchive", .upToNextMajor(from: "2.5.5")),
.package(url: "https://github.com/jpsim/Yams", .upToNextMajor(from: "5.0.6")),
.package(url: "https://github.com/google/GoogleSignIn-iOS", .upToNextMajor(from: "7.0.0")),
Expand Down

0 comments on commit df61882

Please sign in to comment.