Skip to content

Commit 87e5447

Browse files
authored
Merge branch 'main' into watchman
2 parents aaed2d1 + 59e1e0b commit 87e5447

File tree

8 files changed

+1569
-113
lines changed

8 files changed

+1569
-113
lines changed

Package.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ let package = Package(
2828
.iOS(.v13)
2929
],
3030
products: [
31+
.library(
32+
name: "TSCBasic",
33+
targets: ["TSCBasic"]),
3134
.library(
3235
name: "SwiftToolsSupport",
3336
type: .dynamic,

Sources/TSCBasic/Path.swift

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -911,10 +911,42 @@ extension AbsolutePath {
911911
///
912912
/// This method is strictly syntactic and does not access the file system
913913
/// in any way.
914+
@available(*, deprecated, renamed: "isDescendantOfOrEqual(to:)")
914915
public func contains(_ other: AbsolutePath) -> Bool {
915-
return self.components.starts(with: other.components)
916+
return isDescendantOfOrEqual(to: other)
916917
}
917918

919+
/// Returns true if the path is an ancestor of the given path.
920+
///
921+
/// This method is strictly syntactic and does not access the file system
922+
/// in any way.
923+
public func isAncestor(of descendant: AbsolutePath) -> Bool {
924+
return descendant.components.dropLast().starts(with: self.components)
925+
}
926+
927+
/// Returns true if the path is an ancestor of or equal to the given path.
928+
///
929+
/// This method is strictly syntactic and does not access the file system
930+
/// in any way.
931+
public func isAncestorOfOrEqual(to descendant: AbsolutePath) -> Bool {
932+
return descendant.components.starts(with: self.components)
933+
}
934+
935+
/// Returns true if the path is a descendant of the given path.
936+
///
937+
/// This method is strictly syntactic and does not access the file system
938+
/// in any way.
939+
public func isDescendant(of ancestor: AbsolutePath) -> Bool {
940+
return self.components.dropLast().starts(with: ancestor.components)
941+
}
942+
943+
/// Returns true if the path is a descendant of or equal to the given path.
944+
///
945+
/// This method is strictly syntactic and does not access the file system
946+
/// in any way.
947+
public func isDescendantOfOrEqual(to ancestor: AbsolutePath) -> Bool {
948+
return self.components.starts(with: ancestor.components)
949+
}
918950
}
919951

920952
extension PathValidationError: CustomNSError {

Sources/TSCBasic/WritableByteStream.swift

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ public extension WritableByteStream {
6666
// Public alias to the old name to not introduce API compatibility.
6767
public typealias OutputByteStream = WritableByteStream
6868

69+
#if os(Android)
70+
public typealias FILEPointer = OpaquePointer
71+
#else
72+
public typealias FILEPointer = UnsafeMutablePointer<FILE>
73+
#endif
74+
6975
extension WritableByteStream {
7076
/// Write a sequence of bytes to the buffer.
7177
public func write<S: Sequence>(sequence: S) where S.Iterator.Element == UInt8 {
@@ -670,7 +676,7 @@ public class FileOutputByteStream: _WritableByteStreamBase {
670676
public final class LocalFileOutputByteStream: FileOutputByteStream {
671677

672678
/// The pointer to the file.
673-
let filePointer: UnsafeMutablePointer<FILE>
679+
let filePointer: FILEPointer
674680

675681
/// Set to an error value if there were any IO error during writing.
676682
private var error: FileSystemError?
@@ -682,7 +688,7 @@ public final class LocalFileOutputByteStream: FileOutputByteStream {
682688
private let path: AbsolutePath?
683689

684690
/// Instantiate using the file pointer.
685-
public init(filePointer: UnsafeMutablePointer<FILE>, closeOnDeinit: Bool = true, buffered: Bool = true) throws {
691+
public init(filePointer: FILEPointer, closeOnDeinit: Bool = true, buffered: Bool = true) throws {
686692
self.filePointer = filePointer
687693
self.closeOnDeinit = closeOnDeinit
688694
self.path = nil

Sources/TSCUtility/BitstreamReader.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ private struct BitstreamReader {
183183
if case .char6 = element {
184184
// FIXME: Once the minimum deployment target bumps to macOS 11, use
185185
// the more ergonomic stdlib API everywhere.
186-
if #available(macOS 11.0, *) {
186+
if #available(macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0, *) {
187187
payload = try .char6String(String(unsafeUninitializedCapacity: Int(length)) { buffer in
188188
for i in 0..<Int(length) {
189189
buffer[i] = try UInt8(readSingleAbbreviatedRecordOperand(element))

Sources/TSCUtility/FSWatch.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ private protocol _FileWatcher {
100100
func stop()
101101
}
102102

103-
#if os(OpenBSD)
103+
#if os(OpenBSD) || os(iOS)
104104
extension FSWatch._WatcherDelegate: NoOpWatcherDelegate {}
105105
extension NoOpWatcher: _FileWatcher{}
106106
#elseif os(Windows)
@@ -118,7 +118,7 @@ extension FSEventStream: _FileWatcher{}
118118

119119
// MARK:- inotify
120120

121-
#if os(OpenBSD)
121+
#if os(OpenBSD) || os(iOS)
122122

123123
public protocol NoOpWatcherDelegate {
124124
func pathsDidReceiveEvent(_ paths: [AbsolutePath])
@@ -404,10 +404,10 @@ public final class Inotify {
404404
private var wds: [Int32: AbsolutePath] = [:]
405405

406406
/// The queue on which we read the events.
407-
private let readQueue = DispatchQueue(label: "org.swift.swiftpm.\(Inotify.self).read)")
407+
private let readQueue = DispatchQueue(label: "org.swift.swiftpm.\(Inotify.self).read")
408408

409409
/// Callback queue for the delegate.
410-
private let callbacksQueue = DispatchQueue(label: "org.swift.swiftpm.\(Inotify.self).callback)")
410+
private let callbacksQueue = DispatchQueue(label: "org.swift.swiftpm.\(Inotify.self).callback")
411411

412412
/// Condition for handling event reporting.
413413
private var reportCondition = Condition()
@@ -796,7 +796,7 @@ public final class FSEventStream {
796796
private var runLoop: CFRunLoop?
797797

798798
/// Callback queue for the delegate.
799-
fileprivate let callbacksQueue = DispatchQueue(label: "org.swift.swiftpm.\(FSEventStream.self).callback)")
799+
fileprivate let callbacksQueue = DispatchQueue(label: "org.swift.swiftpm.\(FSEventStream.self).callback")
800800

801801
public init(
802802
paths: [AbsolutePath],

0 commit comments

Comments
 (0)