Fix Swift build issues

pull/19704/head
Muxi Yan 6 years ago
parent 82b2dbfc1d
commit d06f544815
  1. 14
      gRPC.podspec
  2. 11
      src/objective-c/BUILD
  3. 2
      src/objective-c/GRPCClient/GRPCCall+ChannelArg.h
  4. 2
      src/objective-c/GRPCClient/GRPCCall+ChannelCredentials.h
  5. 4
      src/objective-c/GRPCClient/GRPCCall+Cronet.h
  6. 2
      src/objective-c/GRPCClient/GRPCCall+GID.h
  7. 4
      src/objective-c/GRPCClient/GRPCCall+OAuth2.h
  8. 2
      src/objective-c/GRPCClient/GRPCCall+Tests.h
  9. 111
      src/objective-c/GRPCClient/GRPCCall.h
  10. 1
      src/objective-c/GRPCClient/GRPCCallLegacy.m
  11. 1
      src/objective-c/GRPCClient/GRPCCallOptions.h
  12. 111
      src/objective-c/GRPCClient/GRPCTypes.h
  13. 1
      src/objective-c/GRPCClient/private/GRPCCore/GRPCHost.m
  14. 4
      src/objective-c/GRPCClient/private/GRPCTransport+Private.m
  15. 8
      src/objective-c/ProtoRPC/ProtoRPCLegacy.h
  16. 6
      src/objective-c/ProtoRPC/ProtoService.h
  17. 6
      src/objective-c/ProtoRPC/ProtoService.m
  18. 24
      src/objective-c/ProtoRPC/ProtoServiceLegacy.m
  19. 14
      templates/gRPC.podspec.template

@ -51,10 +51,20 @@ Pod::Spec.new do |s|
s.subspec 'Interface-Legacy' do |ss|
ss.header_mappings_dir = 'src/objective-c/GRPCClient'
ss.public_header_files = "src/objective-c/GRPCClient/GRPCCallLegacy.h",
ss.public_header_files = "GRPCClient/GRPCCall+ChannelArg.h",
"GRPCClient/GRPCCall+ChannelCredentials.h",
"GRPCClient/GRPCCall+Cronet.h",
"GRPCClient/GRPCCall+OAuth2.h",
"GRPCClient/GRPCCall+Tests.h",
"src/objective-c/GRPCClient/GRPCCallLegacy.h",
"src/objective-c/GRPCClient/GRPCTypes.h"
ss.source_files = "src/objective-c/GRPCClient/GRPCCallLegacy.h",
ss.source_files = "GRPCClient/GRPCCall+ChannelArg.h",
"GRPCClient/GRPCCall+ChannelCredentials.h",
"GRPCClient/GRPCCall+Cronet.h",
"GRPCClient/GRPCCall+OAuth2.h",
"GRPCClient/GRPCCall+Tests.h",
"src/objective-c/GRPCClient/GRPCCallLegacy.h",
"src/objective-c/GRPCClient/GRPCTypes.h"
end

@ -18,11 +18,11 @@ licenses(["notice"]) # Apache v2
package(default_visibility = ["//visibility:public"])
load("//bazel:grpc_build_system.bzl", "grpc_objc_library", "grpc_objc_use_cronet_config")
load("//bazel:grpc_build_system.bzl", "grpc_objc_library", "grpc_generate_objc_one_off_targets")
exports_files(["LICENSE"])
grpc_objc_use_cronet_config()
grpc_generate_objc_one_off_targets()
grpc_objc_library(
name = "rx_library_headers",
@ -41,8 +41,8 @@ grpc_objc_library(
]),
includes = ["."],
deps = [
":rx_library_private",
":rx_library_headers",
":rx_library_private",
],
)
@ -60,6 +60,11 @@ grpc_objc_library(
grpc_objc_library(
name = "grpc_objc_interface_legacy",
hdrs = [
"GRPCClient/GRPCCall+ChannelArg.h",
"GRPCClient/GRPCCall+ChannelCredentials.h",
"GRPCClient/GRPCCall+Cronet.h",
"GRPCClient/GRPCCall+OAuth2.h",
"GRPCClient/GRPCCall+Tests.h",
"GRPCClient/GRPCCallLegacy.h",
"GRPCClient/GRPCTypes.h",
],

@ -15,7 +15,7 @@
* limitations under the License.
*
*/
#import "GRPCCall.h"
#import "GRPCCallLegacy.h"
#include <AvailabilityMacros.h>

@ -16,7 +16,7 @@
*
*/
#import "GRPCCall.h"
#import "GRPCCallLegacy.h"
// Deprecated interface. Please use GRPCCallOptions instead.
@interface GRPCCall (ChannelCredentials)

@ -16,8 +16,8 @@
*
*/
#import "GRPCCall.h"
#import "GRPCTransport.h"
#import "GRPCCallLegacy.h"
#import "GRPCTypes.h"
typedef struct stream_engine stream_engine;

@ -17,7 +17,7 @@
*/
#import "GRPCCall+OAuth2.h"
#import "GRPCCall.h"
#import "GRPCCallLegacy.h"
#import <Google/SignIn.h>

@ -16,9 +16,9 @@
*
*/
#import "GRPCCall.h"
#import "GRPCCallLegacy.h"
#import "GRPCCallOptions.h"
@protocol GRPCAuthorizationProtocol;
// Deprecated interface. Please use GRPCCallOptions instead.
@interface GRPCCall (OAuth2)

@ -16,7 +16,7 @@
*
*/
#import "GRPCCall.h"
#import "GRPCCallLegacy.h"
// Deprecated interface. Please use GRPCCallOptions instead.
@interface GRPCCall (Tests)

@ -36,6 +36,7 @@
#import "GRPCCallOptions.h"
#import "GRPCDispatchable.h"
#import "GRPCTypes.h"
// The legacy header is included for backwards compatibility. Some V1 API users are still using
// GRPCCall by importing GRPCCall.h header so we need this import.
@ -43,116 +44,6 @@
NS_ASSUME_NONNULL_BEGIN
#pragma mark gRPC errors
/** Domain of NSError objects produced by gRPC. */
extern NSString *const kGRPCErrorDomain;
/**
* gRPC error codes.
* Note that a few of these are never produced by the gRPC libraries, but are of general utility for
* server applications to produce.
*/
typedef NS_ENUM(NSUInteger, GRPCErrorCode) {
/** The operation was cancelled (typically by the caller). */
GRPCErrorCodeCancelled = 1,
/**
* Unknown error. Errors raised by APIs that do not return enough error information may be
* converted to this error.
*/
GRPCErrorCodeUnknown = 2,
/**
* The client specified an invalid argument. Note that this differs from FAILED_PRECONDITION.
* INVALID_ARGUMENT indicates arguments that are problematic regardless of the state of the
* server (e.g., a malformed file name).
*/
GRPCErrorCodeInvalidArgument = 3,
/**
* Deadline expired before operation could complete. For operations that change the state of the
* server, this error may be returned even if the operation has completed successfully. For
* example, a successful response from the server could have been delayed long enough for the
* deadline to expire.
*/
GRPCErrorCodeDeadlineExceeded = 4,
/** Some requested entity (e.g., file or directory) was not found. */
GRPCErrorCodeNotFound = 5,
/** Some entity that we attempted to create (e.g., file or directory) already exists. */
GRPCErrorCodeAlreadyExists = 6,
/**
* The caller does not have permission to execute the specified operation. PERMISSION_DENIED isn't
* used for rejections caused by exhausting some resource (RESOURCE_EXHAUSTED is used instead for
* those errors). PERMISSION_DENIED doesn't indicate a failure to identify the caller
* (UNAUTHENTICATED is used instead for those errors).
*/
GRPCErrorCodePermissionDenied = 7,
/**
* The request does not have valid authentication credentials for the operation (e.g. the caller's
* identity can't be verified).
*/
GRPCErrorCodeUnauthenticated = 16,
/** Some resource has been exhausted, perhaps a per-user quota. */
GRPCErrorCodeResourceExhausted = 8,
/**
* The RPC was rejected because the server is not in a state required for the procedure's
* execution. For example, a directory to be deleted may be non-empty, etc.
* The client should not retry until the server state has been explicitly fixed (e.g. by
* performing another RPC). The details depend on the service being called, and should be found in
* the NSError's userInfo.
*/
GRPCErrorCodeFailedPrecondition = 9,
/**
* The RPC was aborted, typically due to a concurrency issue like sequencer check failures,
* transaction aborts, etc. The client should retry at a higher-level (e.g., restarting a read-
* modify-write sequence).
*/
GRPCErrorCodeAborted = 10,
/**
* The RPC was attempted past the valid range. E.g., enumerating past the end of a list.
* Unlike INVALID_ARGUMENT, this error indicates a problem that may be fixed if the system state
* changes. For example, an RPC to get elements of a list will generate INVALID_ARGUMENT if asked
* to return the element at a negative index, but it will generate OUT_OF_RANGE if asked to return
* the element at an index past the current size of the list.
*/
GRPCErrorCodeOutOfRange = 11,
/** The procedure is not implemented or not supported/enabled in this server. */
GRPCErrorCodeUnimplemented = 12,
/**
* Internal error. Means some invariant expected by the server application or the gRPC library has
* been broken.
*/
GRPCErrorCodeInternal = 13,
/**
* The server is currently unavailable. This is most likely a transient condition and may be
* corrected by retrying with a backoff. Note that it is not always safe to retry
* non-idempotent operations.
*/
GRPCErrorCodeUnavailable = 14,
/** Unrecoverable data loss or corruption. */
GRPCErrorCodeDataLoss = 15,
};
/**
* Keys used in |NSError|'s |userInfo| dictionary to store the response headers and trailers sent by
* the server.
*/
extern NSString *const kGRPCHeadersKey;
extern NSString *const kGRPCTrailersKey;
/** An object can implement this protocol to receive responses from server from a call. */
@protocol GRPCResponseHandler<NSObject, GRPCDispatchable>

@ -21,6 +21,7 @@
#import "GRPCCall+Cronet.h"
#import "GRPCCall+OAuth2.h"
#import "GRPCCallOptions.h"
#import "GRPCTypes.h"
#import "private/GRPCCore/GRPCChannelPool.h"
#import "private/GRPCCore/GRPCCompletionQueue.h"

@ -22,7 +22,6 @@
NS_ASSUME_NONNULL_BEGIN
typedef char *GRPCTransportId;
@protocol GRPCInterceptorFactory;
/**

@ -16,6 +16,104 @@
*
*/
/**
* gRPC error codes.
* Note that a few of these are never produced by the gRPC libraries, but are of general utility for
* server applications to produce.
*/
typedef NS_ENUM(NSUInteger, GRPCErrorCode) {
/** The operation was cancelled (typically by the caller). */
GRPCErrorCodeCancelled = 1,
/**
* Unknown error. Errors raised by APIs that do not return enough error information may be
* converted to this error.
*/
GRPCErrorCodeUnknown = 2,
/**
* The client specified an invalid argument. Note that this differs from FAILED_PRECONDITION.
* INVALID_ARGUMENT indicates arguments that are problematic regardless of the state of the
* server (e.g., a malformed file name).
*/
GRPCErrorCodeInvalidArgument = 3,
/**
* Deadline expired before operation could complete. For operations that change the state of the
* server, this error may be returned even if the operation has completed successfully. For
* example, a successful response from the server could have been delayed long enough for the
* deadline to expire.
*/
GRPCErrorCodeDeadlineExceeded = 4,
/** Some requested entity (e.g., file or directory) was not found. */
GRPCErrorCodeNotFound = 5,
/** Some entity that we attempted to create (e.g., file or directory) already exists. */
GRPCErrorCodeAlreadyExists = 6,
/**
* The caller does not have permission to execute the specified operation. PERMISSION_DENIED isn't
* used for rejections caused by exhausting some resource (RESOURCE_EXHAUSTED is used instead for
* those errors). PERMISSION_DENIED doesn't indicate a failure to identify the caller
* (UNAUTHENTICATED is used instead for those errors).
*/
GRPCErrorCodePermissionDenied = 7,
/**
* The request does not have valid authentication credentials for the operation (e.g. the caller's
* identity can't be verified).
*/
GRPCErrorCodeUnauthenticated = 16,
/** Some resource has been exhausted, perhaps a per-user quota. */
GRPCErrorCodeResourceExhausted = 8,
/**
* The RPC was rejected because the server is not in a state required for the procedure's
* execution. For example, a directory to be deleted may be non-empty, etc.
* The client should not retry until the server state has been explicitly fixed (e.g. by
* performing another RPC). The details depend on the service being called, and should be found in
* the NSError's userInfo.
*/
GRPCErrorCodeFailedPrecondition = 9,
/**
* The RPC was aborted, typically due to a concurrency issue like sequencer check failures,
* transaction aborts, etc. The client should retry at a higher-level (e.g., restarting a read-
* modify-write sequence).
*/
GRPCErrorCodeAborted = 10,
/**
* The RPC was attempted past the valid range. E.g., enumerating past the end of a list.
* Unlike INVALID_ARGUMENT, this error indicates a problem that may be fixed if the system state
* changes. For example, an RPC to get elements of a list will generate INVALID_ARGUMENT if asked
* to return the element at a negative index, but it will generate OUT_OF_RANGE if asked to return
* the element at an index past the current size of the list.
*/
GRPCErrorCodeOutOfRange = 11,
/** The procedure is not implemented or not supported/enabled in this server. */
GRPCErrorCodeUnimplemented = 12,
/**
* Internal error. Means some invariant expected by the server application or the gRPC library has
* been broken.
*/
GRPCErrorCodeInternal = 13,
/**
* The server is currently unavailable. This is most likely a transient condition and may be
* corrected by retrying with a backoff. Note that it is not always safe to retry
* non-idempotent operations.
*/
GRPCErrorCodeUnavailable = 14,
/** Unrecoverable data loss or corruption. */
GRPCErrorCodeDataLoss = 15,
};
/**
* Safety remark of a gRPC method as defined in RFC 2616 Section 9.1
*/
@ -55,3 +153,16 @@ typedef NS_ENUM(NSUInteger, GRPCTransportType) {
/** Insecure channel. FOR TEST ONLY! */
GRPCTransportTypeInsecure,
};
/** Domain of NSError objects produced by gRPC. */
extern NSString *const kGRPCErrorDomain;
/**
* Keys used in |NSError|'s |userInfo| dictionary to store the response headers and trailers sent by
* the server.
*/
extern NSString *const kGRPCHeadersKey;
extern NSString *const kGRPCTrailersKey;
/** The id of a transport implementation. */
typedef char *GRPCTransportId;

@ -21,6 +21,7 @@
#import <GRPCClient/GRPCCall+Cronet.h>
#import <GRPCClient/GRPCCall.h>
#import <GRPCClient/GRPCCallOptions.h>
#import <GRPCClient/GRPCTransport.h>
#include <grpc/grpc.h>
#include <grpc/grpc_security.h>

@ -83,7 +83,7 @@
/** Forward initial metadata to the previous interceptor in the chain */
- (void)forwardPreviousInterceptorWithInitialMetadata:(NSDictionary *)initialMetadata {
if (_previousInterceptor == nil) {
if (initialMetadata == nil || _previousInterceptor == nil) {
return;
}
id<GRPCResponseHandler> copiedPreviousInterceptor = _previousInterceptor;
@ -94,7 +94,7 @@
/** Forward a received message to the previous interceptor in the chain */
- (void)forwardPreviousInterceptorWithData:(id)data {
if (_previousInterceptor == nil) {
if (data == nil || _previousInterceptor == nil) {
return;
}
id<GRPCResponseHandler> copiedPreviousInterceptor = _previousInterceptor;

@ -18,6 +18,13 @@
#import <GRPCClient/GRPCCallLegacy.h>
// Import category headers for Swift build
#import <GRPCClient/GRPCCall+ChannelArg.h>
#import <GRPCClient/GRPCCall+ChannelCredentials.h>
#import <GRPCClient/GRPCCall+Cronet.h>
#import <GRPCClient/GRPCCall+OAuth2.h>
#import <GRPCClient/GRPCCall+Tests.h>
@class GRPCProtoMethod;
@class GRXWriter;
@protocol GRXWriteable;
@ -36,6 +43,7 @@ __attribute__((deprecated("Please use GRPCProtoCall."))) @interface ProtoRPC
: (id<GRXWriteable>)responsesWriteable NS_DESIGNATED_INITIALIZER;
- (void)start;
@end
/**

@ -30,11 +30,7 @@
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wnullability-completeness"
__attribute__((deprecated("Please use GRPCProtoService."))) @interface ProtoService : NSObject {
NSString *_host;
NSString *_packageName;
NSString *_serviceName;
}
__attribute__((deprecated("Please use GRPCProtoService."))) @interface ProtoService : NSObject
- (nullable instancetype)initWithHost:(nonnull NSString *)host
packageName:(nonnull NSString *)packageName

@ -29,7 +29,11 @@
#pragma clang diagnostic ignored "-Wdeprecated-implementations"
@implementation ProtoService {
#pragma clang diagnostic pop
GRPCCallOptions *_callOptions;
NSString *_host;
NSString *_packageName;
NSString *_serviceName;
}
#pragma clang diagnostic push
@ -60,8 +64,6 @@
return self;
}
#pragma clang diagnostic pop
- (GRPCUnaryProtoCall *)RPCToMethod:(NSString *)method
message:(id)message
responseHandler:(id<GRPCProtoResponseHandler>)handler

@ -16,6 +16,8 @@
*
*/
#import <objc/runtime.h>
#import "ProtoServiceLegacy.h"
#import "ProtoMethod.h"
#import "ProtoRPCLegacy.h"
@ -34,20 +36,32 @@
packageName:(NSString *)packageName
serviceName:(NSString *)serviceName {
if ((self = [super init])) {
_host = [host copy];
_packageName = [packageName copy];
_serviceName = [serviceName copy];
Ivar hostIvar = class_getInstanceVariable([ProtoService class], "_host");
Ivar packageNameIvar = class_getInstanceVariable([ProtoService class], "_packageName");
Ivar serviceNameIvar = class_getInstanceVariable([ProtoService class], "_serviceName");
object_setIvar(self, hostIvar, [host copy]);
object_setIvar(self, packageNameIvar, [packageName copy]);
object_setIvar(self, serviceNameIvar, [serviceName copy]);
}
return self;
}
#pragma clang diagnostic pop
- (GRPCProtoCall *)RPCToMethod:(NSString *)method
requestsWriter:(GRXWriter *)requestsWriter
responseClass:(Class)responseClass
responsesWriteable:(id<GRXWriteable>)responsesWriteable {
Ivar hostIvar = class_getInstanceVariable([ProtoService class], "_host");
Ivar packageNameIvar = class_getInstanceVariable([ProtoService class], "_packageName");
Ivar serviceNameIvar = class_getInstanceVariable([ProtoService class], "_serviceName");
NSString *host = object_getIvar(self, hostIvar);
NSString *packageName = object_getIvar(self, packageNameIvar);
NSString *serviceName = object_getIvar(self, serviceNameIvar);
GRPCProtoMethod *methodName =
[[GRPCProtoMethod alloc] initWithPackage:_packageName service:_serviceName method:method];
return [[GRPCProtoCall alloc] initWithHost:_host
[[GRPCProtoMethod alloc] initWithPackage:packageName service:serviceName method:method];
return [[GRPCProtoCall alloc] initWithHost:host
method:methodName
requestsWriter:requestsWriter
responseClass:responseClass

@ -53,10 +53,20 @@
s.subspec 'Interface-Legacy' do |ss|
ss.header_mappings_dir = 'src/objective-c/GRPCClient'
ss.public_header_files = "src/objective-c/GRPCClient/GRPCCallLegacy.h",
ss.public_header_files = "GRPCClient/GRPCCall+ChannelArg.h",
"GRPCClient/GRPCCall+ChannelCredentials.h",
"GRPCClient/GRPCCall+Cronet.h",
"GRPCClient/GRPCCall+OAuth2.h",
"GRPCClient/GRPCCall+Tests.h",
"src/objective-c/GRPCClient/GRPCCallLegacy.h",
"src/objective-c/GRPCClient/GRPCTypes.h"
ss.source_files = "src/objective-c/GRPCClient/GRPCCallLegacy.h",
ss.source_files = "GRPCClient/GRPCCall+ChannelArg.h",
"GRPCClient/GRPCCall+ChannelCredentials.h",
"GRPCClient/GRPCCall+Cronet.h",
"GRPCClient/GRPCCall+OAuth2.h",
"GRPCClient/GRPCCall+Tests.h",
"src/objective-c/GRPCClient/GRPCCallLegacy.h",
"src/objective-c/GRPCClient/GRPCTypes.h"
end

Loading…
Cancel
Save