Skip to content

Commit e1d3918

Browse files
authored
Merge pull request #2538 from hartbit/better-unknown-package-diagnostic
[SR-12075] Improve unknown package in dependencies of target diagnostic
2 parents fe23cad + e403ee2 commit e1d3918

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

Sources/PackageLoading/ManifestLoader.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -979,7 +979,12 @@ extension TSCBasic.Diagnostic.Message {
979979
}
980980

981981
static func unknownPackageInTargetDependencies(targetName: String, packageName: String) -> Self {
982-
.error("unknown package '\(packageName)' in dependencies of target '\(targetName)'")
982+
.error("""
983+
unknown package '\(packageName)' in dependencies of target '\(targetName)'; if the package is named \
984+
differently from the product, either use '.product(name: "\(packageName)", package: <package-name>)' to \
985+
specify the package name or give the package the '\(packageName)' name using '.package(name: \
986+
"\(packageName)", ...)'
987+
""")
983988
}
984989

985990
static func invalidBinaryLocation(targetName: String) -> Self {

Tests/PackageLoadingTests/PD5_2LoadingTests.swift

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,11 @@ class PackageDescription5_2LoadingTests: PackageDescriptionLoadingTests {
110110
"""
111111

112112
XCTAssertManifestLoadThrows(stream.bytes) { _, diagnostics in
113-
diagnostics.check(diagnostic: "unknown package 'foo1' in dependencies of target 'foo'", behavior: .error)
113+
diagnostics.check(diagnostic: """
114+
unknown package 'foo1' in dependencies of target 'foo'; if the package is named differently from \
115+
the product, either use '.product(name: "foo1", package: <package-name>)' to specify the package \
116+
name or give the package the 'foo1' name using '.package(name: "foo1", ...)'
117+
""", behavior: .error)
114118
}
115119
}
116120

@@ -133,7 +137,11 @@ class PackageDescription5_2LoadingTests: PackageDescriptionLoadingTests {
133137
"""
134138

135139
XCTAssertManifestLoadThrows(stream.bytes) { _, diagnostics in
136-
diagnostics.check(diagnostic: "unknown package 'bar' in dependencies of target 'foo'", behavior: .error)
140+
diagnostics.check(diagnostic: """
141+
unknown package 'bar' in dependencies of target 'foo'; if the package is named differently from \
142+
the product, either use '.product(name: "bar", package: <package-name>)' to specify the package \
143+
name or give the package the 'bar' name using '.package(name: "bar", ...)'
144+
""", behavior: .error)
137145
}
138146
}
139147
}

0 commit comments

Comments
 (0)