Skip to content

Commit

Permalink
Sort platforms in conditional compilation directives
Browse files Browse the repository at this point in the history
  • Loading branch information
weichsel committed Aug 16, 2023
1 parent 2b183df commit 35c4759
Show file tree
Hide file tree
Showing 11 changed files with 22 additions and 22 deletions.
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ let targets: [Target] = [
let package = Package(
name: "ZIPFoundation",
platforms: [
.macOS(.v10_11), .iOS(.v9), .tvOS(.v9), .watchOS(.v2)
.macOS(.v10_11), .iOS(.v9), .tvOS(.v9), .watchOS(.v2), .visionOS(.v1)
],
products: [
.library(name: "ZIPFoundation", targets: ["ZIPFoundation"])
Expand Down
4 changes: 2 additions & 2 deletions Sources/ZIPFoundation/Archive+MemoryFile.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class MemoryFile {
let cookie = Unmanaged.passRetained(self)
let writable = mode.count > 0 && (mode.first! != "r" || mode.last! == "+")
let append = mode.count > 0 && mode.first! == "a"
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) || os(visionOS) || os(Android)
#if os(macOS) || os(iOS) || os(tvOS) || os(visionOS) || os(watchOS) || os(Android)
let result = writable
? funopen(cookie.toOpaque(), readStub, writeStub, seekStub, closeStub)
: funopen(cookie.toOpaque(), readStub, nil, seekStub, closeStub)
Expand Down Expand Up @@ -99,7 +99,7 @@ private func closeStub(_ cookie: UnsafeMutableRawPointer?) -> Int32 {
return 0
}

#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) || os(visionOS) || os(Android)
#if os(macOS) || os(iOS) || os(tvOS) || os(visionOS) || os(watchOS) || os(Android)
private func readStub(_ cookie: UnsafeMutableRawPointer?,
_ bytePtr: UnsafeMutablePointer<Int8>?,
_ count: Int32) -> Int32 {
Expand Down
2 changes: 1 addition & 1 deletion Sources/ZIPFoundation/Archive+Writing.swift
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ extension Archive {
#endif
} else {
let fileManager = FileManager()
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) || os(visionOS)
#if os(macOS) || os(iOS) || os(tvOS) || os(visionOS) || os(watchOS)
do {
_ = try fileManager.replaceItemAt(self.url, withItemAt: archive.url)
} catch {
Expand Down
8 changes: 4 additions & 4 deletions Sources/ZIPFoundation/Data+Compression.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ extension Data {
/// - consumer: A closure that processes the result of the compress operation.
/// - Returns: The checksum of the processed content.
public static func compress(size: Int64, bufferSize: Int, provider: Provider, consumer: Consumer) throws -> CRC32 {
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) || os(visionOS)
#if os(macOS) || os(iOS) || os(tvOS) || os(visionOS) || os(watchOS)
return try self.process(operation: COMPRESSION_STREAM_ENCODE, size: size, bufferSize: bufferSize,
provider: provider, consumer: consumer)
#else
Expand All @@ -84,7 +84,7 @@ extension Data {
/// - Returns: The checksum of the processed content.
public static func decompress(size: Int64, bufferSize: Int, skipCRC32: Bool,
provider: Provider, consumer: Consumer) throws -> CRC32 {
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) || os(visionOS)
#if os(macOS) || os(iOS) || os(tvOS) || os(visionOS) || os(watchOS)
return try self.process(operation: COMPRESSION_STREAM_DECODE, size: size, bufferSize: bufferSize,
skipCRC32: skipCRC32, provider: provider, consumer: consumer)
#else
Expand All @@ -95,7 +95,7 @@ extension Data {

// MARK: - Apple Platforms

#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) || os(visionOS)
#if os(macOS) || os(iOS) || os(tvOS) || os(visionOS) || os(watchOS)
import Compression

extension Data {
Expand Down Expand Up @@ -351,7 +351,7 @@ extension Data {
}
}

#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) || os(visionOS)
#if os(macOS) || os(iOS) || os(tvOS) || os(visionOS) || os(watchOS)
#else
mutating func withUnsafeMutableBytes<T>(_ body: (UnsafeMutableRawBufferPointer) throws -> T) rethrows -> T {
let count = self.count
Expand Down
4 changes: 2 additions & 2 deletions Sources/ZIPFoundation/Date+ZIP.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ extension Date {
private extension Date {

enum Constants {
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) || os(visionOS)
#if os(macOS) || os(iOS) || os(tvOS) || os(visionOS) || os(watchOS)
static let absoluteTimeIntervalSince1970 = kCFAbsoluteTimeIntervalSince1970
#else
static let absoluteTimeIntervalSince1970: Double = 978307200.0
Expand All @@ -77,7 +77,7 @@ private extension Date {
extension stat {

var lastAccessDate: Date {
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) || os(visionOS)
#if os(macOS) || os(iOS) || os(tvOS) || os(visionOS) || os(watchOS)
return Date(timespec: st_atimespec)
#else
return Date(timespec: st_atim)
Expand Down
8 changes: 4 additions & 4 deletions Sources/ZIPFoundation/FileManager+ZIP.swift
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ extension FileManager {
return
}

#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) || os(visionOS)
#if os(macOS) || os(iOS) || os(tvOS) || os(visionOS) || os(watchOS)
guard let posixPermissions = attributes[.posixPermissions] as? NSNumber else {
throw Entry.EntryError.missingPermissionsAttributeError
}
Expand Down Expand Up @@ -224,7 +224,7 @@ extension FileManager {
let defaultPermissions = entryType == .directory ? defaultDirectoryPermissions : defaultFilePermissions
var attributes = [.posixPermissions: defaultPermissions] as [FileAttributeKey: Any]
// Certain keys are not yet supported in swift-corelibs
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) || os(visionOS)
#if os(macOS) || os(iOS) || os(tvOS) || os(visionOS) || os(watchOS)
attributes[.modificationDate] = Date(dateTime: (fileDate, fileTime))
#endif
let versionMadeBy = centralDirectoryStructure.versionMadeBy
Expand Down Expand Up @@ -280,7 +280,7 @@ extension FileManager {
let entryFileSystemRepresentation = fileManager.fileSystemRepresentation(withPath: url.path)
var fileStat = stat()
lstat(entryFileSystemRepresentation, &fileStat)
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) || os(visionOS)
#if os(macOS) || os(iOS) || os(tvOS) || os(visionOS) || os(watchOS)
let modTimeSpec = fileStat.st_mtimespec
#else
let modTimeSpec = fileStat.st_mtim
Expand Down Expand Up @@ -331,7 +331,7 @@ extension CocoaError {
#if swift(>=4.2)
#else

#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) || os(visionOS)
#if os(macOS) || os(iOS) || os(tvOS) || os(visionOS) || os(watchOS)
#else

// The swift-corelibs-foundation version of NSError.swift was missing a convenience method to create
Expand Down
2 changes: 1 addition & 1 deletion Sources/ZIPFoundation/URL+ZIP.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import Foundation
extension URL {

static func temporaryReplacementDirectoryURL(for archive: Archive) -> URL {
#if swift(>=5.0) || os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
#if swift(>=5.0) || os(macOS) || os(iOS) || os(tvOS) || os(visionOS) || os(watchOS)
if archive.url.isFileURL,
let tempDir = try? FileManager().url(for: .itemReplacementDirectory, in: .userDomainMask,
appropriateFor: archive.url, create: true) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ extension ZIPFoundationTests {
} catch {
XCTFail("Unexpected error while trying to transfer symlink attributes")
}
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) || os(visionOS)
#if os(macOS) || os(iOS) || os(tvOS) || os(visionOS) || os(watchOS)
do {
var resourceValues = URLResourceValues()
resourceValues.isUserImmutable = true
Expand Down
4 changes: 2 additions & 2 deletions Tests/ZIPFoundationTests/ZIPFoundationMemoryTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ extension ZIPFoundationTests {
var didCatchExpectedError = false
// Trigger the code path that is taken if funopen() fails
// We can only do this on Apple platforms
#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS)
#if os(macOS) || os(iOS) || os(tvOS) || os(visionOS) || os(watchOS)
self.runWithoutMemory {
do {
try archive.remove(entryToRemove)
Expand Down Expand Up @@ -145,7 +145,7 @@ extension ZIPFoundationTests {
XCTAssertNil(invalidArchive)
// Trigger the code path that is taken if funopen() fails
// We can only do this on Apple platforms
#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS)
#if os(macOS) || os(iOS) || os(tvOS) || os(visionOS) || os(watchOS)
var unallocatableArchive: Archive?
self.runWithoutMemory {
unallocatableArchive = Archive(data: data, accessMode: .read)
Expand Down
2 changes: 1 addition & 1 deletion Tests/ZIPFoundationTests/ZIPFoundationProgressTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import XCTest
@testable import ZIPFoundation

#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) || os(visionOS)
#if os(macOS) || os(iOS) || os(tvOS) || os(visionOS) || os(watchOS)
extension ZIPFoundationTests {

func testArchiveAddUncompressedEntryProgress() {
Expand Down
6 changes: 3 additions & 3 deletions Tests/ZIPFoundationTests/ZIPFoundationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ class ZIPFoundationTests: XCTestCase {
}

func runWithoutMemory(handler: () -> Void) {
#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS)
#if os(macOS) || os(iOS) || os(tvOS) || os(visionOS) || os(watchOS)
let systemAllocator = CFAllocatorGetDefault().takeUnretainedValue()
CFAllocatorSetDefault(kCFAllocatorNull)
defer { CFAllocatorSetDefault(systemAllocator) }
Expand All @@ -179,7 +179,7 @@ class ZIPFoundationTests: XCTestCase {
extension ZIPFoundationTests {
// From https://oleb.net/blog/2017/03/keeping-xctest-in-sync/
func testLinuxTestSuiteIncludesAllTests() {
#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS)
#if os(macOS) || os(iOS) || os(tvOS) || os(visionOS) || os(watchOS)
let thisClass = type(of: self)
let linuxCount = thisClass.allTests.count
let darwinCount = Int(thisClass.defaultTestSuite.testCaseCount)
Expand Down Expand Up @@ -296,7 +296,7 @@ extension ZIPFoundationTests {
}

static var darwinOnlyTests: [(String, (ZIPFoundationTests) -> () throws -> Void)] {
#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS)
#if os(macOS) || os(iOS) || os(tvOS) || os(visionOS) || os(watchOS)
return [
("testFileModificationDate", testFileModificationDate),
("testFileModificationDateHelperMethods", testFileModificationDateHelperMethods),
Expand Down

0 comments on commit 35c4759

Please sign in to comment.