Skip to content

Commit 3f112d1

Browse files
authored
Merge pull request #154 from apple/tscclibc-implementation-only
Use @_implementationOnly import for TSCclibc
2 parents e129cb0 + abd4642 commit 3f112d1

File tree

9 files changed

+58
-26
lines changed

9 files changed

+58
-26
lines changed

Package.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/*
44
This source file is part of the Swift.org open source project
55

6-
Copyright (c) 2019 Apple Inc. and the Swift project authors
6+
Copyright (c) 2019 - 2020 Apple Inc. and the Swift project authors
77
Licensed under Apache License v2.0 with Runtime Library Exception
88

99
See http://swift.org/LICENSE.txt for license information
@@ -45,15 +45,15 @@ let package = Package(
4545
.target(
4646
/** Cross-platform access to bare `libc` functionality. */
4747
name: "TSCLibc",
48-
dependencies: ["TSCclibc"]),
48+
dependencies: []),
4949
.target(
5050
/** TSCBasic support library */
5151
name: "TSCBasic",
52-
dependencies: ["TSCLibc"]),
52+
dependencies: ["TSCLibc", "TSCclibc"]),
5353
.target(
5454
/** Abstractions for common operations, should migrate to TSCBasic */
5555
name: "TSCUtility",
56-
dependencies: ["TSCBasic"]),
56+
dependencies: ["TSCBasic", "TSCclibc"]),
5757

5858
// MARK: Additional Test Dependencies
5959

@@ -71,7 +71,7 @@ let package = Package(
7171

7272
.testTarget(
7373
name: "TSCBasicTests",
74-
dependencies: ["TSCTestSupport", "TSCTestSupportExecutable"]),
74+
dependencies: ["TSCTestSupport", "TSCTestSupportExecutable", "TSCclibc"]),
7575
.testTarget(
7676
name: "TSCBasicPerformanceTests",
7777
dependencies: ["TSCBasic", "TSCTestSupport"]),

Sources/TSCBasic/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ target_compile_options(TSCBasic PUBLIC
5757
"$<$<PLATFORM_ID:Windows>:SHELL:-Xcc -D_CRT_SECURE_NO_WARNINGS>")
5858
target_link_libraries(TSCBasic PUBLIC
5959
TSCLibc)
60+
target_link_libraries(TSCBasic PRIVATE
61+
TSCclibc)
6062
if(NOT CMAKE_SYSTEM_NAME STREQUAL Darwin)
6163
if(Foundation_FOUND)
6264
target_link_libraries(TSCBasic PUBLIC

Sources/TSCBasic/Process.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import class Foundation.ProcessInfo
1414
import Foundation
1515
#endif
1616

17+
@_implementationOnly import TSCclibc
1718
import TSCLibc
1819
import Dispatch
1920

Sources/TSCLibc/CMakeLists.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This source file is part of the Swift.org open source project
22
#
3-
# Copyright (c) 2014 - 2019 Apple Inc. and the Swift project authors
3+
# Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors
44
# Licensed under Apache License v2.0 with Runtime Library Exception
55
#
66
# See http://swift.org/LICENSE.txt for license information
@@ -13,8 +13,6 @@ if(CMAKE_SYSTEM_NAME STREQUAL Windows)
1313
target_compile_options(TSCLibc PRIVATE
1414
-autolink-force-load)
1515
endif()
16-
target_link_libraries(TSCLibc PUBLIC
17-
TSCclibc)
1816
# NOTE(compnerd) workaround for CMake not setting up include flags yet
1917
set_target_properties(TSCLibc PROPERTIES
2018
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY})

Sources/TSCLibc/libc.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
This source file is part of the Swift.org open source project
33

4-
Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
4+
Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors
55
Licensed under Apache License v2.0 with Runtime Library Exception
66

77
See http://swift.org/LICENSE.txt for license information
@@ -17,8 +17,6 @@
1717
@_exported import Darwin.C
1818
#endif
1919

20-
@_exported import TSCclibc
21-
2220
#if os(Windows)
2321
private func __randname(_ buffer: UnsafeMutablePointer<CChar>) {
2422
let alpha = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"

Sources/TSCUtility/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This source file is part of the Swift.org open source project
22
#
3-
# Copyright (c) 2014 - 2019 Apple Inc. and the Swift project authors
3+
# Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors
44
# Licensed under Apache License v2.0 with Runtime Library Exception
55
#
66
# See http://swift.org/LICENSE.txt for license information
@@ -45,6 +45,8 @@ add_library(TSCUtility
4545
)
4646
target_link_libraries(TSCUtility PUBLIC
4747
TSCBasic)
48+
target_link_libraries(TSCUtility PRIVATE
49+
TSCclibc)
4850
if(NOT CMAKE_SYSTEM_NAME STREQUAL Darwin)
4951
target_link_libraries(TSCUtility PRIVATE
5052
SQLite::SQLite3)

Sources/TSCUtility/IndexStore.swift

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
/*
22
This source file is part of the Swift.org open source project
33

4-
Copyright (c) 2019 Apple Inc. and the Swift project authors
4+
Copyright (c) 2019 - 2020 Apple Inc. and the Swift project authors
55
Licensed under Apache License v2.0 with Runtime Library Exception
66

77
See http://swift.org/LICENSE.txt for license information
88
See http://swift.org/CONTRIBUTORS.txt for Swift project authors
99
*/
1010

1111
import TSCBasic
12-
import TSCclibc
12+
@_implementationOnly import TSCclibc
1313

1414
public final class IndexStore {
1515

@@ -19,22 +19,52 @@ public final class IndexStore {
1919
public var methods: [String]
2020
}
2121

22-
let api: IndexStoreAPI
22+
fileprivate var impl: IndexStoreImpl { _impl as! IndexStoreImpl }
23+
private let _impl: Any
2324

24-
var fn: indexstore_functions_t {
25-
return api.fn
25+
fileprivate init(_ impl: IndexStoreImpl) {
26+
self._impl = impl
2627
}
2728

29+
static public func open(store path: AbsolutePath, api: IndexStoreAPI) throws -> IndexStore {
30+
let impl = try IndexStoreImpl.open(store: path, api: api.impl)
31+
return IndexStore(impl)
32+
}
33+
34+
public func listTests(inObjectFile object: AbsolutePath) throws -> [TestCaseClass] {
35+
return try impl.listTests(inObjectFile: object)
36+
}
37+
}
38+
39+
public final class IndexStoreAPI {
40+
fileprivate var impl: IndexStoreAPIImpl {
41+
_impl as! IndexStoreAPIImpl
42+
}
43+
private let _impl: Any
44+
45+
public init(dylib path: AbsolutePath) throws {
46+
self._impl = try IndexStoreAPIImpl(dylib: path)
47+
}
48+
}
49+
50+
private final class IndexStoreImpl {
51+
52+
typealias TestCaseClass = IndexStore.TestCaseClass
53+
54+
let api: IndexStoreAPIImpl
55+
56+
var fn: indexstore_functions_t { api.fn }
57+
2858
let store: indexstore_t
2959

30-
private init(store: indexstore_t, api: IndexStoreAPI) {
60+
private init(store: indexstore_t, api: IndexStoreAPIImpl) {
3161
self.store = store
3262
self.api = api
3363
}
3464

35-
static public func open(store path: AbsolutePath, api: IndexStoreAPI) throws -> IndexStore {
65+
static public func open(store path: AbsolutePath, api: IndexStoreAPIImpl) throws -> IndexStoreImpl {
3666
if let store = try api.call({ api.fn.store_create(path.pathString, &$0) }) {
37-
return IndexStore(store: store, api: api)
67+
return IndexStoreImpl(store: store, api: api)
3868
}
3969
throw StringError("Unable to open store at \(path)")
4070
}
@@ -156,15 +186,15 @@ public final class IndexStore {
156186
}
157187

158188
private class Ref<T> {
159-
let api: IndexStoreAPI
189+
let api: IndexStoreAPIImpl
160190
var instance: T
161-
init(_ instance: T, api: IndexStoreAPI) {
191+
init(_ instance: T, api: IndexStoreAPIImpl) {
162192
self.instance = instance
163193
self.api = api
164194
}
165195
}
166196

167-
public final class IndexStoreAPI {
197+
private final class IndexStoreAPIImpl {
168198

169199
/// The path of the index store dylib.
170200
private let path: AbsolutePath

Sources/TSCUtility/Versioning.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
/*
22
This source file is part of the Swift.org open source project
33

4-
Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
4+
Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors
55
Licensed under Apache License v2.0 with Runtime Library Exception
66

77
See http://swift.org/LICENSE.txt for license information
88
See http://swift.org/CONTRIBUTORS.txt for Swift project authors
99
*/
1010

11-
import TSCclibc
11+
@_implementationOnly import TSCclibc
1212

1313
/// A Swift version number.
1414
///

Tests/TSCBasicTests/ProcessTests.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@
1010

1111
import TSCTestSupport
1212
import XCTest
13-
import TSCLibc
1413

14+
@_implementationOnly import TSCclibc
15+
import TSCLibc
1516
import TSCBasic
1617

1718
typealias ProcessID = TSCBasic.Process.ProcessID

0 commit comments

Comments
 (0)