Skip to content

Commit 141aa08

Browse files
authored
[6.0] Update diagnostics for duplicated product/target names (#7575)
- Explanation: Improves diagnostic messages for duplicate product/target to include involved packages and other useful information. - Scope: Package manifests/graphs with duplicate product/target names. - Main Branch PRs: #7572 - Resolves: rdar://127623219 - Risk: Very Low - Reviewed By: @xedin - Testing: New tests were added to the suite and existing tests updated. (cherry picked from commit e5123e4)
1 parent 423ffae commit 141aa08

File tree

6 files changed

+88
-218
lines changed

6 files changed

+88
-218
lines changed

Sources/PackageGraph/ModulesGraph.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,8 +282,7 @@ extension PackageGraphError: CustomStringConvertible {
282282
}
283283
return description
284284
}
285-
286-
return "multiple products named '\(product)' in: \(packagesDescriptions.joined(separator: ", "))"
285+
return "multiple packages (\(packagesDescriptions.joined(separator: ", "))) declare products with a conflicting name: '\(product)’; product names need to be unique across the package graph"
287286
case .multipleModuleAliases(let target, let product, let package, let aliases):
288287
return "multiple aliases: ['\(aliases.joined(separator: "', '"))'] found for target '\(target)' in product '\(product)' from package '\(package)'"
289288
case .unsupportedPluginDependency(let targetName, let dependencyName, let dependencyType, let dependencyPackage):

Sources/PackageLoading/PackageBuilder.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ extension ModuleError: CustomStringConvertible {
9898
switch self {
9999
case .duplicateModule(let target, let packages):
100100
let packages = packages.map(\.description).sorted().joined(separator: "', '")
101-
return "multiple targets named '\(target)' in: '\(packages)'"
101+
return "multiple packages ('\(packages)') declare targets with a conflicting name: '\(target)’; target names need to be unique across the package graph"
102102
case .moduleNotFound(let target, let type, let shouldSuggestRelaxedSourceDir):
103103
let folderName = (type == .test) ? "Tests" : (type == .plugin) ? "Plugins" : "Sources"
104104
var clauses = ["Source files for target \(target) should be located under '\(folderName)/\(target)'"]

Tests/BuildTests/BuildPlanTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ final class BuildPlanTests: XCTestCase {
128128
)) { error in
129129
XCTAssertEqual(
130130
(error as? PackageGraphError)?.description,
131-
"multiple products named 'Logging' in: 'barpkg' (at '\(barPkg)'), 'foopkg' (at '\(fooPkg)')"
131+
"multiple packages (\'barpkg\' (at '\(barPkg)'), \'foopkg\' (at '\(fooPkg)')) declare products with a conflicting name: \'Logging’; product names need to be unique across the package graph"
132132
)
133133
}
134134
}
@@ -550,7 +550,7 @@ final class BuildPlanTests: XCTestCase {
550550
)) { error in
551551
XCTAssertEqual(
552552
(error as? PackageGraphError)?.description,
553-
"multiple products named 'Logging' in: 'barpkg' (at '\(barPkg)'), 'foopkg' (at '\(fooPkg)')"
553+
"multiple packages (\'barpkg\' (at '\(barPkg)'), \'foopkg\' (at '\(fooPkg)')) declare products with a conflicting name: \'Logging’; product names need to be unique across the package graph"
554554
)
555555
}
556556
}

Tests/BuildTests/ModuleAliasingBuildTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ final class ModuleAliasingBuildTests: XCTestCase {
262262
],
263263
observabilityScope: observability.topScope
264264
)) { error in
265-
XCTAssertEqual((error as? PackageGraphError)?.description, "multiple products named 'Logging' in: 'barpkg' (at '\(barPkg)'), 'foopkg' (at '\(fooPkg)')")
265+
XCTAssertEqual((error as? PackageGraphError)?.description, "multiple packages (\'barpkg\' (at '\(barPkg)'), \'foopkg\' (at '\(fooPkg)')) declare products with a conflicting name: \'Logging’; product names need to be unique across the package graph")
266266
}
267267
}
268268

@@ -324,7 +324,7 @@ final class ModuleAliasingBuildTests: XCTestCase {
324324
],
325325
observabilityScope: observability.topScope
326326
)) { error in
327-
XCTAssertEqual((error as? PackageGraphError)?.description, "multiple products named 'Logging' in: 'barpkg' (at '\(barPkg)'), 'foopkg' (at '\(fooPkg)')")
327+
XCTAssertEqual((error as? PackageGraphError)?.description, "multiple packages (\'barpkg\' (at '\(barPkg)'), \'foopkg\' (at '\(fooPkg)')) declare products with a conflicting name: \'Logging’; product names need to be unique across the package graph")
328328
}
329329
}
330330

@@ -4692,7 +4692,7 @@ final class ModuleAliasingBuildTests: XCTestCase {
46924692

46934693
XCTFail("unexpectedly resolved the package graph successfully")
46944694
} catch {
4695-
XCTAssertEqual(error.interpolationDescription, "multiple products named 'SomeProduct' in: 'other' (at '\(AbsolutePath("/Other"))'), 'some' (at '\(AbsolutePath("/Some"))')")
4695+
XCTAssertEqual(error.interpolationDescription, "multiple packages ('other' (at '\(AbsolutePath("/Other"))'), 'some' (at '\(AbsolutePath("/Some"))')) declare products with a conflicting name: 'SomeProduct’; product names need to be unique across the package graph")
46964696
}
46974697
XCTAssertEqual(observability.diagnostics.map { $0.description }.sorted(), ["[warning]: product aliasing requires tools-version 5.2 or later, so it is not supported by \'other\'", "[warning]: product aliasing requires tools-version 5.2 or later, so it is not supported by \'some\'"])
46984698
}

Tests/PackageGraphTests/ModulesGraphTests.swift

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ final class ModulesGraphTests: XCTestCase {
336336
)
337337

338338
testDiagnostics(observability.diagnostics) { result in
339-
result.check(diagnostic: "multiple targets named 'Bar' in: 'bar', 'foo'", severity: .error)
339+
result.check(diagnostic: "multiple packages ('bar', 'foo') declare targets with a conflicting name: 'Bar’; target names need to be unique across the package graph", severity: .error)
340340
}
341341
}
342342

@@ -395,7 +395,7 @@ final class ModulesGraphTests: XCTestCase {
395395
)
396396

397397
testDiagnostics(observability.diagnostics) { result in
398-
result.check(diagnostic: "multiple targets named 'First' in: 'first', 'fourth', 'second', 'third'", severity: .error)
398+
result.check(diagnostic: "multiple packages ('first', 'fourth', 'second', 'third') declare targets with a conflicting name: 'First’; target names need to be unique across the package graph", severity: .error)
399399
}
400400
}
401401

@@ -465,8 +465,8 @@ final class ModulesGraphTests: XCTestCase {
465465
)
466466

467467
testDiagnostics(observability.diagnostics) { result in
468-
result.checkUnordered(diagnostic: "multiple targets named 'Bar' in: 'fourth', 'third'", severity: .error)
469-
result.checkUnordered(diagnostic: "multiple targets named 'Foo' in: 'first', 'second'", severity: .error)
468+
result.checkUnordered(diagnostic: "multiple packages ('fourth', 'third') declare targets with a conflicting name: 'Bar’; target names need to be unique across the package graph", severity: .error)
469+
result.checkUnordered(diagnostic: "multiple packages ('first', 'second') declare targets with a conflicting name: 'Foo’; target names need to be unique across the package graph", severity: .error)
470470
}
471471
}
472472

@@ -534,7 +534,7 @@ final class ModulesGraphTests: XCTestCase {
534534
)
535535

536536
testDiagnostics(observability.diagnostics) { result in
537-
result.check(diagnostic: "multiple targets named 'First' in: 'first', 'fourth'", severity: .error)
537+
result.check(diagnostic: "multiple packages ('first', 'fourth') declare targets with a conflicting name: 'First’; target names need to be unique across the package graph", severity: .error)
538538
}
539539
}
540540

@@ -1254,7 +1254,7 @@ final class ModulesGraphTests: XCTestCase {
12541254
)
12551255

12561256
testDiagnostics(observability.diagnostics) { result in
1257-
result.check(diagnostic: "multiple targets named 'Foo' in: 'dep2', 'start'", severity: .error)
1257+
result.check(diagnostic: "multiple packages ('dep2', 'start') declare targets with a conflicting name: 'Foo’; target names need to be unique across the package graph", severity: .error)
12581258
}
12591259
}
12601260

@@ -1303,8 +1303,7 @@ final class ModulesGraphTests: XCTestCase {
13031303
],
13041304
observabilityScope: observability.topScope
13051305
)) { error in
1306-
XCTAssertEqual((error as? PackageGraphError)?.description,
1307-
"multiple products named 'Bar' in: 'bar' (at '\(barPkg)'), 'baz' (at '\(bazPkg)')")
1306+
XCTAssertEqual((error as? PackageGraphError)?.description, "multiple packages (\'bar\' (at '\(barPkg)'), \'baz\' (at '\(bazPkg)')) declare products with a conflicting name: \'Bar’; product names need to be unique across the package graph")
13081307
}
13091308
}
13101309

0 commit comments

Comments
 (0)