Skip to content

Commit 956259f

Browse files
Lutziferemuguy1
andauthored
Fix path escaping on Darwin in SwiftPM plugin (regression of #2085) (#2273)
Resolves #2085 --------- Co-authored-by: Emanuel Erben <emanuel.erben@gmail.com>
1 parent 5770e23 commit 956259f

14 files changed

Lines changed: 76 additions & 52 deletions

File tree

Examples/v1/RouteGuide/Model/route_guide.pb.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,21 +61,21 @@ public struct Routeguide_Rectangle: Sendable {
6161

6262
/// One corner of the rectangle.
6363
public var lo: Routeguide_Point {
64-
get {return _lo ?? Routeguide_Point()}
64+
get {_lo ?? Routeguide_Point()}
6565
set {_lo = newValue}
6666
}
6767
/// Returns true if `lo` has been explicitly set.
68-
public var hasLo: Bool {return self._lo != nil}
68+
public var hasLo: Bool {self._lo != nil}
6969
/// Clears the value of `lo`. Subsequent reads from it will return its default value.
7070
public mutating func clearLo() {self._lo = nil}
7171

7272
/// The other corner of the rectangle.
7373
public var hi: Routeguide_Point {
74-
get {return _hi ?? Routeguide_Point()}
74+
get {_hi ?? Routeguide_Point()}
7575
set {_hi = newValue}
7676
}
7777
/// Returns true if `hi` has been explicitly set.
78-
public var hasHi: Bool {return self._hi != nil}
78+
public var hasHi: Bool {self._hi != nil}
7979
/// Clears the value of `hi`. Subsequent reads from it will return its default value.
8080
public mutating func clearHi() {self._hi = nil}
8181

@@ -100,11 +100,11 @@ public struct Routeguide_Feature: Sendable {
100100

101101
/// The point where the feature is detected.
102102
public var location: Routeguide_Point {
103-
get {return _location ?? Routeguide_Point()}
103+
get {_location ?? Routeguide_Point()}
104104
set {_location = newValue}
105105
}
106106
/// Returns true if `location` has been explicitly set.
107-
public var hasLocation: Bool {return self._location != nil}
107+
public var hasLocation: Bool {self._location != nil}
108108
/// Clears the value of `location`. Subsequent reads from it will return its default value.
109109
public mutating func clearLocation() {self._location = nil}
110110

@@ -123,11 +123,11 @@ public struct Routeguide_RouteNote: Sendable {
123123

124124
/// The location from which the message is sent.
125125
public var location: Routeguide_Point {
126-
get {return _location ?? Routeguide_Point()}
126+
get {_location ?? Routeguide_Point()}
127127
set {_location = newValue}
128128
}
129129
/// Returns true if `location` has been explicitly set.
130-
public var hasLocation: Bool {return self._location != nil}
130+
public var hasLocation: Bool {self._location != nil}
131131
/// Clears the value of `location`. Subsequent reads from it will return its default value.
132132
public mutating func clearLocation() {self._location = nil}
133133

Plugins/GRPCSwiftPlugin/plugin.swift

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,13 +168,13 @@ struct GRPCSwiftPlugin {
168168
) -> Command {
169169
// Construct the `protoc` arguments.
170170
var protocArgs = [
171-
"--plugin=protoc-gen-grpc-swift=\(protocGenGRPCSwiftPath.path())",
172-
"--grpc-swift_out=\(outputDirectory.path())",
171+
"--plugin=protoc-gen-grpc-swift=\(protocGenGRPCSwiftPath.fileSystemPath)",
172+
"--grpc-swift_out=\(outputDirectory.fileSystemPath)",
173173
]
174174

175175
importPaths.forEach { path in
176176
protocArgs.append("-I")
177-
protocArgs.append(path.path())
177+
protocArgs.append(path.fileSystemPath)
178178
}
179179

180180
if let visibility = invocation.visibility {
@@ -255,6 +255,16 @@ struct GRPCSwiftPlugin {
255255
}
256256
}
257257

258+
extension URL {
259+
fileprivate var fileSystemPath: String {
260+
#if canImport(Darwin)
261+
return self.path(percentEncoded: false)
262+
#else
263+
return self.path()
264+
#endif
265+
}
266+
}
267+
258268
extension GRPCSwiftPlugin: BuildToolPlugin {
259269
func createBuildCommands(
260270
context: PluginContext,

Sources/GRPC/AsyncAwaitSupport/GRPCAsyncServerHandler.swift

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ extension GRPCAsyncServerHandler {
6262
requestDeserializer: Deserializer,
6363
responseSerializer: Serializer,
6464
interceptors: [ServerInterceptor<Request, Response>],
65-
wrapping unary: @escaping @Sendable (Request, GRPCAsyncServerCallContext) async throws
65+
wrapping unary:
66+
@escaping @Sendable (Request, GRPCAsyncServerCallContext) async throws
6667
-> Response
6768
) {
6869
self._handler = .init(
@@ -88,10 +89,11 @@ extension GRPCAsyncServerHandler {
8889
requestDeserializer: Deserializer,
8990
responseSerializer: Serializer,
9091
interceptors: [ServerInterceptor<Request, Response>],
91-
wrapping clientStreaming: @escaping @Sendable (
92-
GRPCAsyncRequestStream<Request>,
93-
GRPCAsyncServerCallContext
94-
) async throws -> Response
92+
wrapping clientStreaming:
93+
@escaping @Sendable (
94+
GRPCAsyncRequestStream<Request>,
95+
GRPCAsyncServerCallContext
96+
) async throws -> Response
9597
) {
9698
self._handler = .init(
9799
context: context,
@@ -112,11 +114,12 @@ extension GRPCAsyncServerHandler {
112114
requestDeserializer: Deserializer,
113115
responseSerializer: Serializer,
114116
interceptors: [ServerInterceptor<Request, Response>],
115-
wrapping serverStreaming: @escaping @Sendable (
116-
Request,
117-
GRPCAsyncResponseStreamWriter<Response>,
118-
GRPCAsyncServerCallContext
119-
) async throws -> Void
117+
wrapping serverStreaming:
118+
@escaping @Sendable (
119+
Request,
120+
GRPCAsyncResponseStreamWriter<Response>,
121+
GRPCAsyncServerCallContext
122+
) async throws -> Void
120123
) {
121124
self._handler = .init(
122125
context: context,
@@ -140,11 +143,12 @@ extension GRPCAsyncServerHandler {
140143
requestDeserializer: Deserializer,
141144
responseSerializer: Serializer,
142145
interceptors: [ServerInterceptor<Request, Response>],
143-
wrapping bidirectional: @escaping @Sendable (
144-
GRPCAsyncRequestStream<Request>,
145-
GRPCAsyncResponseStreamWriter<Response>,
146-
GRPCAsyncServerCallContext
147-
) async throws -> Void
146+
wrapping bidirectional:
147+
@escaping @Sendable (
148+
GRPCAsyncRequestStream<Request>,
149+
GRPCAsyncResponseStreamWriter<Response>,
150+
GRPCAsyncServerCallContext
151+
) async throws -> Void
148152
) {
149153
self._handler = .init(
150154
context: context,
@@ -265,11 +269,12 @@ internal final class AsyncServerHandler<
265269
responseSerializer: Serializer,
266270
callType: GRPCCallType,
267271
interceptors: [ServerInterceptor<Request, Response>],
268-
userHandler: @escaping @Sendable (
269-
GRPCAsyncRequestStream<Request>,
270-
GRPCAsyncResponseStreamWriter<Response>,
271-
GRPCAsyncServerCallContext
272-
) async throws -> Void
272+
userHandler:
273+
@escaping @Sendable (
274+
GRPCAsyncRequestStream<Request>,
275+
GRPCAsyncResponseStreamWriter<Response>,
276+
GRPCAsyncServerCallContext
277+
) async throws -> Void
273278
) {
274279
self.serializer = responseSerializer
275280
self.deserializer = requestDeserializer

Sources/GRPC/AsyncAwaitSupport/GRPCSendable.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,6 @@ public typealias GRPCSendable = Swift.Sendable
2121
@preconcurrency
2222
public protocol GRPCPreconcurrencySendable: Sendable {}
2323

24-
@preconcurrency public typealias GRPCChannelInitializer = @Sendable (Channel)
24+
@preconcurrency public typealias GRPCChannelInitializer =
25+
@Sendable (Channel)
2526
-> EventLoopFuture<Void>

Sources/GRPC/CallHandlers/BidirectionalStreamingServerHandler.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ public final class BidirectionalStreamingServerHandler<
7676
requestDeserializer: Deserializer,
7777
responseSerializer: Serializer,
7878
interceptors: [ServerInterceptor<Request, Response>],
79-
observerFactory: @escaping (StreamingResponseCallContext<Response>)
79+
observerFactory:
80+
@escaping (StreamingResponseCallContext<Response>)
8081
-> EventLoopFuture<(StreamEvent<Request>) -> Void>
8182
) {
8283
self.serializer = responseSerializer

Sources/GRPC/CallHandlers/ClientStreamingServerHandler.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ public final class ClientStreamingServerHandler<
7777
requestDeserializer: Deserializer,
7878
responseSerializer: Serializer,
7979
interceptors: [ServerInterceptor<Request, Response>],
80-
observerFactory: @escaping (UnaryResponseCallContext<Response>)
80+
observerFactory:
81+
@escaping (UnaryResponseCallContext<Response>)
8182
-> EventLoopFuture<(StreamEvent<Request>) -> Void>
8283
) {
8384
self.serializer = responseSerializer

Sources/GRPC/CallHandlers/ServerStreamingServerHandler.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ public final class ServerStreamingServerHandler<
7373
requestDeserializer: Deserializer,
7474
responseSerializer: Serializer,
7575
interceptors: [ServerInterceptor<Request, Response>],
76-
userFunction: @escaping (Request, StreamingResponseCallContext<Response>)
76+
userFunction:
77+
@escaping (Request, StreamingResponseCallContext<Response>)
7778
-> EventLoopFuture<GRPCStatus>
7879
) {
7980
self.serializer = responseSerializer

Sources/GRPCReflectionService/v1/reflection-v1.pb.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,11 +170,11 @@ public struct Grpc_Reflection_V1_ServerReflectionResponse: Sendable {
170170
public var validHost: String = String()
171171

172172
public var originalRequest: Grpc_Reflection_V1_ServerReflectionRequest {
173-
get {return _originalRequest ?? Grpc_Reflection_V1_ServerReflectionRequest()}
173+
get {_originalRequest ?? Grpc_Reflection_V1_ServerReflectionRequest()}
174174
set {_originalRequest = newValue}
175175
}
176176
/// Returns true if `originalRequest` has been explicitly set.
177-
public var hasOriginalRequest: Bool {return self._originalRequest != nil}
177+
public var hasOriginalRequest: Bool {self._originalRequest != nil}
178178
/// Clears the value of `originalRequest`. Subsequent reads from it will return its default value.
179179
public mutating func clearOriginalRequest() {self._originalRequest = nil}
180180

Sources/GRPCReflectionService/v1Alpha/reflection-v1alpha.pb.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,11 +173,11 @@ public struct Grpc_Reflection_V1alpha_ServerReflectionResponse: Sendable {
173173
public var validHost: String = String()
174174

175175
public var originalRequest: Grpc_Reflection_V1alpha_ServerReflectionRequest {
176-
get {return _originalRequest ?? Grpc_Reflection_V1alpha_ServerReflectionRequest()}
176+
get {_originalRequest ?? Grpc_Reflection_V1alpha_ServerReflectionRequest()}
177177
set {_originalRequest = newValue}
178178
}
179179
/// Returns true if `originalRequest` has been explicitly set.
180-
public var hasOriginalRequest: Bool {return self._originalRequest != nil}
180+
public var hasOriginalRequest: Bool {self._originalRequest != nil}
181181
/// Clears the value of `originalRequest`. Subsequent reads from it will return its default value.
182182
public mutating func clearOriginalRequest() {self._originalRequest = nil}
183183

Tests/GRPCTests/ClientInterceptorPipelineTests.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,8 @@ class ClientInterceptorPipelineTests: GRPCTestCase {
301301
// MARK: - Test Interceptors
302302

303303
/// A simple interceptor which records and then forwards and request and response parts it sees.
304-
class RecordingInterceptor<Request, Response>: ClientInterceptor<Request, Response>, @unchecked
304+
class RecordingInterceptor<Request, Response>: ClientInterceptor<Request, Response>,
305+
@unchecked
305306
Sendable
306307
{
307308
var requestParts: [GRPCClientRequestPart<Request>] = []

0 commit comments

Comments
 (0)