Skip to content
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

Hide more llbuild-specific APIs #7387

Merged
merged 4 commits into from Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 14 additions & 14 deletions Sources/Build/BuildDescription/ClangTargetBuildDescription.swift
Expand Up @@ -22,17 +22,17 @@ import struct SPMBuildCore.PrebuildCommandResult
import enum TSCBasic.ProcessEnv

/// Target description for a Clang target i.e. C language family target.
public final class ClangTargetBuildDescription {
package final class ClangTargetBuildDescription {
/// The target described by this target.
public let target: ResolvedTarget
package let target: ResolvedTarget

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

/// The tools version of the package that declared the target. This can
/// can be used to conditionalize semantically significant changes in how
/// a target is built.
public let toolsVersion: ToolsVersion
package let toolsVersion: ToolsVersion

/// The build parameters.
let buildParameters: BuildParameters
Expand All @@ -43,7 +43,7 @@ public final class ClangTargetBuildDescription {
}

/// The list of all resource files in the target, including the derived ones.
public var resources: [Resource] {
package var resources: [Resource] {
self.target.underlying.resources + self.pluginDerivedResources
}

Expand All @@ -61,7 +61,7 @@ public final class ClangTargetBuildDescription {
}

/// The modulemap file for this target, if any.
public private(set) var moduleMap: AbsolutePath?
package private(set) var moduleMap: AbsolutePath?

/// Path to the temporary directory for this target.
var tempsPath: AbsolutePath
Expand All @@ -78,13 +78,13 @@ public final class ClangTargetBuildDescription {
private var pluginDerivedResources: [Resource]

/// Path to the resource accessor header file, if generated.
public private(set) var resourceAccessorHeaderFile: AbsolutePath?
package private(set) var resourceAccessorHeaderFile: AbsolutePath?

/// Path to the resource Info.plist file, if generated.
public private(set) var resourceBundleInfoPlistPath: AbsolutePath?
package private(set) var resourceBundleInfoPlistPath: AbsolutePath?

/// The objects in this target.
public var objects: [AbsolutePath] {
package var objects: [AbsolutePath] {
get throws {
try compilePaths().map(\.object)
}
Expand All @@ -100,12 +100,12 @@ public final class ClangTargetBuildDescription {
private let fileSystem: FileSystem

/// If this target is a test target.
public var isTestTarget: Bool {
package var isTestTarget: Bool {
target.type == .test
}

/// The results of applying any build tool plugins to this target.
public let buildToolPluginInvocationResults: [BuildToolPluginInvocationResult]
package let buildToolPluginInvocationResults: [BuildToolPluginInvocationResult]

/// Create a new target description with target and build parameters.
init(
Expand Down Expand Up @@ -182,7 +182,7 @@ public final class ClangTargetBuildDescription {
}

/// An array of tuples containing filename, source, object and dependency path for each of the source in this target.
public func compilePaths()
package func compilePaths()
throws -> [(filename: RelativePath, source: AbsolutePath, object: AbsolutePath, deps: AbsolutePath)]
{
let sources = [
Expand All @@ -206,7 +206,7 @@ public final class ClangTargetBuildDescription {
/// NOTE: The parameter to specify whether to get C++ semantics is currently optional, but this is only for revlock
/// avoidance with clients. Callers should always specify what they want based either the user's indication or on a
/// default value (possibly based on the filename suffix).
public func basicArguments(
package func basicArguments(
isCXX isCXXOverride: Bool? = .none,
isC: Bool = false
) throws -> [String] {
Expand Down Expand Up @@ -308,7 +308,7 @@ public final class ClangTargetBuildDescription {
return args
}

public func emitCommandLine(for filePath: AbsolutePath) throws -> [String] {
package func emitCommandLine(for filePath: AbsolutePath) throws -> [String] {
let standards = [
(clangTarget.cxxLanguageStandard, SupportedLanguageExtension.cppExtensions),
(clangTarget.cLanguageStandard, SupportedLanguageExtension.cExtensions),
Expand Down
12 changes: 6 additions & 6 deletions Sources/Build/BuildDescription/PluginDescription.swift
Expand Up @@ -21,24 +21,24 @@ import protocol Basics.FileSystem
/// But because the package 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 {
package final class PluginDescription: Codable {
/// The identity of the package in which the plugin is defined.
public let package: PackageIdentity
package let package: PackageIdentity

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

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

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

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

/// Initialize a new plugin target description. The target is expected to be
/// a `PluginTarget`.
Expand Down
18 changes: 9 additions & 9 deletions Sources/Build/BuildDescription/ProductBuildDescription.swift
Expand Up @@ -21,25 +21,25 @@ import SPMBuildCore
import struct TSCBasic.SortedArray

/// The build description for a product.
public final class ProductBuildDescription: SPMBuildCore.ProductBuildDescription {
package final class ProductBuildDescription: SPMBuildCore.ProductBuildDescription {
/// The reference to the product.
public let package: ResolvedPackage
package let package: ResolvedPackage

/// The reference to the product.
public let product: ResolvedProduct
package let product: ResolvedProduct

/// The tools version of the package that declared the product. This can
/// can be used to conditionalize semantically significant changes in how
/// a target is built.
public let toolsVersion: ToolsVersion
package let toolsVersion: ToolsVersion

/// The build parameters.
public let buildParameters: BuildParameters
package let buildParameters: BuildParameters

/// All object files to link into this product.
///
// Computed during build planning.
public internal(set) var objects = SortedArray<AbsolutePath>()
package internal(set) var objects = SortedArray<AbsolutePath>()

/// The dynamic libraries this product needs to link with.
// Computed during build planning.
Expand Down Expand Up @@ -128,7 +128,7 @@ public final class ProductBuildDescription: SPMBuildCore.ProductBuildDescription
}

/// The arguments to the librarian to create a static library.
public func archiveArguments() throws -> [String] {
package func archiveArguments() throws -> [String] {
let librarian = self.buildParameters.toolchain.librarianPath.pathString
let triple = self.buildParameters.triple
if triple.isWindows(), librarian.hasSuffix("link") || librarian.hasSuffix("link.exe") {
Expand All @@ -141,7 +141,7 @@ public final class ProductBuildDescription: SPMBuildCore.ProductBuildDescription
}

/// The arguments to link and create this product.
public func linkArguments() throws -> [String] {
package func linkArguments() throws -> [String] {
var args = [buildParameters.toolchain.swiftCompilerPath.pathString]
args += self.buildParameters.sanitizers.linkSwiftFlags()
args += self.additionalFlags
Expand Down Expand Up @@ -390,7 +390,7 @@ public final class ProductBuildDescription: SPMBuildCore.ProductBuildDescription
}

extension SortedArray where Element == AbsolutePath {
public static func +=<S: Sequence>(lhs: inout SortedArray, rhs: S) where S.Iterator.Element == AbsolutePath {
package static func +=<S: Sequence>(lhs: inout SortedArray, rhs: S) where S.Iterator.Element == AbsolutePath {
lhs.insert(contentsOf: rhs)
}
}
Expand Down
36 changes: 18 additions & 18 deletions Sources/Build/BuildDescription/SwiftTargetBuildDescription.swift
Expand Up @@ -28,19 +28,19 @@ import DriverSupport
import struct TSCBasic.ByteString

/// Target description for a Swift target.
public final class SwiftTargetBuildDescription {
package final class SwiftTargetBuildDescription {
/// The package this target belongs to.
public let package: ResolvedPackage
package let package: ResolvedPackage

/// The target described by this target.
public let target: ResolvedTarget
package let target: ResolvedTarget

private let swiftTarget: SwiftTarget

/// The tools version of the package that declared the target. This can
/// can be used to conditionalize semantically significant changes in how
/// a target is built.
public let toolsVersion: ToolsVersion
package let toolsVersion: ToolsVersion

/// The build parameters.
let buildParameters: BuildParameters
Expand Down Expand Up @@ -77,22 +77,22 @@ public final class SwiftTargetBuildDescription {
}

/// The list of all source files in the target, including the derived ones.
public var sources: [AbsolutePath] {
package var sources: [AbsolutePath] {
self.target.sources.paths + self.derivedSources.paths + self.pluginDerivedSources.paths
}

public var sourcesFileListPath: AbsolutePath {
package var sourcesFileListPath: AbsolutePath {
self.tempsPath.appending(component: "sources")
}

/// The list of all resource files in the target, including the derived ones.
public var resources: [Resource] {
package var resources: [Resource] {
self.target.underlying.resources + self.pluginDerivedResources
}

/// The objects in this target, containing either machine code or bitcode
/// depending on the build parameters used.
public var objects: [AbsolutePath] {
package var objects: [AbsolutePath] {
get throws {
let relativeSources = self.target.sources.relativePaths
+ self.derivedSources.relativePaths
Expand All @@ -112,7 +112,7 @@ public final class SwiftTargetBuildDescription {
}

/// The path to the swiftmodule file after compilation.
public var moduleOutputPath: AbsolutePath { // note: needs to be public because of sourcekit-lsp
package var moduleOutputPath: AbsolutePath { // note: needs to be package because of sourcekit-lsp
MaxDesiatov marked this conversation as resolved.
Show resolved Hide resolved
// If we're an executable and we're not allowing test targets to link against us, we hide the module.
let triple = buildParameters.triple
let allowLinkingAgainstExecutables = (triple.isDarwin() || triple.isLinux() || triple.isWindows()) && self.toolsVersion >= .v5_5
Expand All @@ -133,7 +133,7 @@ public final class SwiftTargetBuildDescription {
}

/// Path to the resource Info.plist file, if generated.
public private(set) var resourceBundleInfoPlistPath: AbsolutePath?
package private(set) var resourceBundleInfoPlistPath: AbsolutePath?

/// Paths to the binary libraries the target depends on.
var libraryBinaryPaths: Set<AbsolutePath> = []
Expand All @@ -148,7 +148,7 @@ public final class SwiftTargetBuildDescription {

/// Describes the purpose of a test target, including any special roles such as containing a list of discovered
/// tests or serving as the manifest target which contains the main entry point.
public enum TestTargetRole {
package enum TestTargetRole {
/// An ordinary test target, defined explicitly in a package, containing test code.
case `default`

Expand All @@ -163,10 +163,10 @@ public final class SwiftTargetBuildDescription {
case entryPoint(isSynthesized: Bool)
}

public let testTargetRole: TestTargetRole?
package let testTargetRole: TestTargetRole?

/// If this target is a test target.
public var isTestTarget: Bool {
package var isTestTarget: Bool {
self.testTargetRole != nil
}

Expand Down Expand Up @@ -228,13 +228,13 @@ public final class SwiftTargetBuildDescription {
private(set) var moduleMap: AbsolutePath?

/// The results of applying any build tool plugins to this target.
public let buildToolPluginInvocationResults: [BuildToolPluginInvocationResult]
package let buildToolPluginInvocationResults: [BuildToolPluginInvocationResult]

/// The results of running any prebuild commands for this target.
public let prebuildCommandResults: [PrebuildCommandResult]
package let prebuildCommandResults: [PrebuildCommandResult]

/// Any macro products that this target requires to build.
public let requiredMacroProducts: [ResolvedProduct]
package let requiredMacroProducts: [ResolvedProduct]

/// ObservabilityScope with which to emit diagnostics
private let observabilityScope: ObservabilityScope
Expand Down Expand Up @@ -474,7 +474,7 @@ public final class SwiftTargetBuildDescription {
}

/// The arguments needed to compile this target.
public func compileArguments() throws -> [String] {
package func compileArguments() throws -> [String] {
var args = [String]()
args += try self.buildParameters.targetTripleArgs(for: self.target)
args += ["-swift-version", self.swiftVersion.rawValue]
Expand Down Expand Up @@ -650,7 +650,7 @@ public final class SwiftTargetBuildDescription {

/// When `scanInvocation` argument is set to `true`, omit the side-effect producing arguments
/// such as emitting a module or supplementary outputs.
public func emitCommandLine(scanInvocation: Bool = false) throws -> [String] {
package func emitCommandLine(scanInvocation: Bool = false) throws -> [String] {
var result: [String] = []
result.append(self.buildParameters.toolchain.swiftCompilerPath.pathString)

Expand Down
4 changes: 2 additions & 2 deletions Sources/Build/BuildDescription/TargetBuildDescription.swift
Expand Up @@ -17,12 +17,12 @@ import struct PackageModel.ToolsVersion
import struct SPMBuildCore.BuildToolPluginInvocationResult
import struct SPMBuildCore.BuildParameters

public enum BuildDescriptionError: Swift.Error {
package 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 {
package enum TargetBuildDescription {
/// Swift target description.
case swift(SwiftTargetBuildDescription)

Expand Down
Expand Up @@ -188,7 +188,7 @@ extension LLBuildManifestBuilder {
// dependency graph of B. The driver is then responsible for the necessary post-processing
// to merge the dependency graphs and plan the build for A, using artifacts of B as explicit
// inputs.
public func addTargetsToExplicitBuildManifest() throws {
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 {
Expand Down