Skip to content

Commit 2ba7ad9

Browse files
committed
Update -swift-version to default to 6 for swift-tools-version 6
We missed updating this when adding 6.0.
1 parent 1889cd1 commit 2ba7ad9

File tree

3 files changed

+164
-4
lines changed

3 files changed

+164
-4
lines changed

Sources/PackageModel/ToolsVersion.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,10 +182,11 @@ public struct ToolsVersion: Equatable, Hashable, Codable, Sendable {
182182

183183
// Otherwise, use 4.2
184184
return .v4_2
185-
186-
default:
187-
// Anything above 4 major version uses version 5.
185+
case 5:
188186
return .v5
187+
default:
188+
// Anything above 5 major version uses version 6.
189+
return .v6
189190
}
190191
}
191192
}

Tests/BuildTests/BuildPlanTests.swift

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6217,4 +6217,159 @@ final class BuildPlanTests: XCTestCase {
62176217
let dylibs = Array(buildProduct.dylibs.map({$0.product.name})).sorted()
62186218
XCTAssertEqual(dylibs, ["BarLogging", "FooLogging"])
62196219
}
6220+
6221+
func testSwiftPackageWithProvidedLibraries() throws {
6222+
let fs = InMemoryFileSystem(
6223+
emptyFiles:
6224+
"/A/Sources/ATarget/main.swift",
6225+
"/Libraries/B/BTarget.swiftmodule",
6226+
"/Libraries/C/CTarget.swiftmodule"
6227+
)
6228+
6229+
let observability = ObservabilitySystem.makeForTesting()
6230+
let graph = try loadModulesGraph(
6231+
fileSystem: fs,
6232+
manifests: [
6233+
Manifest.createRootManifest(
6234+
displayName: "A",
6235+
path: "/A",
6236+
dependencies: [
6237+
.localSourceControl(path: "/B", requirement: .upToNextMajor(from: "1.0.0")),
6238+
.localSourceControl(path: "/C", requirement: .upToNextMajor(from: "1.0.0")),
6239+
],
6240+
products: [
6241+
ProductDescription(
6242+
name: "A",
6243+
type: .executable,
6244+
targets: ["ATarget"]
6245+
)
6246+
],
6247+
targets: [
6248+
TargetDescription(name: "ATarget", dependencies: ["BLibrary", "CLibrary"])
6249+
]
6250+
),
6251+
Manifest.createFileSystemManifest(
6252+
displayName: "B",
6253+
path: "/B",
6254+
products: [
6255+
ProductDescription(name: "BLibrary", type: .library(.automatic), targets: ["BTarget"]),
6256+
],
6257+
targets: [
6258+
TargetDescription(
6259+
name: "BTarget",
6260+
path: "/Libraries/B",
6261+
type: .providedLibrary
6262+
)
6263+
]
6264+
),
6265+
Manifest.createFileSystemManifest(
6266+
displayName: "C",
6267+
path: "/C",
6268+
products: [
6269+
ProductDescription(name: "CLibrary", type: .library(.automatic), targets: ["CTarget"]),
6270+
],
6271+
targets: [
6272+
TargetDescription(
6273+
name: "CTarget",
6274+
path: "/Libraries/C",
6275+
type: .providedLibrary
6276+
)
6277+
]
6278+
),
6279+
],
6280+
observabilityScope: observability.topScope
6281+
)
6282+
6283+
XCTAssertNoDiagnostics(observability.diagnostics)
6284+
6285+
let plan = try BuildPlan(
6286+
buildParameters: mockBuildParameters(),
6287+
graph: graph,
6288+
fileSystem: fs,
6289+
observabilityScope: observability.topScope
6290+
)
6291+
let result = try BuildPlanResult(plan: plan)
6292+
6293+
result.checkProductsCount(1)
6294+
result.checkTargetsCount(1)
6295+
6296+
XCTAssertMatch(
6297+
try result.target(for: "ATarget").swiftTarget().compileArguments(),
6298+
[
6299+
.anySequence,
6300+
"-I", "/Libraries/C",
6301+
"-I", "/Libraries/B",
6302+
.anySequence
6303+
]
6304+
)
6305+
6306+
let linkerArgs = try result.buildProduct(for: "A").linkArguments()
6307+
6308+
XCTAssertMatch(
6309+
linkerArgs,
6310+
[
6311+
.anySequence,
6312+
"-L", "/Libraries/B",
6313+
"-l", "BTarget",
6314+
.anySequence
6315+
]
6316+
)
6317+
6318+
XCTAssertMatch(
6319+
linkerArgs,
6320+
[
6321+
.anySequence,
6322+
"-L", "/Libraries/C",
6323+
"-l", "CTarget",
6324+
.anySequence
6325+
]
6326+
)
6327+
}
6328+
6329+
func testDefaultVersions() throws {
6330+
let fs = InMemoryFileSystem(emptyFiles:
6331+
"/Pkg/Sources/foo/foo.swift"
6332+
)
6333+
6334+
let expectedVersions = [
6335+
ToolsVersion.v4: "4",
6336+
ToolsVersion.v4_2: "4.2",
6337+
ToolsVersion.v5: "5",
6338+
ToolsVersion.v6_0: "6",
6339+
ToolsVersion.vNext: "6"
6340+
]
6341+
for (toolsVersion, expectedVersionString) in expectedVersions {
6342+
let observability = ObservabilitySystem.makeForTesting()
6343+
let graph = try loadModulesGraph(
6344+
fileSystem: fs,
6345+
manifests: [
6346+
Manifest.createRootManifest(
6347+
displayName: "Pkg",
6348+
path: "/Pkg",
6349+
toolsVersion: toolsVersion,
6350+
targets: [
6351+
TargetDescription(
6352+
name: "foo"
6353+
),
6354+
]
6355+
),
6356+
],
6357+
observabilityScope: observability.topScope
6358+
)
6359+
6360+
let result = try BuildPlanResult(plan: BuildPlan(
6361+
buildParameters: mockBuildParameters(),
6362+
graph: graph,
6363+
fileSystem: fs,
6364+
observabilityScope: observability.topScope
6365+
))
6366+
6367+
XCTAssertMatch(
6368+
try result.target(for: "foo").swiftTarget().compileArguments(),
6369+
[
6370+
"-swift-version", .equal(expectedVersionString)
6371+
]
6372+
)
6373+
}
6374+
}
62206375
}

Tests/PackageModelTests/ToolsVersionTests.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,12 @@ class ToolsVersionTests: XCTestCase {
9191
XCTAssertEqual(ToolsVersion(string: version)?.swiftLanguageVersion.description, "4.2")
9292
}
9393

94-
for version in ["5.0.0", "5.1.9", "6.0.0", "7.0.0"] {
94+
for version in ["5.0.0", "5.1.9"] {
9595
XCTAssertEqual(ToolsVersion(string: version)?.swiftLanguageVersion.description, "5")
9696
}
97+
98+
for version in ["6.0.0", "7.0.0"] {
99+
XCTAssertEqual(ToolsVersion(string: version)?.swiftLanguageVersion.description, "6")
100+
}
97101
}
98102
}

0 commit comments

Comments
 (0)