Skip to content

Commit d14ff89

Browse files
authored
Start using package for some APIs (#7240)
Use of `package` in our APIs has a particular interest for us, as it allows us to make sure we don't expose certain types and functions in out public API. Here we're making changes to some declarations in `SPMTestSupport` and `Basics` from `public` to `package`.
1 parent 2394eb7 commit d14ff89

File tree

5 files changed

+28
-23
lines changed

5 files changed

+28
-23
lines changed

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,8 @@ find_package(dispatch QUIET)
5151
find_package(Foundation QUIET)
5252
find_package(SQLite3 REQUIRED)
5353

54+
# Enable `package` modifier for the whole package.
55+
add_compile_options("$<$<COMPILE_LANGUAGE:Swift>:-package-name;SwiftPM>")
56+
5457
add_subdirectory(Sources)
5558
add_subdirectory(cmake/modules)

Sources/Basics/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ target_link_libraries(Basics PUBLIC
7070
target_link_libraries(Basics PRIVATE
7171
SPMSQLite3
7272
TSCclibc)
73+
7374
# NOTE(compnerd) workaround for CMake not setting up include flags yet
7475
set_target_properties(Basics PROPERTIES
7576
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY})

Sources/Basics/OSSignpost.swift

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ extension os.OSLog {
2222
#endif
2323

2424
/// Emits a signpost.
25-
@inlinable public func os_signpost(
25+
@inlinable package func os_signpost(
2626
_ type: SignpostType,
2727
name: StaticString,
2828
signpostID: SignpostID = .exclusive
@@ -39,8 +39,8 @@ extension os.OSLog {
3939
#endif
4040
}
4141

42-
43-
public enum SignpostType {
42+
@usableFromInline
43+
package enum SignpostType {
4444
case begin
4545
case end
4646
case event
@@ -61,7 +61,8 @@ public enum SignpostType {
6161
#endif
6262
}
6363

64-
public enum SignpostID {
64+
@usableFromInline
65+
package enum SignpostID {
6566
case exclusive
6667

6768
#if canImport(os)
@@ -77,7 +78,7 @@ public enum SignpostID {
7778
}
7879

7980

80-
public enum SignpostName {
81+
package enum SignpostName {
8182
public static let updatingDependencies: StaticString = "updating"
8283
public static let resolvingDependencies: StaticString = "resolving"
8384
public static let pubgrub: StaticString = "pubgrub"

Sources/SPMTestSupport/GitRepositoryExtensions.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import enum TSCUtility.Git
1818

1919
/// Extensions useful for unit testing purposes.
2020
/// Note: These are not thread safe.
21-
public extension GitRepository {
21+
package extension GitRepository {
2222
/// Create the repository using git init.
2323
func create() throws {
2424
try systemQuietly([Git.tool, "-C", self.path.pathString, "init"])

Sources/SPMTestSupport/MockArchiver.swift

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,22 @@
1212

1313
import Basics
1414

15-
public class MockArchiver: Archiver {
16-
public typealias ExtractionHandler = (
15+
package class MockArchiver: Archiver {
16+
package typealias ExtractionHandler = (
1717
MockArchiver,
1818
AbsolutePath,
1919
AbsolutePath,
2020
(Result<Void, Error>) -> Void
2121
) throws -> Void
22-
public typealias CompressionHandler = (
22+
package typealias CompressionHandler = (
2323
MockArchiver,
2424
AbsolutePath,
2525
AbsolutePath,
2626
(Result<Void, Error>) -> Void
2727
) throws -> Void
28-
public typealias ValidationHandler = (MockArchiver, AbsolutePath, (Result<Bool, Error>) -> Void) throws -> Void
28+
package typealias ValidationHandler = (MockArchiver, AbsolutePath, (Result<Bool, Error>) -> Void) throws -> Void
2929

30-
public struct Extraction: Equatable {
30+
package struct Extraction: Equatable {
3131
public let archivePath: AbsolutePath
3232
public let destinationPath: AbsolutePath
3333

@@ -37,7 +37,7 @@ public class MockArchiver: Archiver {
3737
}
3838
}
3939

40-
public struct Compression: Equatable {
40+
package struct Compression: Equatable {
4141
public let directory: AbsolutePath
4242
public let destinationPath: AbsolutePath
4343

@@ -47,18 +47,18 @@ public class MockArchiver: Archiver {
4747
}
4848
}
4949

50-
public let supportedExtensions: Set<String> = ["zip"]
51-
public let extractions = ThreadSafeArrayStore<Extraction>()
52-
public let compressions = ThreadSafeArrayStore<Compression>()
53-
public let extractionHandler: ExtractionHandler?
54-
public let compressionHandler: CompressionHandler?
55-
public let validationHandler: ValidationHandler?
50+
package let supportedExtensions: Set<String> = ["zip"]
51+
package let extractions = ThreadSafeArrayStore<Extraction>()
52+
package let compressions = ThreadSafeArrayStore<Compression>()
53+
package let extractionHandler: ExtractionHandler?
54+
package let compressionHandler: CompressionHandler?
55+
package let validationHandler: ValidationHandler?
5656

57-
public convenience init(handler: ExtractionHandler? = .none) {
57+
package convenience init(handler: ExtractionHandler? = .none) {
5858
self.init(extractionHandler: handler, compressionHandler: .none, validationHandler: .none)
5959
}
6060

61-
public init(
61+
package init(
6262
extractionHandler: ExtractionHandler? = .none,
6363
compressionHandler: CompressionHandler? = .none,
6464
validationHandler: ValidationHandler? = .none
@@ -68,7 +68,7 @@ public class MockArchiver: Archiver {
6868
self.validationHandler = validationHandler
6969
}
7070

71-
public func extract(
71+
package func extract(
7272
from archivePath: AbsolutePath,
7373
to destinationPath: AbsolutePath,
7474
completion: @escaping (Result<Void, Error>) -> Void
@@ -85,7 +85,7 @@ public class MockArchiver: Archiver {
8585
}
8686
}
8787

88-
public func compress(
88+
package func compress(
8989
directory: AbsolutePath,
9090
to destinationPath: AbsolutePath,
9191
completion: @escaping (Result<Void, Error>) -> Void
@@ -102,7 +102,7 @@ public class MockArchiver: Archiver {
102102
}
103103
}
104104

105-
public func validate(path: AbsolutePath, completion: @escaping (Result<Bool, Error>) -> Void) {
105+
package func validate(path: AbsolutePath, completion: @escaping (Result<Bool, Error>) -> Void) {
106106
do {
107107
if let handler = self.validationHandler {
108108
try handler(self, path, completion)

0 commit comments

Comments
 (0)