From b2dca3f5c7d3ccf73e9a28b5eeccb47062641ddc Mon Sep 17 00:00:00 2001 From: Luis Padron Date: Wed, 15 Nov 2023 10:34:21 -0500 Subject: [PATCH] fix: only add dependency when unresolved (#749) --- .../workspace/Sources/MyExecutable/MyExecutable.swift | 9 +++++++++ gazelle/internal/swift/dependency_index.go | 11 +++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/bzlmod/workspace/Sources/MyExecutable/MyExecutable.swift b/bzlmod/workspace/Sources/MyExecutable/MyExecutable.swift index 2137c5028..cbf04a219 100644 --- a/bzlmod/workspace/Sources/MyExecutable/MyExecutable.swift +++ b/bzlmod/workspace/Sources/MyExecutable/MyExecutable.swift @@ -3,6 +3,11 @@ import Logging import MyLibrary import RegexBuilder +// Because we build on macos/linux this needs to be conditionally imported to test an edge case +#if canImport(os) +import os +#endif + @main struct MyExecutable: AsyncParsableCommand { struct Plugin { } @@ -10,5 +15,9 @@ struct MyExecutable: AsyncParsableCommand { let output = "Hello, \(World().name)!" let logger = Logger(label: "com.example.BestExampleApp.main") logger.info("\(output)") + + #if canImport(os) + os_log("This is a debug message.", log: OSLog.default, type: .debug) + #endif } } diff --git a/gazelle/internal/swift/dependency_index.go b/gazelle/internal/swift/dependency_index.go index ef1094466..1bd7e8f95 100644 --- a/gazelle/internal/swift/dependency_index.go +++ b/gazelle/internal/swift/dependency_index.go @@ -275,8 +275,15 @@ func (di *DependencyIndex) ResolveModulesToProducts( } sort.Sort(sort.Reverse(psrs)) selectedPsr := psrs[0] - selectedPiks = append(selectedPiks, selectedPsr.pik) - modulesToResolve = modulesToResolve.Difference(selectedPsr.intersect) + + if selectedPsr.intersectCnt > 0 { + // We found a product that contains at least one of the modules that we are trying to + // resolve. Add it to the list of selected products and remove the modules that it + // contains from the list of modules that we are trying to resolve. + selectedPiks = append(selectedPiks, selectedPsr.pik) + modulesToResolve = modulesToResolve.Difference(selectedPsr.intersect) + } + potentialPikSet.Remove(selectedPsr.pik) }