Skip to content

Clean up warnings, fix handling of dep version changes #8232

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 2 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
12 changes: 10 additions & 2 deletions Sources/PackageGraph/ModulesGraph+Loading.swift
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,12 @@ extension ModulesGraph {
)

let rootPackages = resolvedPackages.filter { root.manifests.values.contains($0.manifest) }
checkAllDependenciesAreUsed(packages: resolvedPackages, rootPackages, observabilityScope: observabilityScope)
checkAllDependenciesAreUsed(
packages: resolvedPackages,
rootPackages,
prebuilts: prebuilts,
observabilityScope: observabilityScope
)

return try ModulesGraph(
rootPackages: rootPackages,
Expand All @@ -275,6 +280,7 @@ extension ModulesGraph {
private func checkAllDependenciesAreUsed(
packages: IdentifiableSet<ResolvedPackage>,
_ rootPackages: [ResolvedPackage],
prebuilts: [PackageIdentity: [String: PrebuiltLibrary]],
observabilityScope: ObservabilityScope
) {
for package in rootPackages {
Expand Down Expand Up @@ -352,9 +358,11 @@ private func checkAllDependenciesAreUsed(
let usedByPackage = productDependencies.contains { $0.name == product.name }
// We check if any of the products of this dependency is guarded by a trait.
let traitGuarded = traitGuardedProductDependencies.contains(product.name)
// Consider prebuilts as used
let prebuilt = prebuilts[dependency.identity]?.keys.contains(product.name) ?? false

// If the product is either used directly or guarded by a trait we consider it as used
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: this comment has to be updated as well.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just removed that comment. It's redundant.

return usedByPackage || traitGuarded
return usedByPackage || traitGuarded || prebuilt
}

if !dependencyIsUsed && !observabilityScope.errorsReportedInAnyScope {
Expand Down
2 changes: 1 addition & 1 deletion Tests/WorkspaceTests/PrebuiltsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ final class PrebuiltsTests: XCTestCase {
)

try await workspace.checkPackageGraph(roots: ["Foo"]) { modulesGraph, diagnostics in
XCTAssertTrue(diagnostics.filter({ $0.severity == .error }).isEmpty)
XCTAssertTrue(diagnostics.filter({ $0.severity == .error || $0.severity == .warning }).isEmpty)
let rootPackage = try XCTUnwrap(modulesGraph.rootPackages.first)
try checkSettings(rootPackage, "FooMacros", usePrebuilt: true)
try checkSettings(rootPackage, "FooTests", usePrebuilt: true)
Expand Down