Skip to content

Commit e5123e4

Browse files
authored
Update diagnostics for duplicated product/target names (#7572)
rdar://127623219
1 parent d231c3f commit e5123e4

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
@@ -350,8 +350,7 @@ extension PackageGraphError: CustomStringConvertible {
350350
}
351351
return description
352352
}
353-
354-
return "multiple products named '\(product)' in: \(packagesDescriptions.joined(separator: ", "))"
353+
return "multiple packages (\(packagesDescriptions.joined(separator: ", "))) declare products with a conflicting name: '\(product)’; product names need to be unique across the package graph"
355354
case .multipleModuleAliases(let target, let product, let package, let aliases):
356355
return "multiple aliases: ['\(aliases.joined(separator: "', '"))'] found for target '\(target)' in product '\(product)' from package '\(package)'"
357356
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
@@ -130,7 +130,7 @@ final class BuildPlanTests: XCTestCase {
130130
)) { error in
131131
XCTAssertEqual(
132132
(error as? PackageGraphError)?.description,
133-
"multiple products named 'Logging' in: 'barpkg' (at '\(barPkg)'), 'foopkg' (at '\(fooPkg)')"
133+
"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"
134134
)
135135
}
136136
}
@@ -552,7 +552,7 @@ final class BuildPlanTests: XCTestCase {
552552
)) { error in
553553
XCTAssertEqual(
554554
(error as? PackageGraphError)?.description,
555-
"multiple products named 'Logging' in: 'barpkg' (at '\(barPkg)'), 'foopkg' (at '\(fooPkg)')"
555+
"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"
556556
)
557557
}
558558
}

Tests/BuildTests/ModuleAliasingBuildTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ final class ModuleAliasingBuildTests: XCTestCase {
265265
],
266266
observabilityScope: observability.topScope
267267
)) { error in
268-
XCTAssertEqual((error as? PackageGraphError)?.description, "multiple products named 'Logging' in: 'barpkg' (at '\(barPkg)'), 'foopkg' (at '\(fooPkg)')")
268+
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")
269269
}
270270
}
271271

@@ -327,7 +327,7 @@ final class ModuleAliasingBuildTests: XCTestCase {
327327
],
328328
observabilityScope: observability.topScope
329329
)) { error in
330-
XCTAssertEqual((error as? PackageGraphError)?.description, "multiple products named 'Logging' in: 'barpkg' (at '\(barPkg)'), 'foopkg' (at '\(fooPkg)')")
330+
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")
331331
}
332332
}
333333

@@ -4697,7 +4697,7 @@ final class ModuleAliasingBuildTests: XCTestCase {
46974697

46984698
XCTFail("unexpectedly resolved the package graph successfully")
46994699
} catch {
4700-
XCTAssertEqual(error.interpolationDescription, "multiple products named 'SomeProduct' in: 'other' (at '\(AbsolutePath("/Other"))'), 'some' (at '\(AbsolutePath("/Some"))')")
4700+
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")
47014701
}
47024702
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\'"])
47034703
}

Tests/PackageGraphTests/ModulesGraphTests.swift

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ final class ModulesGraphTests: XCTestCase {
384384
)
385385

386386
testDiagnostics(observability.diagnostics) { result in
387-
result.check(diagnostic: "multiple targets named 'Bar' in: 'bar', 'foo'", severity: .error)
387+
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)
388388
}
389389
}
390390

@@ -443,7 +443,7 @@ final class ModulesGraphTests: XCTestCase {
443443
)
444444

445445
testDiagnostics(observability.diagnostics) { result in
446-
result.check(diagnostic: "multiple targets named 'First' in: 'first', 'fourth', 'second', 'third'", severity: .error)
446+
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)
447447
}
448448
}
449449

@@ -513,8 +513,8 @@ final class ModulesGraphTests: XCTestCase {
513513
)
514514

515515
testDiagnostics(observability.diagnostics) { result in
516-
result.checkUnordered(diagnostic: "multiple targets named 'Bar' in: 'fourth', 'third'", severity: .error)
517-
result.checkUnordered(diagnostic: "multiple targets named 'Foo' in: 'first', 'second'", severity: .error)
516+
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)
517+
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)
518518
}
519519
}
520520

@@ -582,7 +582,7 @@ final class ModulesGraphTests: XCTestCase {
582582
)
583583

584584
testDiagnostics(observability.diagnostics) { result in
585-
result.check(diagnostic: "multiple targets named 'First' in: 'first', 'fourth'", severity: .error)
585+
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)
586586
}
587587
}
588588

@@ -1302,7 +1302,7 @@ final class ModulesGraphTests: XCTestCase {
13021302
)
13031303

13041304
testDiagnostics(observability.diagnostics) { result in
1305-
result.check(diagnostic: "multiple targets named 'Foo' in: 'dep2', 'start'", severity: .error)
1305+
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)
13061306
}
13071307
}
13081308

@@ -1351,8 +1351,7 @@ final class ModulesGraphTests: XCTestCase {
13511351
],
13521352
observabilityScope: observability.topScope
13531353
)) { error in
1354-
XCTAssertEqual((error as? PackageGraphError)?.description,
1355-
"multiple products named 'Bar' in: 'bar' (at '\(barPkg)'), 'baz' (at '\(bazPkg)')")
1354+
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")
13561355
}
13571356
}
13581357

0 commit comments

Comments
 (0)