Skip to content

Rename ResolvedTarget to ResolvedModule #7459

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
Apr 15, 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
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import PackageGraph
import PackageLoading
import PackageModel
import struct PackageGraph.ModulesGraph
import struct PackageGraph.ResolvedTarget
import struct PackageGraph.ResolvedModule
import struct SPMBuildCore.BuildParameters
import struct SPMBuildCore.BuildToolPluginInvocationResult
import struct SPMBuildCore.PrebuildCommandResult
Expand All @@ -28,7 +28,7 @@ package final class ClangTargetBuildDescription {
package let package: ResolvedPackage

/// The target described by this target.
package let target: ResolvedTarget
package let target: ResolvedModule
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: looks like the comment needs updating as well :)


/// The underlying clang target.
package let clangTarget: ClangTarget
Expand Down Expand Up @@ -114,7 +114,7 @@ package final class ClangTargetBuildDescription {
/// Create a new target description with target and build parameters.
init(
package: ResolvedPackage,
target: ResolvedTarget,
target: ResolvedModule,
toolsVersion: ToolsVersion,
additionalFileRules: [FileRuleDescription] = [],
buildParameters: BuildParameters,
Expand Down
2 changes: 1 addition & 1 deletion Sources/Build/BuildDescription/PluginDescription.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ package final class PluginDescription: Codable {
/// Initialize a new plugin target description. The target is expected to be
/// a `PluginTarget`.
init(
target: ResolvedTarget,
target: ResolvedModule,
products: [ResolvedProduct],
package: ResolvedPackage,
toolsVersion: ToolsVersion,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ package final class ProductBuildDescription: SPMBuildCore.ProductBuildDescriptio
var additionalFlags: [String] = []

/// The list of targets that are going to be linked statically in this product.
var staticTargets: [ResolvedTarget] = []
var staticTargets: [ResolvedModule] = []
Copy link
Contributor

Choose a reason for hiding this comment

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

Would this be updated in a follow-up?


/// The list of Swift modules that should be passed to the linker. This is required for debugging to work.
var swiftASTs: SortedArray<AbsolutePath> = .init()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ package final class SwiftTargetBuildDescription {
package let package: ResolvedPackage

/// The target described by this target.
package let target: ResolvedTarget
package let target: ResolvedModule
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Same comment issue here.


private let swiftTarget: SwiftTarget

Expand Down Expand Up @@ -248,7 +248,7 @@ package final class SwiftTargetBuildDescription {
/// Create a new target description with target and build parameters.
init(
package: ResolvedPackage,
target: ResolvedTarget,
target: ResolvedModule,
toolsVersion: ToolsVersion,
additionalFileRules: [FileRuleDescription] = [],
buildParameters: BuildParameters,
Expand Down
4 changes: 2 additions & 2 deletions Sources/Build/BuildDescription/TargetBuildDescription.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
//===----------------------------------------------------------------------===//

import Basics
import struct PackageGraph.ResolvedTarget
import struct PackageGraph.ResolvedModule
import struct PackageModel.Resource
import struct PackageModel.ToolsVersion
import struct SPMBuildCore.BuildToolPluginInvocationResult
Expand Down Expand Up @@ -61,7 +61,7 @@ package enum TargetBuildDescription {
}
}

var target: ResolvedTarget {
var target: ResolvedModule {
switch self {
case .swift(let target):
return target.target
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import struct LLBuildManifest.Node
import struct Basics.AbsolutePath
import struct Basics.InternalError
import class Basics.ObservabilityScope
import struct PackageGraph.ResolvedTarget
import struct PackageGraph.ResolvedModule
import PackageModel

extension LLBuildManifestBuilder {
Expand All @@ -32,7 +32,7 @@ extension LLBuildManifestBuilder {
inputs.append(resourcesNode)
}

func addStaticTargetInputs(_ target: ResolvedTarget) {
func addStaticTargetInputs(_ target: ResolvedModule) {
if case .swift(let desc)? = self.plan.targetMap[target.id], target.type == .library {
inputs.append(file: desc.moduleOutputPath)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import struct Basics.TSCAbsolutePath
import struct LLBuildManifest.Node
import struct LLBuildManifest.LLBuildManifest
import struct SPMBuildCore.BuildParameters
import struct PackageGraph.ResolvedTarget
import struct PackageGraph.ResolvedModule
import protocol TSCBasic.FileSystem
import enum TSCBasic.ProcessEnv
import func TSCBasic.topologicalSort
Expand Down Expand Up @@ -191,9 +191,9 @@ extension LLBuildManifestBuilder {
package func addTargetsToExplicitBuildManifest() throws {
// Sort the product targets in topological order in order to collect and "bubble up"
// their respective dependency graphs to the depending targets.
let nodes: [ResolvedTarget.Dependency] = try self.plan.targetMap.keys.compactMap {
let nodes: [ResolvedModule.Dependency] = try self.plan.targetMap.keys.compactMap {
guard let target = self.plan.graph.allTargets[$0] else { throw InternalError("unknown target \($0)") }
return ResolvedTarget.Dependency.target(target, conditions: [])
return ResolvedModule.Dependency.target(target, conditions: [])
}
let allPackageDependencies = try topologicalSort(nodes, successors: { $0.dependencies })
// Instantiate the inter-module dependency oracle which will cache commonly-scanned
Expand Down Expand Up @@ -415,7 +415,7 @@ extension LLBuildManifestBuilder {
inputs.append(resourcesNode)
}

func addStaticTargetInputs(_ target: ResolvedTarget) throws {
func addStaticTargetInputs(_ target: ResolvedModule) throws {
// Ignore C Modules.
if target.underlying is SystemLibraryTarget { return }
// Ignore Binary Modules.
Expand Down
2 changes: 1 addition & 1 deletion Sources/Build/BuildManifest/LLBuildManifestBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ extension TargetBuildDescription {
}
}

extension ResolvedTarget {
extension ResolvedModule {
package func getCommandName(config: String) -> String {
"C." + self.getLLBuildTargetName(config: config)
}
Expand Down
6 changes: 3 additions & 3 deletions Sources/Build/BuildOperation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -535,8 +535,8 @@ package final class BuildOperation: PackageStructureDelegate, SPMBuildCore.Build
private func plan(subset: BuildSubset? = nil) throws -> (description: BuildDescription, manifest: LLBuildManifest) {
// Load the package graph.
let graph = try getPackageGraph()
let buildToolPluginInvocationResults: [ResolvedTarget.ID: (target: ResolvedTarget, results: [BuildToolPluginInvocationResult])]
let prebuildCommandResults: [ResolvedTarget.ID: [PrebuildCommandResult]]
let buildToolPluginInvocationResults: [ResolvedModule.ID: (target: ResolvedModule, results: [BuildToolPluginInvocationResult])]
let prebuildCommandResults: [ResolvedModule.ID: [PrebuildCommandResult]]
// Invoke any build tool plugins in the graph to generate prebuild commands and build commands.
if let pluginConfiguration, !self.productsBuildParameters.shouldSkipBuilding {
// Hacky workaround for rdar://120560817, but it replicates precisely enough the original behavior before
Expand Down Expand Up @@ -879,7 +879,7 @@ extension BuildDescription {
}

extension BuildSubset {
func recursiveDependencies(for graph: ModulesGraph, observabilityScope: ObservabilityScope) throws -> [ResolvedTarget]? {
func recursiveDependencies(for graph: ModulesGraph, observabilityScope: ObservabilityScope) throws -> [ResolvedModule]? {
switch self {
case .allIncludingTests:
return Array(graph.reachableTargets)
Expand Down
14 changes: 7 additions & 7 deletions Sources/Build/BuildPlan/BuildPlan+Product.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import struct Basics.AbsolutePath
import struct Basics.Triple
import struct Basics.InternalError
import struct PackageGraph.ResolvedProduct
import struct PackageGraph.ResolvedTarget
import struct PackageGraph.ResolvedModule
import class PackageModel.BinaryTarget
import class PackageModel.ClangTarget

Expand Down Expand Up @@ -124,8 +124,8 @@ extension BuildPlan {
buildParameters: BuildParameters
) throws -> (
dylibs: [ResolvedProduct],
staticTargets: [ResolvedTarget],
systemModules: [ResolvedTarget],
staticTargets: [ResolvedModule],
systemModules: [ResolvedModule],
libraryBinaryPaths: Set<AbsolutePath>,
availableTools: [String: AbsolutePath]
) {
Expand Down Expand Up @@ -160,7 +160,7 @@ extension BuildPlan {
}

// Sort the product targets in topological order.
let nodes: [ResolvedTarget.Dependency] = product.targets.map { .target($0, conditions: []) }
let nodes: [ResolvedModule.Dependency] = product.targets.map { .target($0, conditions: []) }
let allTargets = try topologicalSort(nodes, successors: { dependency in
switch dependency {
// Include all the dependencies of a target.
Expand All @@ -185,7 +185,7 @@ extension BuildPlan {
return []
}

let productDependencies: [ResolvedTarget.Dependency] = product.targets.map { .target($0, conditions: []) }
let productDependencies: [ResolvedModule.Dependency] = product.targets.map { .target($0, conditions: []) }
switch product.type {
case .library(.automatic), .library(.static):
return productDependencies
Expand All @@ -201,8 +201,8 @@ extension BuildPlan {

// Create empty arrays to collect our results.
var linkLibraries = [ResolvedProduct]()
var staticTargets = [ResolvedTarget]()
var systemModules = [ResolvedTarget]()
var staticTargets = [ResolvedModule]()
var systemModules = [ResolvedModule]()
var libraryBinaryPaths: Set<AbsolutePath> = []
var availableTools = [String: AbsolutePath]()

Expand Down
16 changes: 8 additions & 8 deletions Sources/Build/BuildPlan/BuildPlan+Test.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import struct LLBuildManifest.TestDiscoveryTool
import struct LLBuildManifest.TestEntryPointTool
import struct PackageGraph.ModulesGraph
import struct PackageGraph.ResolvedProduct
import struct PackageGraph.ResolvedTarget
import struct PackageGraph.ResolvedModule
import struct PackageModel.Sources
import class PackageModel.SwiftTarget
import class PackageModel.Target
Expand Down Expand Up @@ -66,7 +66,7 @@ extension BuildPlan {
}

/// Generates test discovery targets, which contain derived sources listing the discovered tests.
func generateDiscoveryTargets() throws -> (target: SwiftTarget, resolved: ResolvedTarget, buildDescription: SwiftTargetBuildDescription) {
func generateDiscoveryTargets() throws -> (target: SwiftTarget, resolved: ResolvedModule, buildDescription: SwiftTargetBuildDescription) {
let discoveryTargetName = "\(package.manifest.displayName)PackageDiscoveredTests"
let discoveryDerivedDir = buildParameters.buildPath.appending(components: "\(discoveryTargetName).derived")
let discoveryMainFile = discoveryDerivedDir.appending(component: TestDiscoveryTool.mainFileName)
Expand All @@ -84,7 +84,7 @@ extension BuildPlan {
packageAccess: true, // test target is allowed access to package decls by default
testDiscoverySrc: Sources(paths: discoveryPaths, root: discoveryDerivedDir)
)
let discoveryResolvedTarget = ResolvedTarget(
let discoveryResolvedTarget = ResolvedModule(
packageIdentity: testProduct.packageIdentity,
underlying: discoveryTarget,
dependencies: testProduct.targets.map { .target($0, conditions: []) },
Expand All @@ -110,7 +110,7 @@ extension BuildPlan {
/// point API and leverages the test discovery target to reference which tests to run.
func generateSynthesizedEntryPointTarget(
swiftTargetDependencies: [Target.Dependency],
resolvedTargetDependencies: [ResolvedTarget.Dependency]
resolvedTargetDependencies: [ResolvedModule.Dependency]
) throws -> SwiftTargetBuildDescription {
let entryPointDerivedDir = buildParameters.buildPath.appending(components: "\(testProduct.name).derived")
let entryPointMainFileName = TestEntryPointTool.mainFileName(for: buildParameters.testingParameters.library)
Expand All @@ -124,7 +124,7 @@ extension BuildPlan {
packageAccess: true, // test target is allowed access to package decls
testEntryPointSources: entryPointSources
)
let entryPointResolvedTarget = ResolvedTarget(
let entryPointResolvedTarget = ResolvedModule(
packageIdentity: testProduct.packageIdentity,
underlying: entryPointTarget,
dependencies: testProduct.targets.map { .target($0, conditions: []) } + resolvedTargetDependencies,
Expand All @@ -144,9 +144,9 @@ extension BuildPlan {
)
}

let discoveryTargets: (target: SwiftTarget, resolved: ResolvedTarget, buildDescription: SwiftTargetBuildDescription)?
let discoveryTargets: (target: SwiftTarget, resolved: ResolvedModule, buildDescription: SwiftTargetBuildDescription)?
let swiftTargetDependencies: [Target.Dependency]
let resolvedTargetDependencies: [ResolvedTarget.Dependency]
let resolvedTargetDependencies: [ResolvedModule.Dependency]

switch buildParameters.testingParameters.library {
case .xctest:
Expand All @@ -169,7 +169,7 @@ extension BuildPlan {
packageAccess: entryPointResolvedTarget.packageAccess,
testEntryPointSources: entryPointResolvedTarget.underlying.sources
)
let entryPointResolvedTarget = ResolvedTarget(
let entryPointResolvedTarget = ResolvedModule(
packageIdentity: testProduct.packageIdentity,
underlying: entryPointTarget,
dependencies: entryPointResolvedTarget.dependencies + resolvedTargetDependencies,
Expand Down
32 changes: 16 additions & 16 deletions Sources/Build/BuildPlan/BuildPlan.swift
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ extension BuildParameters {
}

/// Returns the compiler arguments for the index store, if enabled.
func indexStoreArguments(for target: ResolvedTarget) -> [String] {
func indexStoreArguments(for target: ResolvedModule) -> [String] {
let addIndexStoreArguments: Bool
switch indexStoreMode {
case .on:
Expand All @@ -128,7 +128,7 @@ extension BuildParameters {
}

/// Computes the target triple arguments for a given resolved target.
package func targetTripleArgs(for target: ResolvedTarget) throws -> [String] {
package func targetTripleArgs(for target: ResolvedModule) throws -> [String] {
var args = ["-target"]

// Compute the triple string for Darwin platform using the platform version.
Expand All @@ -144,7 +144,7 @@ extension BuildParameters {

/// Computes the linker flags to use in order to rename a module-named main function to 'main' for the target
/// platform, or nil if the linker doesn't support it for the platform.
func linkerFlagsForRenamingMainFunction(of target: ResolvedTarget) -> [String]? {
func linkerFlagsForRenamingMainFunction(of target: ResolvedModule) -> [String]? {
let args: [String]
if self.triple.isApple() {
args = ["-alias", "_\(target.c99name)_main", "_main"]
Expand All @@ -157,7 +157,7 @@ extension BuildParameters {
}

/// Returns the scoped view of build settings for a given target.
func createScope(for target: ResolvedTarget) -> BuildSettings.Scope {
func createScope(for target: ResolvedModule) -> BuildSettings.Scope {
BuildSettings.Scope(target.underlying.buildSettings, environment: buildEnvironment)
}
}
Expand Down Expand Up @@ -186,7 +186,7 @@ public class BuildPlan: SPMBuildCore.BuildPlan {
public let toolsBuildParameters: BuildParameters

/// Triple for which this target is compiled.
private func buildTriple(for target: ResolvedTarget) -> Basics.Triple {
private func buildTriple(for target: ResolvedModule) -> Basics.Triple {
self.buildParameters(for: target).triple
}

Expand All @@ -199,7 +199,7 @@ public class BuildPlan: SPMBuildCore.BuildPlan {
package let graph: ModulesGraph

/// The target build description map.
package let targetMap: [ResolvedTarget.ID: TargetBuildDescription]
package let targetMap: [ResolvedModule.ID: TargetBuildDescription]

/// The product build description map.
package let productMap: [ResolvedProduct.ID: ProductBuildDescription]
Expand All @@ -219,13 +219,13 @@ public class BuildPlan: SPMBuildCore.BuildPlan {
}

/// The results of invoking any build tool plugins used by targets in this build.
package let buildToolPluginInvocationResults: [ResolvedTarget.ID: [BuildToolPluginInvocationResult]]
package let buildToolPluginInvocationResults: [ResolvedModule.ID: [BuildToolPluginInvocationResult]]

/// The results of running any prebuild commands for the targets in this build. This includes any derived
/// source files as well as directories to which any changes should cause us to reevaluate the build plan.
package let prebuildCommandResults: [ResolvedTarget.ID: [PrebuildCommandResult]]
package let prebuildCommandResults: [ResolvedModule.ID: [PrebuildCommandResult]]

package private(set) var derivedTestTargetsMap: [ResolvedProduct.ID: [ResolvedTarget]] = [:]
package private(set) var derivedTestTargetsMap: [ResolvedProduct.ID: [ResolvedModule]] = [:]

/// Cache for pkgConfig flags.
private var pkgConfigCache = [SystemLibraryTarget: (cFlags: [String], libs: [String])]()
Expand Down Expand Up @@ -273,8 +273,8 @@ public class BuildPlan: SPMBuildCore.BuildPlan {
toolsBuildParameters: BuildParameters,
graph: ModulesGraph,
additionalFileRules: [FileRuleDescription] = [],
buildToolPluginInvocationResults: [ResolvedTarget.ID: [BuildToolPluginInvocationResult]] = [:],
prebuildCommandResults: [ResolvedTarget.ID: [PrebuildCommandResult]] = [:],
buildToolPluginInvocationResults: [ResolvedModule.ID: [BuildToolPluginInvocationResult]] = [:],
prebuildCommandResults: [ResolvedModule.ID: [PrebuildCommandResult]] = [:],
disableSandbox: Bool = false,
fileSystem: any FileSystem,
observabilityScope: ObservabilityScope
Expand Down Expand Up @@ -315,7 +315,7 @@ public class BuildPlan: SPMBuildCore.BuildPlan {
))
}
let macroProductsByTarget = productMap.values.filter { $0.product.type == .macro }
.reduce(into: [ResolvedTarget.ID: ResolvedProduct]()) {
.reduce(into: [ResolvedModule.ID: ResolvedProduct]()) {
if let target = $1.product.targets.first {
$0[target.id] = $1.product
}
Expand All @@ -325,7 +325,7 @@ public class BuildPlan: SPMBuildCore.BuildPlan {
// Plugin targets are noted, since they need to be compiled, but they do
// not get directly incorporated into the build description that will be
// given to LLBuild.
var targetMap = [ResolvedTarget.ID: TargetBuildDescription]()
var targetMap = [ResolvedModule.ID: TargetBuildDescription]()
var pluginDescriptions = [PluginDescription]()
var shouldGenerateTestObservation = true
for target in graph.allTargets.sorted(by: { $0.name < $1.name }) {
Expand Down Expand Up @@ -473,7 +473,7 @@ public class BuildPlan: SPMBuildCore.BuildPlan {

static func validateDeploymentVersionOfProductDependency(
product: ResolvedProduct,
forTarget target: ResolvedTarget,
forTarget target: ResolvedModule,
buildEnvironment: BuildEnvironment,
observabilityScope: ObservabilityScope
) throws {
Expand Down Expand Up @@ -661,7 +661,7 @@ extension Basics.Diagnostic {
}

static func productRequiresHigherPlatformVersion(
target: ResolvedTarget,
target: ResolvedModule,
targetPlatform: SupportedPlatform,
product: String,
productPlatform: SupportedPlatform
Expand Down Expand Up @@ -693,7 +693,7 @@ extension BuildParameters {
/// Generate the resource bundle Info.plist.
func generateResourceInfoPlist(
fileSystem: FileSystem,
target: ResolvedTarget,
target: ResolvedModule,
path: AbsolutePath
) throws -> Bool {
guard let defaultLocalization = target.defaultLocalization else {
Expand Down
Loading