Skip to content

Commit 9183b7c

Browse files
committed
[PackageModel] Associated swift version build setting with SWIFT_VERSION declaration
Instead of putting it into `OTHER_SWIFT_FLAGS`, let's introduce a dedicated declaration scope - `SWIFT_VERSION` to ease handling and discovery. Resolves: rdar://127883018
1 parent e843f4e commit 9183b7c

File tree

5 files changed

+15
-11
lines changed

5 files changed

+15
-11
lines changed

Sources/Build/BuildDescription/SwiftTargetBuildDescription.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -825,6 +825,9 @@ package final class SwiftTargetBuildDescription {
825825
let scope = self.defaultBuildParameters.createScope(for: self.target)
826826
var flags: [String] = []
827827

828+
// A custom swift version.
829+
flags += scope.evaluate(.SWIFT_VERSION).flatMap { ["-swift-version", $0] }
830+
828831
// Swift defines.
829832
let swiftDefines = scope.evaluate(.SWIFT_ACTIVE_COMPILATION_CONDITIONS)
830833
flags += swiftDefines.map { "-D" + $0 }

Sources/PackageLoading/PackageBuilder.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1176,10 +1176,10 @@ public final class PackageBuilder {
11761176
throw InternalError("only Swift supports swift language version")
11771177

11781178
case .swift:
1179-
decl = .OTHER_SWIFT_FLAGS
1179+
decl = .SWIFT_VERSION
11801180
}
11811181

1182-
values = ["-swift-version", version.rawValue]
1182+
values = [version.rawValue]
11831183
}
11841184

11851185
// Create an assignment for this setting.

Sources/PackageModel/BuildSettings.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public enum BuildSettings {
1818
// Swift.
1919
public static let SWIFT_ACTIVE_COMPILATION_CONDITIONS: Declaration = .init("SWIFT_ACTIVE_COMPILATION_CONDITIONS")
2020
public static let OTHER_SWIFT_FLAGS: Declaration = .init("OTHER_SWIFT_FLAGS")
21+
public static let SWIFT_VERSION: Declaration = .init("SWIFT_VERSION")
2122

2223
// C family.
2324
public static let GCC_PREPROCESSOR_DEFINITIONS: Declaration = .init("GCC_PREPROCESSOR_DEFINITIONS")

Tests/BuildTests/BuildPlanTests.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4083,7 +4083,7 @@ final class BuildPlanTests: XCTestCase {
40834083
)
40844084

40854085
let exe = try result.target(for: "exe").swiftTarget().compileArguments()
4086-
XCTAssertMatch(exe, [.anySequence, "-DFOO", "-swift-version", "5", "-g", "-Xcc", "-g", "-Xcc", "-fno-omit-frame-pointer", .end])
4086+
XCTAssertMatch(exe, [.anySequence, "-swift-version", "5", "-DFOO", "-g", "-Xcc", "-g", "-Xcc", "-fno-omit-frame-pointer", .end])
40874087

40884088
let linkExe = try result.buildProduct(for: "exe").linkArguments()
40894089
XCTAssertMatch(linkExe, [.anySequence, "-lsqlite3", "-llibz", "-Ilfoo", "-L", "lbar", "-g", .end])
@@ -4149,7 +4149,7 @@ final class BuildPlanTests: XCTestCase {
41494149
)
41504150

41514151
let exe = try result.target(for: "exe").swiftTarget().compileArguments()
4152-
XCTAssertMatch(exe, [.anySequence, "-DFOO", "-swift-version", "5", "-g", "-Xcc", "-g", "-Xcc", "-fomit-frame-pointer", .end])
4152+
XCTAssertMatch(exe, [.anySequence, "-swift-version", "5", "-DFOO", "-g", "-Xcc", "-g", "-Xcc", "-fomit-frame-pointer", .end])
41534153
}
41544154

41554155
// omit frame pointers explicitly set to false
@@ -4206,7 +4206,7 @@ final class BuildPlanTests: XCTestCase {
42064206
)
42074207

42084208
let exe = try result.target(for: "exe").swiftTarget().compileArguments()
4209-
XCTAssertMatch(exe, [.anySequence, "-DFOO", "-swift-version", "5", "-g", "-Xcc", "-g", "-Xcc", "-fno-omit-frame-pointer", .end])
4209+
XCTAssertMatch(exe, [.anySequence, "-swift-version", "5", "-DFOO", "-g", "-Xcc", "-g", "-Xcc", "-fno-omit-frame-pointer", .end])
42104210
}
42114211

42124212
do {
@@ -4253,10 +4253,10 @@ final class BuildPlanTests: XCTestCase {
42534253
exe,
42544254
[
42554255
.anySequence,
4256+
"-swift-version", "4",
42564257
"-DFOO",
42574258
"-cxx-interoperability-mode=default",
42584259
"-Xcc", "-std=c++17",
4259-
"-swift-version", "4",
42604260
"-g",
42614261
"-Xcc", "-g",
42624262
.end,

Tests/PackageLoadingTests/PackageBuilderTests.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3055,33 +3055,33 @@ final class PackageBuilderTests: XCTestCase {
30553055
package.target.buildSettings,
30563056
environment: BuildEnvironment(platform: .macOS, configuration: .debug)
30573057
)
3058-
XCTAssertEqual(macosDebugScope.evaluate(.OTHER_SWIFT_FLAGS), ["-swift-version", "5"])
3058+
XCTAssertEqual(macosDebugScope.evaluate(.SWIFT_VERSION), ["5"])
30593059

30603060
let macosReleaseScope = BuildSettings.Scope(
30613061
package.target.buildSettings,
30623062
environment: BuildEnvironment(platform: .macOS, configuration: .release)
30633063
)
3064-
XCTAssertEqual(macosReleaseScope.evaluate(.OTHER_SWIFT_FLAGS), ["-swift-version", "5"])
3064+
XCTAssertEqual(macosReleaseScope.evaluate(.SWIFT_VERSION), ["5"])
30653065
}
30663066

30673067
package.checkModule("bar") { package in
30683068
let linuxDebugScope = BuildSettings.Scope(
30693069
package.target.buildSettings,
30703070
environment: BuildEnvironment(platform: .linux, configuration: .debug)
30713071
)
3072-
XCTAssertEqual(linuxDebugScope.evaluate(.OTHER_SWIFT_FLAGS), ["-swift-version", "3"])
3072+
XCTAssertEqual(linuxDebugScope.evaluate(.SWIFT_VERSION), ["3"])
30733073

30743074
let macosDebugScope = BuildSettings.Scope(
30753075
package.target.buildSettings,
30763076
environment: BuildEnvironment(platform: .macOS, configuration: .debug)
30773077
)
3078-
XCTAssertEqual(macosDebugScope.evaluate(.OTHER_SWIFT_FLAGS), ["-swift-version", "4"])
3078+
XCTAssertEqual(macosDebugScope.evaluate(.SWIFT_VERSION), ["4"])
30793079

30803080
let macosReleaseScope = BuildSettings.Scope(
30813081
package.target.buildSettings,
30823082
environment: BuildEnvironment(platform: .macOS, configuration: .release)
30833083
)
3084-
XCTAssertEqual(macosReleaseScope.evaluate(.OTHER_SWIFT_FLAGS), [])
3084+
XCTAssertEqual(macosReleaseScope.evaluate(.SWIFT_VERSION), [])
30853085
}
30863086
}
30873087
}

0 commit comments

Comments
 (0)