Skip to content

Commit 2122276

Browse files
committed
Fix debug logging for Linux.
1 parent e3db983 commit 2122276

File tree

4 files changed

+37
-24
lines changed

4 files changed

+37
-24
lines changed
Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,39 @@
1-
#if DEBUG && canImport(os)
2-
import os
1+
#if DEBUG
2+
#if canImport(os)
3+
import os
34

4-
// NB: Xcode runtime warnings offer a much better experience than traditional assertions and
5-
// breakpoints, but Apple provides no means of creating custom runtime warnings ourselves.
6-
// To work around this, we hook into SwiftUI's runtime issue delivery mechanism, instead.
7-
//
8-
// Feedback filed: https://gist.github.com/stephencelis/a8d06383ed6ccde3e5ef5d1b3ad52bbc
9-
let rw = (
10-
dso: { () -> UnsafeMutableRawPointer in
11-
let count = _dyld_image_count()
12-
for i in 0..<count {
13-
if let name = _dyld_get_image_name(i) {
14-
let swiftString = String(cString: name)
15-
if swiftString.hasSuffix("/SwiftUI") {
16-
if let header = _dyld_get_image_header(i) {
17-
return UnsafeMutableRawPointer(mutating: UnsafeRawPointer(header))
5+
// NB: Xcode runtime warnings offer a much better experience than traditional assertions and
6+
// breakpoints, but Apple provides no means of creating custom runtime warnings ourselves.
7+
// To work around this, we hook into SwiftUI's runtime issue delivery mechanism, instead.
8+
//
9+
// Feedback filed: https://gist.github.com/stephencelis/a8d06383ed6ccde3e5ef5d1b3ad52bbc
10+
let rw = (
11+
dso: { () -> UnsafeMutableRawPointer in
12+
let count = _dyld_image_count()
13+
for i in 0..<count {
14+
if let name = _dyld_get_image_name(i) {
15+
let swiftString = String(cString: name)
16+
if swiftString.hasSuffix("/SwiftUI") {
17+
if let header = _dyld_get_image_header(i) {
18+
return UnsafeMutableRawPointer(mutating: UnsafeRawPointer(header))
19+
}
1820
}
1921
}
2022
}
21-
}
22-
return UnsafeMutableRawPointer(mutating: #dsohandle)
23-
}(),
24-
log: OSLog(subsystem: "com.apple.runtime-issues", category: "ComposableArchitecture")
25-
)
23+
return UnsafeMutableRawPointer(mutating: #dsohandle)
24+
}(),
25+
log: OSLog(subsystem: "com.apple.runtime-issues", category: "ComposableArchitecture")
26+
)
27+
28+
#else
29+
let rw = (dso: (), log: ())
30+
31+
enum OSLogType {
32+
case fault
33+
}
34+
35+
func os_log(_ type: OSLogType, dso: Void, log: Void, _ message: String, _ args: CVarArg...) {
36+
print(String(format: message, arguments: args))
37+
}
38+
#endif
2639
#endif

Sources/ComposableArchitecture/Reducer.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import CasePaths
22
import Foundation
33

4-
#if DEBUG
4+
#if DEBUG && canImport(os)
55
import os
66
#endif
77

Sources/ComposableArchitecture/Store.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import Foundation
22
import ReactiveSwift
33

4-
#if DEBUG
4+
#if DEBUG && canImport(os)
55
import os
66
#endif
77

Sources/ComposableArchitecture/SwiftUI/SwitchStore.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#if canImport(SwiftUI)
22
import SwiftUI
33

4-
#if DEBUG
4+
#if DEBUG && canImport(os)
55
import os
66
#endif
77

0 commit comments

Comments
 (0)