Skip to content

Restore visibility of APIs that have been made package #7568

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 7 commits into from
May 16, 2024
25 changes: 25 additions & 0 deletions Examples/package-info/Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// swift-tools-version:5.5

import PackageDescription

let package = Package(
name: "package-info",
platforms: [
.macOS(.v12),
.iOS(.v13)
],
dependencies: [
// This just points to the SwiftPM at the root of this repository.
.package(name: "swift-package-manager", path: "../../"),
// You will want to depend on a stable semantic version instead:
// .package(url: "https://github.com/apple/swift-package-manager", .exact("0.4.0"))
],
targets: [
.executableTarget(
name: "package-info",
dependencies: [
.product(name: "SwiftPM", package: "swift-package-manager")
]
),
]
)
3 changes: 3 additions & 0 deletions Examples/package-info/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# package-info

Sample package built on top of libSwiftPM.
49 changes: 49 additions & 0 deletions Examples/package-info/Sources/package-info/example.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import Basics
import Workspace

@main
@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
struct Example {
static func main() async throws {
// PREREQUISITES
// ============

// We need a package to work with.
// This computes the path of this package root based on the file location
let packagePath = try AbsolutePath(validating: #file).parentDirectory.parentDirectory.parentDirectory

// LOADING
// =======

// There are several levels of information available.
// Each takes longer to load than the level above it, but provides more detail.

let observability = ObservabilitySystem({ print("\($0): \($1)") })

let workspace = try Workspace(forRootPackage: packagePath)

let manifest = try await workspace.loadRootManifest(at: packagePath, observabilityScope: observability.topScope)

let package = try await workspace.loadRootPackage(at: packagePath, observabilityScope: observability.topScope)

let graph = try workspace.loadPackageGraph(rootPath: packagePath, observabilityScope: observability.topScope)

// EXAMPLES
// ========

// Manifest
let products = manifest.products.map({ $0.name }).joined(separator: ", ")
print("Products:", products)

let targets = manifest.targets.map({ $0.name }).joined(separator: ", ")
print("Targets:", targets)

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

// PackageGraph
let numberOfFiles = graph.reachableTargets.reduce(0, { $0 + $1.sources.paths.count })
print("Total number of source files (including dependencies):", numberOfFiles)
}
}
6 changes: 6 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,12 @@ let package = Package(
dependencies: ["XCBuildSupport", "SPMTestSupport"],
exclude: ["Inputs/Foo.pc"]
),
// Examples (These are built to ensure they stay up to date with the API.)
.executableTarget(
name: "package-info",
dependencies: ["Workspace"],
path: "Examples/package-info/Sources/package-info"
)
],
swiftLanguageVersions: [.v5]
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import protocol TSCBasic.WritableByteStream

extension ProgressAnimation {
/// A ninja-like progress animation that adapts to the provided output stream.
package static func ninja(
@_spi(SwiftPMInternal)
public static func ninja(
stream: WritableByteStream,
verbose: Bool
) -> any ProgressAnimationProtocol {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import protocol TSCBasic.WritableByteStream

extension ProgressAnimation {
/// A percent-based progress animation that adapts to the provided output stream.
package static func percent(
@_spi(SwiftPMInternal)
public static func percent(
stream: WritableByteStream,
verbose: Bool,
header: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ import class TSCBasic.LocalFileOutputByteStream
import protocol TSCBasic.WritableByteStream
import protocol TSCUtility.ProgressAnimationProtocol

package typealias ProgressAnimationProtocol = TSCUtility.ProgressAnimationProtocol
@_spi(SwiftPMInternal)
public typealias ProgressAnimationProtocol = TSCUtility.ProgressAnimationProtocol

/// Namespace to nest public progress animations under.
package enum ProgressAnimation {
@_spi(SwiftPMInternal)
public enum ProgressAnimation {
/// Dynamically create a progress animation based on the current stream
/// capabilities and desired verbosity.
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,23 +56,27 @@ final class ThrottledProgressAnimation: ProgressAnimationProtocol {
}
}

@_spi(SwiftPMInternal)
extension ProgressAnimationProtocol {
package func throttled<C: Clock>(
@_spi(SwiftPMInternal)
public func throttled<C: Clock>(
now: @escaping () -> C.Instant,
interval: C.Duration,
clock: C.Type = C.self
) -> some ProgressAnimationProtocol {
ThrottledProgressAnimation(self, now: now, interval: interval, clock: clock)
}

package func throttled<C: Clock>(
@_spi(SwiftPMInternal)
public func throttled<C: Clock>(
clock: C,
interval: C.Duration
) -> some ProgressAnimationProtocol {
self.throttled(now: { clock.now }, interval: interval, clock: C.self)
}

package func throttled(
@_spi(SwiftPMInternal)
public func throttled(
interval: ContinuousClock.Duration
) -> some ProgressAnimationProtocol {
self.throttled(clock: ContinuousClock(), interval: interval)
Expand Down
30 changes: 15 additions & 15 deletions Sources/Build/BuildDescription/ClangTargetBuildDescription.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,20 @@ import struct SPMBuildCore.PrebuildCommandResult
import enum TSCBasic.ProcessEnv

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

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

/// The underlying clang target.
package let clangTarget: ClangTarget
public 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.
package let toolsVersion: ToolsVersion
public let toolsVersion: ToolsVersion

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

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

Expand All @@ -65,7 +65,7 @@ package final class ClangTargetBuildDescription {
}

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

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

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

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

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

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

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

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

/// An array of tuples containing filename, source, object and dependency path for each of the source in this target.
package func compilePaths()
public func compilePaths()
throws -> [(filename: RelativePath, source: AbsolutePath, object: AbsolutePath, deps: AbsolutePath)]
{
let sources = [
Expand All @@ -212,7 +212,7 @@ package 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).
package func basicArguments(
public func basicArguments(
isCXX isCXXOverride: Bool? = .none,
isC: Bool = false
) throws -> [String] {
Expand Down Expand Up @@ -335,7 +335,7 @@ package final class ClangTargetBuildDescription {
return args
}

package func emitCommandLine(for filePath: AbsolutePath) throws -> [String] {
public 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
Original file line number Diff line number Diff line change
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.
package final class PluginDescription: Codable {
public final class PluginDescription: Codable {
/// The identity of the package in which the plugin is defined.
package let package: PackageIdentity
public let package: PackageIdentity

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

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

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

/// Swift source files that comprise the plugin.
package let sources: Sources
public 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
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,25 @@ import SPMBuildCore
import struct TSCBasic.SortedArray

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

/// The reference to the product.
package let product: ResolvedProduct
public 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.
package let toolsVersion: ToolsVersion
public let toolsVersion: ToolsVersion

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

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

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

/// The arguments to the librarian to create a static library.
package func archiveArguments() throws -> [String] {
public 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 @@ -145,7 +145,7 @@ package final class ProductBuildDescription: SPMBuildCore.ProductBuildDescriptio
}

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

extension SortedArray where Element == AbsolutePath {
package static func +=<S: Sequence>(lhs: inout SortedArray, rhs: S) where S.Iterator.Element == AbsolutePath {
public static func +=<S: Sequence>(lhs: inout SortedArray, rhs: S) where S.Iterator.Element == AbsolutePath {
lhs.insert(contentsOf: rhs)
}
}
Expand Down
Loading