Skip to content

Commit c07d4ae

Browse files
authored
Xcode 13.3 Beta 3 support (#21)
* bump swiftnio to 2.38.0 * bump swift-tools-version to 5.3 and macos to 11 * add support for Xcode 13.3 * move over to os_log * add 13.3 to Bazel build * add context to os_log calls * debug > default
1 parent 86b1472 commit c07d4ae

62 files changed

Lines changed: 283 additions & 38 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

BUILD.bazel

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,9 @@ alias(
4040
visibility = ["//visibility:public"],
4141
)
4242

43+
alias(
44+
name = "XCBProtocol_13_3",
45+
actual = "//Sources/XCBProtocol_13_3",
46+
visibility = ["//visibility:public"],
47+
)
48+

Package.resolved

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
1-
// swift-tools-version:5.1
1+
// swift-tools-version:5.3
22

33
import PackageDescription
44

55
let package = Package(
6-
name: "BazelXCBBuildServiceProxy",
7-
platforms: [.macOS(.v10_14)],
6+
name: "XCBBuildServiceProxy",
7+
platforms: [.macOS(.v11)],
88
products: [
99
.library(name: "XCBProtocol", targets: ["XCBProtocol"]),
1010
.library(name: "XCBProtocol_11_3", targets: ["XCBProtocol_11_3"]),
1111
.library(name: "XCBProtocol_11_4", targets: ["XCBProtocol_11_4"]),
1212
.library(name: "XCBProtocol_12_0", targets: ["XCBProtocol_12_0"]),
1313
.library(name: "XCBProtocol_12_5", targets: ["XCBProtocol_12_5"]),
1414
.library(name: "XCBProtocol_13_0", targets: ["XCBProtocol_13_0"]),
15+
.library(name: "XCBProtocol_13_3", targets: ["XCBProtocol_13_3"]),
1516
.library(name: "XCBBuildServiceProxy", targets: ["XCBBuildServiceProxy"]),
1617
],
1718
dependencies: [
1819
// Make sure to update the versions used in the `repositories.bzl` file if you change them here
1920
.package(url: "https://github.com/apple/swift-log", .exact("1.4.2")),
20-
.package(url: "https://github.com/apple/swift-nio", .exact("2.30.0")),
21+
.package(url: "https://github.com/apple/swift-nio", .exact("2.38.0")),
2122
],
2223
targets: [
2324
.target(
@@ -30,14 +31,17 @@ let package = Package(
3031
),
3132
.testTarget(
3233
name: "MessagePackTests",
33-
dependencies: ["MessagePack"]
34+
dependencies: ["MessagePack"],
35+
exclude: [
36+
"BUILD.bazel"
37+
]
3438
),
3539
.target(
3640
name: "XCBProtocol",
3741
dependencies: [
38-
"Logging",
42+
.product(name: "Logging", package: "swift-log"),
3943
"MessagePack",
40-
"NIO",
44+
.product(name: "NIO", package: "swift-nio"),
4145
],
4246
exclude: [
4347
"BUILD.bazel"
@@ -93,11 +97,21 @@ let package = Package(
9397
"BUILD.bazel"
9498
]
9599
),
100+
.target(
101+
name: "XCBProtocol_13_3",
102+
dependencies: [
103+
"MessagePack",
104+
"XCBProtocol",
105+
],
106+
exclude: [
107+
"BUILD.bazel"
108+
]
109+
),
96110
.target(
97111
name: "XCBBuildServiceProxy",
98112
dependencies: [
99-
"Logging",
100-
"NIO",
113+
.product(name: "Logging", package: "swift-log"),
114+
.product(name: "NIO", package: "swift-nio"),
101115
"XCBProtocol",
102116
],
103117
exclude: [

Sources/XCBBuildServiceProxy/Hybrid/HybridRPCRequestHandler.swift

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import Foundation
22
import Logging
33
import NIO
4+
import os
45
import XCBProtocol
56

67
// swiftlint:disable opening_brace
@@ -40,7 +41,7 @@ final class HybridRPCRequestHandler<RequestHandler: HybridXCBBuildServiceRequest
4041
// Here we are receiving a request from Xcode
4142
let request = unwrapInboundIn(data)
4243

43-
logger.debug("Received RPCRequest from Xcode: \(request)")
44+
os_log(.debug, "Received RPCRequest from Xcode: \(request)")
4445

4546
// Start the proxied XCBBuildService if needed
4647
if let xcodePath = request.payload.createSessionXcodePath {
@@ -73,12 +74,12 @@ final class HybridRPCRequestHandler<RequestHandler: HybridXCBBuildServiceRequest
7374

7475
// Return a result for `sendRequest()`
7576
if let promise = responsePromises.removeValue(forKey: response.channel) {
76-
logger.debug("Received RPCResponse from XCBBuildService: \(response)")
77+
os_log(.debug, "Received RPCResponse from XCBBuildService: \(response)")
7778
promise.succeed(response)
7879
} else {
7980
// Unknown channel, because of event stream or forwarded request
8081
// Just forward it back to Xcode
81-
logger.debug("Received RPCResponse from XCBBuildService and sending to Xcode: \(response)")
82+
os_log(.debug, "Received RPCResponse from XCBBuildService and sending to Xcode: \(response)")
8283
context.writeAndFlush(data, promise: promise)
8384
}
8485
}
@@ -88,7 +89,7 @@ final class HybridRPCRequestHandler<RequestHandler: HybridXCBBuildServiceRequest
8889
responsePromises[request.channel] = promise
8990
}
9091

91-
logger.debug("Sending RPCRequest to XCBBuildService: \(request)")
92+
os_log(.debug, "Sending RPCRequest to XCBBuildService: \(request)")
9293

9394
xcbBuildService.channel.writeAndFlush(request, promise: nil)
9495
}
@@ -102,7 +103,7 @@ final class HybridRPCRequestHandler<RequestHandler: HybridXCBBuildServiceRequest
102103
}
103104

104105
private func sendResponse(_ response: Response, context: ChannelHandlerContext) {
105-
logger.debug("Sending RPCResponse to Xcode: \(response)")
106+
os_log(.debug, "Sending RPCResponse to Xcode: \(response)")
106107
context.writeAndFlush(wrapOutboundOut(response), promise: nil)
107108
}
108109
}

Sources/XCBBuildServiceProxy/Hybrid/HybridXCBBuildService.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import Foundation
22
import NIO
3+
import os
34
import XCBProtocol
45

56
public final class HybridXCBBuildService<RequestHandler: HybridXCBBuildServiceRequestHandler> {
@@ -44,7 +45,7 @@ public final class HybridXCBBuildService<RequestHandler: HybridXCBBuildServiceRe
4445
public func start() throws -> Channel {
4546
let channel = try bootstrap.withPipes(inputDescriptor: STDIN_FILENO, outputDescriptor: STDOUT_FILENO).wait()
4647

47-
logger.info("\(name) started and listening on STDIN")
48+
os_log(.info, "\(self.name) started and listening on STDIN")
4849

4950
return channel
5051
}
@@ -53,9 +54,9 @@ public final class HybridXCBBuildService<RequestHandler: HybridXCBBuildServiceRe
5354
do {
5455
try group.syncShutdownGracefully()
5556
} catch {
56-
logger.error("Error shutting down: \(error)")
57+
os_log(.error, "Error shutting down: \(error.localizedDescription)")
5758
exit(0)
5859
}
59-
logger.info("\(name) stopped")
60+
os_log(.info, "\(self.name) stopped")
6061
}
6162
}

Sources/XCBBuildServiceProxy/Hybrid/HybridXCBBuildServiceRequestHandler.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import Logging
22
import NIO
3+
import os
34
import XCBProtocol
45

56
// swiftformat:disable braces
@@ -81,12 +82,11 @@ public final class HybridXCBBuildServiceRequestHandlerContext<RequestPayload, Re
8182
}
8283

8384
public func sendErrorResponse(
84-
_ messageClosure: @autoclosure () -> Logger.Message,
85+
_ messageClosure: @autoclosure () -> String,
8586
request: Request,
8687
file: String = #file, function: String = #function, line: UInt = #line
8788
) {
8889
let message = messageClosure()
89-
logger.error(message, file: file, function: function, line: line)
9090
sendResponseMessage(.errorResponse(message.description), channel: request.channel)
9191
}
9292
}

Sources/XCBBuildServiceProxy/Hybrid/XCBBuildService.swift

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import Foundation
22
import Logging
33
import NIO
4+
import os
45
import XCBProtocol
56

67
// swiftformat:disable braces
@@ -42,12 +43,12 @@ final class XCBBuildService {
4243
guard !process.isRunning else {
4344
if process.launchPath != processPath {
4445
let launchPath = process.launchPath ?? ""
45-
logger.error("XCBBuildService start request for “\(processPath)” but it’s already running at “\(launchPath)")
46+
os_log(.error, "XCBBuildService start request for “\(processPath)” but it’s already running at “\(launchPath)")
4647
}
4748
return
4849
}
4950

50-
logger.info("Starting XCBBuildService at “\(processPath)")
51+
os_log(.info, "Starting XCBBuildService at “\(processPath)")
5152

5253
process.launchPath = processPath
5354
process.launch()
@@ -96,21 +97,21 @@ final class XCBBuildServiceBootstrap<RequestPayload, ResponsePayload> where
9697
stderr.fileHandleForReading.readabilityHandler = { handle in
9798
let data = handle.availableData
9899
guard !data.isEmpty else {
99-
logger.trace("Received XCBBuildService standard error EOF")
100+
os_log(.debug, "Received XCBBuildService standard error EOF")
100101
stderr.fileHandleForReading.readabilityHandler = nil
101102
return
102103
}
103104

104105
if let output = String(data: data, encoding: .utf8) {
105-
logger.info("XCBBuildService stderr: \(output)")
106+
os_log(.info, "XCBBuildService stderr: \(output)")
106107
}
107108
}
108109

109110
process.terminationHandler = { process in
110-
logger.debug("XCBBuildService exited with status code: \(process.terminationStatus)")
111+
os_log(.info, "XCBBuildService exited with status code: \(process.terminationStatus)")
111112
}
112113

113-
logger.info("Prepping XCBBuildService")
114+
os_log(.info, "Prepping XCBBuildService")
114115

115116
let channelFuture = bootstrap.withPipes(
116117
inputDescriptor: stdout.fileHandleForReading.fileDescriptor,
@@ -125,7 +126,7 @@ final class XCBBuildServiceBootstrap<RequestPayload, ResponsePayload> where
125126

126127
channelFuture
127128
.whenSuccess { _ in
128-
logger.info("XCBBuildService prepped")
129+
os_log(.info, "XCBBuildService prepped")
129130
}
130131

131132
return channelFuture.map { XCBBuildService(process: process, channel: $0) }

Sources/XCBProtocol/RPC/RPCPacket.swift

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
import Foundation
22
import MessagePack
33
import NIO
4+
import os
45

56
/// An intermediate representation of an RPC message.
67
///
78
/// Bytes are decoded to form an `RPCPacket`. `RPCPacket`s are decoded to form `RPCRequest` and `RPCResponse` instances.
8-
public struct RPCPacket {
9+
public struct RPCPacket: CustomStringConvertible {
10+
public var description: String { "Channel: \(channel) - Body: \(body) "}
11+
912
/// The RPC channel that is being communicated on.
1013
///
1114
/// A response will come back on the same channel as a request.
@@ -37,7 +40,7 @@ public class RPCPacketCodec: ByteToMessageDecoder, MessageToByteEncoder {
3740

3841
public func decode(context: ChannelHandlerContext, buffer: inout ByteBuffer) throws -> DecodingState {
3942
if let packet = try findNextPacket(buffer: &buffer) {
40-
logger.trace("[\(label)] Decoded RPCPacket: \(packet)")
43+
os_log(.debug, "[\(self.label)] Decoded RPCPacket: \(packet)")
4144
context.fireChannelRead(wrapInboundOut(packet))
4245
return .continue
4346
} else {
@@ -56,7 +59,7 @@ public class RPCPacketCodec: ByteToMessageDecoder, MessageToByteEncoder {
5659
// Reset header state since we have read the full packet now
5760
decodedHeader = nil
5861

59-
logger.trace("[\(label)] Decoded RPCPacket payload: \(payload)")
62+
os_log(.debug, "[\(self.label)] Decoded RPCPacket payload: \(payload)")
6063

6164
let body = try MessagePackValue.unpackAll(Data(payload))
6265

@@ -85,7 +88,7 @@ public class RPCPacketCodec: ByteToMessageDecoder, MessageToByteEncoder {
8588
}
8689

8790
public func encode(data packet: RPCPacket, out: inout ByteBuffer) throws {
88-
logger.trace("[\(label)] Encoding RPCPacket: \(packet)")
91+
os_log(.debug, "[\(self.label)] Encoding RPCPacket: \(packet)")
8992

9093
let body = packet.body.reduce(into: Data()) { body, element in body.append(element.pack()) }
9194

Sources/XCBProtocol/RPC/RPCRequest.swift

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
import Foundation
22
import MessagePack
33
import NIO
4+
import os
45

56
/// An RPC request sent from Xcode.
6-
public struct RPCRequest<Payload: RequestPayload> {
7+
public struct RPCRequest<Payload: RequestPayload>: CustomStringConvertible {
8+
public var description: String { "Channel: \(channel) - Payload: \(payload) "}
9+
710
public let channel: UInt64
811
public let payload: Payload
912

@@ -23,7 +26,7 @@ public final class RPCRequestDecoder<Payload: RequestPayload>: ChannelInboundHan
2326
public func channelRead(context: ChannelHandlerContext, data: NIOAny) {
2427
let request = RPCRequest<Payload>(unwrapInboundIn(data))
2528

26-
logger.trace("RPCRequest decoded: \(request)")
29+
os_log(.debug, "RPCRequest decoded: \(request)")
2730

2831
context.fireChannelRead(wrapInboundOut(request))
2932
}
@@ -35,7 +38,8 @@ extension RPCRequest {
3538
do {
3639
payload = try packet.body.parseObject(indexPath: IndexPath())
3740
} catch {
38-
logger.error("Failed parsing RequestPayload received from Xcode: \(error)\nValues: \(packet.body)")
41+
let errorStr = "\(error)"
42+
os_log(.error, "Failed parsing RequestPayload received from Xcode: \(errorStr)\nValues: \(packet.body)")
3943

4044
payload = .unknownRequest(values: packet.body)
4145
}

Sources/XCBProtocol/RPC/RPCResponse.swift

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
import Foundation
22
import MessagePack
33
import NIO
4+
import os
45

56
/// An RPC response sent to Xcode.
6-
public struct RPCResponse<Payload: ResponsePayload> {
7+
public struct RPCResponse<Payload: ResponsePayload>: CustomStringConvertible {
8+
public var description: String { "Channel: \(channel) - Payload: \(payload) "}
9+
710
public let channel: UInt64
811
public let payload: Payload
912

@@ -39,7 +42,7 @@ public final class RPCResponseDecoder<Payload: ResponsePayload>: ChannelInboundH
3942
let packet = unwrapInboundIn(data)
4043
let response = RPCResponse<Payload>(packet)
4144

42-
logger.trace("RPCResponse decoded: \(response)")
45+
os_log(.debug, "RPCResponse decoded: \(response)")
4346

4447
context.fireChannelRead(wrapInboundOut(response))
4548
}
@@ -51,7 +54,8 @@ extension RPCResponse {
5154
do {
5255
payload = try packet.body.parseObject(indexPath: IndexPath())
5356
} catch {
54-
logger.error("Failed parsing ResponsePayload received from XCBBuildService: \(error)\nValues: \(packet.body)")
57+
let errorStr = "\(error)"
58+
os_log(.error, "Failed parsing ResponsePayload received from XCBBuildService: \(errorStr)\nValues: \(packet.body)")
5559

5660
payload = .unknownResponse(values: packet.body)
5761
}

0 commit comments

Comments
 (0)