Skip to content

Fix most "target"/"module" internal naming inconsistencies #7690

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 6 commits into from
Jun 20, 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
4 changes: 2 additions & 2 deletions Examples/package-info/Sources/package-info/example.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ struct Example {
print("Targets:", targets)

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

// PackageGraph
let numberOfFiles = graph.reachableTargets.reduce(0, { $0 + $1.sources.paths.count })
let numberOfFiles = graph.reachableModules.reduce(0, { $0 + $1.sources.paths.count })
print("Total number of source files (including dependencies):", numberOfFiles)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,19 @@ import struct SPMBuildCore.PrebuildCommandResult

import enum TSCBasic.ProcessEnv

/// Target description for a Clang target i.e. C language family target.
public final class ClangTargetBuildDescription {
@available(*, deprecated, renamed: "ClangModuleBuildDescription")
public typealias ClangTargetBuildDescription = ClangModuleBuildDescription

/// Build description for a Clang target i.e. C language family module.
public final class ClangModuleBuildDescription {
/// The package this target belongs to.
public let package: ResolvedPackage

/// The target described by this target.
public let target: ResolvedModule

/// The underlying clang target.
public let clangTarget: ClangTarget
public let clangTarget: ClangModule

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,52 +21,55 @@ public enum BuildDescriptionError: Swift.Error {
case requestedFileNotPartOfTarget(targetName: String, requestedFilePath: AbsolutePath)
}

/// A target description which can either be for a Swift or Clang target.
public enum TargetBuildDescription {
@available(*, deprecated, renamed: "ModuleBuildDescription")
public typealias TargetBuildDescription = ModuleBuildDescription

/// A module build description which can either be for a Swift or Clang module.
public enum ModuleBuildDescription {
/// Swift target description.
case swift(SwiftTargetBuildDescription)
case swift(SwiftModuleBuildDescription)

/// Clang target description.
case clang(ClangTargetBuildDescription)
case clang(ClangModuleBuildDescription)

/// The objects in this target.
var objects: [AbsolutePath] {
get throws {
switch self {
case .swift(let target):
return try target.objects
case .clang(let target):
return try target.objects
case .swift(let module):
return try module.objects
case .clang(let module):
return try module.objects
}
}
}

/// The resources in this target.
var resources: [Resource] {
switch self {
case .swift(let target):
return target.resources
case .clang(let target):
return target.resources
case .swift(let buildDescription):
return buildDescription.resources
case .clang(let buildDescription):
return buildDescription.resources
}
}

/// Path to the bundle generated for this module (if any).
var bundlePath: AbsolutePath? {
switch self {
case .swift(let target):
return target.bundlePath
case .clang(let target):
return target.bundlePath
case .swift(let buildDescription):
return buildDescription.bundlePath
case .clang(let buildDescription):
return buildDescription.bundlePath
}
}

var target: ResolvedModule {
switch self {
case .swift(let target):
return target.target
case .clang(let target):
return target.target
case .swift(let buildDescription):
return buildDescription.target
case .clang(let buildDescription):
return buildDescription.target
}
}

Expand All @@ -82,46 +85,46 @@ public enum TargetBuildDescription {

var resourceBundleInfoPlistPath: AbsolutePath? {
switch self {
case .swift(let target):
return target.resourceBundleInfoPlistPath
case .clang(let target):
return target.resourceBundleInfoPlistPath
case .swift(let buildDescription):
return buildDescription.resourceBundleInfoPlistPath
case .clang(let buildDescription):
return buildDescription.resourceBundleInfoPlistPath
}
}

var buildToolPluginInvocationResults: [BuildToolPluginInvocationResult] {
switch self {
case .swift(let target):
return target.buildToolPluginInvocationResults
case .clang(let target):
return target.buildToolPluginInvocationResults
case .swift(let buildDescription):
return buildDescription.buildToolPluginInvocationResults
case .clang(let buildDescription):
return buildDescription.buildToolPluginInvocationResults
}
}

var buildParameters: BuildParameters {
switch self {
case .swift(let swiftTargetBuildDescription):
return swiftTargetBuildDescription.buildParameters
case .clang(let clangTargetBuildDescription):
return clangTargetBuildDescription.buildParameters
case .swift(let buildDescription):
return buildDescription.buildParameters
case .clang(let buildDescription):
return buildDescription.buildParameters
}
}

var toolsVersion: ToolsVersion {
switch self {
case .swift(let swiftTargetBuildDescription):
return swiftTargetBuildDescription.toolsVersion
case .clang(let clangTargetBuildDescription):
return clangTargetBuildDescription.toolsVersion
case .swift(let buildDescription):
return buildDescription.toolsVersion
case .clang(let buildDescription):
return buildDescription.toolsVersion
}
}

/// Determines the arguments needed to run `swift-symbolgraph-extract` for
/// this module.
package func symbolGraphExtractArguments() throws -> [String] {
switch self {
case .swift(let target): try target.symbolGraphExtractArguments()
case .clang(let target): try target.symbolGraphExtractArguments()
case .swift(let buildDescription): try buildDescription.symbolGraphExtractArguments()
case .clang(let buildDescription): try buildDescription.symbolGraphExtractArguments()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,52 +16,52 @@ import PackageModel
import struct Basics.InternalError
import protocol Basics.FileSystem

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

/// The name of the plugin target in that package (this is also the name of
/// The name of the plugin module in that package (this is also the name of
/// the plugin).
public let targetName: String
public let moduleName: String

/// The language-level target name.
public let targetC99Name: String
/// The language-level module name.
public let moduleC99Name: String

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

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

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

/// Initialize a new plugin target description. The target is expected to be
/// Initialize a new plugin module description. The module is expected to be
/// a `PluginTarget`.
init(
target: ResolvedModule,
module: ResolvedModule,
products: [ResolvedProduct],
package: ResolvedPackage,
toolsVersion: ToolsVersion,
testDiscoveryTarget: Bool = false,
fileSystem: FileSystem
) throws {
guard target.underlying is PluginTarget else {
throw InternalError("underlying target type mismatch \(target)")
guard module.underlying is PluginModule else {
throw InternalError("underlying target type mismatch \(module)")
}

self.package = package.identity
self.targetName = target.name
self.targetC99Name = target.c99name
self.moduleName = module.name
self.moduleC99Name = module.c99name
self.productNames = products.map(\.name)
self.toolsVersion = toolsVersion
self.sources = target.sources
self.sources = module.sources
}
}
10 changes: 5 additions & 5 deletions Sources/Build/BuildDescription/ProductBuildDescription.swift
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ public final class ProductBuildDescription: SPMBuildCore.ProductBuildDescription
args += ["-profile-coverage-mapping", "-profile-generate"]
}

let containsSwiftTargets = self.product.containsSwiftTargets
let containsSwiftTargets = self.product.containsSwiftModules

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

// Add arguments from declared build settings.
args += self.buildSettingsFlags
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,18 @@ import DriverSupport

import struct TSCBasic.ByteString

/// Target description for a Swift target.
public final class SwiftTargetBuildDescription {
@available(*, deprecated, renamed: "SwiftModuleBuildDescription")
public typealias SwiftTargetBuildDescription = SwiftModuleBuildDescription

/// Build description for a Swift module.
public final class SwiftModuleBuildDescription {
/// The package this target belongs to.
public let package: ResolvedPackage

/// The target described by this target.
public let target: ResolvedModule

private let swiftTarget: SwiftTarget
private let swiftTarget: SwiftModule

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

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

// Include path for the toolchain's copy of SwiftSyntax.
#if BUILD_MACROS_AS_DYLIBS
if target.type == .macro {
if module.type == .macro {
flags += try ["-I", self.defaultBuildParameters.toolchain.hostLibDir.pathString]
}
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import PackageModel
extension LLBuildManifestBuilder {
/// Create a llbuild target for a Clang target description.
func createClangCompileCommand(
_ target: ClangTargetBuildDescription
_ target: ClangModuleBuildDescription
) throws {
var inputs: [Node] = []

Expand All @@ -40,7 +40,7 @@ extension LLBuildManifestBuilder {

for dependency in target.target.dependencies(satisfying: target.buildEnvironment) {
switch dependency {
case .target(let target, _):
case .module(let target, _):
addStaticTargetInputs(target)

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

case .library(.automatic), .library(.static), .plugin:
for target in product.targets {
for target in product.modules {
addStaticTargetInputs(target)
}
case .test:
Expand Down Expand Up @@ -113,7 +113,7 @@ extension LLBuildManifestBuilder {

/// Create a llbuild target for a Clang target preparation
func createClangPrepareCommand(
_ target: ClangTargetBuildDescription
_ target: ClangModuleBuildDescription
) throws {
// Create the node for the target so you can --target it.
// It is a no-op for index preparation.
Expand Down
Loading