Skip to content

Update diagnostics for duplicated product/target names #7572

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions Sources/PackageGraph/ModulesGraph.swift
Original file line number Diff line number Diff line change
Expand Up @@ -350,8 +350,7 @@ extension PackageGraphError: CustomStringConvertible {
}
return description
}

return "multiple products named '\(product)' in: \(packagesDescriptions.joined(separator: ", "))"
return "multiple packages (\(packagesDescriptions.joined(separator: ", "))) declare products with a conflicting name: '\(product)’; product names need to be unique across the package graph"
case .multipleModuleAliases(let target, let product, let package, let aliases):
return "multiple aliases: ['\(aliases.joined(separator: "', '"))'] found for target '\(target)' in product '\(product)' from package '\(package)'"
case .unsupportedPluginDependency(let targetName, let dependencyName, let dependencyType, let dependencyPackage):
Expand Down
2 changes: 1 addition & 1 deletion Sources/PackageLoading/PackageBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ extension ModuleError: CustomStringConvertible {
switch self {
case .duplicateModule(let target, let packages):
let packages = packages.map(\.description).sorted().joined(separator: "', '")
return "multiple targets named '\(target)' in: '\(packages)'"
return "multiple packages ('\(packages)') declare targets with a conflicting name: '\(target)’; target names need to be unique across the package graph"
case .moduleNotFound(let target, let type, let shouldSuggestRelaxedSourceDir):
let folderName = (type == .test) ? "Tests" : (type == .plugin) ? "Plugins" : "Sources"
var clauses = ["Source files for target \(target) should be located under '\(folderName)/\(target)'"]
Expand Down
4 changes: 2 additions & 2 deletions Tests/BuildTests/BuildPlanTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ final class BuildPlanTests: XCTestCase {
)) { error in
XCTAssertEqual(
(error as? PackageGraphError)?.description,
"multiple products named 'Logging' in: 'barpkg' (at '\(barPkg)'), 'foopkg' (at '\(fooPkg)')"
"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"
)
}
}
Expand Down Expand Up @@ -552,7 +552,7 @@ final class BuildPlanTests: XCTestCase {
)) { error in
XCTAssertEqual(
(error as? PackageGraphError)?.description,
"multiple products named 'Logging' in: 'barpkg' (at '\(barPkg)'), 'foopkg' (at '\(fooPkg)')"
"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"
)
}
}
Expand Down
6 changes: 3 additions & 3 deletions Tests/BuildTests/ModuleAliasingBuildTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ final class ModuleAliasingBuildTests: XCTestCase {
],
observabilityScope: observability.topScope
)) { error in
XCTAssertEqual((error as? PackageGraphError)?.description, "multiple products named 'Logging' in: 'barpkg' (at '\(barPkg)'), 'foopkg' (at '\(fooPkg)')")
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")
}
}

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

Expand Down Expand Up @@ -4697,7 +4697,7 @@ final class ModuleAliasingBuildTests: XCTestCase {

XCTFail("unexpectedly resolved the package graph successfully")
} catch {
XCTAssertEqual(error.interpolationDescription, "multiple products named 'SomeProduct' in: 'other' (at '\(AbsolutePath("/Other"))'), 'some' (at '\(AbsolutePath("/Some"))')")
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")
}
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\'"])
}
Expand Down
15 changes: 7 additions & 8 deletions Tests/PackageGraphTests/ModulesGraphTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ final class ModulesGraphTests: XCTestCase {
)

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

Expand Down Expand Up @@ -443,7 +443,7 @@ final class ModulesGraphTests: XCTestCase {
)

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

Expand Down Expand Up @@ -513,8 +513,8 @@ final class ModulesGraphTests: XCTestCase {
)

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

Expand Down Expand Up @@ -582,7 +582,7 @@ final class ModulesGraphTests: XCTestCase {
)

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

Expand Down Expand Up @@ -1302,7 +1302,7 @@ final class ModulesGraphTests: XCTestCase {
)

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

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

Expand Down
Loading