Skip to content

WIP: Improve settingsForProductReferenceTarget #32

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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: 2 additions & 1 deletion Sources/SWBCore/BuildFileResolution.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ extension BuildFileResolution {
public protocol GlobalTargetInfoProvider {
func getTargetSettings(_ configuredTarget: ConfiguredTarget) -> Settings
func dependencies(of target: ConfiguredTarget) -> [ConfiguredTarget]
func transitiveDependencies(of: ConfiguredTarget) -> [ConfiguredTarget]
var dynamicallyBuildingTargets: Set<Target> { get }
}

Expand All @@ -41,7 +42,7 @@ extension BuildFileResolution {
/// - remark: If the producing target is a dependency of the current target (likely, but not guaranteed), then the `Settings` will be looked up from the `TargetInfoProvider` (which is likely the `GlobalProductPlan`). Otherwise a more complicated heuristic is used.
public func settingsForProductReferenceTarget(_ productRefTarget: Target, parameters: BuildParameters) -> Settings {
// If we have a concrete client target, we can look up the exact configured target that is producing the referenced product.
if let clientConfiguredTarget = self.configuredTarget, let productRefConfiguredTarget = globalTargetInfoProvider.dependencies(of: clientConfiguredTarget).filter({ $0.target.guid == productRefTarget.guid }).only {
if let clientConfiguredTarget = self.configuredTarget, let productRefConfiguredTarget = globalTargetInfoProvider.transitiveDependencies(of: clientConfiguredTarget).filter({ $0.target.guid == productRefTarget.guid }).only {
return globalTargetInfoProvider.getTargetSettings(productRefConfiguredTarget)
} else {
// FIXME: A more reliable fallback might be to use GlobalProductPlan.productPathsToProducingTargets (where GlobalProductPlan conforms to TargetInfoProvider) if the absolute path of the product reference in this context were passed in.
Expand Down
18 changes: 18 additions & 0 deletions Sources/SWBTaskConstruction/ProductPlanning/ProductPlan.swift
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,24 @@ package final class GlobalProductPlan: GlobalTargetInfoProvider
resolvedDependencies(of: target).map { $0.target }
}

package func transitiveDependencies(of target: ConfiguredTarget) -> [ConfiguredTarget] {
// Use the static target for lookup if necessary.
let configuredTarget: ConfiguredTarget
if let staticTarget = staticallyBuildingTargetsWithDiamondLinkage[target.target] {
configuredTarget = target.replacingTarget(staticTarget)
} else {
configuredTarget = target
}

return transitiveClosure([configuredTarget], successors: planRequest.buildGraph.dependencies(of:)).0.map { dependency in
if let dynamicTarget = dynamicallyBuildingTargetsWithDiamondLinkage[dependency.target] {
return dependency.replacingTarget(dynamicTarget)
} else {
return dependency
}
}
}

package func resolvedDependencies(of target: ConfiguredTarget) -> [ResolvedTargetDependency] {
// Use the static target for lookup if necessary.
let configuredTarget: ConfiguredTarget
Expand Down