Skip to content

Commit 973e3c5

Browse files
authored
Throw an error if Target.Dependency.productItem is used instead of .product. (#4275)
Target.Dependency.productItem should not be used. Throw an error if used instead of .product. Resolves rdar://91013735
1 parent 4be2e14 commit 973e3c5

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

Sources/PackageDescription/Target.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -922,6 +922,11 @@ public final class Target {
922922
}
923923

924924
extension Target.Dependency {
925+
@available(_PackageDescription, obsoleted: 5.7, message: "use .product(name:package:condition) instead.")
926+
public static func productItem(name: String, package: String? = nil, condition: TargetDependencyCondition? = nil) -> Target.Dependency {
927+
return .productItem(name: name, package: package, moduleAliases: nil, condition: nil)
928+
}
929+
925930
/// Creates a dependency on a target in the same package.
926931
///
927932
/// - parameters:

Tests/PackageLoadingTests/PD_5_7_LoadingTests .swift

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,31 @@ class PackageDescription5_7LoadingTests: PackageDescriptionLoadingTests {
9999
}
100100
}
101101
}
102+
103+
func testTargetDeprecatedDependencyCase() throws {
104+
let content = """
105+
import PackageDescription
106+
let package = Package(
107+
name: "Foo",
108+
dependencies: [
109+
.package(url: "http://localhost/BarPkg", from: "1.1.1"),
110+
],
111+
targets: [
112+
.target(name: "Foo",
113+
dependencies: [
114+
.productItem(name: "Bar", package: "BarPkg", condition: nil),
115+
]),
116+
]
117+
)
118+
"""
119+
120+
let observability = ObservabilitySystem.makeForTesting()
121+
XCTAssertThrowsError(try loadManifest(content, observabilityScope: observability.topScope)) { error in
122+
if case ManifestParseError.invalidManifestFormat(let message, _) = error {
123+
XCTAssertMatch(message, .contains("error: 'productItem(name:package:condition:)' is unavailable: use .product(name:package:condition) instead."))
124+
} else {
125+
XCTFail("unexpected error: \(error)")
126+
}
127+
}
128+
}
102129
}

0 commit comments

Comments
 (0)