mirror of
https://github.com/apple/swift-nio
synced 2026-11-28 05:14:23 +00:00
Use the new Android overlay and Bionic module from Swift 6 (#2784)
Motivation: Get this repo building again for Android with the new overlay Modifications: - Import the new module or overlay wherever `Glibc` is used - Keep this repo building with Swift 5 by duplicating some declarations Result: All the same tests keep passing on my Android CI, finagolfin/swift-android-sdk#158
This commit is contained in:
1 parent
284125791a
commit
4feff3c2f6
33 files changed
+164
-43
No files matched your search
@@ -23,6 +23,9 @@ import CNIOLinux
|
||||
#elseif canImport(Musl)
|
||||
import Musl
|
||||
import CNIOLinux
|
||||
#elseif canImport(Android)
|
||||
import Android
|
||||
import CNIOLinux
|
||||
#endif
|
||||
|
||||
/// Information about a file system object.
|
||||
@@ -85,7 +88,7 @@ public struct FileInfo: Hashable, Sendable {
|
||||
self.lastAccessTime = Timespec(platformSpecificStatus.st_atimespec)
|
||||
self.lastDataModificationTime = Timespec(platformSpecificStatus.st_mtimespec)
|
||||
self.lastStatusChangeTime = Timespec(platformSpecificStatus.st_ctimespec)
|
||||
#elseif canImport(Glibc) || canImport(Musl)
|
||||
#elseif canImport(Glibc) || canImport(Musl) || canImport(Android)
|
||||
self.lastAccessTime = Timespec(platformSpecificStatus.st_atim)
|
||||
self.lastDataModificationTime = Timespec(platformSpecificStatus.st_mtim)
|
||||
self.lastStatusChangeTime = Timespec(platformSpecificStatus.st_ctim)
|
||||
@@ -150,7 +153,7 @@ extension FileInfo {
|
||||
#if canImport(Darwin)
|
||||
private static let utimeOmit = Int(UTIME_OMIT)
|
||||
private static let utimeNow = Int(UTIME_NOW)
|
||||
#elseif canImport(Glibc) || canImport(Musl)
|
||||
#elseif canImport(Glibc) || canImport(Musl) || canImport(Android)
|
||||
private static let utimeOmit = Int(CNIOLinux_UTIME_OMIT)
|
||||
private static let utimeNow = Int(CNIOLinux_UTIME_NOW)
|
||||
#endif
|
||||
@@ -218,7 +221,7 @@ private struct Stat: Hashable {
|
||||
hasher.combine(FileInfo.Timespec(stat.st_birthtimespec))
|
||||
hasher.combine(stat.st_flags)
|
||||
hasher.combine(stat.st_gen)
|
||||
#elseif canImport(Glibc) || canImport(Musl)
|
||||
#elseif canImport(Glibc) || canImport(Musl) || canImport(Android)
|
||||
hasher.combine(FileInfo.Timespec(stat.st_atim))
|
||||
hasher.combine(FileInfo.Timespec(stat.st_mtim))
|
||||
hasher.combine(FileInfo.Timespec(stat.st_ctim))
|
||||
@@ -259,7 +262,7 @@ private struct Stat: Hashable {
|
||||
== FileInfo.Timespec(rStat.st_birthtimespec)
|
||||
isEqual = isEqual && lStat.st_flags == rStat.st_flags
|
||||
isEqual = isEqual && lStat.st_gen == rStat.st_gen
|
||||
#elseif canImport(Glibc) || canImport(Musl)
|
||||
#elseif canImport(Glibc) || canImport(Musl) || canImport(Android)
|
||||
isEqual = isEqual && FileInfo.Timespec(lStat.st_atim) == FileInfo.Timespec(rStat.st_atim)
|
||||
isEqual = isEqual && FileInfo.Timespec(lStat.st_mtim) == FileInfo.Timespec(rStat.st_mtim)
|
||||
isEqual = isEqual && FileInfo.Timespec(lStat.st_ctim) == FileInfo.Timespec(rStat.st_ctim)
|
||||
|
||||
@@ -25,6 +25,8 @@ import Darwin
|
||||
import Glibc
|
||||
#elseif canImport(Musl)
|
||||
import Musl
|
||||
#elseif canImport(Bionic)
|
||||
import Bionic
|
||||
#endif
|
||||
|
||||
/// A file system which interacts with the local system. The file system uses a thread pool to
|
||||
@@ -1086,7 +1088,7 @@ extension FileSystem {
|
||||
location: .here()
|
||||
)
|
||||
}
|
||||
#elseif canImport(Glibc) || canImport(Musl)
|
||||
#elseif canImport(Glibc) || canImport(Musl) || canImport(Bionic)
|
||||
var offset = 0
|
||||
|
||||
while offset < sourceInfo.size {
|
||||
|
||||
@@ -21,6 +21,8 @@ import Darwin
|
||||
import Glibc
|
||||
#elseif canImport(Musl)
|
||||
import Musl
|
||||
#elseif canImport(Android)
|
||||
import Android
|
||||
#endif
|
||||
|
||||
/// The type of a file system object.
|
||||
|
||||
@@ -24,6 +24,9 @@ import CNIOLinux
|
||||
#elseif canImport(Musl)
|
||||
import Musl
|
||||
import CNIOLinux
|
||||
#elseif canImport(Android)
|
||||
import Android
|
||||
import CNIOLinux
|
||||
#endif
|
||||
|
||||
/// Aliases for platform-dependent types used for system calls.
|
||||
@@ -34,6 +37,8 @@ extension CInterop {
|
||||
public typealias Stat = Glibc.stat
|
||||
#elseif canImport(Musl)
|
||||
public typealias Stat = Musl.stat
|
||||
#elseif canImport(Android)
|
||||
public typealias Stat = Android.stat
|
||||
#endif
|
||||
|
||||
#if canImport(Darwin)
|
||||
@@ -45,11 +50,14 @@ extension CInterop {
|
||||
#elseif canImport(Musl)
|
||||
@_spi(Testing)
|
||||
public static let maxPathLength = Musl.PATH_MAX
|
||||
#elseif canImport(Android)
|
||||
@_spi(Testing)
|
||||
public static let maxPathLength = Android.PATH_MAX
|
||||
#endif
|
||||
|
||||
#if canImport(Darwin)
|
||||
typealias DirPointer = UnsafeMutablePointer<Darwin.DIR>
|
||||
#elseif canImport(Glibc) || canImport(Musl)
|
||||
#elseif canImport(Glibc) || canImport(Musl) || canImport(Android)
|
||||
typealias DirPointer = OpaquePointer
|
||||
#endif
|
||||
|
||||
@@ -59,12 +67,14 @@ extension CInterop {
|
||||
typealias DirEnt = Glibc.dirent
|
||||
#elseif canImport(Musl)
|
||||
typealias DirEnt = Musl.dirent
|
||||
#elseif canImport(Android)
|
||||
typealias DirEnt = Android.dirent
|
||||
#endif
|
||||
|
||||
#if canImport(Darwin)
|
||||
typealias FTS = CNIODarwin.FTS
|
||||
typealias FTSEnt = CNIODarwin.FTSENT
|
||||
#elseif canImport(Glibc) || canImport(Musl)
|
||||
#elseif canImport(Glibc) || canImport(Musl) || canImport(Android)
|
||||
typealias FTS = CNIOLinux.FTS
|
||||
typealias FTSEnt = CNIOLinux.FTSENT
|
||||
#endif
|
||||
|
||||
@@ -21,6 +21,8 @@ import Darwin
|
||||
import Glibc
|
||||
#elseif canImport(Musl)
|
||||
import Musl
|
||||
#elseif canImport(Android)
|
||||
import Android
|
||||
#endif
|
||||
|
||||
extension Errno {
|
||||
@@ -33,6 +35,8 @@ extension Errno {
|
||||
return Errno(rawValue: Glibc.errno)
|
||||
#elseif canImport(Musl)
|
||||
return Errno(rawValue: Musl.errno)
|
||||
#elseif canImport(Android)
|
||||
return Errno(rawValue: Android.errno)
|
||||
#endif
|
||||
}
|
||||
set {
|
||||
@@ -42,6 +46,8 @@ extension Errno {
|
||||
Glibc.errno = newValue.rawValue
|
||||
#elseif canImport(Musl)
|
||||
Musl.errno = newValue.rawValue
|
||||
#elseif canImport(Android)
|
||||
Android.errno = newValue.rawValue
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -53,6 +59,8 @@ extension Errno {
|
||||
Glibc.errno = 0
|
||||
#elseif canImport(Musl)
|
||||
Musl.errno = 0
|
||||
#elseif canImport(Android)
|
||||
Android.errno = 0
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,9 @@ import CNIOLinux
|
||||
#elseif canImport(Musl)
|
||||
import Musl
|
||||
import CNIOLinux
|
||||
#elseif canImport(Bionic)
|
||||
import Bionic
|
||||
import CNIOLinux
|
||||
#endif
|
||||
|
||||
extension FileDescriptor {
|
||||
@@ -309,7 +312,7 @@ extension FileDescriptor {
|
||||
}
|
||||
}
|
||||
|
||||
#if canImport(Glibc) || canImport(Musl)
|
||||
#if canImport(Glibc) || canImport(Musl) || canImport(Bionic)
|
||||
extension FileDescriptor.OpenOptions {
|
||||
static var temporaryFile: Self {
|
||||
Self(rawValue: CNIOLinux_O_TMPFILE)
|
||||
|
||||
@@ -28,6 +28,9 @@ import CNIOLinux
|
||||
#elseif canImport(Musl)
|
||||
import Musl
|
||||
import CNIOLinux
|
||||
#elseif canImport(Android)
|
||||
import Android
|
||||
import CNIOLinux
|
||||
#endif
|
||||
|
||||
// Syscall mocking support.
|
||||
@@ -284,6 +287,11 @@ internal var system_errno: CInt {
|
||||
get { Musl.errno }
|
||||
set { Musl.errno = newValue }
|
||||
}
|
||||
#elseif canImport(Android)
|
||||
internal var system_errno: CInt {
|
||||
get { Android.errno }
|
||||
set { Android.errno = newValue }
|
||||
}
|
||||
#endif
|
||||
|
||||
// MARK: C stdlib decls
|
||||
|
||||
@@ -24,6 +24,9 @@ import CNIOLinux
|
||||
#elseif canImport(Musl)
|
||||
import Musl
|
||||
import CNIOLinux
|
||||
#elseif canImport(Bionic)
|
||||
import Bionic
|
||||
import CNIOLinux
|
||||
#endif
|
||||
|
||||
@_spi(Testing)
|
||||
@@ -106,7 +109,7 @@ public enum Syscall {
|
||||
}
|
||||
#endif
|
||||
|
||||
#if canImport(Glibc) || canImport(Musl)
|
||||
#if canImport(Glibc) || canImport(Musl) || canImport(Bionic)
|
||||
@_spi(Testing)
|
||||
public static func rename(
|
||||
from old: FilePath,
|
||||
@@ -148,7 +151,7 @@ public enum Syscall {
|
||||
}
|
||||
#endif
|
||||
|
||||
#if canImport(Glibc) || canImport(Musl)
|
||||
#if canImport(Glibc) || canImport(Musl) || canImport(Bionic)
|
||||
@_spi(Testing)
|
||||
public struct LinkAtFlags: OptionSet {
|
||||
@_spi(Testing)
|
||||
@@ -253,7 +256,7 @@ public enum Syscall {
|
||||
}
|
||||
}
|
||||
|
||||
#if canImport(Glibc) || canImport(Musl)
|
||||
#if canImport(Glibc) || canImport(Musl) || canImport(Bionic)
|
||||
@_spi(Testing)
|
||||
public static func sendfile(
|
||||
to output: FileDescriptor,
|
||||
|
||||
@@ -24,6 +24,9 @@ import CNIOLinux
|
||||
#elseif canImport(Musl)
|
||||
import Musl
|
||||
import CNIOLinux
|
||||
#elseif canImport(Android)
|
||||
import Android
|
||||
import CNIOLinux
|
||||
#endif
|
||||
|
||||
// MARK: - system
|
||||
@@ -175,7 +178,7 @@ internal func system_flistxattr(
|
||||
#if canImport(Darwin)
|
||||
// The final parameter is 'options'; there is no equivalent on Linux.
|
||||
return flistxattr(fd, namebuf, size, 0)
|
||||
#elseif canImport(Glibc) || canImport(Musl)
|
||||
#elseif canImport(Glibc) || canImport(Musl) || canImport(Android)
|
||||
return flistxattr(fd, namebuf, size)
|
||||
#endif
|
||||
}
|
||||
@@ -197,7 +200,7 @@ internal func system_fgetxattr(
|
||||
// Penultimate parameter is position which is reserved and should be zero.
|
||||
// The final parameter is 'options'; there is no equivalent on Linux.
|
||||
return fgetxattr(fd, name, value, size, 0, 0)
|
||||
#elseif canImport(Glibc) || canImport(Musl)
|
||||
#elseif canImport(Glibc) || canImport(Musl) || canImport(Android)
|
||||
return fgetxattr(fd, name, value, size)
|
||||
#endif
|
||||
}
|
||||
@@ -219,7 +222,7 @@ internal func system_fsetxattr(
|
||||
#if canImport(Darwin)
|
||||
// Penultimate parameter is position which is reserved and should be zero.
|
||||
return fsetxattr(fd, name, value, size, 0, 0)
|
||||
#elseif canImport(Glibc) || canImport(Musl)
|
||||
#elseif canImport(Glibc) || canImport(Musl) || canImport(Android)
|
||||
return fsetxattr(fd, name, value, size, 0)
|
||||
#endif
|
||||
}
|
||||
@@ -238,7 +241,7 @@ internal func system_fremovexattr(
|
||||
#if canImport(Darwin)
|
||||
// The final parameter is 'options'; there is no equivalent on Linux.
|
||||
return fremovexattr(fd, name, 0)
|
||||
#elseif canImport(Glibc) || canImport(Musl)
|
||||
#elseif canImport(Glibc) || canImport(Musl) || canImport(Android)
|
||||
return fremovexattr(fd, name)
|
||||
#endif
|
||||
}
|
||||
@@ -271,7 +274,7 @@ internal func system_renamex_np(
|
||||
}
|
||||
#endif
|
||||
|
||||
#if canImport(Glibc) || canImport(Musl)
|
||||
#if canImport(Glibc) || canImport(Musl) || canImport(Android)
|
||||
internal func system_renameat2(
|
||||
_ oldFD: FileDescriptor.RawValue,
|
||||
_ old: UnsafePointer<CInterop.PlatformChar>,
|
||||
@@ -289,7 +292,7 @@ internal func system_renameat2(
|
||||
#endif
|
||||
|
||||
/// link(2): Creates a new link for a file.
|
||||
#if canImport(Glibc) || canImport(Musl)
|
||||
#if canImport(Glibc) || canImport(Musl) || canImport(Android)
|
||||
internal func system_linkat(
|
||||
_ oldFD: FileDescriptor.RawValue,
|
||||
_ old: UnsafePointer<CInterop.PlatformChar>,
|
||||
@@ -331,7 +334,7 @@ internal func system_unlink(
|
||||
return unlink(path)
|
||||
}
|
||||
|
||||
#if canImport(Glibc) || canImport(Musl)
|
||||
#if canImport(Glibc) || canImport(Musl) || canImport(Android)
|
||||
/// sendfile(2): Transfer data between descriptors
|
||||
internal func system_sendfile(
|
||||
_ outFD: CInt,
|
||||
|
||||
@@ -26,6 +26,8 @@ import CNIOLinux
|
||||
#elseif canImport(Musl)
|
||||
import Musl
|
||||
import CNIOLinux
|
||||
#elseif canImport(Bionic)
|
||||
import Bionic
|
||||
#endif
|
||||
|
||||
/// An implementation of ``FileHandleProtocol`` which is backed by system calls and a file
|
||||
@@ -55,7 +57,7 @@ public final class SystemFileHandle {
|
||||
enum Mode {
|
||||
/// Rename the created file to become the desired file.
|
||||
case rename
|
||||
#if canImport(Glibc) || canImport(Musl)
|
||||
#if canImport(Glibc) || canImport(Musl) || canImport(Bionic)
|
||||
/// Link the unnamed file to the desired file using 'linkat(2)'.
|
||||
case link
|
||||
#endif
|
||||
@@ -289,7 +291,7 @@ extension SystemFileHandle: FileHandleProtocol {
|
||||
}
|
||||
|
||||
switch materialization.mode {
|
||||
#if canImport(Glibc) || canImport(Musl)
|
||||
#if canImport(Glibc) || canImport(Musl) || canImport(Bionic)
|
||||
case .link:
|
||||
let result = self.sendableView._materializeLink(
|
||||
descriptor: descriptor,
|
||||
@@ -695,7 +697,7 @@ extension SystemFileHandle.SendableView {
|
||||
}
|
||||
}
|
||||
|
||||
#if canImport(Glibc) || canImport(Musl)
|
||||
#if canImport(Glibc) || canImport(Musl) || canImport(Bionic)
|
||||
fileprivate func _materializeLink(
|
||||
descriptor: FileDescriptor,
|
||||
from createdPath: FilePath,
|
||||
@@ -806,7 +808,7 @@ extension SystemFileHandle.SendableView {
|
||||
|
||||
let result: Result<Void, FileSystemError>
|
||||
switch materialization.mode {
|
||||
#if canImport(Glibc) || canImport(Musl)
|
||||
#if canImport(Glibc) || canImport(Musl) || canImport(Bionic)
|
||||
case .link:
|
||||
if materialize {
|
||||
result = self._materializeLink(
|
||||
@@ -831,7 +833,7 @@ extension SystemFileHandle.SendableView {
|
||||
to: desiredPath,
|
||||
options: materialization.exclusive ? [.exclusive] : []
|
||||
)
|
||||
#elseif canImport(Glibc) || canImport(Musl)
|
||||
#elseif canImport(Glibc) || canImport(Musl) || canImport(Bionic)
|
||||
// The created and desired paths are absolute, so the relative descriptors are
|
||||
// ignored. However, they must still be provided to 'rename' in order to pass
|
||||
// flags.
|
||||
@@ -860,7 +862,7 @@ extension SystemFileHandle.SendableView {
|
||||
// If 'renameat2' failed on Linux with EINVAL then in all likelihood the
|
||||
// 'RENAME_NOREPLACE' option isn't supported. As we're doing an exclusive
|
||||
// create, check the desired path doesn't exist then do a regular rename.
|
||||
#if canImport(Glibc) || canImport(Musl)
|
||||
#if canImport(Glibc) || canImport(Musl) || canImport(Bionic)
|
||||
switch Syscall.stat(path: desiredPath) {
|
||||
case .failure(.noSuchFileOrDirectory):
|
||||
// File doesn't exist, do a 'regular' rename.
|
||||
@@ -1450,7 +1452,7 @@ extension SystemFileHandle {
|
||||
}
|
||||
|
||||
func makePath() -> FilePath {
|
||||
#if canImport(Glibc) || canImport(Musl)
|
||||
#if canImport(Glibc) || canImport(Musl) || canImport(Bionic)
|
||||
if useTemporaryFileIfPossible {
|
||||
return currentWorkingDirectory.appending(path.components.dropLast())
|
||||
}
|
||||
@@ -1463,7 +1465,7 @@ extension SystemFileHandle {
|
||||
desiredPath = currentWorkingDirectory.appending(path.components)
|
||||
} else {
|
||||
func makePath() -> FilePath {
|
||||
#if canImport(Glibc) || canImport(Musl)
|
||||
#if canImport(Glibc) || canImport(Musl) || canImport(Bionic)
|
||||
if useTemporaryFileIfPossible {
|
||||
return path.removingLastComponent()
|
||||
}
|
||||
@@ -1479,7 +1481,7 @@ extension SystemFileHandle {
|
||||
let materializationMode: Materialization.Mode
|
||||
let options: FileDescriptor.OpenOptions
|
||||
|
||||
#if canImport(Glibc) || canImport(Musl)
|
||||
#if canImport(Glibc) || canImport(Musl) || canImport(Bionic)
|
||||
if useTemporaryFileIfPossible {
|
||||
options = [.temporaryFile]
|
||||
materializationMode = .link
|
||||
@@ -1516,7 +1518,7 @@ extension SystemFileHandle {
|
||||
|
||||
return .success(handle)
|
||||
} catch {
|
||||
#if canImport(Glibc) || canImport(Musl)
|
||||
#if canImport(Glibc) || canImport(Musl) || canImport(Bionic)
|
||||
// 'O_TMPFILE' isn't supported for the current file system, try again but using
|
||||
// rename instead.
|
||||
if useTemporaryFileIfPossible, let errno = error as? Errno, errno == .notSupported {
|
||||
|
||||
Reference in new issue
Block a user