Skip to content

Commit 43d4e20

Browse files
committed
Merge branch 'fix/frizlab/wasi_and_android' into develop
2 parents c6c2c3b + ec9639a commit 43d4e20

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

Sources/CLTLogger.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
#if canImport(Android)
2+
import Android
3+
#endif
14
import Foundation
25
#if canImport(WinSDK)
36
import WinSDK
@@ -217,11 +220,13 @@ public struct CLTLogger : LogHandler {
217220
* (When Package.swift is built we can check if the value of the __CFBundleIdentifier env var is "com.apple.dt.Xcode".)
218221
* The solution we’re currently using is to check whether the fd on which we write has a foreground process group as Xcode does not set one.
219222
* Note: If Xcode detection is changed here, it should also be changed in defaultConstantsByLogLevelForEmoji. */
223+
#if canImport(Darwin)
220224
if tcgetpgrp(fh.fileDescriptor) == -1 && errno == ENOTTY {
221225
/* We log using emojis in Xcode. */
222226
return .emoji
223227
}
224-
/* If the TERM env var is not set we assume colors are not supported and return the text logging style.
228+
#endif
229+
/* If the TERM env var is not set we assume colors are not supported and return the text logging style.
225230
* In theory we should use the curses database to check for colors (ncurses has the `has_colors` function for this). */
226231
return (ProcessInfo.processInfo.environment["TERM"] == nil ? .text : .color)
227232
}

Sources/OutputEnvironment.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ internal enum OutputEnvironment : String, CaseIterable {
4242
return OutputEnvironment(rawValue: envStr) ?? .unknown
4343
}
4444

45-
#if !os(Windows)
45+
#if canImport(Darwin)
4646
/* Let’s detect Xcode. */
4747
if isatty(fh.fileDescriptor) != 0 && tcgetpgrp(fh.fileDescriptor) == -1 && errno == ENOTTY {
4848
return .xcode

Tests/LinuxMain.swift

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
import Foundation
12
import XCTest
23

34
@testable import CLTLoggerTests
45

6+
7+
58
var tests: [XCTestCaseEntry] = [
69
testCase([
710
("testFromDoc", CLTLoggerTests.testFromDoc),
@@ -34,4 +37,25 @@ var tests: [XCTestCaseEntry] = [
3437
("testBackslashEscape", StringEscapingTests.testBackslashEscape),
3538
]),
3639
]
40+
#if !os(WASI)
3741
XCTMain(tests)
42+
43+
#else
44+
/* Compilation fails for Swift <5.5… */
45+
//await XCTMain(tests)
46+
47+
/* Let’s print a message to inform the tests on WASI are disabled. */
48+
import struct CLTLogger.SGR
49+
try FileHandle.standardError.write(contentsOf: Data("""
50+
\(SGR(.fgColorTo4BitBrightRed, .bold).rawValue)Tests are disabled on WASI\(SGR.reset.rawValue):
51+
\(SGR(.fgColorTo256PaletteValue(245)).rawValue)CLTLogger is compatible with Swift <5.4, so we have to add a LinuxMain file in which we call XCTMain.
52+
On WASI the XCTMain function is async, so we have to #if the XCTMain call, one with the await keyword, the other without.
53+
However, on Swift <5.5 the LinuxMain setup like this does not compile because the old compiler does not know the await keyword
54+
(even though the whole code is ignored because we do not compile for WASI whe compiling with an old compiler).
55+
I also tried doing a #if swift(>=5.5) check, but that do not work either.\(SGR.reset.rawValue)
56+
57+
\(SGR(.fgColorTo4BitMagenta, .bold).rawValue)To temporarily enable the tests for WASI, uncomment the `await XCTMain(tests)` line in LinuxMain.swift.\(SGR.reset.rawValue)
58+
59+
""".utf8))
60+
61+
#endif

0 commit comments

Comments
 (0)