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

Remove @testable imports WIP #8145

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from
1 change: 1 addition & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,7 @@ let package = Package(
.product(name: "ArgumentParser", package: "swift-argument-parser"),
"Basics",
"Build",
"CoreCommands",
"PackageGraph",
"PackageLoading",
"PackageModel",
Expand Down
26 changes: 13 additions & 13 deletions Sources/Basics/AuthorizationProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ extension AuthorizationProvider {
// MARK: - netrc

public final class NetrcAuthorizationProvider: AuthorizationProvider, AuthorizationWriter {
// marked internal for testing
internal let path: AbsolutePath
// marked `package` for testing
package let path: AbsolutePath
private let fileSystem: FileSystem

private let cache = ThreadSafeKeyValueStore<String, (user: String, password: String)>()
Expand Down Expand Up @@ -139,7 +139,7 @@ public final class NetrcAuthorizationProvider: AuthorizationProvider, Authorizat
}

// marked internal for testing
internal var machines: [Basics.Netrc.Machine] {
package var machines: [Basics.Netrc.Machine] {
// this ignores any errors reading the file
// initial validation is done at the time of initializing the provider
// and if the file becomes corrupt at runtime it will handle it gracefully
Expand Down Expand Up @@ -270,7 +270,7 @@ public final class KeychainAuthorizationProvider: AuthorizationProvider, Authori
throw AuthorizationProviderError
.other("Failed to extract credentials for '\(protocolHostPort)' from keychain")
}

let password = String(decoding: passwordData, as: UTF8.self)

return (user: account, password: password)
Expand Down Expand Up @@ -407,16 +407,16 @@ public final class KeychainAuthorizationProvider: AuthorizationProvider, Authori
return item
}

struct ProtocolHostPort: Hashable, CustomStringConvertible {
let `protocol`: String?
let host: String
let port: Int?
package struct ProtocolHostPort: Hashable, CustomStringConvertible {
package let `protocol`: String?
package let host: String
package let port: Int?

var server: String {
self.host
}

var protocolCFString: CFString {
package var protocolCFString: CFString {
// See
// https://developer.apple.com/documentation/security/keychain_services/keychain_items/item_attribute_keys_and_values?language=swift
// for a list of possible values for the `kSecAttrProtocol` attribute.
Expand All @@ -430,7 +430,7 @@ public final class KeychainAuthorizationProvider: AuthorizationProvider, Authori
}
}

init?(from url: URL) {
package init?(from url: URL) {
guard let host = url.host?.lowercased(), !host.isEmpty else {
return nil
}
Expand All @@ -440,7 +440,7 @@ public final class KeychainAuthorizationProvider: AuthorizationProvider, Authori
self.port = url.port
}

var description: String {
package var description: String {
"\(self.protocol.map { "\($0)://" } ?? "")\(self.host)\(self.port.map { ":\($0)" } ?? "")"
}
}
Expand All @@ -450,8 +450,8 @@ public final class KeychainAuthorizationProvider: AuthorizationProvider, Authori
// MARK: - Composite

public struct CompositeAuthorizationProvider: AuthorizationProvider {
// marked internal for testing
internal let providers: [AuthorizationProvider]
// marked `package` for testing
package let providers: [AuthorizationProvider]
private let observabilityScope: ObservabilityScope

public init(_ providers: AuthorizationProvider..., observabilityScope: ObservabilityScope) {
Expand Down
4 changes: 2 additions & 2 deletions Sources/Basics/Cancellator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,9 @@ public final class Cancellator: Cancellable, Sendable {
self._cancel(deadline: deadline)
}

// marked internal for testing
// marked `package` for testing
@discardableResult
internal func _cancel(deadline: DispatchTime? = .none) -> Int {
package func _cancel(deadline: DispatchTime? = .none) -> Int {
self.cancelling.put(true)

self.observabilityScope?
Expand Down
10 changes: 5 additions & 5 deletions Sources/Basics/Concurrency/SendableBox.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,29 @@ import struct Foundation.Date
/// an `async` closure. This type serves as a replacement for `ThreadSafeBox`
/// implemented with Swift Concurrency primitives.
public actor SendableBox<Value: Sendable> {
init(_ value: Value? = nil) {
package init(_ value: Value? = nil) {
self.value = value
}

var value: Value?
package var value: Value?
}

extension SendableBox where Value == Int {
func increment() {
package func increment() {
if let value {
self.value = value + 1
}
}

func decrement() {
package func decrement() {
if let value {
self.value = value - 1
}
}
}

extension SendableBox where Value == Date {
func resetDate() {
package func resetDate() {
value = Date()
}
}
8 changes: 4 additions & 4 deletions Sources/Basics/Graph/AdjacencyMatrix.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
/// edge exists.
///
/// See https://en.wikipedia.org/wiki/Adjacency_matrix for more details.
struct AdjacencyMatrix {
package struct AdjacencyMatrix {
let columns: Int
let rows: Int
private var bytes: [UInt8]
Expand All @@ -27,15 +27,15 @@ struct AdjacencyMatrix {
/// - Parameters:
/// - rows: Number of rows in the matrix.
/// - columns: Number of columns in the matrix.
init(rows: Int, columns: Int) {
package init(rows: Int, columns: Int) {
self.columns = columns
self.rows = rows

let (quotient, remainder) = (rows * columns).quotientAndRemainder(dividingBy: 8)
self.bytes = .init(repeating: 0, count: quotient + (remainder > 0 ? 1 : 0))
}

var bitCount: Int {
package var bitCount: Int {
bytes.count * 8
}

Expand All @@ -44,7 +44,7 @@ struct AdjacencyMatrix {
return (byteOffset: totalBitOffset / 8, bitOffsetInByte: totalBitOffset % 8)
}

subscript(row: Int, column: Int) -> Bool {
package subscript(row: Int, column: Int) -> Bool {
get {
let (byteOffset, bitOffsetInByte) = calculateOffsets(row: row, column: column)

Expand Down
4 changes: 2 additions & 2 deletions Sources/Basics/HTTPClient/HTTPClientHeaders.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ public struct HTTPClientHeaders: Sendable {
}

public struct Item: Equatable, Sendable {
let name: String
let value: String
package let name: String
package let value: String

public init(name: String, value: String) {
self.name = name
Expand Down
2 changes: 1 addition & 1 deletion Sources/Basics/HTTPClient/HTTPMethod.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public enum HTTPMethod: Sendable {
case put
case delete

var string: String {
package var string: String {
switch self {
case .head:
return "HEAD"
Expand Down
10 changes: 5 additions & 5 deletions Sources/Basics/HTTPClient/URLSessionHTTPClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ import struct TSCUtility.Versioning
import FoundationNetworking
#endif

final class URLSessionHTTPClient: Sendable {
package final class URLSessionHTTPClient: Sendable {
private let dataSession: URLSession
private let downloadSession: URLSession
private let dataTaskManager: DataTaskManager
private let downloadTaskManager: DownloadTaskManager

init(configuration: URLSessionConfiguration = .default) {
package init(configuration: URLSessionConfiguration = .default) {
let dataDelegateQueue = OperationQueue()
dataDelegateQueue.name = "org.swift.swiftpm.urlsession-http-client-data-delegate"
dataDelegateQueue.maxConcurrentOperationCount = 1
Expand Down Expand Up @@ -52,7 +52,7 @@ final class URLSessionHTTPClient: Sendable {
}

@Sendable
func execute(
package func execute(
_ request: HTTPClient.Request,
progress: HTTPClient.ProgressHandler? = nil
) async throws -> LegacyHTTPClient.Response {
Expand Down Expand Up @@ -364,7 +364,7 @@ private final class DownloadTaskManager: NSObject, URLSessionDownloadDelegate {
}

extension URLRequest {
init(_ request: LegacyHTTPClient.Request) {
package init(_ request: LegacyHTTPClient.Request) {
self.init(url: request.url)
self.httpMethod = request.method.string
request.headers.forEach { header in
Expand All @@ -376,7 +376,7 @@ extension URLRequest {
}
}

init(_ request: HTTPClient.Request) {
package init(_ request: HTTPClient.Request) {
self.init(url: request.url)
self.httpMethod = request.method.string
request.headers.forEach { header in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
import _Concurrency

/// A progress animation wrapper that throttles updates to a given interval.
final class ThrottledProgressAnimation: ProgressAnimationProtocol {
package final class ThrottledProgressAnimation: ProgressAnimationProtocol {
private let animation: ProgressAnimationProtocol
private let shouldUpdate: () -> Bool
private var pendingUpdate: (Int, Int, String)?

init<C: Clock>(
package init<C: Clock>(
_ animation: ProgressAnimationProtocol,
now: @escaping () -> C.Instant, interval: C.Duration, clock: C.Type = C.self
) {
Expand All @@ -35,7 +35,7 @@ final class ThrottledProgressAnimation: ProgressAnimationProtocol {
}
}

func update(step: Int, total: Int, text: String) {
package func update(step: Int, total: Int, text: String) {
guard shouldUpdate() else {
pendingUpdate = (step, total, text)
return
Expand All @@ -44,14 +44,14 @@ final class ThrottledProgressAnimation: ProgressAnimationProtocol {
animation.update(step: step, total: total, text: text)
}

func complete(success: Bool) {
package func complete(success: Bool) {
if let (step, total, text) = pendingUpdate {
animation.update(step: step, total: total, text: text)
}
animation.complete(success: success)
}

func clear() {
package func clear() {
animation.clear()
}
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/Basics/Serialization/SerializedJSON.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
/// Wrapper type representing serialized escaped JSON strings providing helpers
/// for escaped string interpolations for common types such as `AbsolutePath`.
public struct SerializedJSON {
let underlying: String
package let underlying: String
}

extension SerializedJSON: ExpressibleByStringLiteral {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public final class ClangModuleBuildDescription {
public let buildToolPluginInvocationResults: [BuildToolPluginInvocationResult]

/// Create a new target description with target and build parameters.
init(
package init(
package: ResolvedPackage,
target: ResolvedModule,
toolsVersion: ToolsVersion,
Expand Down Expand Up @@ -549,4 +549,4 @@ extension ClangModuleBuildDescription {
) -> [ModuleBuildDescription.Dependency] {
ModuleBuildDescription.clang(self).recursiveDependencies(using: plan)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public enum ModuleBuildDescription: SPMBuildCore.ModuleBuildDescription {
}
}

var destination: BuildParameters.Destination {
package var destination: BuildParameters.Destination {
switch self {
case .swift(let buildDescription):
buildDescription.destination
Expand Down Expand Up @@ -152,6 +152,11 @@ public enum ModuleBuildDescription: SPMBuildCore.ModuleBuildDescription {

extension ModuleBuildDescription: Identifiable {
public struct ID: Hashable {
package init(moduleID: ResolvedModule.ID, destination: BuildParameters.Destination) {
self.moduleID = moduleID
self.destination = destination
}

let moduleID: ResolvedModule.ID
let destination: BuildParameters.Destination
}
Expand Down
11 changes: 8 additions & 3 deletions Sources/Build/BuildDescription/ProductBuildDescription.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public final class ProductBuildDescription: SPMBuildCore.ProductBuildDescription

/// The dynamic libraries this product needs to link with.
// Computed during build planning.
var dylibs: [ProductBuildDescription] = []
package var dylibs: [ProductBuildDescription] = []

/// Any additional flags to be added. These flags are expected to be computed during build planning.
var additionalFlags: [String] = []
Expand All @@ -64,7 +64,7 @@ public final class ProductBuildDescription: SPMBuildCore.ProductBuildDescription
var libraryBinaryPaths: Set<AbsolutePath> = []

/// Paths to tools shipped in binary dependencies
var availableTools: [String: AbsolutePath] = [:]
package var availableTools: [String: AbsolutePath] = [:]

/// Path to the temporary directory for this product.
var tempsPath: AbsolutePath {
Expand All @@ -84,7 +84,7 @@ public final class ProductBuildDescription: SPMBuildCore.ProductBuildDescription
private let observabilityScope: ObservabilityScope

/// Create a build description for a product.
init(
package init(
package: ResolvedPackage,
product: ResolvedProduct,
toolsVersion: ToolsVersion,
Expand Down Expand Up @@ -406,6 +406,11 @@ public final class ProductBuildDescription: SPMBuildCore.ProductBuildDescription

extension ProductBuildDescription: Identifiable {
public struct ID: Hashable {
package init(productID: ResolvedProduct.ID, destination: BuildParameters.Destination) {
self.productID = productID
self.destination = destination
}

let productID: ResolvedProduct.ID
let destination: BuildParameters.Destination
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import struct PackageGraph.ResolvedModule
import struct PackageGraph.ResolvedProduct

extension LLBuildManifestBuilder {
func createProductCommand(_ buildProduct: ProductBuildDescription) throws {
package func createProductCommand(_ buildProduct: ProductBuildDescription) throws {
let cmdName = try buildProduct.commandName

// Add dependency on Info.plist generation on Darwin platforms.
Expand Down
2 changes: 1 addition & 1 deletion Sources/Build/BuildManifest/LLBuildManifestBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public class LLBuildManifestBuilder {
public internal(set) var manifest: LLBuildManifest = .init()

/// Mapping from Swift compiler path to Swift get version files.
var swiftGetVersionFiles = [AbsolutePath: AbsolutePath]()
package var swiftGetVersionFiles = [AbsolutePath: AbsolutePath]()

/// Create a new builder with a build plan.
public init(
Expand Down
4 changes: 2 additions & 2 deletions Sources/Build/BuildOperation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ public final class BuildOperation: PackageStructureDelegate, SPMBuildCore.BuildS
}

/// Compute the llbuild target name using the given subset.
func computeLLBuildTargetName(for subset: BuildSubset) async throws -> String {
package func computeLLBuildTargetName(for subset: BuildSubset) async throws -> String {
func inferTestDestination(
testModule: ResolvedModule,
graph: ModulesGraph
Expand Down Expand Up @@ -1017,7 +1017,7 @@ extension BuildDescription {
}

extension BuildSubset {
func recursiveDependencies(for graph: ModulesGraph, observabilityScope: ObservabilityScope) throws -> [ResolvedModule]? {
package func recursiveDependencies(for graph: ModulesGraph, observabilityScope: ObservabilityScope) throws -> [ResolvedModule]? {
switch self {
case .allIncludingTests:
return Array(graph.reachableModules)
Expand Down
Loading