Skip to content

Commit ca3f569

Browse files
authored
make target dependency lookup non-case-sensitive (#3615) (#3618)
motivation: starting tools-version 5.2, SwiftPM validates the target depedenies by name but the validation is case sensitive changes: * udpate the validation to be non-case sensitive (the actual lookup is not case sensitive) * add a test rdar://80594761
1 parent 6f25cda commit ca3f569

File tree

6 files changed

+55
-2
lines changed

6 files changed

+55
-2
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// swift-tools-version:5.0
2+
3+
import PackageDescription
4+
5+
let package = Package(
6+
name: "Dep",
7+
products: [
8+
.library(name: "Dep", targets: ["Dep"]),
9+
],
10+
targets: [
11+
.target(name: "Dep", dependencies: []),
12+
]
13+
)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
public struct dep {
2+
public private(set) var text = "Hello, World!"
3+
4+
public init() {
5+
}
6+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// swift-tools-version:5.4
2+
3+
import PackageDescription
4+
5+
let package = Package(
6+
name: "pkg",
7+
products: [
8+
.library(name: "pkg", targets: ["pkg"]),
9+
],
10+
dependencies: [
11+
.package(path: "../dep"),
12+
],
13+
targets: [
14+
.target(
15+
name: "pkg",
16+
dependencies: [.product(name: "Dep", package: "Dep")]),
17+
]
18+
)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
public struct pkg {
2+
public private(set) var text = "Hello, World!"
3+
4+
public init() {
5+
}
6+
}

Sources/PackageModel/Manifest.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,10 @@ public final class Manifest: ObjectIdentifierProtocol {
274274
return nil
275275
}
276276

277-
return self.dependencies.first(where: { $0.nameForTargetDependencyResolutionOnly == packageName })
277+
return self.dependencies.first(where: {
278+
// rdar://80594761 make sure validation is case insensitive
279+
$0.nameForTargetDependencyResolutionOnly.lowercased() == packageName.lowercased()
280+
})
278281
}
279282

280283
/// Registers a required product with a particular dependency if possible, or registers it as unknown.
@@ -341,7 +344,7 @@ public final class Manifest: ObjectIdentifierProtocol {
341344
/// - Parameters:
342345
/// - product: The product to try registering.
343346
/// - package: The package to try associating it with.
344-
/// - registry: The registry in which to record the assocation.
347+
/// - registry: The registry in which to record the association.
345348
/// - availablePackages: The set of available packages.
346349
///
347350
/// - Returns: `true` if the particular dependency was found and the product was registered; `false` if no matching dependency was found and the product has not yet been handled.

Tests/FunctionalTests/DependencyResolutionTests.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,4 +133,11 @@ class DependencyResolutionTests: XCTestCase {
133133
}
134134
}
135135
}
136+
137+
func testPackageLookupCaseInsensitive() throws {
138+
fixture(name: "DependencyResolution/External/PackageLookupCaseInsensitive") { path in
139+
let result = try SwiftPMProduct.SwiftPackage.executeProcess(["update"], packagePath: path.appending(component: "pkg"))
140+
XCTAssert(result.exitStatus == .terminated(code: 0), try! result.utf8Output() + result.utf8stderrOutput())
141+
}
142+
}
136143
}

0 commit comments

Comments
 (0)