Skip to content

Remove available check below macOS 10.15.4 #438

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 6, 2021
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: 1 addition & 1 deletion Sources/LSPLogging/Logging.swift
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ public final class Logger {

var usedOSLog = false
#if canImport(os)
if !disableOSLog, #available(OSX 10.12, *) {
if !disableOSLog {
// If os_log is available, we call it unconditionally since it has its own log-level handling that we respect.
os_log("%@", type: level.osLogType, message)
usedOSLog = true
Expand Down
23 changes: 6 additions & 17 deletions Sources/LSPTestSupport/CheckCoding.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@ import XCTest
public func checkCoding<T>(_ value: T, json: String, file: StaticString = #filePath, line: UInt = #line) where T: Codable & Equatable {
let encoder = JSONEncoder()
encoder.outputFormatting.insert(.prettyPrinted)
if #available(macOS 10.13, *) {
encoder.outputFormatting.insert(.sortedKeys)
}
encoder.outputFormatting.insert(.sortedKeys)

let data = try! encoder.encode(WrapFragment(value: value))
let wrappedStr = String(data: data, encoding: .utf8)!

Expand All @@ -36,11 +35,7 @@ public func checkCoding<T>(_ value: T, json: String, file: StaticString = #fileP
.replacingOccurrences(of: "\n ", with: "\n")
// Remove trailing whitespace to normalize between corelibs and Apple Foundation.
.trimmingTrailingWhitespace()

// Requires sortedKeys. Silently drop the check if it's not available.
if #available(macOS 10.13, *) {
XCTAssertEqual(json, str, file: file, line: line)
}
XCTAssertEqual(json, str, file: file, line: line)

let decoder = JSONDecoder()
let decodedValue = try! decoder.decode(WrapFragment<T>.self, from: data).value
Expand Down Expand Up @@ -70,19 +65,13 @@ public func checkDecoding<T>(json: String, expected value: T, file: StaticString
public func checkCoding<T>(_ value: T, json: String, userInfo: [CodingUserInfoKey: Any] = [:], file: StaticString = #filePath, line: UInt = #line, body: (T) -> Void) where T: Codable {
let encoder = JSONEncoder()
encoder.outputFormatting.insert(.prettyPrinted)
if #available(macOS 10.13, *) {
encoder.outputFormatting.insert(.sortedKeys)
}
encoder.outputFormatting.insert(.sortedKeys)
let data = try! encoder.encode(value)
let str = String(data: data, encoding: .utf8)!
// Remove trailing whitespace to normalize between corelibs and Apple Foundation.
.trimmingTrailingWhitespace()

// Requires sortedKeys. Silently drop the check if it's not available.
if #available(macOS 10.13, *) {
XCTAssertEqual(json, str, file: file, line: line)
}

XCTAssertEqual(json, str, file: file, line: line)

let decoder = JSONDecoder()
decoder.userInfo = userInfo
let decodedValue = try! decoder.decode(T.self, from: data)
Expand Down
16 changes: 2 additions & 14 deletions Sources/SKCore/BuildServerBuildSystem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -260,26 +260,14 @@ private func makeJSONRPCBuildServer(client: MessageHandler, serverPath: Absolute
withExtendedLifetime((clientToServer, serverToClient)) {}
}
let process = Foundation.Process()

if #available(OSX 10.13, *) {
process.executableURL = serverPath.asURL
} else {
process.launchPath = serverPath.pathString
}

process.executableURL = serverPath.asURL
process.arguments = serverFlags
process.standardOutput = serverToClient
process.standardInput = clientToServer
process.terminationHandler = { process in
log("build server exited: \(process.terminationReason) \(process.terminationStatus)")
connection.close()
}

if #available(OSX 10.13, *) {
try process.run()
} else {
process.launch()
}

try process.run()
return connection
}
21 changes: 4 additions & 17 deletions Sources/SourceKitLSP/Clang/ClangLanguageServer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,8 @@ final class ClangLanguageServerShim: LanguageServer, ToolchainLanguageServer {
/// Changing the property automatically notified the state change handlers.
private var state: LanguageServerState {
didSet {
if #available(OSX 10.12, *) {
// `state` must only be set from `queue`.
dispatchPrecondition(condition: .onQueue(queue))
}
// `state` must only be set from `queue`.
dispatchPrecondition(condition: .onQueue(queue))
for handler in stateChangeHandlers {
handler(oldValue, state)
}
Expand Down Expand Up @@ -131,13 +129,7 @@ final class ClangLanguageServerShim: LanguageServer, ToolchainLanguageServer {
}

let process = Foundation.Process()

if #available(OSX 10.13, *) {
process.executableURL = clangdPath.asURL
} else {
process.launchPath = clangdPath.pathString
}

process.executableURL = clangdPath.asURL
process.arguments = [
"-compile_args_from=lsp", // Provide compiler args programmatically.
"-background-index=false", // Disable clangd indexing, we use the build
Expand All @@ -162,12 +154,7 @@ final class ClangLanguageServerShim: LanguageServer, ToolchainLanguageServer {
}
}
}

if #available(OSX 10.13, *) {
try process.run()
} else {
process.launch()
}
try process.run()
#if os(Windows)
self.hClangd = process.processHandle
#else
Expand Down
6 changes: 2 additions & 4 deletions Sources/SourceKitLSP/Swift/SwiftLanguageServer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,8 @@ public final class SwiftLanguageServer: ToolchainLanguageServer {

private var state: LanguageServerState {
didSet {
if #available(OSX 10.12, *) {
// `state` must only be set from `queue`.
dispatchPrecondition(condition: .onQueue(queue))
}
// `state` must only be set from `queue`.
dispatchPrecondition(condition: .onQueue(queue))
for handler in stateChangeHandlers {
handler(oldValue, state)
}
Expand Down
26 changes: 12 additions & 14 deletions Tests/SKCoreTests/CompilationDatabaseTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,21 +60,19 @@ final class CompilationDatabaseTests: XCTestCase {

func testEncodeCompDBCommand() {
// Requires JSONEncoder.OutputFormatting.sortedKeys
if #available(macOS 10.13, *) {
func check(_ cmd: CompilationDatabase.Command, _ expected: String, file: StaticString = #filePath, line: UInt = #line) {
let encoder = JSONEncoder()
encoder.outputFormatting.insert(.sortedKeys)
let encodedString = try! String(data: encoder.encode(cmd), encoding: .utf8)
XCTAssertEqual(encodedString, expected, file: file, line: line)
}

check(.init(directory: "a", filename: "b", commandLine: [], output: "c"), """
{"arguments":[],"directory":"a","file":"b","output":"c"}
""")
check(.init(directory: "a", filename: "b", commandLine: ["c", "d"], output: nil), """
{"arguments":["c","d"],"directory":"a","file":"b"}
""")
func check(_ cmd: CompilationDatabase.Command, _ expected: String, file: StaticString = #filePath, line: UInt = #line) {
let encoder = JSONEncoder()
encoder.outputFormatting.insert(.sortedKeys)
let encodedString = try! String(data: encoder.encode(cmd), encoding: .utf8)
XCTAssertEqual(encodedString, expected, file: file, line: line)
}

check(.init(directory: "a", filename: "b", commandLine: [], output: "c"), """
{"arguments":[],"directory":"a","file":"b","output":"c"}
""")
check(.init(directory: "a", filename: "b", commandLine: ["c", "d"], output: nil), """
{"arguments":["c","d"],"directory":"a","file":"b"}
""")
}

func testDecodeCompDBCommand() {
Expand Down