Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Sources/SwiftDocC/Benchmark/Benchmark.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ public class Benchmark: Encodable {
public let platform = "iOS"
#elseif os(Linux)
public let platform = "Linux"
#elseif os(Android)
public let platform = "Android"
#else
public let platform = "unsupported"
#endif
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftDocC/Benchmark/Metrics/PeakMemory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ extension Benchmark {
return Double(vmInfo.ledger_phys_footprint_peak)
}

#elseif os(Linux)
#elseif os(Linux) || os(Android)
private static func peakMemory() -> Double? {
// On Linux we cannot use the Kernel framework, so we tap into the
// kernel proc file system to read the vm peak reported in the process status.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ private class LongRunningService: ExternalLinkResolving {
/// This private class is only used by the ``OutOfProcessReferenceResolver`` and shouldn't be used for general communication with other processes.
private class LongRunningProcess: ExternalLinkResolving {

#if os(macOS) || os(Linux)
#if os(macOS) || os(Linux) || os(Android)
private let process: Process

init(location: URL, errorOutputHandler: @escaping (String) -> Void) throws {
Expand Down
4 changes: 2 additions & 2 deletions Sources/SwiftDocC/Model/Rendering/RenderContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ public struct RenderContext {
)
}

#if os(macOS) || os(iOS)
// Concurrently render content on macOS & iOS
#if os(macOS) || os(iOS) || os(Android)
// Concurrently render content on macOS/iOS & Android
let results: [(reference: ResolvedTopicReference, content: RenderReferenceStore.TopicContent)] = references.concurrentPerform { reference, results in
results.append((reference, renderContentFor(reference)))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
See https://swift.org/CONTRIBUTORS.txt for Swift project authors
*/

#if os(Linux)
#if os(Linux) || os(Android)
/// A shim for Linux that runs the given block of code.
///
/// The existence of this shim allows you the use of auto-release pools to optimize memory footprint on Darwin platforms while maintaining
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftDocC/Utility/LMDB/LMDB.swift
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ extension String: LMDBData {
}
}

#if !os(Linux)
#if !os(Linux) && !os(Android)
// This is required for macOS and Swift 4.2, for Linux the default implementation works as expected.
extension Array: LMDBData where Element: FixedWidthInteger {

Expand Down
8 changes: 4 additions & 4 deletions Sources/SwiftDocC/Utility/Synchronization.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class Synchronized<Value> {
/// A lock type appropriate for the current platform.
/// > Note: To avoid access race reports we manage the memory manually.
var lock: UnsafeMutablePointer<os_unfair_lock>
#elseif os(Linux)
#elseif os(Linux) || os(Android)
/// A lock type appropriate for the current platform.
var lock: UnsafeMutablePointer<pthread_mutex_t>
#else
Expand All @@ -44,7 +44,7 @@ public class Synchronized<Value> {
#if os(macOS) || os(iOS)
lock = UnsafeMutablePointer<os_unfair_lock>.allocate(capacity: 1)
lock.initialize(to: os_unfair_lock())
#elseif os(Linux)
#elseif os(Linux) || os(Android)
lock = UnsafeMutablePointer<pthread_mutex_t>.allocate(capacity: 1)
lock.initialize(to: pthread_mutex_t())
pthread_mutex_init(lock, nil)
Expand All @@ -66,7 +66,7 @@ public class Synchronized<Value> {
#if os(macOS) || os(iOS)
os_unfair_lock_lock(lock)
defer { os_unfair_lock_unlock(lock) }
#elseif os(Linux)
#elseif os(Linux) || os(Android)
pthread_mutex_lock(lock)
defer { pthread_mutex_unlock(lock) }
#else
Expand Down Expand Up @@ -99,7 +99,7 @@ public extension Lock {
#if os(macOS) || os(iOS)
os_unfair_lock_lock(lock)
defer { os_unfair_lock_unlock(lock) }
#elseif os(Linux)
#elseif os(Linux) || os(Android)
pthread_mutex_lock(lock)
defer { pthread_mutex_unlock(lock) }
#else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ public final class PreviewAction: Action, RecreatingContext {
trapSignals()

// Monitor the source folder if possible.
#if !os(Linux)
#if !os(Linux) && !os(Android)
try watch()
#endif
// This will wait until the server is manually killed.
Expand Down Expand Up @@ -225,7 +225,7 @@ public final class PreviewAction: Action, RecreatingContext {

// Monitoring a source folder: Asynchronous output reading and file system events are supported only on macOS.

#if !os(Linux)
#if !os(Linux) && !os(Android)
/// If needed, a retained directory monitor.
fileprivate var monitor: DirectoryMonitor! = nil

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import Foundation
import SwiftDocC

#if !os(Linux)
#if !os(Linux) && !os(Android)
import Darwin

/// A throttle object to filter events that come too fast.
Expand Down
2 changes: 2 additions & 0 deletions Sources/SwiftDocCUtilities/Utility/Signal.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public struct Signal {
#if os(Linux)
// This is where we get to use a triple underscore in a method name.
signalAction.__sigaction_handler = unsafeBitCast(callback, to: sigaction.__Unnamed_union___sigaction_handler.self)
#elseif os(Android)
signalAction.sa_handler = callback
#else
signalAction.__sigaction_u = unsafeBitCast(callback, to: __sigaction_u.self)
#endif
Expand Down
2 changes: 1 addition & 1 deletion Sources/docc/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
See https://swift.org/CONTRIBUTORS.txt for Swift project authors
*/

#if os(macOS) || os(Linux)
#if os(macOS) || os(Linux) || os(Android)
import SwiftDocCUtilities

Docc.main()
Expand Down
2 changes: 1 addition & 1 deletion Tests/SwiftDocCTests/Indexing/NavigatorIndexTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -947,7 +947,7 @@ Root
}

func testAvailabilityIndexCreation() throws {
#if !os(Linux)
#if !os(Linux) && !os(Android)
let availabilityIndex = AvailabilityIndex()

let macOS_10_14 = Platform(name: .macOS, version: Platform.Version(string: "10.14")!)
Expand Down
2 changes: 1 addition & 1 deletion Tests/SwiftDocCTests/Rendering/RoundTripCoding.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func assertJSONRepresentation<Value: Decodable & Equatable>(
var decoded: Value? = nil

let encoding: String.Encoding
#if os(Linux)
#if os(Linux) || os(Android)
// Work around a JSON decoding issue on Linux (SR-15035).
encoding = .utf8
#else
Expand Down
2 changes: 1 addition & 1 deletion Tests/SwiftDocCTests/Servers/FileServerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ class FileServerTests: XCTestCase {
(response, data) = fileServer.response(to: failingRequest)
XCTAssertNil(data)
// Initializing a URLResponse with `nil` as MIME type in Linux returns nil
#if os(Linux)
#if os(Linux) || os(Android)
XCTAssertNil(response.mimeType)
#else
// Doing the same in macOS or iOS returns the default MIME type
Expand Down
4 changes: 2 additions & 2 deletions Tests/SwiftDocCTests/Servers/TopicRefenceSchemeTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class TopicRefenceSchemeTests: XCTestCase {
forResource: "TestBundle", withExtension: "docc", subdirectory: "Test Bundles")!

func testTopicReferenceSchemeHandler() {
#if !os(Linux)
#if !os(Linux) && !os(Android)
let topicSchemeHandler = DocumentationSchemeHandler(withTemplateURL: templateURL)

let request = URLRequest(url: baseURL.appendingPathComponent("/images/figure1.jpg"))
Expand All @@ -50,7 +50,7 @@ class TopicRefenceSchemeTests: XCTestCase {
}

func testSetData() {
#if !os(Linux)
#if !os(Linux) && !os(Android)
let topicSchemeHandler = DocumentationSchemeHandler(withTemplateURL: templateURL)

let data = "hello!".data(using: .utf8)!
Expand Down
2 changes: 1 addition & 1 deletion Tests/SwiftDocCTests/Utility/LMDBTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ final class SwiftLMDBTests: XCTestCase {
}

func testArrayOfInt() throws {
#if !os(Linux)
#if !os(Linux) && !os(Android)
let database = try environment.openDatabase()

var array: [UInt32] = []
Expand Down
10 changes: 5 additions & 5 deletions Tests/SwiftDocCUtilitiesTests/DirectoryMonitorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import XCTest
@testable import SwiftDocCUtilities

#if !os(Linux)
#if !os(Linux) && !os(Android)
fileprivate extension NSNotification.Name {
static let testNodeUpdated = NSNotification.Name(rawValue: "testNodeUpdated")
static let testDirectoryReloaded = NSNotification.Name(rawValue: "testDirectoryReloaded")
Expand All @@ -24,7 +24,7 @@ func fileURLsAreEqual(_ url1: URL, _ url2: URL) -> Bool {
#endif

class DirectoryMonitorTests: XCTestCase {
#if !os(Linux)
#if !os(Linux) && !os(Android)
// - MARK: Directory watching test infra

/// Method that automates setting up a directory monitor, setting up the relevant expectations for a test,
Expand Down Expand Up @@ -118,7 +118,7 @@ class DirectoryMonitorTests: XCTestCase {
/// Tests a succession of file system changes and verifies that they produce
/// the expected monitor events.
func testMonitorUpdates() throws {
#if !os(Linux)
#if !os(Linux) && !os(Android)

// Create temp folder & sub-folder.
let tempFolderURL = Foundation.URL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent(UUID().uuidString)
Expand Down Expand Up @@ -171,7 +171,7 @@ class DirectoryMonitorTests: XCTestCase {
}

func testMonitorDoesNotTriggerUpdates() throws {
#if !os(Linux)
#if !os(Linux) && !os(Android)

// Create temp folder & sub-folder.
let tempFolderURL = Foundation.URL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent(UUID().uuidString)
Expand Down Expand Up @@ -208,7 +208,7 @@ class DirectoryMonitorTests: XCTestCase {

/// Tests a zero sum change aggregation triggers an event.
func testMonitorZeroSumSizeChangesUpdates() throws {
#if !os(Linux)
#if !os(Linux) && !os(Android)

// Create temp folder & sub-folder.
let tempFolderURL = Foundation.URL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent(UUID().uuidString)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class PreviewServerTests: XCTestCase {
])
try tempFolder.write(to: URL(fileURLWithPath: NSTemporaryDirectory().appending(UUID().uuidString)))

let socketURL = URL(fileURLWithPath: "/var/tmp").appendingPathComponent(UUID().uuidString).appendingPathExtension("sock")
let socketURL = URL(fileURLWithPath: FileManager.default.temporaryDirectory.path).appendingPathComponent(UUID().uuidString).appendingPathExtension("sock")
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No /var/tmp on Android.


// Run test server
var log = LogHandle.none
Expand Down Expand Up @@ -106,7 +106,7 @@ class PreviewServerTests: XCTestCase {
let tempFolder = try makeTempFolder()

// Socket URL
let socketURL = URL(fileURLWithPath: "/var/tmp").appendingPathComponent(UUID().uuidString).appendingPathExtension("sock")
let socketURL = URL(fileURLWithPath: FileManager.default.temporaryDirectory.path).appendingPathComponent(UUID().uuidString).appendingPathExtension("sock")

// Create the server
var log = LogHandle.none
Expand Down Expand Up @@ -153,7 +153,7 @@ class PreviewServerTests: XCTestCase {
let tempFolder = try makeTempFolder()

// Socket URL
let socketURL = URL(fileURLWithPath: "/var/tmp").appendingPathComponent(UUID().uuidString).appendingPathExtension("sock")
let socketURL = URL(fileURLWithPath: FileManager.default.temporaryDirectory.path).appendingPathComponent(UUID().uuidString).appendingPathExtension("sock")

// Create the server
var log = LogHandle.none
Expand Down
4 changes: 2 additions & 2 deletions Tests/SwiftDocCUtilitiesTests/SignalTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ import XCTest
@testable import SwiftDocCUtilities

class SignalTests: XCTestCase {
#if os(macOS) || os(Linux)
#if os(macOS) || os(Linux) || os(Android)
/// The path to the built products directory.
private var productDirectory: URL {
#if !os(Linux)
#if !os(Linux) && !os(Android)
guard let xcTestBundle = Bundle.allBundles.first(where: { bundle in
bundle.bundleURL.pathExtension == "xctest"
}) else {
Expand Down
2 changes: 1 addition & 1 deletion Tests/signal-test-app/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// Check Tests/SwiftDocCUtilitiesTests/SignalTests.swift for more details.
//

#if os(macOS) || os(Linux)
#if os(macOS) || os(Linux) || os(Android)

import Foundation
import SwiftDocCUtilities
Expand Down