Skip to content

Commit d231c3f

Browse files
authored
Restore visibility of APIs that have been made package (#7568)
This change reverts the following PRs and makes it possible to use public and @_spi APIs again. - #7365 - #7372 - #7381 - #7387 - #7434
1 parent 092f80d commit d231c3f

File tree

129 files changed

+1246
-1212
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

129 files changed

+1246
-1212
lines changed

Examples/package-info/Package.swift

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// swift-tools-version:5.5
2+
3+
import PackageDescription
4+
5+
let package = Package(
6+
name: "package-info",
7+
platforms: [
8+
.macOS(.v12),
9+
.iOS(.v13)
10+
],
11+
dependencies: [
12+
// This just points to the SwiftPM at the root of this repository.
13+
.package(name: "swift-package-manager", path: "../../"),
14+
// You will want to depend on a stable semantic version instead:
15+
// .package(url: "https://github.com/apple/swift-package-manager", .exact("0.4.0"))
16+
],
17+
targets: [
18+
.executableTarget(
19+
name: "package-info",
20+
dependencies: [
21+
.product(name: "SwiftPM", package: "swift-package-manager")
22+
]
23+
),
24+
]
25+
)

Examples/package-info/README.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# package-info
2+
3+
Sample package built on top of libSwiftPM.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import Basics
2+
import Workspace
3+
4+
@main
5+
@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
6+
struct Example {
7+
static func main() async throws {
8+
// PREREQUISITES
9+
// ============
10+
11+
// We need a package to work with.
12+
// This computes the path of this package root based on the file location
13+
let packagePath = try AbsolutePath(validating: #file).parentDirectory.parentDirectory.parentDirectory
14+
15+
// LOADING
16+
// =======
17+
18+
// There are several levels of information available.
19+
// Each takes longer to load than the level above it, but provides more detail.
20+
21+
let observability = ObservabilitySystem({ print("\($0): \($1)") })
22+
23+
let workspace = try Workspace(forRootPackage: packagePath)
24+
25+
let manifest = try await workspace.loadRootManifest(at: packagePath, observabilityScope: observability.topScope)
26+
27+
let package = try await workspace.loadRootPackage(at: packagePath, observabilityScope: observability.topScope)
28+
29+
let graph = try workspace.loadPackageGraph(rootPath: packagePath, observabilityScope: observability.topScope)
30+
31+
// EXAMPLES
32+
// ========
33+
34+
// Manifest
35+
let products = manifest.products.map({ $0.name }).joined(separator: ", ")
36+
print("Products:", products)
37+
38+
let targets = manifest.targets.map({ $0.name }).joined(separator: ", ")
39+
print("Targets:", targets)
40+
41+
// Package
42+
let executables = package.targets.filter({ $0.type == .executable }).map({ $0.name })
43+
print("Executable targets:", executables)
44+
45+
// PackageGraph
46+
let numberOfFiles = graph.reachableTargets.reduce(0, { $0 + $1.sources.paths.count })
47+
print("Total number of source files (including dependencies):", numberOfFiles)
48+
}
49+
}

Package.swift

+6
Original file line numberDiff line numberDiff line change
@@ -725,6 +725,12 @@ let package = Package(
725725
dependencies: ["XCBuildSupport", "SPMTestSupport"],
726726
exclude: ["Inputs/Foo.pc"]
727727
),
728+
// Examples (These are built to ensure they stay up to date with the API.)
729+
.executableTarget(
730+
name: "package-info",
731+
dependencies: ["Workspace"],
732+
path: "Examples/package-info/Sources/package-info"
733+
)
728734
],
729735
swiftLanguageVersions: [.v5]
730736
)

Sources/Basics/ProgressAnimation/NinjaProgressAnimation.swift

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ import protocol TSCBasic.WritableByteStream
1515

1616
extension ProgressAnimation {
1717
/// A ninja-like progress animation that adapts to the provided output stream.
18-
package static func ninja(
18+
@_spi(SwiftPMInternal)
19+
public static func ninja(
1920
stream: WritableByteStream,
2021
verbose: Bool
2122
) -> any ProgressAnimationProtocol {

Sources/Basics/ProgressAnimation/PercentProgressAnimation.swift

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ import protocol TSCBasic.WritableByteStream
1515

1616
extension ProgressAnimation {
1717
/// A percent-based progress animation that adapts to the provided output stream.
18-
package static func percent(
18+
@_spi(SwiftPMInternal)
19+
public static func percent(
1920
stream: WritableByteStream,
2021
verbose: Bool,
2122
header: String

Sources/Basics/ProgressAnimation/ProgressAnimationProtocol.swift

+4-2
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@ import class TSCBasic.LocalFileOutputByteStream
1515
import protocol TSCBasic.WritableByteStream
1616
import protocol TSCUtility.ProgressAnimationProtocol
1717

18-
package typealias ProgressAnimationProtocol = TSCUtility.ProgressAnimationProtocol
18+
@_spi(SwiftPMInternal)
19+
public typealias ProgressAnimationProtocol = TSCUtility.ProgressAnimationProtocol
1920

2021
/// Namespace to nest public progress animations under.
21-
package enum ProgressAnimation {
22+
@_spi(SwiftPMInternal)
23+
public enum ProgressAnimation {
2224
/// Dynamically create a progress animation based on the current stream
2325
/// capabilities and desired verbosity.
2426
///

Sources/Basics/ProgressAnimation/ThrottledProgressAnimation.swift

+7-3
Original file line numberDiff line numberDiff line change
@@ -56,23 +56,27 @@ final class ThrottledProgressAnimation: ProgressAnimationProtocol {
5656
}
5757
}
5858

59+
@_spi(SwiftPMInternal)
5960
extension ProgressAnimationProtocol {
60-
package func throttled<C: Clock>(
61+
@_spi(SwiftPMInternal)
62+
public func throttled<C: Clock>(
6163
now: @escaping () -> C.Instant,
6264
interval: C.Duration,
6365
clock: C.Type = C.self
6466
) -> some ProgressAnimationProtocol {
6567
ThrottledProgressAnimation(self, now: now, interval: interval, clock: clock)
6668
}
6769

68-
package func throttled<C: Clock>(
70+
@_spi(SwiftPMInternal)
71+
public func throttled<C: Clock>(
6972
clock: C,
7073
interval: C.Duration
7174
) -> some ProgressAnimationProtocol {
7275
self.throttled(now: { clock.now }, interval: interval, clock: C.self)
7376
}
7477

75-
package func throttled(
78+
@_spi(SwiftPMInternal)
79+
public func throttled(
7680
interval: ContinuousClock.Duration
7781
) -> some ProgressAnimationProtocol {
7882
self.throttled(clock: ContinuousClock(), interval: interval)

Sources/Build/BuildDescription/ClangTargetBuildDescription.swift

+15-15
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,20 @@ import struct SPMBuildCore.PrebuildCommandResult
2323
import enum TSCBasic.ProcessEnv
2424

2525
/// Target description for a Clang target i.e. C language family target.
26-
package final class ClangTargetBuildDescription {
26+
public final class ClangTargetBuildDescription {
2727
/// The package this target belongs to.
28-
package let package: ResolvedPackage
28+
public let package: ResolvedPackage
2929

3030
/// The target described by this target.
31-
package let target: ResolvedModule
31+
public let target: ResolvedModule
3232

3333
/// The underlying clang target.
34-
package let clangTarget: ClangTarget
34+
public let clangTarget: ClangTarget
3535

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

4141
/// The build parameters.
4242
let buildParameters: BuildParameters
@@ -47,7 +47,7 @@ package final class ClangTargetBuildDescription {
4747
}
4848

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

@@ -65,7 +65,7 @@ package final class ClangTargetBuildDescription {
6565
}
6666

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

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

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

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

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

106106
/// If this target is a test target.
107-
package var isTestTarget: Bool {
107+
public var isTestTarget: Bool {
108108
target.type == .test
109109
}
110110

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

114114
/// Create a new target description with target and build parameters.
115115
init(
@@ -188,7 +188,7 @@ package final class ClangTargetBuildDescription {
188188
}
189189

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

338-
package func emitCommandLine(for filePath: AbsolutePath) throws -> [String] {
338+
public func emitCommandLine(for filePath: AbsolutePath) throws -> [String] {
339339
let standards = [
340340
(clangTarget.cxxLanguageStandard, SupportedLanguageExtension.cppExtensions),
341341
(clangTarget.cLanguageStandard, SupportedLanguageExtension.cExtensions),

Sources/Build/BuildDescription/PluginDescription.swift

+6-6
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,24 @@ import protocol Basics.FileSystem
2121
/// But because the package graph and build plan are not loaded for incremental
2222
/// builds, this information is included in the BuildDescription, and the plugin
2323
/// targets are compiled directly.
24-
package final class PluginDescription: Codable {
24+
public final class PluginDescription: Codable {
2525
/// The identity of the package in which the plugin is defined.
26-
package let package: PackageIdentity
26+
public let package: PackageIdentity
2727

2828
/// The name of the plugin target in that package (this is also the name of
2929
/// the plugin).
30-
package let targetName: String
30+
public let targetName: String
3131

3232
/// The names of any plugin products in that package that vend the plugin
3333
/// to other packages.
34-
package let productNames: [String]
34+
public let productNames: [String]
3535

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

4040
/// Swift source files that comprise the plugin.
41-
package let sources: Sources
41+
public let sources: Sources
4242

4343
/// Initialize a new plugin target description. The target is expected to be
4444
/// a `PluginTarget`.

Sources/Build/BuildDescription/ProductBuildDescription.swift

+9-9
Original file line numberDiff line numberDiff line change
@@ -22,25 +22,25 @@ import SPMBuildCore
2222
import struct TSCBasic.SortedArray
2323

2424
/// The build description for a product.
25-
package final class ProductBuildDescription: SPMBuildCore.ProductBuildDescription {
25+
public final class ProductBuildDescription: SPMBuildCore.ProductBuildDescription {
2626
/// The reference to the product.
27-
package let package: ResolvedPackage
27+
public let package: ResolvedPackage
2828

2929
/// The reference to the product.
30-
package let product: ResolvedProduct
30+
public let product: ResolvedProduct
3131

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

3737
/// The build parameters.
38-
package let buildParameters: BuildParameters
38+
public let buildParameters: BuildParameters
3939

4040
/// All object files to link into this product.
4141
///
4242
// Computed during build planning.
43-
package internal(set) var objects = SortedArray<AbsolutePath>()
43+
public internal(set) var objects = SortedArray<AbsolutePath>()
4444

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

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

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

404404
extension SortedArray where Element == AbsolutePath {
405-
package static func +=<S: Sequence>(lhs: inout SortedArray, rhs: S) where S.Iterator.Element == AbsolutePath {
405+
public static func +=<S: Sequence>(lhs: inout SortedArray, rhs: S) where S.Iterator.Element == AbsolutePath {
406406
lhs.insert(contentsOf: rhs)
407407
}
408408
}

0 commit comments

Comments
 (0)