Skip to content

Commit ce264ad

Browse files
authored
Merge pull request #906 from ahoppen/ahoppen/non-darwin-logger-for-tests
Use NonDarwinLogger when running tests instead of os_log
2 parents 80955f8 + 86751b8 commit ce264ad

File tree

3 files changed

+26
-6
lines changed

3 files changed

+26
-6
lines changed

Package.swift

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ func hasEnvironmentVariable(_ name: String) -> Bool {
99
return ProcessInfo.processInfo.environment[name] != nil
1010
}
1111

12+
/// Use the `NonDarwinLogger` even if `os_log` can be imported.
13+
///
14+
/// This is useful when running tests using `swift test` because xctest will not display the output from `os_log` on the
15+
/// command line.
16+
let forceNonDarwinLogger = hasEnvironmentVariable("SOURCEKITLSP_FORCE_NON_DARWIN_LOGGER")
17+
1218
// When building the toolchain on the CI, don't add the CI's runpath for the
1319
// final build before installing.
1420
let installAction = hasEnvironmentVariable("SOURCEKIT_LSP_CI_INSTALL")
@@ -19,11 +25,14 @@ let useLocalDependencies = hasEnvironmentVariable("SWIFTCI_USE_LOCAL_DEPS")
1925

2026
// MARK: - Compute custom build settings
2127

22-
let sourcekitLSPLinkSettings: [LinkerSetting]
28+
var sourcekitLSPLinkSettings: [LinkerSetting] = []
2329
if installAction {
24-
sourcekitLSPLinkSettings = [.unsafeFlags(["-no-toolchain-stdlib-rpath"], .when(platforms: [.linux, .android]))]
25-
} else {
26-
sourcekitLSPLinkSettings = []
30+
sourcekitLSPLinkSettings += [.unsafeFlags(["-no-toolchain-stdlib-rpath"], .when(platforms: [.linux, .android]))]
31+
}
32+
33+
var lspLoggingSwiftSettings: [SwiftSetting] = []
34+
if forceNonDarwinLogger {
35+
lspLoggingSwiftSettings += [.define("SOURCEKITLSP_FORCE_NON_DARWIN_LOGGER")]
2736
}
2837

2938
// MARK: - Build the package
@@ -135,7 +144,8 @@ let package = Package(
135144
dependencies: [
136145
.product(name: "Crypto", package: "swift-crypto")
137146
],
138-
exclude: ["CMakeLists.txt"]
147+
exclude: ["CMakeLists.txt"],
148+
swiftSettings: lspLoggingSwiftSettings
139149
),
140150

141151
.testTarget(

Sources/LSPLogging/Logging.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import Foundation
2222
/// The subsystem that should be used for any logging by default.
2323
public let subsystem = "org.swift.sourcekit-lsp"
2424

25-
#if canImport(os)
25+
#if canImport(os) && !SOURCEKITLSP_FORCE_NON_DARWIN_LOGGER
2626
import os // os_log
2727

2828
public typealias LogLevel = os.OSLogType

Utilities/build-script-helper.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,16 @@ def run_tests(swift_exec: str, args: argparse.Namespace) -> None:
202202
"""
203203
swiftpm_args = get_swiftpm_options(swift_exec, args)
204204
additional_env = get_swiftpm_environment_variables(swift_exec, args)
205+
# 'swift test' doesn't print os_log output to the command line. Use the
206+
# `NonDarwinLogger` that prints to stderr so we can view the log output in CI test
207+
# runs.
208+
additional_env['SOURCEKITLSP_FORCE_NON_DARWIN_LOGGER'] = '1'
209+
210+
# CI doesn't contain any sensitive information. Log everything.
211+
additional_env['SOURCEKITLSP_LOG_PRIVACY_LEVEL'] = 'sensitive'
212+
213+
# Log with the highest log level to simplify debugging of CI failures.
214+
additional_env['SOURCEKITLSP_LOG_LEVEL'] = 'debug'
205215

206216
bin_path = swiftpm_bin_path(swift_exec, swiftpm_args, additional_env=additional_env)
207217
tests = os.path.join(bin_path, 'sk-tests')

0 commit comments

Comments
 (0)