Skip to content

[Build] NFC: Rename ModuleBuildDescription property from target t… #7867

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
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 @@ -66,7 +66,7 @@ public enum ModuleBuildDescription: SPMBuildCore.ModuleBuildDescription {
}
}

var target: ResolvedModule {
public var module: ResolvedModule {
switch self {
case .swift(let buildDescription):
return buildDescription.target
Expand All @@ -84,10 +84,6 @@ public enum ModuleBuildDescription: SPMBuildCore.ModuleBuildDescription {
}
}

public var module: ResolvedModule {
self.target
}

/// Paths to the binary libraries the target depends on.
var libraryBinaryPaths: Set<AbsolutePath> {
switch self {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ extension LLBuildManifestBuilder {
// Sort the product targets in topological order in order to collect and "bubble up"
// their respective dependency graphs to the depending targets.
let nodes = self.plan.targets.compactMap {
ResolvedModule.Dependency.module($0.target, conditions: [])
ResolvedModule.Dependency.module($0.module, conditions: [])
}
let allPackageDependencies = try topologicalSort(nodes, successors: { $0.dependencies })
// Instantiate the inter-module dependency oracle which will cache commonly-scanned
Expand Down Expand Up @@ -319,7 +319,7 @@ extension LLBuildManifestBuilder {
for targetDescription: ModuleBuildDescription,
dependencyModuleDetailsMap: inout SwiftDriver.ExternalTargetModuleDetailsMap
) throws {
for dependency in targetDescription.target.dependencies(satisfying: targetDescription.buildParameters.buildEnvironment) {
for dependency in targetDescription.module.dependencies(satisfying: targetDescription.buildParameters.buildEnvironment) {
switch dependency {
case .product:
// Product dependencies are broken down into the targets that make them up.
Expand Down Expand Up @@ -358,7 +358,7 @@ extension LLBuildManifestBuilder {
guard case .swift(let dependencySwiftTargetDescription) = targetDescription else {
return
}
dependencyModuleDetailsMap[ModuleDependencyId.swiftPlaceholder(targetDescription.target.c99name)] =
dependencyModuleDetailsMap[ModuleDependencyId.swiftPlaceholder(targetDescription.module.c99name)] =
SwiftDriver.ExternalTargetModuleDetails(
path: TSCAbsolutePath(dependencySwiftTargetDescription.moduleOutputPath),
isFramework: false
Expand Down
6 changes: 3 additions & 3 deletions Sources/Build/BuildManifest/LLBuildManifestBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -239,11 +239,11 @@ extension LLBuildManifestBuilder {
let additionalOutputs: [Node]
if command.outputFiles.isEmpty {
if target.toolsVersion >= .v6_0 {
additionalOutputs = [.virtual("\(target.target.c99name)-\(command.configuration.displayName ?? "\(pluginNumber)")")]
additionalOutputs = [.virtual("\(target.module.c99name)-\(command.configuration.displayName ?? "\(pluginNumber)")")]
phonyOutputs += additionalOutputs
} else {
additionalOutputs = []
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.")
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.")
}
pluginNumber += 1
} else {
Expand Down Expand Up @@ -334,7 +334,7 @@ extension ModuleBuildDescription {

extension ModuleBuildDescription {
package var llbuildResourcesCmdName: String {
"\(self.target.name)-\(self.buildParameters.triple.tripleString)-\(self.buildParameters.buildConfig)\(self.buildParameters.suffix).module-resources"
"\(self.module.name)-\(self.buildParameters.triple.tripleString)-\(self.buildParameters.buildConfig)\(self.buildParameters.suffix).module-resources"
}
}

Expand Down
8 changes: 4 additions & 4 deletions Sources/Build/BuildOperation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -812,19 +812,19 @@ public final class BuildOperation: PackageStructureDelegate, SPMBuildCore.BuildS

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

// Check for cases involving modules that cannot be found.
if let importedModule = try? RegEx(pattern: "no such module '(.+)'").matchGroups(in: message).first?.first {
// 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.

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

Expand Down
4 changes: 2 additions & 2 deletions Sources/Build/LLBuildDescription.swift
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,11 @@ public struct BuildDescription: Codable {
self.traitConfiguration = traitConfiguration
self.targetDependencyMap = try plan.targets
.reduce(into: [TargetName: [TargetName]]()) { partial, targetBuildDescription in
let deps = try targetBuildDescription.target.recursiveDependencies(
let deps = try targetBuildDescription.module.recursiveDependencies(
satisfying: targetBuildDescription.buildParameters.buildEnvironment
)
.compactMap(\.module).map(\.c99name)
partial[targetBuildDescription.target.c99name] = deps
partial[targetBuildDescription.module.c99name] = deps
}
var targetCommandLines: [TargetName: [CommandLineFlag]] = [:]
var generatedSourceTargets: [TargetName] = []
Expand Down
36 changes: 18 additions & 18 deletions Tests/BuildTests/BuildPlanTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,8 @@ final class BuildPlanTests: XCTestCase {
))
result.checkProductsCount(2)
result.checkTargetsCount(3)
XCTAssertTrue(result.targetMap.values.contains { $0.target.name == "FooLogging" })
XCTAssertTrue(result.targetMap.values.contains { $0.target.name == "BarLogging" })
XCTAssertTrue(result.targetMap.values.contains { $0.module.name == "FooLogging" })
XCTAssertTrue(result.targetMap.values.contains { $0.module.name == "BarLogging" })
}

func testDuplicateProductNamesUpstream1() async throws {
Expand Down Expand Up @@ -304,11 +304,11 @@ final class BuildPlanTests: XCTestCase {
))
result.checkProductsCount(1)
result.checkTargetsCount(6)
XCTAssertTrue(result.targetMap.values.contains { $0.target.name == "FooLogging" })
XCTAssertTrue(result.targetMap.values.contains { $0.target.name == "BarLogging" })
XCTAssertTrue(result.targetMap.values.contains { $0.target.name == "BazLogging" })
XCTAssertTrue(result.targetMap.values.contains { $0.target.name == "XUtils" })
XCTAssertTrue(result.targetMap.values.contains { $0.target.name == "YUtils" })
XCTAssertTrue(result.targetMap.values.contains { $0.module.name == "FooLogging" })
XCTAssertTrue(result.targetMap.values.contains { $0.module.name == "BarLogging" })
XCTAssertTrue(result.targetMap.values.contains { $0.module.name == "BazLogging" })
XCTAssertTrue(result.targetMap.values.contains { $0.module.name == "XUtils" })
XCTAssertTrue(result.targetMap.values.contains { $0.module.name == "YUtils" })
}

func testDuplicateProductNamesUpstream2() async throws {
Expand Down Expand Up @@ -399,9 +399,9 @@ final class BuildPlanTests: XCTestCase {
))
result.checkProductsCount(1)
result.checkTargetsCount(4)
XCTAssertTrue(result.targetMap.values.contains { $0.target.name == "Logging" })
XCTAssertTrue(result.targetMap.values.contains { $0.target.name == "BarLogging" })
XCTAssertTrue(result.targetMap.values.contains { $0.target.name == "BazLogging" })
XCTAssertTrue(result.targetMap.values.contains { $0.module.name == "Logging" })
XCTAssertTrue(result.targetMap.values.contains { $0.module.name == "BarLogging" })
XCTAssertTrue(result.targetMap.values.contains { $0.module.name == "BazLogging" })
}

func testDuplicateProductNamesChained() async throws {
Expand Down Expand Up @@ -476,8 +476,8 @@ final class BuildPlanTests: XCTestCase {
))
result.checkProductsCount(1)
result.checkTargetsCount(3)
XCTAssertTrue(result.targetMap.values.contains { $0.target.name == "FooLogging" })
XCTAssertTrue(result.targetMap.values.contains { $0.target.name == "BarLogging" })
XCTAssertTrue(result.targetMap.values.contains { $0.module.name == "FooLogging" })
XCTAssertTrue(result.targetMap.values.contains { $0.module.name == "BarLogging" })
}

func testDuplicateProductNamesThrowError() async throws {
Expand Down Expand Up @@ -609,8 +609,8 @@ final class BuildPlanTests: XCTestCase {
))
result.checkProductsCount(1)
result.checkTargetsCount(3)
XCTAssertTrue(result.targetMap.values.contains { $0.target.name == "FooLogging" })
XCTAssertTrue(result.targetMap.values.contains { $0.target.name == "BarLogging" })
XCTAssertTrue(result.targetMap.values.contains { $0.module.name == "FooLogging" })
XCTAssertTrue(result.targetMap.values.contains { $0.module.name == "BarLogging" })
}

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

let yaml = buildPath.appending("release.yaml")
let llbuild = LLBuildManifestBuilder(plan, fileSystem: fs, observabilityScope: observability.topScope)
Expand Down Expand Up @@ -6438,8 +6438,8 @@ final class BuildPlanTests: XCTestCase {
))
result.checkProductsCount(3)
result.checkTargetsCount(3)
XCTAssertTrue(result.targetMap.values.contains { $0.target.name == "FooLogging" })
XCTAssertTrue(result.targetMap.values.contains { $0.target.name == "BarLogging" })
XCTAssertTrue(result.targetMap.values.contains { $0.module.name == "FooLogging" })
XCTAssertTrue(result.targetMap.values.contains { $0.module.name == "BarLogging" })
let buildProduct = try XCTUnwrap(
result.productMap[.init(
productName: "exe",
Expand Down
Loading