Skip to content

Commit e13a3aa

Browse files
authored
Fix most "target"/"module" internal naming inconsistencies (#7690)
Cleaning up `PackageGraph` and `Build` code naming inconsistencies after `ResolvedTarget` to `ResolvedModule` renaming. User-visible strings and symbols still reference it as "target", but at least it's easier to navigate for contributors. `public` symbols gained deprecation notices where this was possible and easy to add.
1 parent b617ed3 commit e13a3aa

File tree

105 files changed

+1786
-1691
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

105 files changed

+1786
-1691
lines changed

Examples/package-info/Sources/package-info/example.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ struct Example {
3939
print("Targets:", targets)
4040

4141
// Package
42-
let executables = package.targets.filter({ $0.type == .executable }).map({ $0.name })
42+
let executables = package.modules.filter({ $0.type == .executable }).map({ $0.name })
4343
print("Executable targets:", executables)
4444

4545
// PackageGraph
46-
let numberOfFiles = graph.reachableTargets.reduce(0, { $0 + $1.sources.paths.count })
46+
let numberOfFiles = graph.reachableModules.reduce(0, { $0 + $1.sources.paths.count })
4747
print("Total number of source files (including dependencies):", numberOfFiles)
4848
}
4949
}

Sources/Build/BuildDescription/ClangTargetBuildDescription.swift renamed to Sources/Build/BuildDescription/ClangModuleBuildDescription.swift

+7-4
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,19 @@ import struct SPMBuildCore.PrebuildCommandResult
2222

2323
import enum TSCBasic.ProcessEnv
2424

25-
/// Target description for a Clang target i.e. C language family target.
26-
public final class ClangTargetBuildDescription {
25+
@available(*, deprecated, renamed: "ClangModuleBuildDescription")
26+
public typealias ClangTargetBuildDescription = ClangModuleBuildDescription
27+
28+
/// Build description for a Clang target i.e. C language family module.
29+
public final class ClangModuleBuildDescription {
2730
/// The package this target belongs to.
2831
public let package: ResolvedPackage
2932

3033
/// The target described by this target.
3134
public let target: ResolvedModule
3235

3336
/// The underlying clang target.
34-
public let clangTarget: ClangTarget
37+
public let clangTarget: ClangModule
3538

3639
/// The tools version of the package that declared the target. This can
3740
/// can be used to conditionalize semantically significant changes in how
@@ -123,7 +126,7 @@ public final class ClangTargetBuildDescription {
123126
fileSystem: FileSystem,
124127
observabilityScope: ObservabilityScope
125128
) throws {
126-
guard let clangTarget = target.underlying as? ClangTarget else {
129+
guard let clangTarget = target.underlying as? ClangModule else {
127130
throw InternalError("underlying target type mismatch \(target)")
128131
}
129132

Sources/Build/BuildDescription/TargetBuildDescription.swift renamed to Sources/Build/BuildDescription/ModuleBuildDescription.swift

+41-38
Original file line numberDiff line numberDiff line change
@@ -21,52 +21,55 @@ public enum BuildDescriptionError: Swift.Error {
2121
case requestedFileNotPartOfTarget(targetName: String, requestedFilePath: AbsolutePath)
2222
}
2323

24-
/// A target description which can either be for a Swift or Clang target.
25-
public enum TargetBuildDescription {
24+
@available(*, deprecated, renamed: "ModuleBuildDescription")
25+
public typealias TargetBuildDescription = ModuleBuildDescription
26+
27+
/// A module build description which can either be for a Swift or Clang module.
28+
public enum ModuleBuildDescription {
2629
/// Swift target description.
27-
case swift(SwiftTargetBuildDescription)
30+
case swift(SwiftModuleBuildDescription)
2831

2932
/// Clang target description.
30-
case clang(ClangTargetBuildDescription)
33+
case clang(ClangModuleBuildDescription)
3134

3235
/// The objects in this target.
3336
var objects: [AbsolutePath] {
3437
get throws {
3538
switch self {
36-
case .swift(let target):
37-
return try target.objects
38-
case .clang(let target):
39-
return try target.objects
39+
case .swift(let module):
40+
return try module.objects
41+
case .clang(let module):
42+
return try module.objects
4043
}
4144
}
4245
}
4346

4447
/// The resources in this target.
4548
var resources: [Resource] {
4649
switch self {
47-
case .swift(let target):
48-
return target.resources
49-
case .clang(let target):
50-
return target.resources
50+
case .swift(let buildDescription):
51+
return buildDescription.resources
52+
case .clang(let buildDescription):
53+
return buildDescription.resources
5154
}
5255
}
5356

5457
/// Path to the bundle generated for this module (if any).
5558
var bundlePath: AbsolutePath? {
5659
switch self {
57-
case .swift(let target):
58-
return target.bundlePath
59-
case .clang(let target):
60-
return target.bundlePath
60+
case .swift(let buildDescription):
61+
return buildDescription.bundlePath
62+
case .clang(let buildDescription):
63+
return buildDescription.bundlePath
6164
}
6265
}
6366

6467
var target: ResolvedModule {
6568
switch self {
66-
case .swift(let target):
67-
return target.target
68-
case .clang(let target):
69-
return target.target
69+
case .swift(let buildDescription):
70+
return buildDescription.target
71+
case .clang(let buildDescription):
72+
return buildDescription.target
7073
}
7174
}
7275

@@ -82,46 +85,46 @@ public enum TargetBuildDescription {
8285

8386
var resourceBundleInfoPlistPath: AbsolutePath? {
8487
switch self {
85-
case .swift(let target):
86-
return target.resourceBundleInfoPlistPath
87-
case .clang(let target):
88-
return target.resourceBundleInfoPlistPath
88+
case .swift(let buildDescription):
89+
return buildDescription.resourceBundleInfoPlistPath
90+
case .clang(let buildDescription):
91+
return buildDescription.resourceBundleInfoPlistPath
8992
}
9093
}
9194

9295
var buildToolPluginInvocationResults: [BuildToolPluginInvocationResult] {
9396
switch self {
94-
case .swift(let target):
95-
return target.buildToolPluginInvocationResults
96-
case .clang(let target):
97-
return target.buildToolPluginInvocationResults
97+
case .swift(let buildDescription):
98+
return buildDescription.buildToolPluginInvocationResults
99+
case .clang(let buildDescription):
100+
return buildDescription.buildToolPluginInvocationResults
98101
}
99102
}
100103

101104
var buildParameters: BuildParameters {
102105
switch self {
103-
case .swift(let swiftTargetBuildDescription):
104-
return swiftTargetBuildDescription.buildParameters
105-
case .clang(let clangTargetBuildDescription):
106-
return clangTargetBuildDescription.buildParameters
106+
case .swift(let buildDescription):
107+
return buildDescription.buildParameters
108+
case .clang(let buildDescription):
109+
return buildDescription.buildParameters
107110
}
108111
}
109112

110113
var toolsVersion: ToolsVersion {
111114
switch self {
112-
case .swift(let swiftTargetBuildDescription):
113-
return swiftTargetBuildDescription.toolsVersion
114-
case .clang(let clangTargetBuildDescription):
115-
return clangTargetBuildDescription.toolsVersion
115+
case .swift(let buildDescription):
116+
return buildDescription.toolsVersion
117+
case .clang(let buildDescription):
118+
return buildDescription.toolsVersion
116119
}
117120
}
118121

119122
/// Determines the arguments needed to run `swift-symbolgraph-extract` for
120123
/// this module.
121124
package func symbolGraphExtractArguments() throws -> [String] {
122125
switch self {
123-
case .swift(let target): try target.symbolGraphExtractArguments()
124-
case .clang(let target): try target.symbolGraphExtractArguments()
126+
case .swift(let buildDescription): try buildDescription.symbolGraphExtractArguments()
127+
case .clang(let buildDescription): try buildDescription.symbolGraphExtractArguments()
125128
}
126129
}
127130
}

Sources/Build/BuildDescription/PluginDescription.swift renamed to Sources/Build/BuildDescription/PluginBuildDescription.swift

+17-17
Original file line numberDiff line numberDiff line change
@@ -16,52 +16,52 @@ import PackageModel
1616
import struct Basics.InternalError
1717
import protocol Basics.FileSystem
1818

19-
/// Description for a plugin target. This is treated a bit differently from the
20-
/// regular kinds of targets, and is not included in the LLBuild description.
21-
/// But because the package graph and build plan are not loaded for incremental
19+
/// Description for a plugin module. This is treated a bit differently from the
20+
/// regular kinds of modules, and is not included in the LLBuild description.
21+
/// But because the modules graph and build plan are not loaded for incremental
2222
/// builds, this information is included in the BuildDescription, and the plugin
23-
/// targets are compiled directly.
24-
public final class PluginDescription: Codable {
23+
/// modules are compiled directly.
24+
public final class PluginBuildDescription: Codable {
2525
/// The identity of the package in which the plugin is defined.
2626
public let package: PackageIdentity
2727

28-
/// The name of the plugin target in that package (this is also the name of
28+
/// The name of the plugin module in that package (this is also the name of
2929
/// the plugin).
30-
public let targetName: String
30+
public let moduleName: String
3131

32-
/// The language-level target name.
33-
public let targetC99Name: String
32+
/// The language-level module name.
33+
public let moduleC99Name: String
3434

3535
/// The names of any plugin products in that package that vend the plugin
3636
/// to other packages.
3737
public let productNames: [String]
3838

39-
/// The tools version of the package that declared the target. This affects
39+
/// The tools version of the package that declared the module. This affects
4040
/// the API that is available in the PackagePlugin module.
4141
public let toolsVersion: ToolsVersion
4242

4343
/// Swift source files that comprise the plugin.
4444
public let sources: Sources
4545

46-
/// Initialize a new plugin target description. The target is expected to be
46+
/// Initialize a new plugin module description. The module is expected to be
4747
/// a `PluginTarget`.
4848
init(
49-
target: ResolvedModule,
49+
module: ResolvedModule,
5050
products: [ResolvedProduct],
5151
package: ResolvedPackage,
5252
toolsVersion: ToolsVersion,
5353
testDiscoveryTarget: Bool = false,
5454
fileSystem: FileSystem
5555
) throws {
56-
guard target.underlying is PluginTarget else {
57-
throw InternalError("underlying target type mismatch \(target)")
56+
guard module.underlying is PluginModule else {
57+
throw InternalError("underlying target type mismatch \(module)")
5858
}
5959

6060
self.package = package.identity
61-
self.targetName = target.name
62-
self.targetC99Name = target.c99name
61+
self.moduleName = module.name
62+
self.moduleC99Name = module.c99name
6363
self.productNames = products.map(\.name)
6464
self.toolsVersion = toolsVersion
65-
self.sources = target.sources
65+
self.sources = module.sources
6666
}
6767
}

Sources/Build/BuildDescription/ProductBuildDescription.swift

+5-5
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ public final class ProductBuildDescription: SPMBuildCore.ProductBuildDescription
172172
args += ["-profile-coverage-mapping", "-profile-generate"]
173173
}
174174

175-
let containsSwiftTargets = self.product.containsSwiftTargets
175+
let containsSwiftTargets = self.product.containsSwiftModules
176176

177177
let derivedProductType: ProductType
178178
switch self.product.type {
@@ -240,8 +240,8 @@ public final class ProductBuildDescription: SPMBuildCore.ProductBuildDescription
240240
// we will instead have generated a source file containing the redirect.
241241
// Support for linking tests against executables is conditional on the tools
242242
// version of the package that defines the executable product.
243-
let executableTarget = try product.executableTarget
244-
if let target = executableTarget.underlying as? SwiftTarget,
243+
let executableTarget = try product.executableModule
244+
if let target = executableTarget.underlying as? SwiftModule,
245245
self.toolsVersion >= .v5_5,
246246
self.buildParameters.driverParameters.canRenameEntrypointFunctionName,
247247
target.supportsTestableExecutablesFeature
@@ -280,7 +280,7 @@ public final class ProductBuildDescription: SPMBuildCore.ProductBuildDescription
280280
// Pass experimental features to link jobs in addition to compile jobs. Preserve ordering while eliminating
281281
// duplicates with `OrderedSet`.
282282
var experimentalFeatures = OrderedSet<String>()
283-
for target in self.product.targets {
283+
for target in self.product.modules {
284284
let swiftSettings = target.underlying.buildSettingsDescription.filter { $0.tool == .swift }
285285
for case let .enableExperimentalFeature(feature) in swiftSettings.map(\.kind) {
286286
experimentalFeatures.append(feature)
@@ -327,7 +327,7 @@ public final class ProductBuildDescription: SPMBuildCore.ProductBuildDescription
327327
// setting is the package-level right now. We might need to figure out a better
328328
// answer for libraries if/when we support specifying deployment target at the
329329
// target-level.
330-
args += try self.buildParameters.tripleArgs(for: self.product.targets[self.product.targets.startIndex])
330+
args += try self.buildParameters.tripleArgs(for: self.product.modules[self.product.modules.startIndex])
331331

332332
// Add arguments from declared build settings.
333333
args += self.buildSettingsFlags

Sources/Build/BuildDescription/SwiftTargetBuildDescription.swift renamed to Sources/Build/BuildDescription/SwiftModuleBuildDescription.swift

+11-8
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,18 @@ import DriverSupport
2828

2929
import struct TSCBasic.ByteString
3030

31-
/// Target description for a Swift target.
32-
public final class SwiftTargetBuildDescription {
31+
@available(*, deprecated, renamed: "SwiftModuleBuildDescription")
32+
public typealias SwiftTargetBuildDescription = SwiftModuleBuildDescription
33+
34+
/// Build description for a Swift module.
35+
public final class SwiftModuleBuildDescription {
3336
/// The package this target belongs to.
3437
public let package: ResolvedPackage
3538

3639
/// The target described by this target.
3740
public let target: ResolvedModule
3841

39-
private let swiftTarget: SwiftTarget
42+
private let swiftTarget: SwiftModule
4043

4144
/// The tools version of the package that declared the target. This can
4245
/// can be used to conditionalize semantically significant changes in how
@@ -262,7 +265,7 @@ public final class SwiftTargetBuildDescription {
262265
fileSystem: FileSystem,
263266
observabilityScope: ObservabilityScope
264267
) throws {
265-
guard let swiftTarget = target.underlying as? SwiftTarget else {
268+
guard let swiftTarget = target.underlying as? SwiftModule else {
266269
throw InternalError("underlying target type mismatch \(target)")
267270
}
268271

@@ -417,7 +420,7 @@ public final class SwiftTargetBuildDescription {
417420
}
418421
#else
419422
try self.requiredMacroProducts.forEach { macro in
420-
if let macroTarget = macro.product.targets.first {
423+
if let macroTarget = macro.product.modules.first {
421424
let executablePath = try macro.binaryPath.pathString
422425
args += ["-Xfrontend", "-load-plugin-executable", "-Xfrontend", "\(executablePath)#\(macroTarget.c99name)"]
423426
} else {
@@ -485,7 +488,7 @@ public final class SwiftTargetBuildDescription {
485488
// when we link the executable, we will ask the linker to rename the entry point
486489
// symbol to just `_main` again (or if the linker doesn't support it, we'll
487490
// generate a source containing a redirect).
488-
if (self.target.underlying as? SwiftTarget)?.supportsTestableExecutablesFeature == true
491+
if (self.target.underlying as? SwiftModule)?.supportsTestableExecutablesFeature == true
489492
&& !self.isTestTarget && self.toolsVersion >= .v5_5
490493
{
491494
// We only do this if the linker supports it, as indicated by whether we
@@ -686,7 +689,7 @@ public final class SwiftTargetBuildDescription {
686689
// enables cxx interop and copy it's flag.
687690
switch self.testTargetRole {
688691
case .discovery, .entryPoint:
689-
for module in try self.target.recursiveTargetDependencies() {
692+
for module in try self.target.recursiveModuleDependencies() {
690693
if let args = cxxInteroperabilityModeAndStandard(for: module) {
691694
return args
692695
}
@@ -894,7 +897,7 @@ public final class SwiftTargetBuildDescription {
894897

895898
// Include path for the toolchain's copy of SwiftSyntax.
896899
#if BUILD_MACROS_AS_DYLIBS
897-
if target.type == .macro {
900+
if module.type == .macro {
898901
flags += try ["-I", self.defaultBuildParameters.toolchain.hostLibDir.pathString]
899902
}
900903
#endif

Sources/Build/BuildManifest/LLBuildManifestBuilder+Clang.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import PackageModel
2020
extension LLBuildManifestBuilder {
2121
/// Create a llbuild target for a Clang target description.
2222
func createClangCompileCommand(
23-
_ target: ClangTargetBuildDescription
23+
_ target: ClangModuleBuildDescription
2424
) throws {
2525
var inputs: [Node] = []
2626

@@ -40,7 +40,7 @@ extension LLBuildManifestBuilder {
4040

4141
for dependency in target.target.dependencies(satisfying: target.buildEnvironment) {
4242
switch dependency {
43-
case .target(let target, _):
43+
case .module(let target, _):
4444
addStaticTargetInputs(target)
4545

4646
case .product(let product, _):
@@ -54,7 +54,7 @@ extension LLBuildManifestBuilder {
5454
inputs.append(file: binary)
5555

5656
case .library(.automatic), .library(.static), .plugin:
57-
for target in product.targets {
57+
for target in product.modules {
5858
addStaticTargetInputs(target)
5959
}
6060
case .test:
@@ -113,7 +113,7 @@ extension LLBuildManifestBuilder {
113113

114114
/// Create a llbuild target for a Clang target preparation
115115
func createClangPrepareCommand(
116-
_ target: ClangTargetBuildDescription
116+
_ target: ClangModuleBuildDescription
117117
) throws {
118118
// Create the node for the target so you can --target it.
119119
// It is a no-op for index preparation.

0 commit comments

Comments
 (0)