Skip to content

Commit fcaa2ce

Browse files
committed
Initial commit
This initial commit copies all files from the following targets from the Swift package manager repository here to be usable from other projects as well: TSCBasic, TSCUtility, TSCclibc, TSCLibc, TSCTestSupport, TSCTestSupportExecutable, TSCUtility
1 parent c1eaa9b commit fcaa2ce

File tree

165 files changed

+20353
-17
lines changed

Some content is hidden

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

165 files changed

+20353
-17
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.DS_Store
2+
/.build
3+
/Packages
4+
/*.xcodeproj
5+
xcuserdata/

LICENSE.txt

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -208,19 +208,3 @@
208208
portions of this Software are embedded into the binary product as a result,
209209
you may redistribute such product without providing attribution as would
210210
otherwise be required by Sections 4(a), 4(b) and 4(d) of the License.
211-
212-
213-
## Copyrights and Licenses for Third Party Software Distributed with llbuild: ##
214-
215-
The llbuild software contains code written by third parties. Such software will
216-
have its own individual LICENSE.TXT file as part of its source or in the
217-
directory in which it appears. This file will describe the copyrights, license,
218-
and restrictions which apply to that code.
219-
220-
The following pieces of software have additional or alternate copyrights,
221-
licenses, and/or restrictions:
222-
223-
Program Directory
224-
------- ---------
225-
Google Test llbuild/utils/unittest/googletest
226-
LLVM llbuild/lib/llvm, llbuild/include/llvm

Package.swift

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
// swift-tools-version:4.2
2+
3+
/*
4+
This source file is part of the Swift.org open source project
5+
6+
Copyright (c) 2019 Apple Inc. and the Swift project authors
7+
Licensed under Apache License v2.0 with Runtime Library Exception
8+
9+
See http://swift.org/LICENSE.txt for license information
10+
See http://swift.org/CONTRIBUTORS.txt for Swift project authors
11+
*/
12+
13+
14+
import PackageDescription
15+
16+
let package = Package(
17+
name: "swift-tools-support-core",
18+
products: [
19+
.library(
20+
name: "SwiftToolsSupport",
21+
type: .dynamic,
22+
targets: ["TSCBasic", "TSCUtility"]),
23+
.library(
24+
name: "SwiftToolsSupport-auto",
25+
targets: ["TSCBasic", "TSCUtility"]),
26+
],
27+
dependencies: [
28+
29+
],
30+
targets: [
31+
32+
// MARK: Tools support core targets
33+
34+
.target(
35+
/** Shim target to import missing C headers in Darwin and Glibc modulemap. */
36+
name: "TSCclibc",
37+
dependencies: []),
38+
.target(
39+
/** Cross-platform access to bare `libc` functionality. */
40+
name: "TSCLibc",
41+
dependencies: ["TSCclibc"]),
42+
.target(
43+
/** TSCBasic support library */
44+
name: "TSCBasic",
45+
dependencies: ["TSCLibc"]),
46+
.target(
47+
/** Abstractions for common operations, should migrate to TSCBasic */
48+
name: "TSCUtility",
49+
dependencies: ["TSCBasic"]),
50+
51+
// MARK: Additional Test Dependencies
52+
53+
.target(
54+
/** Generic test support library */
55+
name: "TSCTestSupport",
56+
dependencies: ["TSCBasic", "TSCUtility"]),
57+
.target(
58+
/** Test support executable */
59+
name: "TSCTestSupportExecutable",
60+
dependencies: ["TSCBasic", "TSCUtility"]),
61+
62+
63+
// MARK: Tools support core tests
64+
65+
.testTarget(
66+
name: "TSCBasicTests",
67+
dependencies: ["TSCTestSupport", "TSCTestSupportExecutable"]),
68+
.testTarget(
69+
name: "TSCBasicPerformanceTests",
70+
dependencies: ["TSCBasic", "TSCTestSupport"]),
71+
.testTarget(
72+
name: "TSCTestSupportTests",
73+
dependencies: ["TSCTestSupport"]),
74+
.testTarget(
75+
name: "TSCUtilityTests",
76+
dependencies: ["TSCUtility", "TSCTestSupport", "TSCTestSupportExecutable"]),
77+
]
78+
)

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,16 @@ swift-tools-support-core
44
Contains common infrastructural code for both [SwiftPM](https://github.com/apple/swift-package-manager)
55
and [llbuild](https://github.com/apple/swift-llbuild).
66

7+
Development
8+
-------------
9+
10+
All changes to source files in this repository need to be done in the repository of the Swift Package Manager repository ([link](https://github.com/apple/swift-package-manager)) and then copied here using the Script in `Utilities/import` which takes the local path to the SwiftPM directory as input (or uses `../swiftpm` as default).
11+
All targets with a TSC prefix in [SwiftPM](https://github.com/apple/swift-package-manager) are part of the swift-tools-support-core and will be imported by the import script. The plan is to eventually move ownership to this repository.
12+
713
License
814
-------
915

10-
Copyright (c) 2014 - 2018 Apple Inc. and the Swift project authors.
16+
Copyright (c) 2014 - 2019 Apple Inc. and the Swift project authors.
1117
Licensed under Apache License v2.0 with Runtime Library Exception.
1218

1319
See http://swift.org/LICENSE.txt for license information.

Sources/TSCBasic/Await.swift

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
This source file is part of the Swift.org open source project
3+
4+
Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
5+
Licensed under Apache License v2.0 with Runtime Library Exception
6+
7+
See http://swift.org/LICENSE.txt for license information
8+
See http://swift.org/CONTRIBUTORS.txt for Swift project authors
9+
*/
10+
11+
/// Converts an asynchronous method having callback using Result enum to synchronous.
12+
///
13+
/// - Parameter body: The async method must be called inside this body and closure provided in the parameter
14+
/// should be passed to the async method's completion handler.
15+
/// - Returns: The value wrapped by the async method's result.
16+
/// - Throws: The error wrapped by the async method's result
17+
public func await<T, ErrorType>(_ body: (@escaping (Result<T, ErrorType>) -> Void) -> Void) throws -> T {
18+
return try await(body).dematerialize()
19+
}
20+
21+
public func await<T>(_ body: (@escaping (T) -> Void) -> Void) -> T {
22+
let condition = Condition()
23+
var result: T? = nil
24+
body { theResult in
25+
condition.whileLocked {
26+
result = theResult
27+
condition.signal()
28+
}
29+
}
30+
condition.whileLocked {
31+
while result == nil {
32+
condition.wait()
33+
}
34+
}
35+
return result!
36+
}

Sources/TSCBasic/ByteString.swift

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
/*
2+
This source file is part of the Swift.org open source project
3+
4+
Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
5+
Licensed under Apache License v2.0 with Runtime Library Exception
6+
7+
See http://swift.org/LICENSE.txt for license information
8+
See http://swift.org/CONTRIBUTORS.txt for Swift project authors
9+
*/
10+
11+
/// A `ByteString` represents a sequence of bytes.
12+
///
13+
/// This struct provides useful operations for working with buffers of
14+
/// bytes. Conceptually it is just a contiguous array of bytes (UInt8), but it
15+
/// contains methods and default behavor suitable for common operations done
16+
/// using bytes strings.
17+
///
18+
/// This struct *is not* intended to be used for significant mutation of byte
19+
/// strings, we wish to retain the flexibility to micro-optimize the memory
20+
/// allocation of the storage (for example, by inlining the storage for small
21+
/// strings or and by eliminating wasted space in growable arrays). For
22+
/// construction of byte arrays, clients should use the `OutputByteStream` class
23+
/// and then convert to a `ByteString` when complete.
24+
public struct ByteString: ExpressibleByArrayLiteral, Hashable {
25+
/// The buffer contents.
26+
@usableFromInline
27+
internal var _bytes: [UInt8]
28+
29+
/// Create an empty byte string.
30+
@inlinable
31+
public init() {
32+
_bytes = []
33+
}
34+
35+
/// Create a byte string from a byte array literal.
36+
@inlinable
37+
public init(arrayLiteral contents: UInt8...) {
38+
_bytes = contents
39+
}
40+
41+
/// Create a byte string from an array of bytes.
42+
@inlinable
43+
public init(_ contents: [UInt8]) {
44+
_bytes = contents
45+
}
46+
47+
/// Create a byte string from an array slice.
48+
@inlinable
49+
public init(_ contents: ArraySlice<UInt8>) {
50+
_bytes = Array(contents)
51+
}
52+
53+
/// Create a byte string from an byte buffer.
54+
@inlinable
55+
public init<S: Sequence> (_ contents: S) where S.Iterator.Element == UInt8 {
56+
_bytes = [UInt8](contents)
57+
}
58+
59+
/// Create a byte string from the UTF8 encoding of a string.
60+
@inlinable
61+
public init(encodingAsUTF8 string: String) {
62+
_bytes = [UInt8](string.utf8)
63+
}
64+
65+
/// Access the byte string contents as an array.
66+
@inlinable
67+
public var contents: [UInt8] {
68+
return _bytes
69+
}
70+
71+
/// Return the byte string size.
72+
@inlinable
73+
public var count: Int {
74+
return _bytes.count
75+
}
76+
}
77+
78+
/// Conform to CustomDebugStringConvertible.
79+
extension ByteString: CustomStringConvertible {
80+
/// Return the string decoded as a UTF8 sequence, or traps if not possible.
81+
public var description: String {
82+
guard let description = validDescription else {
83+
fatalError("invalid byte string: \(cString)")
84+
}
85+
86+
return description
87+
}
88+
89+
/// Return the string decoded as a UTF8 sequence, if possible.
90+
@inlinable
91+
public var validDescription: String? {
92+
// FIXME: This is very inefficient, we need a way to pass a buffer. It
93+
// is also wrong if the string contains embedded '\0' characters.
94+
let tmp = _bytes + [UInt8(0)]
95+
return tmp.withUnsafeBufferPointer { ptr in
96+
return String(validatingUTF8: unsafeBitCast(ptr.baseAddress, to: UnsafePointer<CChar>.self))
97+
}
98+
}
99+
100+
/// Return the string decoded as a UTF8 sequence, substituting replacement
101+
/// characters for ill-formed UTF8 sequences.
102+
@inlinable
103+
public var cString: String {
104+
return String(decoding: _bytes, as: Unicode.UTF8.self)
105+
}
106+
107+
@available(*, deprecated, message: "use description or validDescription instead")
108+
public var asString: String? {
109+
return validDescription
110+
}
111+
}
112+
113+
/// ByteStreamable conformance for a ByteString.
114+
extension ByteString: ByteStreamable {
115+
@inlinable
116+
public func write(to stream: OutputByteStream) {
117+
stream.write(_bytes)
118+
}
119+
}
120+
121+
/// StringLiteralConvertable conformance for a ByteString.
122+
extension ByteString: ExpressibleByStringLiteral {
123+
public typealias UnicodeScalarLiteralType = StringLiteralType
124+
public typealias ExtendedGraphemeClusterLiteralType = StringLiteralType
125+
126+
public init(unicodeScalarLiteral value: UnicodeScalarLiteralType) {
127+
_bytes = [UInt8](value.utf8)
128+
}
129+
public init(extendedGraphemeClusterLiteral value: ExtendedGraphemeClusterLiteralType) {
130+
_bytes = [UInt8](value.utf8)
131+
}
132+
public init(stringLiteral value: StringLiteralType) {
133+
_bytes = [UInt8](value.utf8)
134+
}
135+
}

Sources/TSCBasic/CMakeLists.txt

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# This source file is part of the Swift.org open source project
2+
#
3+
# Copyright (c) 2014 - 2019 Apple Inc. and the Swift project authors
4+
# Licensed under Apache License v2.0 with Runtime Library Exception
5+
#
6+
# See http://swift.org/LICENSE.txt for license information
7+
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors
8+
9+
add_library(TSCBasic
10+
Await.swift
11+
ByteString.swift
12+
CacheableSequence.swift
13+
CollectionAlgorithms.swift
14+
CollectionExtensions.swift
15+
Condition.swift
16+
CStringArray.swift
17+
DeltaAlgorithm.swift
18+
DiagnosticsEngine.swift
19+
DictionaryExtensions.swift
20+
DictionaryLiteralExtensions.swift
21+
EditDistance.swift
22+
FileInfo.swift
23+
FileSystem.swift
24+
GraphAlgorithms.swift
25+
JSON.swift
26+
JSONMapper.swift
27+
KeyedPair.swift
28+
LazyCache.swift
29+
Lock.swift
30+
misc.swift
31+
OSLog.swift
32+
ObjectIdentifierProtocol.swift
33+
OrderedDictionary.swift
34+
OrderedSet.swift
35+
OutputByteStream.swift
36+
Path.swift
37+
PathShims.swift
38+
Process.swift
39+
ProcessEnv.swift
40+
ProcessSet.swift
41+
RegEx.swift
42+
Result.swift
43+
SHA256.swift
44+
SortedArray.swift
45+
StringConversions.swift
46+
SynchronizedQueue.swift
47+
TemporaryFile.swift
48+
TerminalController.swift
49+
Thread.swift
50+
Tuple.swift)
51+
target_link_libraries(TSCBasic PUBLIC
52+
TSCLibc)
53+
# NOTE(compnerd) workaround for CMake not setting up include flags yet
54+
set_target_properties(TSCBasic PROPERTIES
55+
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY})
56+
57+
install(TARGETS TSCBasic
58+
ARCHIVE DESTINATION lib
59+
LIBRARY DESTINATION lib
60+
RUNTIME DESTINATION bin)
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
This source file is part of the Swift.org open source project
3+
4+
Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
5+
Licensed under Apache License v2.0 with Runtime Library Exception
6+
7+
See http://swift.org/LICENSE.txt for license information
8+
See http://swift.org/CONTRIBUTORS.txt for Swift project authors
9+
*/
10+
11+
import TSCLibc
12+
13+
/// `CStringArray` represents a C null-terminated array of pointers to C strings.
14+
///
15+
/// The lifetime of the C strings will correspond to the lifetime of the `CStringArray`
16+
/// instance so be careful about copying the buffer as it may contain dangling pointers.
17+
public final class CStringArray {
18+
/// The null-terminated array of C string pointers.
19+
public let cArray: [UnsafeMutablePointer<Int8>?]
20+
21+
/// Creates an instance from an array of strings.
22+
public init(_ array: [String]) {
23+
cArray = array.map({ $0.withCString({ strdup($0) }) }) + [nil]
24+
}
25+
26+
deinit {
27+
for case let element? in cArray {
28+
free(element)
29+
}
30+
}
31+
}

0 commit comments

Comments
 (0)