Skip to content

Commit 06aa77e

Browse files
authored
[Build] NFC: Rename ModuleBuildDescription property from target t… (#7867)
…o `module` Looks like this was missed by previous refactorings.
1 parent 4ee6cd1 commit 06aa77e

File tree

7 files changed

+219
-223
lines changed

7 files changed

+219
-223
lines changed

Sources/Build/BuildDescription/ModuleBuildDescription.swift

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public enum ModuleBuildDescription: SPMBuildCore.ModuleBuildDescription {
6666
}
6767
}
6868

69-
var target: ResolvedModule {
69+
public var module: ResolvedModule {
7070
switch self {
7171
case .swift(let buildDescription):
7272
return buildDescription.target
@@ -84,10 +84,6 @@ public enum ModuleBuildDescription: SPMBuildCore.ModuleBuildDescription {
8484
}
8585
}
8686

87-
public var module: ResolvedModule {
88-
self.target
89-
}
90-
9187
/// Paths to the binary libraries the target depends on.
9288
var libraryBinaryPaths: Set<AbsolutePath> {
9389
switch self {

Sources/Build/BuildManifest/LLBuildManifestBuilder+Swift.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ extension LLBuildManifestBuilder {
192192
// Sort the product targets in topological order in order to collect and "bubble up"
193193
// their respective dependency graphs to the depending targets.
194194
let nodes = self.plan.targets.compactMap {
195-
ResolvedModule.Dependency.module($0.target, conditions: [])
195+
ResolvedModule.Dependency.module($0.module, conditions: [])
196196
}
197197
let allPackageDependencies = try topologicalSort(nodes, successors: { $0.dependencies })
198198
// Instantiate the inter-module dependency oracle which will cache commonly-scanned
@@ -319,7 +319,7 @@ extension LLBuildManifestBuilder {
319319
for targetDescription: ModuleBuildDescription,
320320
dependencyModuleDetailsMap: inout SwiftDriver.ExternalTargetModuleDetailsMap
321321
) throws {
322-
for dependency in targetDescription.target.dependencies(satisfying: targetDescription.buildParameters.buildEnvironment) {
322+
for dependency in targetDescription.module.dependencies(satisfying: targetDescription.buildParameters.buildEnvironment) {
323323
switch dependency {
324324
case .product:
325325
// Product dependencies are broken down into the targets that make them up.
@@ -358,7 +358,7 @@ extension LLBuildManifestBuilder {
358358
guard case .swift(let dependencySwiftTargetDescription) = targetDescription else {
359359
return
360360
}
361-
dependencyModuleDetailsMap[ModuleDependencyId.swiftPlaceholder(targetDescription.target.c99name)] =
361+
dependencyModuleDetailsMap[ModuleDependencyId.swiftPlaceholder(targetDescription.module.c99name)] =
362362
SwiftDriver.ExternalTargetModuleDetails(
363363
path: TSCAbsolutePath(dependencySwiftTargetDescription.moduleOutputPath),
364364
isFramework: false

Sources/Build/BuildManifest/LLBuildManifestBuilder.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,11 +239,11 @@ extension LLBuildManifestBuilder {
239239
let additionalOutputs: [Node]
240240
if command.outputFiles.isEmpty {
241241
if target.toolsVersion >= .v6_0 {
242-
additionalOutputs = [.virtual("\(target.target.c99name)-\(command.configuration.displayName ?? "\(pluginNumber)")")]
242+
additionalOutputs = [.virtual("\(target.module.c99name)-\(command.configuration.displayName ?? "\(pluginNumber)")")]
243243
phonyOutputs += additionalOutputs
244244
} else {
245245
additionalOutputs = []
246-
observabilityScope.emit(warning: "Build tool command '\(displayName)' (applied to target '\(target.target.name)') does not declare any output files and therefore will not run. You may want to consider updating the given package to tools-version 6.0 (or higher) which would run such a build tool command even without declared outputs.")
246+
observabilityScope.emit(warning: "Build tool command '\(displayName)' (applied to target '\(target.module.name)') does not declare any output files and therefore will not run. You may want to consider updating the given package to tools-version 6.0 (or higher) which would run such a build tool command even without declared outputs.")
247247
}
248248
pluginNumber += 1
249249
} else {
@@ -334,7 +334,7 @@ extension ModuleBuildDescription {
334334

335335
extension ModuleBuildDescription {
336336
package var llbuildResourcesCmdName: String {
337-
"\(self.target.name)-\(self.buildParameters.triple.tripleString)-\(self.buildParameters.buildConfig)\(self.buildParameters.suffix).module-resources"
337+
"\(self.module.name)-\(self.buildParameters.triple.tripleString)-\(self.buildParameters.buildConfig)\(self.buildParameters.suffix).module-resources"
338338
}
339339
}
340340

Sources/Build/BuildOperation.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -812,19 +812,19 @@ public final class BuildOperation: PackageStructureDelegate, SPMBuildCore.BuildS
812812

813813
public func provideBuildErrorAdvice(for target: String, command: String, message: String) -> String? {
814814
// Find the target for which the error was emitted. If we don't find it, we can't give any advice.
815-
guard let _ = self._buildPlan?.targets.first(where: { $0.target.name == target }) else { return nil }
815+
guard let _ = self._buildPlan?.targets.first(where: { $0.module.name == target }) else { return nil }
816816

817817
// Check for cases involving modules that cannot be found.
818818
if let importedModule = try? RegEx(pattern: "no such module '(.+)'").matchGroups(in: message).first?.first {
819819
// A target is importing a module that can't be found. We take a look at the build plan and see if can offer any advice.
820820

821821
// Look for a target with the same module name as the one that's being imported.
822-
if let importedTarget = self._buildPlan?.targets.first(where: { $0.target.c99name == importedModule }) {
822+
if let importedTarget = self._buildPlan?.targets.first(where: { $0.module.c99name == importedModule }) {
823823
// For the moment we just check for executables that other targets try to import.
824-
if importedTarget.target.type == .executable {
824+
if importedTarget.module.type == .executable {
825825
return "module '\(importedModule)' is the main module of an executable, and cannot be imported by tests and other targets"
826826
}
827-
if importedTarget.target.type == .macro {
827+
if importedTarget.module.type == .macro {
828828
return "module '\(importedModule)' is a macro, and cannot be imported by tests and other targets"
829829
}
830830

Sources/Build/LLBuildDescription.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,11 @@ public struct BuildDescription: Codable {
109109
self.traitConfiguration = traitConfiguration
110110
self.targetDependencyMap = try plan.targets
111111
.reduce(into: [TargetName: [TargetName]]()) { partial, targetBuildDescription in
112-
let deps = try targetBuildDescription.target.recursiveDependencies(
112+
let deps = try targetBuildDescription.module.recursiveDependencies(
113113
satisfying: targetBuildDescription.buildParameters.buildEnvironment
114114
)
115115
.compactMap(\.module).map(\.c99name)
116-
partial[targetBuildDescription.target.c99name] = deps
116+
partial[targetBuildDescription.module.c99name] = deps
117117
}
118118
var targetCommandLines: [TargetName: [CommandLineFlag]] = [:]
119119
var generatedSourceTargets: [TargetName] = []

Tests/BuildTests/BuildPlanTests.swift

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,8 @@ final class BuildPlanTests: XCTestCase {
179179
))
180180
result.checkProductsCount(2)
181181
result.checkTargetsCount(3)
182-
XCTAssertTrue(result.targetMap.values.contains { $0.target.name == "FooLogging" })
183-
XCTAssertTrue(result.targetMap.values.contains { $0.target.name == "BarLogging" })
182+
XCTAssertTrue(result.targetMap.values.contains { $0.module.name == "FooLogging" })
183+
XCTAssertTrue(result.targetMap.values.contains { $0.module.name == "BarLogging" })
184184
}
185185

186186
func testDuplicateProductNamesUpstream1() async throws {
@@ -304,11 +304,11 @@ final class BuildPlanTests: XCTestCase {
304304
))
305305
result.checkProductsCount(1)
306306
result.checkTargetsCount(6)
307-
XCTAssertTrue(result.targetMap.values.contains { $0.target.name == "FooLogging" })
308-
XCTAssertTrue(result.targetMap.values.contains { $0.target.name == "BarLogging" })
309-
XCTAssertTrue(result.targetMap.values.contains { $0.target.name == "BazLogging" })
310-
XCTAssertTrue(result.targetMap.values.contains { $0.target.name == "XUtils" })
311-
XCTAssertTrue(result.targetMap.values.contains { $0.target.name == "YUtils" })
307+
XCTAssertTrue(result.targetMap.values.contains { $0.module.name == "FooLogging" })
308+
XCTAssertTrue(result.targetMap.values.contains { $0.module.name == "BarLogging" })
309+
XCTAssertTrue(result.targetMap.values.contains { $0.module.name == "BazLogging" })
310+
XCTAssertTrue(result.targetMap.values.contains { $0.module.name == "XUtils" })
311+
XCTAssertTrue(result.targetMap.values.contains { $0.module.name == "YUtils" })
312312
}
313313

314314
func testDuplicateProductNamesUpstream2() async throws {
@@ -399,9 +399,9 @@ final class BuildPlanTests: XCTestCase {
399399
))
400400
result.checkProductsCount(1)
401401
result.checkTargetsCount(4)
402-
XCTAssertTrue(result.targetMap.values.contains { $0.target.name == "Logging" })
403-
XCTAssertTrue(result.targetMap.values.contains { $0.target.name == "BarLogging" })
404-
XCTAssertTrue(result.targetMap.values.contains { $0.target.name == "BazLogging" })
402+
XCTAssertTrue(result.targetMap.values.contains { $0.module.name == "Logging" })
403+
XCTAssertTrue(result.targetMap.values.contains { $0.module.name == "BarLogging" })
404+
XCTAssertTrue(result.targetMap.values.contains { $0.module.name == "BazLogging" })
405405
}
406406

407407
func testDuplicateProductNamesChained() async throws {
@@ -476,8 +476,8 @@ final class BuildPlanTests: XCTestCase {
476476
))
477477
result.checkProductsCount(1)
478478
result.checkTargetsCount(3)
479-
XCTAssertTrue(result.targetMap.values.contains { $0.target.name == "FooLogging" })
480-
XCTAssertTrue(result.targetMap.values.contains { $0.target.name == "BarLogging" })
479+
XCTAssertTrue(result.targetMap.values.contains { $0.module.name == "FooLogging" })
480+
XCTAssertTrue(result.targetMap.values.contains { $0.module.name == "BarLogging" })
481481
}
482482

483483
func testDuplicateProductNamesThrowError() async throws {
@@ -609,8 +609,8 @@ final class BuildPlanTests: XCTestCase {
609609
))
610610
result.checkProductsCount(1)
611611
result.checkTargetsCount(3)
612-
XCTAssertTrue(result.targetMap.values.contains { $0.target.name == "FooLogging" })
613-
XCTAssertTrue(result.targetMap.values.contains { $0.target.name == "BarLogging" })
612+
XCTAssertTrue(result.targetMap.values.contains { $0.module.name == "FooLogging" })
613+
XCTAssertTrue(result.targetMap.values.contains { $0.module.name == "BarLogging" })
614614
}
615615

616616
func testPackageNameFlag() async throws {
@@ -6092,8 +6092,8 @@ final class BuildPlanTests: XCTestCase {
60926092
let result = try BuildPlanResult(plan: plan)
60936093
result.checkProductsCount(1)
60946094
result.checkTargetsCount(2)
6095-
XCTAssertTrue(result.targetMap.values.contains { $0.target.name == "ASnippet" && $0.target.type == .snippet })
6096-
XCTAssertTrue(result.targetMap.values.contains { $0.target.name == "Lib" })
6095+
XCTAssertTrue(result.targetMap.values.contains { $0.module.name == "ASnippet" && $0.module.type == .snippet })
6096+
XCTAssertTrue(result.targetMap.values.contains { $0.module.name == "Lib" })
60976097

60986098
let yaml = buildPath.appending("release.yaml")
60996099
let llbuild = LLBuildManifestBuilder(plan, fileSystem: fs, observabilityScope: observability.topScope)
@@ -6438,8 +6438,8 @@ final class BuildPlanTests: XCTestCase {
64386438
))
64396439
result.checkProductsCount(3)
64406440
result.checkTargetsCount(3)
6441-
XCTAssertTrue(result.targetMap.values.contains { $0.target.name == "FooLogging" })
6442-
XCTAssertTrue(result.targetMap.values.contains { $0.target.name == "BarLogging" })
6441+
XCTAssertTrue(result.targetMap.values.contains { $0.module.name == "FooLogging" })
6442+
XCTAssertTrue(result.targetMap.values.contains { $0.module.name == "BarLogging" })
64436443
let buildProduct = try XCTUnwrap(
64446444
result.productMap[.init(
64456445
productName: "exe",

0 commit comments

Comments
 (0)