From c6b301775c4a783dec72f3939e489bce8eadf8a5 Mon Sep 17 00:00:00 2001 From: Kristopher Wuollett Date: Sun, 31 Jan 2016 14:26:39 -0500 Subject: [PATCH 01/55] Add channel args to enable user agent string for Objective-C --- examples/objective-c/helloworld/main.m | 2 + .../GRPCClient/GRPCCall+ChannelArg.h | 52 +++++ .../GRPCClient/GRPCCall+ChannelArg.m | 58 ++++++ src/objective-c/GRPCClient/private/GRPCHost.h | 2 + src/objective-c/GRPCClient/private/GRPCHost.m | 18 +- .../GRPCClient/private/GRPCSecureChannel.h | 15 +- .../GRPCClient/private/GRPCSecureChannel.m | 27 +-- .../GRPCClient/private/GRPCUnsecuredChannel.h | 6 +- .../GRPCClient/private/GRPCUnsecuredChannel.m | 13 +- .../private/GRPCWrappedChannelArgs.h | 29 +++ .../private/GRPCWrappedChannelArgs.m | 188 ++++++++++++++++++ 11 files changed, 385 insertions(+), 25 deletions(-) create mode 100644 src/objective-c/GRPCClient/GRPCCall+ChannelArg.h create mode 100644 src/objective-c/GRPCClient/GRPCCall+ChannelArg.m create mode 100644 src/objective-c/GRPCClient/private/GRPCWrappedChannelArgs.h create mode 100644 src/objective-c/GRPCClient/private/GRPCWrappedChannelArgs.m diff --git a/examples/objective-c/helloworld/main.m b/examples/objective-c/helloworld/main.m index a62f8362a22..f390b5a0f9b 100644 --- a/examples/objective-c/helloworld/main.m +++ b/examples/objective-c/helloworld/main.m @@ -34,6 +34,7 @@ #import #import "AppDelegate.h" +#import #import #import @@ -42,6 +43,7 @@ static NSString * const kHostAddress = @"localhost:50051"; int main(int argc, char * argv[]) { @autoreleasepool { [GRPCCall useInsecureConnectionsForHost:kHostAddress]; + [GRPCCall usePrimaryUserAgent:@"HelloWorld/1.0" forHost:kHostAddress]; HLWGreeter *client = [[HLWGreeter alloc] initWithHost:kHostAddress]; diff --git a/src/objective-c/GRPCClient/GRPCCall+ChannelArg.h b/src/objective-c/GRPCClient/GRPCCall+ChannelArg.h new file mode 100644 index 00000000000..11b2babbe72 --- /dev/null +++ b/src/objective-c/GRPCClient/GRPCCall+ChannelArg.h @@ -0,0 +1,52 @@ +/* + * + * Copyright 2016, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#import "GRPCCall.h" + +/** + * Methods to configure GRPC channel options for specific hosts. + */ +@interface GRPCCall (ChannelArg) + +/** + * Use the provided @c primaryUserAgent at the beginning of the HTTP User Agent string for the + * provided @c host. + */ ++ (void)usePrimaryUserAgent:(NSString *)primaryUserAgent forHost:(NSString *)host; + +/** + * Use the provided @c secondaryUserAgent at the end of the HTTP User Agent string for the + * provided @c host. + */ ++ (void)useSecondaryUserAgent:(NSString *)secondaryUserAgent forHost:(NSString *)host; + +@end diff --git a/src/objective-c/GRPCClient/GRPCCall+ChannelArg.m b/src/objective-c/GRPCClient/GRPCCall+ChannelArg.m new file mode 100644 index 00000000000..159e12c7e85 --- /dev/null +++ b/src/objective-c/GRPCClient/GRPCCall+ChannelArg.m @@ -0,0 +1,58 @@ +/* + * + * Copyright 2016, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#import "GRPCCall+ChannelArg.h" + +#import "private/GRPCHost.h" + +@implementation GRPCCall (ChannelArg) + ++ (void)usePrimaryUserAgent:(NSString *)primaryUserAgent forHost:(NSString *)host { + if (!primaryUserAgent || !host) { + [NSException raise:NSInvalidArgumentException + format:@"primaryUserAgent and host must be provided."]; + } + GRPCHost *hostConfig = [GRPCHost hostWithAddress:host]; + hostConfig.primaryUserAgent = primaryUserAgent; +} + ++ (void)useSecondaryUserAgent:(NSString *)secondaryUserAgent forHost:(NSString *)host { + if (!secondaryUserAgent || !host) { + [NSException raise:NSInvalidArgumentException + format:@"secondaryUserAgent and host must be provided."]; + } + GRPCHost *hostConfig = [GRPCHost hostWithAddress:host]; + hostConfig.secondaryUserAgent = secondaryUserAgent; +} + +@end diff --git a/src/objective-c/GRPCClient/private/GRPCHost.h b/src/objective-c/GRPCClient/private/GRPCHost.h index 6b4f98746d0..673ed9060ef 100644 --- a/src/objective-c/GRPCClient/private/GRPCHost.h +++ b/src/objective-c/GRPCClient/private/GRPCHost.h @@ -39,6 +39,8 @@ struct grpc_call; @interface GRPCHost : NSObject @property(nonatomic, readonly) NSString *address; +@property(nonatomic, copy) NSString *primaryUserAgent; +@property(nonatomic, copy) NSString *secondaryUserAgent; /** The following properties should only be modified for testing: */ diff --git a/src/objective-c/GRPCClient/private/GRPCHost.m b/src/objective-c/GRPCClient/private/GRPCHost.m index a8cd3a0e742..3ea89104d05 100644 --- a/src/objective-c/GRPCClient/private/GRPCHost.m +++ b/src/objective-c/GRPCClient/private/GRPCHost.m @@ -39,6 +39,7 @@ #import "GRPCCompletionQueue.h" #import "GRPCSecureChannel.h" #import "GRPCUnsecuredChannel.h" +#import "GRPCWrappedChannelArgs.h" @interface GRPCHost () // TODO(mlumish): Investigate whether caching channels with strong links is a good idea. @@ -107,12 +108,25 @@ // Create it lazily, because we don't want to open a connection just because someone is // configuring a host. if (!_channel) { + GRPCWrappedChannelArgsBuilder *argsBuilder = [[GRPCWrappedChannelArgsBuilder alloc] init]; + if (_primaryUserAgent) { + [argsBuilder addKey:@GRPC_ARG_PRIMARY_USER_AGENT_STRING stringValue:_primaryUserAgent]; + } + if (_secondaryUserAgent) { + [argsBuilder addKey:@GRPC_ARG_SECONDARY_USER_AGENT_STRING stringValue:_secondaryUserAgent]; + } + if (_secure) { + if (_hostNameOverride) { + [argsBuilder addKey:@GRPC_SSL_TARGET_NAME_OVERRIDE_ARG stringValue:_hostNameOverride]; + } + _channel = [[GRPCSecureChannel alloc] initWithHost:_address pathToCertificates:_pathToCertificates - hostNameOverride:_hostNameOverride]; + channelArgs:[argsBuilder build]]; } else { - _channel = [[GRPCUnsecuredChannel alloc] initWithHost:_address]; + _channel = [[GRPCUnsecuredChannel alloc] initWithHost:_address + channelArgs:[argsBuilder build]]; } } return _channel; diff --git a/src/objective-c/GRPCClient/private/GRPCSecureChannel.h b/src/objective-c/GRPCClient/private/GRPCSecureChannel.h index b82b9fe35ac..bbe01081cbf 100644 --- a/src/objective-c/GRPCClient/private/GRPCSecureChannel.h +++ b/src/objective-c/GRPCClient/private/GRPCSecureChannel.h @@ -35,21 +35,26 @@ #import "GRPCChannel.h" +@class GRPCWrappedChannelArgs; + struct grpc_channel_credentials; @interface GRPCSecureChannel : GRPCChannel - (instancetype)initWithHost:(NSString *)host; /** - * Only in tests shouldn't pathToCertificates or hostNameOverride be nil. Passing nil for - * pathToCertificates results in using the default root certificates distributed with the library. + * Only in tests should pathToCertificates or @c GRPC_SSL_TARGET_NAME_OVERRIDE_ARG arg be set. + * Passing nil for pathToCertificates results in using the default root certificates distributed + * with the library. */ - (instancetype)initWithHost:(NSString *)host pathToCertificates:(NSString *)path - hostNameOverride:(NSString *)hostNameOverride; + channelArgs:(GRPCWrappedChannelArgs *)channelArgs; -/** The passed arguments aren't required to be valid beyond the invocation of this initializer. */ +/** + * The passed arguments are copied and no longer needed after the invocation of this initializer. + */ - (instancetype)initWithHost:(NSString *)host credentials:(struct grpc_channel_credentials *)credentials - args:(grpc_channel_args *)args NS_DESIGNATED_INITIALIZER; + channelArgs:(GRPCWrappedChannelArgs *)channelArgs NS_DESIGNATED_INITIALIZER; @end diff --git a/src/objective-c/GRPCClient/private/GRPCSecureChannel.m b/src/objective-c/GRPCClient/private/GRPCSecureChannel.m index a573c171e93..156ff9b3441 100644 --- a/src/objective-c/GRPCClient/private/GRPCSecureChannel.m +++ b/src/objective-c/GRPCClient/private/GRPCSecureChannel.m @@ -34,6 +34,7 @@ #import "GRPCSecureChannel.h" #include +#import "GRPCWrappedChannelArgs.h" // Returns NULL if the file at path couldn't be read. In that case, if errorPtr isn't NULL, // *errorPtr will be an object describing what went wrong. @@ -55,12 +56,12 @@ static grpc_channel_credentials *CertificatesAtPath(NSString *path, NSError **er @implementation GRPCSecureChannel - (instancetype)initWithHost:(NSString *)host { - return [self initWithHost:host pathToCertificates:nil hostNameOverride:nil]; + return [self initWithHost:host pathToCertificates:nil channelArgs:nil]; } - (instancetype)initWithHost:(NSString *)host pathToCertificates:(NSString *)path - hostNameOverride:(NSString *)hostNameOverride { + channelArgs:(GRPCWrappedChannelArgs *)channelArgs { // Load default SSL certificates once. static grpc_channel_credentials *kDefaultCertificates; static dispatch_once_t loading; @@ -86,26 +87,20 @@ static grpc_channel_credentials *CertificatesAtPath(NSString *path, NSError **er return nil; } - // Ritual to pass the SSL host name override to the C library. - grpc_channel_args channelArgs; - grpc_arg nameOverrideArg; - channelArgs.num_args = 1; - channelArgs.args = &nameOverrideArg; - nameOverrideArg.type = GRPC_ARG_STRING; - nameOverrideArg.key = GRPC_SSL_TARGET_NAME_OVERRIDE_ARG; - // Cast const away. Hope C gRPC doesn't modify it! - nameOverrideArg.value.string = (char *) hostNameOverride.UTF8String; - grpc_channel_args *args = hostNameOverride ? &channelArgs : NULL; - - return [self initWithHost:host credentials:certificates args:args]; + return [self initWithHost:host credentials:certificates channelArgs:channelArgs]; } - (instancetype)initWithHost:(NSString *)host credentials:(grpc_channel_credentials *)credentials - args:(grpc_channel_args *)args { + channelArgs:(GRPCWrappedChannelArgs *)channelArgs { + grpc_channel_args args = (grpc_channel_args) { .num_args = 0, .args = NULL }; + if (channelArgs) { + args = channelArgs.channelArgs; + } + return (self = [super initWithChannel:grpc_secure_channel_create( - credentials, host.UTF8String, args, NULL)]); + credentials, host.UTF8String, &args, NULL)]); } // TODO(jcanizales): GRPCSecureChannel and GRPCUnsecuredChannel are just convenience initializers diff --git a/src/objective-c/GRPCClient/private/GRPCUnsecuredChannel.h b/src/objective-c/GRPCClient/private/GRPCUnsecuredChannel.h index 8528be44c00..b3190e8b0f5 100644 --- a/src/objective-c/GRPCClient/private/GRPCUnsecuredChannel.h +++ b/src/objective-c/GRPCClient/private/GRPCUnsecuredChannel.h @@ -33,6 +33,10 @@ #import "GRPCChannel.h" +@class GRPCWrappedChannelArgs; + @interface GRPCUnsecuredChannel : GRPCChannel -- (instancetype)initWithHost:(NSString *)host NS_DESIGNATED_INITIALIZER; +- (instancetype)initWithHost:(NSString *)host; +- (instancetype)initWithHost:(NSString *)host + channelArgs:(GRPCWrappedChannelArgs *)channelArgs NS_DESIGNATED_INITIALIZER; @end diff --git a/src/objective-c/GRPCClient/private/GRPCUnsecuredChannel.m b/src/objective-c/GRPCClient/private/GRPCUnsecuredChannel.m index 15b6ffc75cf..f349bb7783e 100644 --- a/src/objective-c/GRPCClient/private/GRPCUnsecuredChannel.m +++ b/src/objective-c/GRPCClient/private/GRPCUnsecuredChannel.m @@ -34,11 +34,22 @@ #import "GRPCUnsecuredChannel.h" #include +#import "GRPCWrappedChannelArgs.h" @implementation GRPCUnsecuredChannel - (instancetype)initWithHost:(NSString *)host { - return (self = [super initWithChannel:grpc_insecure_channel_create(host.UTF8String, NULL, NULL)]); + return [self initWithHost:host channelArgs:nil]; +} + +- (instancetype)initWithHost:(NSString *)host channelArgs:(GRPCWrappedChannelArgs *)channelArgs { + + grpc_channel_args args = (grpc_channel_args) { .num_args = 0, .args = NULL }; + if (channelArgs) { + args = channelArgs.channelArgs; + } + return (self = [super + initWithChannel:grpc_insecure_channel_create(host.UTF8String, &args, NULL)]); } // TODO(jcanizales): GRPCSecureChannel and GRPCUnsecuredChannel are just convenience initializers diff --git a/src/objective-c/GRPCClient/private/GRPCWrappedChannelArgs.h b/src/objective-c/GRPCClient/private/GRPCWrappedChannelArgs.h new file mode 100644 index 00000000000..3f1f5e6dee3 --- /dev/null +++ b/src/objective-c/GRPCClient/private/GRPCWrappedChannelArgs.h @@ -0,0 +1,29 @@ +#import + +#pragma mark - Wrapped Channel Arguments + +/** + * A wrapper @c grpc_channel_args that frees allocated memory used to copy key / value pairs by the + * @c GRPCWrappedChannelArgsBuilder. + */ +@interface GRPCWrappedChannelArgs : NSObject + +@property(nonatomic, readonly) grpc_channel_args channelArgs; + +- (instancetype)init NS_UNAVAILABLE; + +@end + +#pragma mark - Wrapped Channel Arguments Builder + +/** + * A builder that simplifies construction and usage of @c grpc_channel_args by building a + * @c GRPCWrappedChannelArgs. + */ +@interface GRPCWrappedChannelArgsBuilder : NSObject + +- (instancetype)addKey:(NSString *)key stringValue:(NSString *)value; +- (instancetype)addKey:(NSString *)key integerValue:(int)value; +- (GRPCWrappedChannelArgs *)build; + +@end \ No newline at end of file diff --git a/src/objective-c/GRPCClient/private/GRPCWrappedChannelArgs.m b/src/objective-c/GRPCClient/private/GRPCWrappedChannelArgs.m new file mode 100644 index 00000000000..c91b670db76 --- /dev/null +++ b/src/objective-c/GRPCClient/private/GRPCWrappedChannelArgs.m @@ -0,0 +1,188 @@ +#import "GRPCWrappedChannelArgs.h" + +#import + +#pragma mark - Argument Types + +@interface GRPCWrappedChannelArg : NSObject + +@property(nonatomic, readonly) NSString *grpc_key; + +- (instancetype)init NS_UNAVAILABLE; + +- (instancetype)initWithKey:(NSString *)key NS_DESIGNATED_INITIALIZER; + +@end + +@implementation GRPCWrappedChannelArg { + NSString *grpc_key_; +} + +- (instancetype)initWithKey:(NSString *)key { + GPR_ASSERT(key); + if (self = [super init]) { + grpc_key_ = [key copy]; + } + return self; +} + +- (NSString *)grpc_key { + return grpc_key_; +} + +@end + +#pragma mark String Argument Type + +@interface GRPCWrappedChannelStringArg : GRPCWrappedChannelArg + +@property(nonatomic, readonly) NSString *grpc_string; + +- (instancetype)initWithKey:(NSString *)key NS_UNAVAILABLE; + +- (instancetype)initWithKey:(NSString *)key value:(NSString *)value NS_DESIGNATED_INITIALIZER; + +@end + + +@implementation GRPCWrappedChannelStringArg { + NSString *grpc_value_; +} + +- (instancetype)initWithKey:(NSString *)key value:(NSString *)value { + GPR_ASSERT(value); + if (self = [super initWithKey:key]) { + grpc_value_ = [value copy]; + } + return self; +} + +- (NSString *)grpc_string { + return grpc_value_; +} + +@end + +#pragma mark Integer Argument Type + +@interface GRPCWrappedChannelIntegerArg : GRPCWrappedChannelArg + +@property(nonatomic, readonly) int grpc_integer; + +- (instancetype)initWithKey:(NSString *)key NS_UNAVAILABLE; + +- (instancetype)initWithKey:(NSString *)key value:(int)value NS_DESIGNATED_INITIALIZER; + +@end + + +@implementation GRPCWrappedChannelIntegerArg { + int grpc_value_; +} + +- (instancetype)initWithKey:(NSString *)key value:(int)value { + if (self = [super initWithKey:key]) { + grpc_value_ = value; + } + return self; +} + +- (int)grpc_integer { + return grpc_value_; +} + +@end + +#pragma mark - Wrapped Channel Arguments + +@interface GRPCWrappedChannelArgs () + +- (instancetype)initWithChannelArgs:(grpc_channel_args)channelArgs; + +@end + +@implementation GRPCWrappedChannelArgs { + grpc_channel_args channelArgs_; +} + +- (instancetype)initWithChannelArgs:(grpc_channel_args)channelArgs { + if (self = [super init]) { + channelArgs_ = channelArgs; + } + return self; +} + +- (grpc_channel_args)channelArgs { + return channelArgs_; +} + +- (void)dealloc { + for (size_t i = 0; i < channelArgs_.num_args; ++i) { + grpc_arg *arg = &channelArgs_.args[i]; + free(arg->key); + if (arg->type == GRPC_ARG_STRING) { + free(arg->value.string); + } + } + free(channelArgs_.args); +} + +@end + +#pragma mark - Wrapped Channel Arguments Builder + +@implementation GRPCWrappedChannelArgsBuilder { + NSMutableArray *args_; +} + +- (instancetype)init { + if (self = [super init]) { + args_ = [NSMutableArray array]; + } + return self; +} + +- (instancetype)addKey:(NSString *)key stringValue:(NSString *)value { + GRPCWrappedChannelStringArg *arg = [[GRPCWrappedChannelStringArg alloc] initWithKey:key value:value]; + [args_ addObject:arg]; + return self; +} + +- (instancetype)addKey:(NSString *)key integerValue:(int)value { + GRPCWrappedChannelIntegerArg *arg = [[GRPCWrappedChannelIntegerArg alloc] initWithKey:key value:value]; + [args_ addObject:arg]; + return self; +} + +- (GRPCWrappedChannelArgs *)build { + grpc_channel_args channelArgs; + + // channelArgs.args and contents is freed by GRPCWrappedChannelArgs::dealloc + channelArgs.num_args = args_.count; + channelArgs.args = (grpc_arg *) calloc(args_.count, sizeof(grpc_arg)); + + for (NSInteger i = 0; i < args_.count; ++i) { + if ([args_[i] respondsToSelector:@selector(grpc_string)]) { + GRPCWrappedChannelStringArg *arg = (GRPCWrappedChannelStringArg *)args_[i]; + grpc_arg *wrappedArg = &channelArgs.args[i]; + wrappedArg->key = strdup(arg.grpc_key.UTF8String); + wrappedArg->type = GRPC_ARG_STRING; + wrappedArg->value.string = strdup(arg.grpc_string.UTF8String); + GPR_ASSERT(wrappedArg->key); + GPR_ASSERT(wrappedArg->value.string); + } else if ([args_[i] respondsToSelector:@selector(grpc_integer)]) { + GRPCWrappedChannelIntegerArg *arg = (GRPCWrappedChannelIntegerArg *)args_[i]; + grpc_arg *wrappedArg = &channelArgs.args[i]; + wrappedArg->key = strdup(arg.grpc_key.UTF8String); + wrappedArg->type = GRPC_ARG_INTEGER; + wrappedArg->value.integer = arg.grpc_integer; + GPR_ASSERT(wrappedArg->key); + } else { + GPR_ASSERT(0); // Argument type not recognized + } + } + + return [[GRPCWrappedChannelArgs alloc] initWithChannelArgs:channelArgs]; +} + +@end From 85bf57410602e8a706867f3bda7fa06af6dfde91 Mon Sep 17 00:00:00 2001 From: Kristopher Wuollett Date: Sun, 31 Jan 2016 14:34:43 -0500 Subject: [PATCH 02/55] Fixed some formatting --- src/objective-c/GRPCClient/private/GRPCUnsecuredChannel.m | 1 - src/objective-c/GRPCClient/private/GRPCWrappedChannelArgs.h | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/objective-c/GRPCClient/private/GRPCUnsecuredChannel.m b/src/objective-c/GRPCClient/private/GRPCUnsecuredChannel.m index f349bb7783e..d0640e600b2 100644 --- a/src/objective-c/GRPCClient/private/GRPCUnsecuredChannel.m +++ b/src/objective-c/GRPCClient/private/GRPCUnsecuredChannel.m @@ -43,7 +43,6 @@ } - (instancetype)initWithHost:(NSString *)host channelArgs:(GRPCWrappedChannelArgs *)channelArgs { - grpc_channel_args args = (grpc_channel_args) { .num_args = 0, .args = NULL }; if (channelArgs) { args = channelArgs.channelArgs; diff --git a/src/objective-c/GRPCClient/private/GRPCWrappedChannelArgs.h b/src/objective-c/GRPCClient/private/GRPCWrappedChannelArgs.h index 3f1f5e6dee3..e9cb054ab8b 100644 --- a/src/objective-c/GRPCClient/private/GRPCWrappedChannelArgs.h +++ b/src/objective-c/GRPCClient/private/GRPCWrappedChannelArgs.h @@ -26,4 +26,4 @@ - (instancetype)addKey:(NSString *)key integerValue:(int)value; - (GRPCWrappedChannelArgs *)build; -@end \ No newline at end of file +@end From 96d9dc34ffd48e45a4ecdb7aedc5906e336d9517 Mon Sep 17 00:00:00 2001 From: Dan Born Date: Tue, 2 Feb 2016 14:57:36 -0800 Subject: [PATCH 03/55] Fix comments in tcp_server.h --- src/core/iomgr/tcp_server.h | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/core/iomgr/tcp_server.h b/src/core/iomgr/tcp_server.h index 8f3184ff1e0..a39dd3bafce 100644 --- a/src/core/iomgr/tcp_server.h +++ b/src/core/iomgr/tcp_server.h @@ -40,15 +40,14 @@ /* Forward decl of grpc_tcp_server */ typedef struct grpc_tcp_server grpc_tcp_server; -typedef struct grpc_tcp_server_acceptor grpc_tcp_server_acceptor; -struct grpc_tcp_server_acceptor { +typedef struct grpc_tcp_server_acceptor { /* grpc_tcp_server_cb functions share a ref on from_server that is valid until the function returns. */ grpc_tcp_server *from_server; /* Indices that may be passed to grpc_tcp_server_port_fd(). */ unsigned port_index; unsigned fd_index; -}; +} grpc_tcp_server_acceptor; /* Called for newly connected TCP connections. */ typedef void (*grpc_tcp_server_cb)(grpc_exec_ctx *exec_ctx, void *arg, @@ -57,7 +56,7 @@ typedef void (*grpc_tcp_server_cb)(grpc_exec_ctx *exec_ctx, void *arg, /* Create a server, initially not bound to any ports. The caller owns one ref. If shutdown_complete is not NULL, it will be used by - grpc_tcp_server_unref(). */ + grpc_tcp_server_unref() when the ref count reaches zero. */ grpc_tcp_server *grpc_tcp_server_create(grpc_closure *shutdown_complete); /* Start listening to bound ports */ @@ -84,7 +83,7 @@ unsigned grpc_tcp_server_port_fd_count(grpc_tcp_server *s, unsigned port_index); /* Returns the file descriptor of the Mth (fd_index) listening socket of the Nth (port_index) call to add_port() on this server, or -1 if the indices are out of bounds. The file descriptor remains owned by the server, and will be - cleaned up when grpc_tcp_server_destroy is called. */ + cleaned up when the ref count reaches zero. */ int grpc_tcp_server_port_fd(grpc_tcp_server *s, unsigned port_index, unsigned fd_index); @@ -97,7 +96,7 @@ grpc_tcp_server *grpc_tcp_server_ref(grpc_tcp_server *s); void grpc_tcp_server_shutdown_starting_add(grpc_tcp_server *s, grpc_closure *shutdown_starting); -/* If the recount drops to zero, delete s, and call (exec_ctx==NULL) or enqueue +/* If the refcount drops to zero, delete s, and call (exec_ctx==NULL) or enqueue a call (exec_ctx!=NULL) to shutdown_complete. */ void grpc_tcp_server_unref(grpc_exec_ctx *exec_ctx, grpc_tcp_server *s); From 2c6d2bd32787f9bdce1d46875dfee39e08881a3b Mon Sep 17 00:00:00 2001 From: Kristopher Wuollett Date: Tue, 2 Feb 2016 20:23:11 -0500 Subject: [PATCH 04/55] Removed (un)secure channel subclasses --- .../GRPCClient/private/GRPCChannel.h | 45 ++++- .../GRPCClient/private/GRPCChannel.m | 153 +++++++++++++- src/objective-c/GRPCClient/private/GRPCHost.m | 22 +- .../GRPCClient/private/GRPCSecureChannel.h | 60 ------ .../GRPCClient/private/GRPCSecureChannel.m | 113 ----------- .../GRPCClient/private/GRPCUnsecuredChannel.h | 42 ---- .../GRPCClient/private/GRPCUnsecuredChannel.m | 60 ------ .../private/GRPCWrappedChannelArgs.h | 29 --- .../private/GRPCWrappedChannelArgs.m | 188 ------------------ 9 files changed, 193 insertions(+), 519 deletions(-) delete mode 100644 src/objective-c/GRPCClient/private/GRPCSecureChannel.h delete mode 100644 src/objective-c/GRPCClient/private/GRPCSecureChannel.m delete mode 100644 src/objective-c/GRPCClient/private/GRPCUnsecuredChannel.h delete mode 100644 src/objective-c/GRPCClient/private/GRPCUnsecuredChannel.m delete mode 100644 src/objective-c/GRPCClient/private/GRPCWrappedChannelArgs.h delete mode 100644 src/objective-c/GRPCClient/private/GRPCWrappedChannelArgs.m diff --git a/src/objective-c/GRPCClient/private/GRPCChannel.h b/src/objective-c/GRPCClient/private/GRPCChannel.h index e2d19d506ad..3e277b0f1a3 100644 --- a/src/objective-c/GRPCClient/private/GRPCChannel.h +++ b/src/objective-c/GRPCClient/private/GRPCChannel.h @@ -33,18 +33,51 @@ #import -struct grpc_channel; +#include + +struct grpc_channel_credentials; + /** * Each separate instance of this class represents at least one TCP connection to the provided host. - * Create them using one of the subclasses |GRPCSecureChannel| and |GRPCUnsecuredChannel|. */ @interface GRPCChannel : NSObject -@property(nonatomic, readonly) struct grpc_channel *unmanagedChannel; +@property(nonatomic, readonly, nonnull) struct grpc_channel *unmanagedChannel; +@property(nonatomic, readonly, getter=isSecure) BOOL secure; + +- (nullable instancetype)init NS_UNAVAILABLE; + +/** + * Creates a secure channel to the specified @c host using default credentials and channel + * arguments. If certificates could not be found to create a secure channel, then @c nil is + * returned. + */ ++ (nullable GRPCChannel *)secureChannelWithHost:(nonnull NSString *)host; + +/** + * Creates a secure channel to the specified @c host using the specified @c pathToCertificates and + * @c channelArgs. Only in tests should @c pathToCertificates be nil or + * @c GRPC_SSL_TARGET_NAME_OVERRIDE_ARG channel arg be set. Passing nil for @c pathToCertificates + * results in using the default root certificates distributed with the library. If certificates + * could not be found in any case, then @c nil is returned. + */ ++ (nullable GRPCChannel *)secureChannelWithHost:(nonnull NSString *)host + pathToCertificates:(nullable NSString *)pathToCertificates + channelArgs:(nullable NSDictionary *)channelArgs; + /** - * This initializer takes ownership of the passed channel, and will destroy it when this object is - * deallocated. It's illegal to pass the same grpc_channel to two different GRPCChannel objects. + * Creates a secure channel to the specified @c host using the specified @c credentials and + * @c channelArgs. Only in tests should @c GRPC_SSL_TARGET_NAME_OVERRIDE_ARG channel arg be set. */ -- (instancetype)initWithChannel:(struct grpc_channel *)unmanagedChannel NS_DESIGNATED_INITIALIZER; ++ (nonnull GRPCChannel *)secureChannelWithHost:(nonnull NSString *)host + credentials:(nonnull struct grpc_channel_credentials *)credentials + channelArgs:(nullable NSDictionary *)channelArgs; + +/** + * Creates an insecure channel to the specified @c host using the specified @c channelArgs. + */ ++ (nonnull GRPCChannel *)insecureChannelWithHost:(nonnull NSString *)host + channelArgs:(nullable NSDictionary *)channelArgs; + @end diff --git a/src/objective-c/GRPCClient/private/GRPCChannel.m b/src/objective-c/GRPCClient/private/GRPCChannel.m index 4366e633208..5aecdb1cbeb 100644 --- a/src/objective-c/GRPCClient/private/GRPCChannel.m +++ b/src/objective-c/GRPCClient/private/GRPCChannel.m @@ -33,22 +33,101 @@ #import "GRPCChannel.h" -#include +#include +#include +#include -@implementation GRPCChannel +/** + * Returns @c grpc_channel_credentials from the specifie @c path. If the file at the path could not + * be read then NULL is returned. If NULL is returned, @c errorPtr may not be NULL if there are + * details available describing what went wrong. + */ +static grpc_channel_credentials *CertificatesAtPath(NSString *path, NSError **errorPtr) { + // Files in PEM format can have non-ASCII characters in their comments (e.g. for the name of the + // issuer). Load them as UTF8 and produce an ASCII equivalent. + NSString *contentInUTF8 = [NSString stringWithContentsOfFile:path + encoding:NSUTF8StringEncoding + error:errorPtr]; + NSData *contentInASCII = [contentInUTF8 dataUsingEncoding:NSASCIIStringEncoding + allowLossyConversion:YES]; + if (!contentInASCII.bytes) { + // Passing NULL to grpc_ssl_credentials_create produces behavior we don't want, so return. + return NULL; + } + return grpc_ssl_credentials_create(contentInASCII.bytes, NULL, NULL); +} + +/** + * Allocates a @c grpc_channel_args and populates it with the options specified in the + * @c dictionary. Keys must be @c NSString. If the value responds to @c @selector(UTF8String) then + * it will be mapped to @c GRPC_ARG_STRING. If not, it will be mapped to @c GRPC_ARG_INTEGER if the + * value responds to @c @selector(intValue). Otherwise, an exception will be raised. + */ +grpc_channel_args * buildChannelArgs(NSDictionary *dictionary) { + if (!dictionary) { + return NULL; + } + + NSUInteger argCount = [dictionary count]; + + // Allocate memory for both the individual args and their container + grpc_channel_args *channelArgs = gpr_malloc(sizeof(grpc_channel_args) + + argCount * sizeof(grpc_arg)); + channelArgs->num_args = argCount; + channelArgs->args = (grpc_arg *) (channelArgs + sizeof(grpc_channel_args)); -- (instancetype)init { - return [self initWithChannel:NULL]; + __block NSUInteger argIndex = 0; + [dictionary enumerateKeysAndObjectsUsingBlock:^(id _Nonnull key, id _Nonnull obj, + BOOL * _Nonnull stop) { + // use of UTF8String assumes that grpc won't modify the pointers + grpc_arg *arg = &channelArgs->args[argIndex++]; + arg->key = (char *) [key UTF8String]; // allow exception to be raised if not supported + + if ([obj respondsToSelector:@selector(UTF8String)]) { + arg->type = GRPC_ARG_STRING; + arg->value.string = (char *) [obj UTF8String]; + } else if ([obj respondsToSelector:@selector(intValue)]) { + arg->type = GRPC_ARG_INTEGER; + arg->value.integer = [obj intValue]; + } else { + [NSException raise:NSInvalidArgumentException format:@"Invalid value type: %@", [obj class]]; + } + }]; + + return channelArgs; +} + +@implementation GRPCChannel { + // Retain arguments to channel_create because they may not be used on the thread that invoked + // the channel_create function. + NSString *_host; + grpc_channel_args *_channelArgs; } -// Designated initializer -- (instancetype)initWithChannel:(grpc_channel *)unmanagedChannel { - if (!unmanagedChannel) { + +- (instancetype)initWithHost:(NSString *)host + secure:(BOOL)secure + credentials:(struct grpc_channel_credentials *)credentials + channelArgs:(NSDictionary *)channelArgs { + if (!host) { + [NSException raise:NSInvalidArgumentException format:@"host argument missing"]; + } + + if (secure && !credentials) { return nil; } - if ((self = [super init])) { - _unmanagedChannel = unmanagedChannel; + + if (self = [super init]) { + _channelArgs = buildChannelArgs(channelArgs); + _host = [host copy]; + if (secure) { + _unmanagedChannel = grpc_secure_channel_create(credentials, _host.UTF8String, _channelArgs, + NULL); + } else { + _unmanagedChannel = grpc_insecure_channel_create(host.UTF8String, _channelArgs, NULL); + } } + return self; } @@ -56,5 +135,61 @@ // TODO(jcanizales): Be sure to add a test with a server that closes the connection prematurely, // as in the past that made this call to crash. grpc_channel_destroy(_unmanagedChannel); + gpr_free(_channelArgs); +} + ++ (GRPCChannel *)secureChannelWithHost:(NSString *)host { + return [[GRPCChannel alloc] initWithHost:host secure:YES credentials:NULL channelArgs:NULL]; +} + ++ (GRPCChannel *)secureChannelWithHost:(NSString *)host + pathToCertificates:(NSString *)path + channelArgs:(NSDictionary *)channelArgs { + // Load default SSL certificates once. + static grpc_channel_credentials *kDefaultCertificates; + static dispatch_once_t loading; + dispatch_once(&loading, ^{ + NSString *defaultPath = @"gRPCCertificates.bundle/roots"; // .pem + // Do not use NSBundle.mainBundle, as it's nil for tests of library projects. + NSBundle *bundle = [NSBundle bundleForClass:self.class]; + NSString *path = [bundle pathForResource:defaultPath ofType:@"pem"]; + NSError *error; + kDefaultCertificates = CertificatesAtPath(path, &error); + NSAssert(kDefaultCertificates, @"Could not read %@/%@.pem. This file, with the root " + "certificates, is needed to establish secure (TLS) connections. Because the file is " + "distributed with the gRPC library, this error is usually a sign that the library " + "wasn't configured correctly for your project. Error: %@", + bundle.bundlePath, defaultPath, error); + }); + + //TODO(jcanizales): Add NSError** parameter to the initializer. + grpc_channel_credentials *certificates = path + ? CertificatesAtPath(path, NULL) + : kDefaultCertificates; + + return [[GRPCChannel alloc] initWithHost:host + secure:YES + credentials:certificates + channelArgs:channelArgs]; } + + ++ (GRPCChannel *)secureChannelWithHost:(NSString *)host + credentials:(struct grpc_channel_credentials *)credentials + channelArgs:(NSDictionary *)channelArgs { + return [[GRPCChannel alloc] initWithHost:host + secure:YES + credentials:credentials + channelArgs:channelArgs]; + +} + ++ (GRPCChannel *)insecureChannelWithHost:(NSString *)host + channelArgs:(NSDictionary *)channelArgs { + return [[GRPCChannel alloc] initWithHost:host + secure:NO + credentials:NULL + channelArgs:channelArgs]; +} + @end diff --git a/src/objective-c/GRPCClient/private/GRPCHost.m b/src/objective-c/GRPCClient/private/GRPCHost.m index 3ea89104d05..5a21df523f2 100644 --- a/src/objective-c/GRPCClient/private/GRPCHost.m +++ b/src/objective-c/GRPCClient/private/GRPCHost.m @@ -37,9 +37,7 @@ #import "GRPCChannel.h" #import "GRPCCompletionQueue.h" -#import "GRPCSecureChannel.h" -#import "GRPCUnsecuredChannel.h" -#import "GRPCWrappedChannelArgs.h" +#import "NSDictionary+GRPC.h" @interface GRPCHost () // TODO(mlumish): Investigate whether caching channels with strong links is a good idea. @@ -107,26 +105,26 @@ - (GRPCChannel *)channel { // Create it lazily, because we don't want to open a connection just because someone is // configuring a host. + if (!_channel) { - GRPCWrappedChannelArgsBuilder *argsBuilder = [[GRPCWrappedChannelArgsBuilder alloc] init]; + NSMutableDictionary *args = [NSMutableDictionary dictionary]; if (_primaryUserAgent) { - [argsBuilder addKey:@GRPC_ARG_PRIMARY_USER_AGENT_STRING stringValue:_primaryUserAgent]; + args[@GRPC_ARG_PRIMARY_USER_AGENT_STRING] = _primaryUserAgent; } if (_secondaryUserAgent) { - [argsBuilder addKey:@GRPC_ARG_SECONDARY_USER_AGENT_STRING stringValue:_secondaryUserAgent]; + args[@GRPC_ARG_SECONDARY_USER_AGENT_STRING] = _secondaryUserAgent; } if (_secure) { if (_hostNameOverride) { - [argsBuilder addKey:@GRPC_SSL_TARGET_NAME_OVERRIDE_ARG stringValue:_hostNameOverride]; + args[@GRPC_SSL_TARGET_NAME_OVERRIDE_ARG] = _hostNameOverride; } - _channel = [[GRPCSecureChannel alloc] initWithHost:_address - pathToCertificates:_pathToCertificates - channelArgs:[argsBuilder build]]; + _channel = [GRPCChannel secureChannelWithHost:_address + pathToCertificates:_pathToCertificates + channelArgs:args]; } else { - _channel = [[GRPCUnsecuredChannel alloc] initWithHost:_address - channelArgs:[argsBuilder build]]; + _channel = [GRPCChannel insecureChannelWithHost:_address channelArgs:args]; } } return _channel; diff --git a/src/objective-c/GRPCClient/private/GRPCSecureChannel.h b/src/objective-c/GRPCClient/private/GRPCSecureChannel.h deleted file mode 100644 index bbe01081cbf..00000000000 --- a/src/objective-c/GRPCClient/private/GRPCSecureChannel.h +++ /dev/null @@ -1,60 +0,0 @@ -/* - * - * Copyright 2015, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#include - -#import "GRPCChannel.h" - -@class GRPCWrappedChannelArgs; - -struct grpc_channel_credentials; - -@interface GRPCSecureChannel : GRPCChannel -- (instancetype)initWithHost:(NSString *)host; - -/** - * Only in tests should pathToCertificates or @c GRPC_SSL_TARGET_NAME_OVERRIDE_ARG arg be set. - * Passing nil for pathToCertificates results in using the default root certificates distributed - * with the library. - */ -- (instancetype)initWithHost:(NSString *)host - pathToCertificates:(NSString *)path - channelArgs:(GRPCWrappedChannelArgs *)channelArgs; - -/** - * The passed arguments are copied and no longer needed after the invocation of this initializer. - */ -- (instancetype)initWithHost:(NSString *)host - credentials:(struct grpc_channel_credentials *)credentials - channelArgs:(GRPCWrappedChannelArgs *)channelArgs NS_DESIGNATED_INITIALIZER; -@end diff --git a/src/objective-c/GRPCClient/private/GRPCSecureChannel.m b/src/objective-c/GRPCClient/private/GRPCSecureChannel.m deleted file mode 100644 index 156ff9b3441..00000000000 --- a/src/objective-c/GRPCClient/private/GRPCSecureChannel.m +++ /dev/null @@ -1,113 +0,0 @@ -/* - * - * Copyright 2015, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#import "GRPCSecureChannel.h" - -#include -#import "GRPCWrappedChannelArgs.h" - -// Returns NULL if the file at path couldn't be read. In that case, if errorPtr isn't NULL, -// *errorPtr will be an object describing what went wrong. -static grpc_channel_credentials *CertificatesAtPath(NSString *path, NSError **errorPtr) { - // Files in PEM format can have non-ASCII characters in their comments (e.g. for the name of the - // issuer). Load them as UTF8 and produce an ASCII equivalent. - NSString *contentInUTF8 = [NSString stringWithContentsOfFile:path - encoding:NSUTF8StringEncoding - error:errorPtr]; - NSData *contentInASCII = [contentInUTF8 dataUsingEncoding:NSASCIIStringEncoding - allowLossyConversion:YES]; - if (!contentInASCII.bytes) { - // Passing NULL to grpc_ssl_credentials_create produces behavior we don't want, so return. - return NULL; - } - return grpc_ssl_credentials_create(contentInASCII.bytes, NULL, NULL); -} - -@implementation GRPCSecureChannel - -- (instancetype)initWithHost:(NSString *)host { - return [self initWithHost:host pathToCertificates:nil channelArgs:nil]; -} - -- (instancetype)initWithHost:(NSString *)host - pathToCertificates:(NSString *)path - channelArgs:(GRPCWrappedChannelArgs *)channelArgs { - // Load default SSL certificates once. - static grpc_channel_credentials *kDefaultCertificates; - static dispatch_once_t loading; - dispatch_once(&loading, ^{ - NSString *defaultPath = @"gRPCCertificates.bundle/roots"; // .pem - // Do not use NSBundle.mainBundle, as it's nil for tests of library projects. - NSBundle *bundle = [NSBundle bundleForClass:self.class]; - NSString *path = [bundle pathForResource:defaultPath ofType:@"pem"]; - NSError *error; - kDefaultCertificates = CertificatesAtPath(path, &error); - NSAssert(kDefaultCertificates, @"Could not read %@/%@.pem. This file, with the root " - "certificates, is needed to establish secure (TLS) connections. Because the file is " - "distributed with the gRPC library, this error is usually a sign that the library " - "wasn't configured correctly for your project. Error: %@", - bundle.bundlePath, defaultPath, error); - }); - - //TODO(jcanizales): Add NSError** parameter to the initializer. - grpc_channel_credentials *certificates = path - ? CertificatesAtPath(path, NULL) - : kDefaultCertificates; - if (!certificates) { - return nil; - } - - return [self initWithHost:host credentials:certificates channelArgs:channelArgs]; -} - -- (instancetype)initWithHost:(NSString *)host - credentials:(grpc_channel_credentials *)credentials - channelArgs:(GRPCWrappedChannelArgs *)channelArgs { - grpc_channel_args args = (grpc_channel_args) { .num_args = 0, .args = NULL }; - if (channelArgs) { - args = channelArgs.channelArgs; - } - - return (self = [super - initWithChannel:grpc_secure_channel_create( - credentials, host.UTF8String, &args, NULL)]); -} - -// TODO(jcanizales): GRPCSecureChannel and GRPCUnsecuredChannel are just convenience initializers -// for GRPCChannel. Move them into GRPCChannel, which will make the following unnecessary. -- (instancetype)initWithChannel:(grpc_channel *)unmanagedChannel { - [NSException raise:NSInternalInconsistencyException format:@"use another initializer"]; - return [self initWithHost:nil]; // silence warnings -} - -@end diff --git a/src/objective-c/GRPCClient/private/GRPCUnsecuredChannel.h b/src/objective-c/GRPCClient/private/GRPCUnsecuredChannel.h deleted file mode 100644 index b3190e8b0f5..00000000000 --- a/src/objective-c/GRPCClient/private/GRPCUnsecuredChannel.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * - * Copyright 2015, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#import "GRPCChannel.h" - -@class GRPCWrappedChannelArgs; - -@interface GRPCUnsecuredChannel : GRPCChannel -- (instancetype)initWithHost:(NSString *)host; -- (instancetype)initWithHost:(NSString *)host - channelArgs:(GRPCWrappedChannelArgs *)channelArgs NS_DESIGNATED_INITIALIZER; -@end diff --git a/src/objective-c/GRPCClient/private/GRPCUnsecuredChannel.m b/src/objective-c/GRPCClient/private/GRPCUnsecuredChannel.m deleted file mode 100644 index d0640e600b2..00000000000 --- a/src/objective-c/GRPCClient/private/GRPCUnsecuredChannel.m +++ /dev/null @@ -1,60 +0,0 @@ -/* - * - * Copyright 2015, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#import "GRPCUnsecuredChannel.h" - -#include -#import "GRPCWrappedChannelArgs.h" - -@implementation GRPCUnsecuredChannel - -- (instancetype)initWithHost:(NSString *)host { - return [self initWithHost:host channelArgs:nil]; -} - -- (instancetype)initWithHost:(NSString *)host channelArgs:(GRPCWrappedChannelArgs *)channelArgs { - grpc_channel_args args = (grpc_channel_args) { .num_args = 0, .args = NULL }; - if (channelArgs) { - args = channelArgs.channelArgs; - } - return (self = [super - initWithChannel:grpc_insecure_channel_create(host.UTF8String, &args, NULL)]); -} - -// TODO(jcanizales): GRPCSecureChannel and GRPCUnsecuredChannel are just convenience initializers -// for GRPCChannel. Move them into GRPCChannel, which will make the following unnecessary. -- (instancetype)initWithChannel:(grpc_channel *)unmanagedChannel { - [NSException raise:NSInternalInconsistencyException format:@"use the other initializer"]; - return [self initWithHost:nil]; // silence warnings -} -@end diff --git a/src/objective-c/GRPCClient/private/GRPCWrappedChannelArgs.h b/src/objective-c/GRPCClient/private/GRPCWrappedChannelArgs.h deleted file mode 100644 index e9cb054ab8b..00000000000 --- a/src/objective-c/GRPCClient/private/GRPCWrappedChannelArgs.h +++ /dev/null @@ -1,29 +0,0 @@ -#import - -#pragma mark - Wrapped Channel Arguments - -/** - * A wrapper @c grpc_channel_args that frees allocated memory used to copy key / value pairs by the - * @c GRPCWrappedChannelArgsBuilder. - */ -@interface GRPCWrappedChannelArgs : NSObject - -@property(nonatomic, readonly) grpc_channel_args channelArgs; - -- (instancetype)init NS_UNAVAILABLE; - -@end - -#pragma mark - Wrapped Channel Arguments Builder - -/** - * A builder that simplifies construction and usage of @c grpc_channel_args by building a - * @c GRPCWrappedChannelArgs. - */ -@interface GRPCWrappedChannelArgsBuilder : NSObject - -- (instancetype)addKey:(NSString *)key stringValue:(NSString *)value; -- (instancetype)addKey:(NSString *)key integerValue:(int)value; -- (GRPCWrappedChannelArgs *)build; - -@end diff --git a/src/objective-c/GRPCClient/private/GRPCWrappedChannelArgs.m b/src/objective-c/GRPCClient/private/GRPCWrappedChannelArgs.m deleted file mode 100644 index c91b670db76..00000000000 --- a/src/objective-c/GRPCClient/private/GRPCWrappedChannelArgs.m +++ /dev/null @@ -1,188 +0,0 @@ -#import "GRPCWrappedChannelArgs.h" - -#import - -#pragma mark - Argument Types - -@interface GRPCWrappedChannelArg : NSObject - -@property(nonatomic, readonly) NSString *grpc_key; - -- (instancetype)init NS_UNAVAILABLE; - -- (instancetype)initWithKey:(NSString *)key NS_DESIGNATED_INITIALIZER; - -@end - -@implementation GRPCWrappedChannelArg { - NSString *grpc_key_; -} - -- (instancetype)initWithKey:(NSString *)key { - GPR_ASSERT(key); - if (self = [super init]) { - grpc_key_ = [key copy]; - } - return self; -} - -- (NSString *)grpc_key { - return grpc_key_; -} - -@end - -#pragma mark String Argument Type - -@interface GRPCWrappedChannelStringArg : GRPCWrappedChannelArg - -@property(nonatomic, readonly) NSString *grpc_string; - -- (instancetype)initWithKey:(NSString *)key NS_UNAVAILABLE; - -- (instancetype)initWithKey:(NSString *)key value:(NSString *)value NS_DESIGNATED_INITIALIZER; - -@end - - -@implementation GRPCWrappedChannelStringArg { - NSString *grpc_value_; -} - -- (instancetype)initWithKey:(NSString *)key value:(NSString *)value { - GPR_ASSERT(value); - if (self = [super initWithKey:key]) { - grpc_value_ = [value copy]; - } - return self; -} - -- (NSString *)grpc_string { - return grpc_value_; -} - -@end - -#pragma mark Integer Argument Type - -@interface GRPCWrappedChannelIntegerArg : GRPCWrappedChannelArg - -@property(nonatomic, readonly) int grpc_integer; - -- (instancetype)initWithKey:(NSString *)key NS_UNAVAILABLE; - -- (instancetype)initWithKey:(NSString *)key value:(int)value NS_DESIGNATED_INITIALIZER; - -@end - - -@implementation GRPCWrappedChannelIntegerArg { - int grpc_value_; -} - -- (instancetype)initWithKey:(NSString *)key value:(int)value { - if (self = [super initWithKey:key]) { - grpc_value_ = value; - } - return self; -} - -- (int)grpc_integer { - return grpc_value_; -} - -@end - -#pragma mark - Wrapped Channel Arguments - -@interface GRPCWrappedChannelArgs () - -- (instancetype)initWithChannelArgs:(grpc_channel_args)channelArgs; - -@end - -@implementation GRPCWrappedChannelArgs { - grpc_channel_args channelArgs_; -} - -- (instancetype)initWithChannelArgs:(grpc_channel_args)channelArgs { - if (self = [super init]) { - channelArgs_ = channelArgs; - } - return self; -} - -- (grpc_channel_args)channelArgs { - return channelArgs_; -} - -- (void)dealloc { - for (size_t i = 0; i < channelArgs_.num_args; ++i) { - grpc_arg *arg = &channelArgs_.args[i]; - free(arg->key); - if (arg->type == GRPC_ARG_STRING) { - free(arg->value.string); - } - } - free(channelArgs_.args); -} - -@end - -#pragma mark - Wrapped Channel Arguments Builder - -@implementation GRPCWrappedChannelArgsBuilder { - NSMutableArray *args_; -} - -- (instancetype)init { - if (self = [super init]) { - args_ = [NSMutableArray array]; - } - return self; -} - -- (instancetype)addKey:(NSString *)key stringValue:(NSString *)value { - GRPCWrappedChannelStringArg *arg = [[GRPCWrappedChannelStringArg alloc] initWithKey:key value:value]; - [args_ addObject:arg]; - return self; -} - -- (instancetype)addKey:(NSString *)key integerValue:(int)value { - GRPCWrappedChannelIntegerArg *arg = [[GRPCWrappedChannelIntegerArg alloc] initWithKey:key value:value]; - [args_ addObject:arg]; - return self; -} - -- (GRPCWrappedChannelArgs *)build { - grpc_channel_args channelArgs; - - // channelArgs.args and contents is freed by GRPCWrappedChannelArgs::dealloc - channelArgs.num_args = args_.count; - channelArgs.args = (grpc_arg *) calloc(args_.count, sizeof(grpc_arg)); - - for (NSInteger i = 0; i < args_.count; ++i) { - if ([args_[i] respondsToSelector:@selector(grpc_string)]) { - GRPCWrappedChannelStringArg *arg = (GRPCWrappedChannelStringArg *)args_[i]; - grpc_arg *wrappedArg = &channelArgs.args[i]; - wrappedArg->key = strdup(arg.grpc_key.UTF8String); - wrappedArg->type = GRPC_ARG_STRING; - wrappedArg->value.string = strdup(arg.grpc_string.UTF8String); - GPR_ASSERT(wrappedArg->key); - GPR_ASSERT(wrappedArg->value.string); - } else if ([args_[i] respondsToSelector:@selector(grpc_integer)]) { - GRPCWrappedChannelIntegerArg *arg = (GRPCWrappedChannelIntegerArg *)args_[i]; - grpc_arg *wrappedArg = &channelArgs.args[i]; - wrappedArg->key = strdup(arg.grpc_key.UTF8String); - wrappedArg->type = GRPC_ARG_INTEGER; - wrappedArg->value.integer = arg.grpc_integer; - GPR_ASSERT(wrappedArg->key); - } else { - GPR_ASSERT(0); // Argument type not recognized - } - } - - return [[GRPCWrappedChannelArgs alloc] initWithChannelArgs:channelArgs]; -} - -@end From 300f7e43225e21490dd7de3165d6fac3e29d2d5d Mon Sep 17 00:00:00 2001 From: Kristopher Wuollett Date: Tue, 2 Feb 2016 22:38:40 -0500 Subject: [PATCH 05/55] Renamed user agent setting to userAgentPrefix and changed its scope to global --- examples/objective-c/helloworld/main.m | 2 +- .../GRPCClient/GRPCCall+ChannelArg.h | 13 ++++-------- .../GRPCClient/GRPCCall+ChannelArg.m | 20 ++++++++----------- .../GRPCClient/private/GRPCChannel.h | 2 +- src/objective-c/GRPCClient/private/GRPCHost.h | 2 -- src/objective-c/GRPCClient/private/GRPCHost.m | 9 ++++----- 6 files changed, 18 insertions(+), 30 deletions(-) diff --git a/examples/objective-c/helloworld/main.m b/examples/objective-c/helloworld/main.m index f390b5a0f9b..b67380812b4 100644 --- a/examples/objective-c/helloworld/main.m +++ b/examples/objective-c/helloworld/main.m @@ -43,7 +43,7 @@ static NSString * const kHostAddress = @"localhost:50051"; int main(int argc, char * argv[]) { @autoreleasepool { [GRPCCall useInsecureConnectionsForHost:kHostAddress]; - [GRPCCall usePrimaryUserAgent:@"HelloWorld/1.0" forHost:kHostAddress]; + [GRPCCall setUserAgentPrefix:@"HelloWorld/1.0"]; HLWGreeter *client = [[HLWGreeter alloc] initWithHost:kHostAddress]; diff --git a/src/objective-c/GRPCClient/GRPCCall+ChannelArg.h b/src/objective-c/GRPCClient/GRPCCall+ChannelArg.h index 11b2babbe72..045d31caf1a 100644 --- a/src/objective-c/GRPCClient/GRPCCall+ChannelArg.h +++ b/src/objective-c/GRPCClient/GRPCCall+ChannelArg.h @@ -33,20 +33,15 @@ #import "GRPCCall.h" /** - * Methods to configure GRPC channel options for specific hosts. + * Methods to configure GRPC channel options. */ @interface GRPCCall (ChannelArg) /** - * Use the provided @c primaryUserAgent at the beginning of the HTTP User Agent string for the - * provided @c host. + * Use the provided @c userAgentPrefix at the beginning of the HTTP User Agent string for all calls. */ -+ (void)usePrimaryUserAgent:(NSString *)primaryUserAgent forHost:(NSString *)host; ++ (void)setUserAgentPrefix:(NSString *)userAgentPrefix; -/** - * Use the provided @c secondaryUserAgent at the end of the HTTP User Agent string for the - * provided @c host. - */ -+ (void)useSecondaryUserAgent:(NSString *)secondaryUserAgent forHost:(NSString *)host; ++ (NSString *)useUserAgentPrefix; @end diff --git a/src/objective-c/GRPCClient/GRPCCall+ChannelArg.m b/src/objective-c/GRPCClient/GRPCCall+ChannelArg.m index 159e12c7e85..a6a61188fa0 100644 --- a/src/objective-c/GRPCClient/GRPCCall+ChannelArg.m +++ b/src/objective-c/GRPCClient/GRPCCall+ChannelArg.m @@ -37,22 +37,18 @@ @implementation GRPCCall (ChannelArg) -+ (void)usePrimaryUserAgent:(NSString *)primaryUserAgent forHost:(NSString *)host { - if (!primaryUserAgent || !host) { - [NSException raise:NSInvalidArgumentException - format:@"primaryUserAgent and host must be provided."]; +static NSString *_userAgentPrefix; + ++ (void)setUserAgentPrefix:(NSString *)userAgentPrefix { + @synchronized(self) { + _userAgentPrefix = userAgentPrefix; } - GRPCHost *hostConfig = [GRPCHost hostWithAddress:host]; - hostConfig.primaryUserAgent = primaryUserAgent; } -+ (void)useSecondaryUserAgent:(NSString *)secondaryUserAgent forHost:(NSString *)host { - if (!secondaryUserAgent || !host) { - [NSException raise:NSInvalidArgumentException - format:@"secondaryUserAgent and host must be provided."]; ++ (NSString *)useUserAgentPrefix { + @synchronized(self) { + return _userAgentPrefix; } - GRPCHost *hostConfig = [GRPCHost hostWithAddress:host]; - hostConfig.secondaryUserAgent = secondaryUserAgent; } @end diff --git a/src/objective-c/GRPCClient/private/GRPCChannel.h b/src/objective-c/GRPCClient/private/GRPCChannel.h index 3e277b0f1a3..01a6cfd2ec9 100644 --- a/src/objective-c/GRPCClient/private/GRPCChannel.h +++ b/src/objective-c/GRPCClient/private/GRPCChannel.h @@ -42,8 +42,8 @@ struct grpc_channel_credentials; * Each separate instance of this class represents at least one TCP connection to the provided host. */ @interface GRPCChannel : NSObject + @property(nonatomic, readonly, nonnull) struct grpc_channel *unmanagedChannel; -@property(nonatomic, readonly, getter=isSecure) BOOL secure; - (nullable instancetype)init NS_UNAVAILABLE; diff --git a/src/objective-c/GRPCClient/private/GRPCHost.h b/src/objective-c/GRPCClient/private/GRPCHost.h index 673ed9060ef..6b4f98746d0 100644 --- a/src/objective-c/GRPCClient/private/GRPCHost.h +++ b/src/objective-c/GRPCClient/private/GRPCHost.h @@ -39,8 +39,6 @@ struct grpc_call; @interface GRPCHost : NSObject @property(nonatomic, readonly) NSString *address; -@property(nonatomic, copy) NSString *primaryUserAgent; -@property(nonatomic, copy) NSString *secondaryUserAgent; /** The following properties should only be modified for testing: */ diff --git a/src/objective-c/GRPCClient/private/GRPCHost.m b/src/objective-c/GRPCClient/private/GRPCHost.m index 5a21df523f2..9d5d1a16cbd 100644 --- a/src/objective-c/GRPCClient/private/GRPCHost.m +++ b/src/objective-c/GRPCClient/private/GRPCHost.m @@ -34,6 +34,7 @@ #import "GRPCHost.h" #include +#import #import "GRPCChannel.h" #import "GRPCCompletionQueue.h" @@ -108,11 +109,9 @@ if (!_channel) { NSMutableDictionary *args = [NSMutableDictionary dictionary]; - if (_primaryUserAgent) { - args[@GRPC_ARG_PRIMARY_USER_AGENT_STRING] = _primaryUserAgent; - } - if (_secondaryUserAgent) { - args[@GRPC_ARG_SECONDARY_USER_AGENT_STRING] = _secondaryUserAgent; + NSString *userAgentPrefix = [[GRPCCall useUserAgentPrefix] copy]; + if (userAgentPrefix) { + args[@GRPC_ARG_PRIMARY_USER_AGENT_STRING] = userAgentPrefix; } if (_secure) { From 55484da58aa973aeb2ae56b5b61f94a2bf646174 Mon Sep 17 00:00:00 2001 From: Kristopher Wuollett Date: Wed, 3 Feb 2016 08:00:08 -0500 Subject: [PATCH 06/55] Restored strdup of keys and values to ensure ownership of their memory --- .../GRPCClient/private/GRPCChannel.m | 56 +++++++++++++------ 1 file changed, 38 insertions(+), 18 deletions(-) diff --git a/src/objective-c/GRPCClient/private/GRPCChannel.m b/src/objective-c/GRPCClient/private/GRPCChannel.m index 5aecdb1cbeb..bb25743ed17 100644 --- a/src/objective-c/GRPCClient/private/GRPCChannel.m +++ b/src/objective-c/GRPCClient/private/GRPCChannel.m @@ -36,6 +36,7 @@ #include #include #include +#include /** * Returns @c grpc_channel_credentials from the specifie @c path. If the file at the path could not @@ -57,6 +58,17 @@ static grpc_channel_credentials *CertificatesAtPath(NSString *path, NSError **er return grpc_ssl_credentials_create(contentInASCII.bytes, NULL, NULL); } +void freeChannelArgs(grpc_channel_args *channel_args) { + for (size_t i = 0; i < channel_args->num_args; ++i) { + grpc_arg *arg = &channel_args->args[i]; + gpr_free(arg->key); + if (arg->type == GRPC_ARG_STRING) { + gpr_free(arg->value.string); + } + } + gpr_free(channel_args); +} + /** * Allocates a @c grpc_channel_args and populates it with the options specified in the * @c dictionary. Keys must be @c NSString. If the value responds to @c @selector(UTF8String) then @@ -68,31 +80,39 @@ grpc_channel_args * buildChannelArgs(NSDictionary *dictionary) { return NULL; } - NSUInteger argCount = [dictionary count]; + NSArray *keys = [dictionary allKeys]; + NSUInteger argCount = [keys count]; - // Allocate memory for both the individual args and their container - grpc_channel_args *channelArgs = gpr_malloc(sizeof(grpc_channel_args) - + argCount * sizeof(grpc_arg)); + grpc_channel_args *channelArgs = gpr_malloc(sizeof(grpc_channel_args)); channelArgs->num_args = argCount; - channelArgs->args = (grpc_arg *) (channelArgs + sizeof(grpc_channel_args)); + channelArgs->args = gpr_malloc(argCount * sizeof(grpc_arg)); + + // TODO(kriswuollett) Check that keys adhere to GRPC core library requirements - __block NSUInteger argIndex = 0; - [dictionary enumerateKeysAndObjectsUsingBlock:^(id _Nonnull key, id _Nonnull obj, - BOOL * _Nonnull stop) { - // use of UTF8String assumes that grpc won't modify the pointers - grpc_arg *arg = &channelArgs->args[argIndex++]; - arg->key = (char *) [key UTF8String]; // allow exception to be raised if not supported + Class invalidValueType = NULL; - if ([obj respondsToSelector:@selector(UTF8String)]) { + for (NSUInteger i = 0; i < argCount; ++i) { + grpc_arg *arg = &channelArgs->args[i]; + arg->key = gpr_strdup([keys[i] UTF8String]); + + id value = dictionary[keys[i]]; + if ([value respondsToSelector:@selector(UTF8String)]) { arg->type = GRPC_ARG_STRING; - arg->value.string = (char *) [obj UTF8String]; - } else if ([obj respondsToSelector:@selector(intValue)]) { + arg->value.string = gpr_strdup([value UTF8String]); + } else if ([value respondsToSelector:@selector(intValue)]) { arg->type = GRPC_ARG_INTEGER; - arg->value.integer = [obj intValue]; + arg->value.integer = [value intValue]; } else { - [NSException raise:NSInvalidArgumentException format:@"Invalid value type: %@", [obj class]]; + invalidValueType = [value class]; + break; } - }]; + } + + if (invalidValueType) { + freeChannelArgs(channelArgs); + [NSException raise:NSInvalidArgumentException + format:@"Invalid value type: %@", invalidValueType]; + } return channelArgs; } @@ -135,7 +155,7 @@ grpc_channel_args * buildChannelArgs(NSDictionary *dictionary) { // TODO(jcanizales): Be sure to add a test with a server that closes the connection prematurely, // as in the past that made this call to crash. grpc_channel_destroy(_unmanagedChannel); - gpr_free(_channelArgs); + freeChannelArgs(_channelArgs); } + (GRPCChannel *)secureChannelWithHost:(NSString *)host { From 99354c3cadf21a350fc259fcb235d3c34ba200c3 Mon Sep 17 00:00:00 2001 From: Kristopher Wuollett Date: Wed, 3 Feb 2016 19:49:03 -0500 Subject: [PATCH 07/55] Formatting and naming fixes --- .../GRPCClient/GRPCCall+ChannelArg.h | 2 +- .../GRPCClient/GRPCCall+ChannelArg.m | 2 +- .../GRPCClient/private/GRPCChannel.h | 2 +- .../GRPCClient/private/GRPCChannel.m | 29 +++++++------------ src/objective-c/GRPCClient/private/GRPCHost.m | 2 +- 5 files changed, 15 insertions(+), 22 deletions(-) diff --git a/src/objective-c/GRPCClient/GRPCCall+ChannelArg.h b/src/objective-c/GRPCClient/GRPCCall+ChannelArg.h index 045d31caf1a..ec1557df7fa 100644 --- a/src/objective-c/GRPCClient/GRPCCall+ChannelArg.h +++ b/src/objective-c/GRPCClient/GRPCCall+ChannelArg.h @@ -42,6 +42,6 @@ */ + (void)setUserAgentPrefix:(NSString *)userAgentPrefix; -+ (NSString *)useUserAgentPrefix; ++ (NSString *)userAgentPrefix; @end diff --git a/src/objective-c/GRPCClient/GRPCCall+ChannelArg.m b/src/objective-c/GRPCClient/GRPCCall+ChannelArg.m index a6a61188fa0..32244c3d313 100644 --- a/src/objective-c/GRPCClient/GRPCCall+ChannelArg.m +++ b/src/objective-c/GRPCClient/GRPCCall+ChannelArg.m @@ -45,7 +45,7 @@ static NSString *_userAgentPrefix; } } -+ (NSString *)useUserAgentPrefix { ++ (NSString *)userAgentPrefix { @synchronized(self) { return _userAgentPrefix; } diff --git a/src/objective-c/GRPCClient/private/GRPCChannel.h b/src/objective-c/GRPCClient/private/GRPCChannel.h index 01a6cfd2ec9..1888dea1b47 100644 --- a/src/objective-c/GRPCClient/private/GRPCChannel.h +++ b/src/objective-c/GRPCClient/private/GRPCChannel.h @@ -58,7 +58,7 @@ struct grpc_channel_credentials; * Creates a secure channel to the specified @c host using the specified @c pathToCertificates and * @c channelArgs. Only in tests should @c pathToCertificates be nil or * @c GRPC_SSL_TARGET_NAME_OVERRIDE_ARG channel arg be set. Passing nil for @c pathToCertificates - * results in using the default root certificates distributed with the library. If certificates + * results in using the default root certificates distributed with the library. If certificates * could not be found in any case, then @c nil is returned. */ + (nullable GRPCChannel *)secureChannelWithHost:(nonnull NSString *)host diff --git a/src/objective-c/GRPCClient/private/GRPCChannel.m b/src/objective-c/GRPCClient/private/GRPCChannel.m index bb25743ed17..7a676060c16 100644 --- a/src/objective-c/GRPCClient/private/GRPCChannel.m +++ b/src/objective-c/GRPCClient/private/GRPCChannel.m @@ -39,8 +39,8 @@ #include /** - * Returns @c grpc_channel_credentials from the specifie @c path. If the file at the path could not - * be read then NULL is returned. If NULL is returned, @c errorPtr may not be NULL if there are + * Returns @c grpc_channel_credentials from the specified @c path. If the file at the path could not + * be read then NULL is returned. If NULL is returned, @c errorPtr may not be NULL if there are * details available describing what went wrong. */ static grpc_channel_credentials *CertificatesAtPath(NSString *path, NSError **errorPtr) { @@ -71,9 +71,10 @@ void freeChannelArgs(grpc_channel_args *channel_args) { /** * Allocates a @c grpc_channel_args and populates it with the options specified in the - * @c dictionary. Keys must be @c NSString. If the value responds to @c @selector(UTF8String) then - * it will be mapped to @c GRPC_ARG_STRING. If not, it will be mapped to @c GRPC_ARG_INTEGER if the - * value responds to @c @selector(intValue). Otherwise, an exception will be raised. + * @c dictionary. Keys must be @c NSString. If the value responds to @c @selector(UTF8String) then + * it will be mapped to @c GRPC_ARG_STRING. If not, it will be mapped to @c GRPC_ARG_INTEGER if the + * value responds to @c @selector(intValue). Otherwise, an exception will be raised. The caller of + * this function is responsible for calling @c freeChannelArgs on a non-NULL returned value. */ grpc_channel_args * buildChannelArgs(NSDictionary *dictionary) { if (!dictionary) { @@ -89,8 +90,6 @@ grpc_channel_args * buildChannelArgs(NSDictionary *dictionary) { // TODO(kriswuollett) Check that keys adhere to GRPC core library requirements - Class invalidValueType = NULL; - for (NSUInteger i = 0; i < argCount; ++i) { grpc_arg *arg = &channelArgs->args[i]; arg->key = gpr_strdup([keys[i] UTF8String]); @@ -103,17 +102,11 @@ grpc_channel_args * buildChannelArgs(NSDictionary *dictionary) { arg->type = GRPC_ARG_INTEGER; arg->value.integer = [value intValue]; } else { - invalidValueType = [value class]; - break; + [NSException raise:NSInvalidArgumentException + format:@"Invalid value type: %@", [value class]]; } } - if (invalidValueType) { - freeChannelArgs(channelArgs); - [NSException raise:NSInvalidArgumentException - format:@"Invalid value type: %@", invalidValueType]; - } - return channelArgs; } @@ -144,7 +137,7 @@ grpc_channel_args * buildChannelArgs(NSDictionary *dictionary) { _unmanagedChannel = grpc_secure_channel_create(credentials, _host.UTF8String, _channelArgs, NULL); } else { - _unmanagedChannel = grpc_insecure_channel_create(host.UTF8String, _channelArgs, NULL); + _unmanagedChannel = grpc_insecure_channel_create(_host.UTF8String, _channelArgs, NULL); } } @@ -184,8 +177,8 @@ grpc_channel_args * buildChannelArgs(NSDictionary *dictionary) { //TODO(jcanizales): Add NSError** parameter to the initializer. grpc_channel_credentials *certificates = path - ? CertificatesAtPath(path, NULL) - : kDefaultCertificates; + ? CertificatesAtPath(path, NULL) + : kDefaultCertificates; return [[GRPCChannel alloc] initWithHost:host secure:YES diff --git a/src/objective-c/GRPCClient/private/GRPCHost.m b/src/objective-c/GRPCClient/private/GRPCHost.m index 9d5d1a16cbd..8fb9d917227 100644 --- a/src/objective-c/GRPCClient/private/GRPCHost.m +++ b/src/objective-c/GRPCClient/private/GRPCHost.m @@ -109,7 +109,7 @@ if (!_channel) { NSMutableDictionary *args = [NSMutableDictionary dictionary]; - NSString *userAgentPrefix = [[GRPCCall useUserAgentPrefix] copy]; + NSString *userAgentPrefix = [[GRPCCall userAgentPrefix] copy]; if (userAgentPrefix) { args[@GRPC_ARG_PRIMARY_USER_AGENT_STRING] = userAgentPrefix; } From 20b79e702db4cb811c67a1d9d199c0a462927fc5 Mon Sep 17 00:00:00 2001 From: Kristopher Wuollett Date: Wed, 3 Feb 2016 21:38:44 -0500 Subject: [PATCH 08/55] Updated user agent to be a host-level setting --- examples/objective-c/helloworld/main.m | 2 +- src/objective-c/GRPCClient/GRPCCall+ChannelArg.h | 7 +++---- src/objective-c/GRPCClient/GRPCCall+ChannelArg.m | 15 ++++++--------- src/objective-c/GRPCClient/private/GRPCHost.h | 1 + src/objective-c/GRPCClient/private/GRPCHost.m | 5 ++--- 5 files changed, 13 insertions(+), 17 deletions(-) diff --git a/examples/objective-c/helloworld/main.m b/examples/objective-c/helloworld/main.m index b67380812b4..755dce33df9 100644 --- a/examples/objective-c/helloworld/main.m +++ b/examples/objective-c/helloworld/main.m @@ -43,7 +43,7 @@ static NSString * const kHostAddress = @"localhost:50051"; int main(int argc, char * argv[]) { @autoreleasepool { [GRPCCall useInsecureConnectionsForHost:kHostAddress]; - [GRPCCall setUserAgentPrefix:@"HelloWorld/1.0"]; + [GRPCCall setUserAgentPrefix:@"HelloWorld/1.0" forHost:kHostAddress]; HLWGreeter *client = [[HLWGreeter alloc] initWithHost:kHostAddress]; diff --git a/src/objective-c/GRPCClient/GRPCCall+ChannelArg.h b/src/objective-c/GRPCClient/GRPCCall+ChannelArg.h index ec1557df7fa..bd6b064f166 100644 --- a/src/objective-c/GRPCClient/GRPCCall+ChannelArg.h +++ b/src/objective-c/GRPCClient/GRPCCall+ChannelArg.h @@ -38,10 +38,9 @@ @interface GRPCCall (ChannelArg) /** - * Use the provided @c userAgentPrefix at the beginning of the HTTP User Agent string for all calls. + * Use the provided @c userAgentPrefix at the beginning of the HTTP User Agent string for all calls + * to the specified @c host. */ -+ (void)setUserAgentPrefix:(NSString *)userAgentPrefix; - -+ (NSString *)userAgentPrefix; ++ (void)setUserAgentPrefix:(NSString *)userAgentPrefix forHost:(NSString *)host; @end diff --git a/src/objective-c/GRPCClient/GRPCCall+ChannelArg.m b/src/objective-c/GRPCClient/GRPCCall+ChannelArg.m index 32244c3d313..f2821f6abc0 100644 --- a/src/objective-c/GRPCClient/GRPCCall+ChannelArg.m +++ b/src/objective-c/GRPCClient/GRPCCall+ChannelArg.m @@ -39,16 +39,13 @@ static NSString *_userAgentPrefix; -+ (void)setUserAgentPrefix:(NSString *)userAgentPrefix { - @synchronized(self) { - _userAgentPrefix = userAgentPrefix; - } -} - -+ (NSString *)userAgentPrefix { - @synchronized(self) { - return _userAgentPrefix; ++ (void)setUserAgentPrefix:(NSString *)userAgentPrefix forHost:(NSString *)host { + if (!host) { + [NSException raise:NSInvalidArgumentException + format:@"host and userAgentPrefix must be provided."]; } + GRPCHost *hostConfig = [GRPCHost hostWithAddress:host]; + hostConfig.userAgentPrefix = userAgentPrefix; } @end diff --git a/src/objective-c/GRPCClient/private/GRPCHost.h b/src/objective-c/GRPCClient/private/GRPCHost.h index 6b4f98746d0..69a115e88cf 100644 --- a/src/objective-c/GRPCClient/private/GRPCHost.h +++ b/src/objective-c/GRPCClient/private/GRPCHost.h @@ -39,6 +39,7 @@ struct grpc_call; @interface GRPCHost : NSObject @property(nonatomic, readonly) NSString *address; +@property(nonatomic, copy) NSString *userAgentPrefix; /** The following properties should only be modified for testing: */ diff --git a/src/objective-c/GRPCClient/private/GRPCHost.m b/src/objective-c/GRPCClient/private/GRPCHost.m index 8fb9d917227..5b1ca16e120 100644 --- a/src/objective-c/GRPCClient/private/GRPCHost.m +++ b/src/objective-c/GRPCClient/private/GRPCHost.m @@ -109,9 +109,8 @@ if (!_channel) { NSMutableDictionary *args = [NSMutableDictionary dictionary]; - NSString *userAgentPrefix = [[GRPCCall userAgentPrefix] copy]; - if (userAgentPrefix) { - args[@GRPC_ARG_PRIMARY_USER_AGENT_STRING] = userAgentPrefix; + if (_userAgentPrefix) { + args[@GRPC_ARG_PRIMARY_USER_AGENT_STRING] = _userAgentPrefix; } if (_secure) { From be303e12cb8f9affe9dc022a13c33967eafabb33 Mon Sep 17 00:00:00 2001 From: Jorge Canizales Date: Thu, 4 Feb 2016 02:52:47 -0800 Subject: [PATCH 09/55] Add user agent of the library to that of the app. --- src/objective-c/GRPCClient/private/GRPCHost.m | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/objective-c/GRPCClient/private/GRPCHost.m b/src/objective-c/GRPCClient/private/GRPCHost.m index 5b1ca16e120..f750841a446 100644 --- a/src/objective-c/GRPCClient/private/GRPCHost.m +++ b/src/objective-c/GRPCClient/private/GRPCHost.m @@ -40,6 +40,10 @@ #import "GRPCCompletionQueue.h" #import "NSDictionary+GRPC.h" +// TODO(jcanizales): Generate the version in a standalone header, from templates. Like +// templates/src/core/surface/version.c.template . +#define GRPC_OBJC_VERSION_STRING @"0.13.0" + @interface GRPCHost () // TODO(mlumish): Investigate whether caching channels with strong links is a good idea. @property(nonatomic, strong) GRPCChannel *channel; @@ -109,9 +113,14 @@ if (!_channel) { NSMutableDictionary *args = [NSMutableDictionary dictionary]; + + // TODO(jcanizales): Add OS and device information (see + // https://github.com/grpc/grpc/blob/master/doc/PROTOCOL-HTTP2.md#user-agents ). + NSString *userAgent = @"grpc-objc/" GRPC_OBJC_VERSION_STRING; if (_userAgentPrefix) { - args[@GRPC_ARG_PRIMARY_USER_AGENT_STRING] = _userAgentPrefix; + userAgent = [@[_userAgentPrefix, userAgent] componentsJoinedByString:@" "]; } + args[@GRPC_ARG_PRIMARY_USER_AGENT_STRING] = userAgent; if (_secure) { if (_hostNameOverride) { From 7a81fb830f09b1a31680a88b046a0942a6cdd913 Mon Sep 17 00:00:00 2001 From: Masood Malekghassemi Date: Thu, 4 Feb 2016 14:57:48 -0800 Subject: [PATCH 10/55] Bump python version --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 720e4f75f6c..1004bc3936e 100644 --- a/setup.py +++ b/setup.py @@ -216,7 +216,7 @@ else: setuptools.setup( name='grpcio', - version='0.12.0b8', + version='0.12.0b9', license=LICENSE, ext_modules=CYTHON_EXTENSION_MODULES, packages=list(PACKAGES), From 309830f6b8c09347db305acf3b05fca333030989 Mon Sep 17 00:00:00 2001 From: murgatroid99 Date: Fri, 5 Feb 2016 11:30:00 -0800 Subject: [PATCH 11/55] Replace 'long' with 'int64_t' in public core headers --- include/grpc/impl/codegen/time.h | 16 ++--- include/grpc/support/avl.h | 4 +- src/core/iomgr/iocp_windows.c | 2 +- src/core/iomgr/pollset_posix.c | 2 +- src/core/support/avl.c | 10 +-- src/core/support/time.c | 36 +++++----- src/node/ext/timeval.cc | 3 +- .../grpcio/grpc/_cython/imports.generated.c | 36 +++++----- .../grpcio/grpc/_cython/imports.generated.h | 70 +++++++++---------- src/ruby/ext/grpc/rb_grpc_imports.generated.h | 12 ++-- test/core/statistics/census_log_tests.c | 2 +- test/core/support/avl_test.c | 2 +- test/core/support/sync_test.c | 2 +- test/core/support/time_test.c | 6 +- test/core/util/test_config.h | 4 +- test/cpp/util/time_test.cc | 2 +- 16 files changed, 100 insertions(+), 109 deletions(-) diff --git a/include/grpc/impl/codegen/time.h b/include/grpc/impl/codegen/time.h index b40c2b260cc..21fd9dedef9 100644 --- a/include/grpc/impl/codegen/time.h +++ b/include/grpc/impl/codegen/time.h @@ -102,14 +102,14 @@ GPR_API gpr_timespec gpr_time_min(gpr_timespec a, gpr_timespec b); GPR_API gpr_timespec gpr_time_add(gpr_timespec a, gpr_timespec b); GPR_API gpr_timespec gpr_time_sub(gpr_timespec a, gpr_timespec b); -/* Return a timespec representing a given number of time units. LONG_MIN is - interpreted as gpr_inf_past, and LONG_MAX as gpr_inf_future. */ -GPR_API gpr_timespec gpr_time_from_micros(long x, gpr_clock_type clock_type); -GPR_API gpr_timespec gpr_time_from_nanos(long x, gpr_clock_type clock_type); -GPR_API gpr_timespec gpr_time_from_millis(long x, gpr_clock_type clock_type); -GPR_API gpr_timespec gpr_time_from_seconds(long x, gpr_clock_type clock_type); -GPR_API gpr_timespec gpr_time_from_minutes(long x, gpr_clock_type clock_type); -GPR_API gpr_timespec gpr_time_from_hours(long x, gpr_clock_type clock_type); +/* Return a timespec representing a given number of time units. INT64_MIN is + interpreted as gpr_inf_past, and INT64_MAX as gpr_inf_future. */ +GPR_API gpr_timespec gpr_time_from_micros(int64_t x, gpr_clock_type clock_type); +GPR_API gpr_timespec gpr_time_from_nanos(int64_t x, gpr_clock_type clock_type); +GPR_API gpr_timespec gpr_time_from_millis(int64_t x, gpr_clock_type clock_type); +GPR_API gpr_timespec gpr_time_from_seconds(int64_t x, gpr_clock_type clock_type); +GPR_API gpr_timespec gpr_time_from_minutes(int64_t x, gpr_clock_type clock_type); +GPR_API gpr_timespec gpr_time_from_hours(int64_t x, gpr_clock_type clock_type); GPR_API int32_t gpr_time_to_millis(gpr_timespec timespec); diff --git a/include/grpc/support/avl.h b/include/grpc/support/avl.h index 3433124c6fa..623da6698c4 100644 --- a/include/grpc/support/avl.h +++ b/include/grpc/support/avl.h @@ -43,7 +43,7 @@ typedef struct gpr_avl_node { void *value; struct gpr_avl_node *left; struct gpr_avl_node *right; - long height; + int64_t height; } gpr_avl_node; typedef struct gpr_avl_vtable { @@ -53,7 +53,7 @@ typedef struct gpr_avl_vtable { void *(*copy_key)(void *key); /** compare key1, key2; return <0 if key1 < key2, >0 if key1 > key2, 0 if key1 == key2 */ - long (*compare_keys)(void *key1, void *key2); + int64_t (*compare_keys)(void *key1, void *key2); /** destroy a value */ void (*destroy_value)(void *value); /** copy a value */ diff --git a/src/core/iomgr/iocp_windows.c b/src/core/iomgr/iocp_windows.c index 96b6f810248..759340e00ef 100644 --- a/src/core/iomgr/iocp_windows.c +++ b/src/core/iomgr/iocp_windows.c @@ -57,7 +57,7 @@ static HANDLE g_iocp; static DWORD deadline_to_millis_timeout(gpr_timespec deadline, gpr_timespec now) { gpr_timespec timeout; - static const int max_spin_polling_us = 10; + static const int64_t max_spin_polling_us = 10; if (gpr_time_cmp(deadline, gpr_inf_future(deadline.clock_type)) == 0) { return INFINITE; } diff --git a/src/core/iomgr/pollset_posix.c b/src/core/iomgr/pollset_posix.c index a8e2e229777..19ee6650f00 100644 --- a/src/core/iomgr/pollset_posix.c +++ b/src/core/iomgr/pollset_posix.c @@ -393,7 +393,7 @@ void grpc_pollset_shutdown(grpc_exec_ctx *exec_ctx, grpc_pollset *pollset, int grpc_poll_deadline_to_millis_timeout(gpr_timespec deadline, gpr_timespec now) { gpr_timespec timeout; - static const int max_spin_polling_us = 10; + static const int64_t max_spin_polling_us = 10; if (gpr_time_cmp(deadline, gpr_inf_future(deadline.clock_type)) == 0) { return -1; } diff --git a/src/core/support/avl.c b/src/core/support/avl.c index 9734c9987fe..1767fc12b50 100644 --- a/src/core/support/avl.c +++ b/src/core/support/avl.c @@ -67,12 +67,12 @@ static void unref_node(const gpr_avl_vtable *vtable, gpr_avl_node *node) { } } -static long node_height(gpr_avl_node *node) { +static int64_t node_height(gpr_avl_node *node) { return node == NULL ? 0 : node->height; } #ifndef NDEBUG -static long calculate_height(gpr_avl_node *node) { +static int64_t calculate_height(gpr_avl_node *node) { return node == NULL ? 0 : 1 + GPR_MAX(calculate_height(node->left), calculate_height(node->right)); } @@ -103,7 +103,7 @@ gpr_avl_node *new_node(void *key, void *value, gpr_avl_node *left, static gpr_avl_node *get(const gpr_avl_vtable *vtable, gpr_avl_node *node, void *key) { - long cmp; + int64_t cmp; if (node == NULL) { return NULL; @@ -198,7 +198,7 @@ static gpr_avl_node *rebalance(const gpr_avl_vtable *vtable, void *key, static gpr_avl_node *add(const gpr_avl_vtable *vtable, gpr_avl_node *node, void *key, void *value) { - long cmp; + int64_t cmp; if (node == NULL) { return new_node(key, value, NULL, NULL); } @@ -240,7 +240,7 @@ static gpr_avl_node *in_order_tail(gpr_avl_node *node) { static gpr_avl_node *remove(const gpr_avl_vtable *vtable, gpr_avl_node *node, void *key) { - long cmp; + int64_t cmp; if (node == NULL) { return NULL; } diff --git a/src/core/support/time.c b/src/core/support/time.c index ac8c3bcde5b..2a1e40c633c 100644 --- a/src/core/support/time.c +++ b/src/core/support/time.c @@ -83,12 +83,12 @@ gpr_timespec gpr_inf_past(gpr_clock_type type) { /* TODO(ctiller): consider merging _nanos, _micros, _millis into a single function for maintainability. Similarly for _seconds, _minutes, and _hours */ -gpr_timespec gpr_time_from_nanos(long ns, gpr_clock_type type) { +gpr_timespec gpr_time_from_nanos(int64_t ns, gpr_clock_type type) { gpr_timespec result; result.clock_type = type; - if (ns == LONG_MAX) { + if (ns == INT64_MAX) { result = gpr_inf_future(type); - } else if (ns == LONG_MIN) { + } else if (ns == INT64_MIN) { result = gpr_inf_past(type); } else if (ns >= 0) { result.tv_sec = ns / GPR_NS_PER_SEC; @@ -101,12 +101,12 @@ gpr_timespec gpr_time_from_nanos(long ns, gpr_clock_type type) { return result; } -gpr_timespec gpr_time_from_micros(long us, gpr_clock_type type) { +gpr_timespec gpr_time_from_micros(int64_t us, gpr_clock_type type) { gpr_timespec result; result.clock_type = type; - if (us == LONG_MAX) { + if (us == INT64_MAX) { result = gpr_inf_future(type); - } else if (us == LONG_MIN) { + } else if (us == INT64_MIN) { result = gpr_inf_past(type); } else if (us >= 0) { result.tv_sec = us / 1000000; @@ -119,12 +119,12 @@ gpr_timespec gpr_time_from_micros(long us, gpr_clock_type type) { return result; } -gpr_timespec gpr_time_from_millis(long ms, gpr_clock_type type) { +gpr_timespec gpr_time_from_millis(int64_t ms, gpr_clock_type type) { gpr_timespec result; result.clock_type = type; - if (ms == LONG_MAX) { + if (ms == INT64_MAX) { result = gpr_inf_future(type); - } else if (ms == LONG_MIN) { + } else if (ms == INT64_MIN) { result = gpr_inf_past(type); } else if (ms >= 0) { result.tv_sec = ms / 1000; @@ -137,12 +137,12 @@ gpr_timespec gpr_time_from_millis(long ms, gpr_clock_type type) { return result; } -gpr_timespec gpr_time_from_seconds(long s, gpr_clock_type type) { +gpr_timespec gpr_time_from_seconds(int64_t s, gpr_clock_type type) { gpr_timespec result; result.clock_type = type; - if (s == LONG_MAX) { + if (s == INT64_MAX) { result = gpr_inf_future(type); - } else if (s == LONG_MIN) { + } else if (s == INT64_MIN) { result = gpr_inf_past(type); } else { result.tv_sec = s; @@ -151,12 +151,12 @@ gpr_timespec gpr_time_from_seconds(long s, gpr_clock_type type) { return result; } -gpr_timespec gpr_time_from_minutes(long m, gpr_clock_type type) { +gpr_timespec gpr_time_from_minutes(int64_t m, gpr_clock_type type) { gpr_timespec result; result.clock_type = type; - if (m >= LONG_MAX / 60) { + if (m >= INT64_MAX / 60) { result = gpr_inf_future(type); - } else if (m <= LONG_MIN / 60) { + } else if (m <= INT64_MIN / 60) { result = gpr_inf_past(type); } else { result.tv_sec = m * 60; @@ -165,12 +165,12 @@ gpr_timespec gpr_time_from_minutes(long m, gpr_clock_type type) { return result; } -gpr_timespec gpr_time_from_hours(long h, gpr_clock_type type) { +gpr_timespec gpr_time_from_hours(int64_t h, gpr_clock_type type) { gpr_timespec result; result.clock_type = type; - if (h >= LONG_MAX / 3600) { + if (h >= INT64_MAX / 3600) { result = gpr_inf_future(type); - } else if (h <= LONG_MIN / 3600) { + } else if (h <= INT64_MIN / 3600) { result = gpr_inf_past(type); } else { result.tv_sec = h * 3600; diff --git a/src/node/ext/timeval.cc b/src/node/ext/timeval.cc index 64015e8412e..9284db62ef6 100644 --- a/src/node/ext/timeval.cc +++ b/src/node/ext/timeval.cc @@ -32,6 +32,7 @@ */ #include +#include #include "grpc/grpc.h" #include "grpc/support/time.h" @@ -46,7 +47,7 @@ gpr_timespec MillisecondsToTimespec(double millis) { } else if (millis == -std::numeric_limits::infinity()) { return gpr_inf_past(GPR_CLOCK_REALTIME); } else { - return gpr_time_from_micros(static_cast(millis * 1000), + return gpr_time_from_micros(static_cast(millis * 1000), GPR_CLOCK_REALTIME); } } diff --git a/src/python/grpcio/grpc/_cython/imports.generated.c b/src/python/grpcio/grpc/_cython/imports.generated.c index b818f3491bf..817303c8a4a 100644 --- a/src/python/grpcio/grpc/_cython/imports.generated.c +++ b/src/python/grpcio/grpc/_cython/imports.generated.c @@ -41,7 +41,14 @@ census_initialize_type census_initialize_import; census_shutdown_type census_shutdown_import; census_supported_type census_supported_import; census_enabled_type census_enabled_import; -census_context_serialize_type census_context_serialize_import; +census_context_create_type census_context_create_import; +census_context_destroy_type census_context_destroy_import; +census_context_get_status_type census_context_get_status_import; +census_context_initialize_iterator_type census_context_initialize_iterator_import; +census_context_next_tag_type census_context_next_tag_import; +census_context_get_tag_type census_context_get_tag_import; +census_context_encode_type census_context_encode_import; +census_context_decode_type census_context_decode_import; census_trace_mask_type census_trace_mask_import; census_set_trace_mask_type census_set_trace_mask_import; census_start_rpc_op_timestamp_type census_start_rpc_op_timestamp_import; @@ -54,15 +61,6 @@ census_trace_print_type census_trace_print_import; census_trace_scan_start_type census_trace_scan_start_import; census_get_trace_record_type census_get_trace_record_import; census_trace_scan_end_type census_trace_scan_end_import; -census_tag_set_create_type census_tag_set_create_import; -census_tag_set_destroy_type census_tag_set_destroy_import; -census_tag_set_get_create_status_type census_tag_set_get_create_status_import; -census_tag_set_initialize_iterator_type census_tag_set_initialize_iterator_import; -census_tag_set_next_tag_type census_tag_set_next_tag_import; -census_tag_set_get_tag_by_key_type census_tag_set_get_tag_by_key_import; -census_tag_set_encode_type census_tag_set_encode_import; -census_tag_set_decode_type census_tag_set_decode_import; -census_context_tag_set_type census_context_tag_set_import; census_record_values_type census_record_values_import; census_view_create_type census_view_create_import; census_view_delete_type census_view_delete_import; @@ -303,7 +301,14 @@ void pygrpc_load_imports(HMODULE library) { census_shutdown_import = (census_shutdown_type) GetProcAddress(library, "census_shutdown"); census_supported_import = (census_supported_type) GetProcAddress(library, "census_supported"); census_enabled_import = (census_enabled_type) GetProcAddress(library, "census_enabled"); - census_context_serialize_import = (census_context_serialize_type) GetProcAddress(library, "census_context_serialize"); + census_context_create_import = (census_context_create_type) GetProcAddress(library, "census_context_create"); + census_context_destroy_import = (census_context_destroy_type) GetProcAddress(library, "census_context_destroy"); + census_context_get_status_import = (census_context_get_status_type) GetProcAddress(library, "census_context_get_status"); + census_context_initialize_iterator_import = (census_context_initialize_iterator_type) GetProcAddress(library, "census_context_initialize_iterator"); + census_context_next_tag_import = (census_context_next_tag_type) GetProcAddress(library, "census_context_next_tag"); + census_context_get_tag_import = (census_context_get_tag_type) GetProcAddress(library, "census_context_get_tag"); + census_context_encode_import = (census_context_encode_type) GetProcAddress(library, "census_context_encode"); + census_context_decode_import = (census_context_decode_type) GetProcAddress(library, "census_context_decode"); census_trace_mask_import = (census_trace_mask_type) GetProcAddress(library, "census_trace_mask"); census_set_trace_mask_import = (census_set_trace_mask_type) GetProcAddress(library, "census_set_trace_mask"); census_start_rpc_op_timestamp_import = (census_start_rpc_op_timestamp_type) GetProcAddress(library, "census_start_rpc_op_timestamp"); @@ -316,15 +321,6 @@ void pygrpc_load_imports(HMODULE library) { census_trace_scan_start_import = (census_trace_scan_start_type) GetProcAddress(library, "census_trace_scan_start"); census_get_trace_record_import = (census_get_trace_record_type) GetProcAddress(library, "census_get_trace_record"); census_trace_scan_end_import = (census_trace_scan_end_type) GetProcAddress(library, "census_trace_scan_end"); - census_tag_set_create_import = (census_tag_set_create_type) GetProcAddress(library, "census_tag_set_create"); - census_tag_set_destroy_import = (census_tag_set_destroy_type) GetProcAddress(library, "census_tag_set_destroy"); - census_tag_set_get_create_status_import = (census_tag_set_get_create_status_type) GetProcAddress(library, "census_tag_set_get_create_status"); - census_tag_set_initialize_iterator_import = (census_tag_set_initialize_iterator_type) GetProcAddress(library, "census_tag_set_initialize_iterator"); - census_tag_set_next_tag_import = (census_tag_set_next_tag_type) GetProcAddress(library, "census_tag_set_next_tag"); - census_tag_set_get_tag_by_key_import = (census_tag_set_get_tag_by_key_type) GetProcAddress(library, "census_tag_set_get_tag_by_key"); - census_tag_set_encode_import = (census_tag_set_encode_type) GetProcAddress(library, "census_tag_set_encode"); - census_tag_set_decode_import = (census_tag_set_decode_type) GetProcAddress(library, "census_tag_set_decode"); - census_context_tag_set_import = (census_context_tag_set_type) GetProcAddress(library, "census_context_tag_set"); census_record_values_import = (census_record_values_type) GetProcAddress(library, "census_record_values"); census_view_create_import = (census_view_create_type) GetProcAddress(library, "census_view_create"); census_view_delete_import = (census_view_delete_type) GetProcAddress(library, "census_view_delete"); diff --git a/src/python/grpcio/grpc/_cython/imports.generated.h b/src/python/grpcio/grpc/_cython/imports.generated.h index 2a8a910055a..6d0a6e06c00 100644 --- a/src/python/grpcio/grpc/_cython/imports.generated.h +++ b/src/python/grpcio/grpc/_cython/imports.generated.h @@ -73,9 +73,30 @@ extern census_supported_type census_supported_import; typedef int(*census_enabled_type)(void); extern census_enabled_type census_enabled_import; #define census_enabled census_enabled_import -typedef size_t(*census_context_serialize_type)(const census_context *context, char *buffer, size_t buf_size); -extern census_context_serialize_type census_context_serialize_import; -#define census_context_serialize census_context_serialize_import +typedef census_context *(*census_context_create_type)(const census_context *base, const census_tag *tags, int ntags, census_context_status const **status); +extern census_context_create_type census_context_create_import; +#define census_context_create census_context_create_import +typedef void(*census_context_destroy_type)(census_context *context); +extern census_context_destroy_type census_context_destroy_import; +#define census_context_destroy census_context_destroy_import +typedef const census_context_status *(*census_context_get_status_type)(const census_context *context); +extern census_context_get_status_type census_context_get_status_import; +#define census_context_get_status census_context_get_status_import +typedef void(*census_context_initialize_iterator_type)(const census_context *context, census_context_iterator *iterator); +extern census_context_initialize_iterator_type census_context_initialize_iterator_import; +#define census_context_initialize_iterator census_context_initialize_iterator_import +typedef int(*census_context_next_tag_type)(census_context_iterator *iterator, census_tag *tag); +extern census_context_next_tag_type census_context_next_tag_import; +#define census_context_next_tag census_context_next_tag_import +typedef int(*census_context_get_tag_type)(const census_context *context, const char *key, census_tag *tag); +extern census_context_get_tag_type census_context_get_tag_import; +#define census_context_get_tag census_context_get_tag_import +typedef char *(*census_context_encode_type)(const census_context *context, char *buffer, size_t buf_size, size_t *print_buf_size, size_t *bin_buf_size); +extern census_context_encode_type census_context_encode_import; +#define census_context_encode census_context_encode_import +typedef census_context *(*census_context_decode_type)(const char *buffer, size_t size, const char *bin_buffer, size_t bin_size); +extern census_context_decode_type census_context_decode_import; +#define census_context_decode census_context_decode_import typedef int(*census_trace_mask_type)(const census_context *context); extern census_trace_mask_type census_trace_mask_import; #define census_trace_mask census_trace_mask_import @@ -112,37 +133,10 @@ extern census_get_trace_record_type census_get_trace_record_import; typedef void(*census_trace_scan_end_type)(); extern census_trace_scan_end_type census_trace_scan_end_import; #define census_trace_scan_end census_trace_scan_end_import -typedef census_tag_set *(*census_tag_set_create_type)(const census_tag_set *base, const census_tag *tags, int ntags, census_tag_set_create_status const **status); -extern census_tag_set_create_type census_tag_set_create_import; -#define census_tag_set_create census_tag_set_create_import -typedef void(*census_tag_set_destroy_type)(census_tag_set *tags); -extern census_tag_set_destroy_type census_tag_set_destroy_import; -#define census_tag_set_destroy census_tag_set_destroy_import -typedef const census_tag_set_create_status *(*census_tag_set_get_create_status_type)(const census_tag_set *tags); -extern census_tag_set_get_create_status_type census_tag_set_get_create_status_import; -#define census_tag_set_get_create_status census_tag_set_get_create_status_import -typedef void(*census_tag_set_initialize_iterator_type)(const census_tag_set *tags, census_tag_set_iterator *iterator); -extern census_tag_set_initialize_iterator_type census_tag_set_initialize_iterator_import; -#define census_tag_set_initialize_iterator census_tag_set_initialize_iterator_import -typedef int(*census_tag_set_next_tag_type)(census_tag_set_iterator *iterator, census_tag *tag); -extern census_tag_set_next_tag_type census_tag_set_next_tag_import; -#define census_tag_set_next_tag census_tag_set_next_tag_import -typedef int(*census_tag_set_get_tag_by_key_type)(const census_tag_set *tags, const char *key, census_tag *tag); -extern census_tag_set_get_tag_by_key_type census_tag_set_get_tag_by_key_import; -#define census_tag_set_get_tag_by_key census_tag_set_get_tag_by_key_import -typedef char *(*census_tag_set_encode_type)(const census_tag_set *tags, char *buffer, size_t buf_size, size_t *print_buf_size, size_t *bin_buf_size); -extern census_tag_set_encode_type census_tag_set_encode_import; -#define census_tag_set_encode census_tag_set_encode_import -typedef census_tag_set *(*census_tag_set_decode_type)(const char *buffer, size_t size, const char *bin_buffer, size_t bin_size); -extern census_tag_set_decode_type census_tag_set_decode_import; -#define census_tag_set_decode census_tag_set_decode_import -typedef census_tag_set *(*census_context_tag_set_type)(census_context *context); -extern census_context_tag_set_type census_context_tag_set_import; -#define census_context_tag_set census_context_tag_set_import typedef void(*census_record_values_type)(census_context *context, census_value *values, size_t nvalues); extern census_record_values_type census_record_values_import; #define census_record_values census_record_values_import -typedef census_view *(*census_view_create_type)(uint32_t metric_id, const census_tag_set *tags, const census_aggregation *aggregations, size_t naggregations); +typedef census_view *(*census_view_create_type)(uint32_t metric_id, const census_context *tags, const census_aggregation *aggregations, size_t naggregations); extern census_view_create_type census_view_create_import; #define census_view_create census_view_create_import typedef void(*census_view_delete_type)(census_view *view); @@ -154,7 +148,7 @@ extern census_view_metric_type census_view_metric_import; typedef size_t(*census_view_naggregations_type)(const census_view *view); extern census_view_naggregations_type census_view_naggregations_import; #define census_view_naggregations census_view_naggregations_import -typedef const census_tag_set *(*census_view_tags_type)(const census_view *view); +typedef const census_context *(*census_view_tags_type)(const census_view *view); extern census_view_tags_type census_view_tags_import; #define census_view_tags census_view_tags_import typedef const census_aggregation *(*census_view_aggregrations_type)(const census_view *view); @@ -661,22 +655,22 @@ extern gpr_time_add_type gpr_time_add_import; typedef gpr_timespec(*gpr_time_sub_type)(gpr_timespec a, gpr_timespec b); extern gpr_time_sub_type gpr_time_sub_import; #define gpr_time_sub gpr_time_sub_import -typedef gpr_timespec(*gpr_time_from_micros_type)(long x, gpr_clock_type clock_type); +typedef gpr_timespec(*gpr_time_from_micros_type)(int64_t x, gpr_clock_type clock_type); extern gpr_time_from_micros_type gpr_time_from_micros_import; #define gpr_time_from_micros gpr_time_from_micros_import -typedef gpr_timespec(*gpr_time_from_nanos_type)(long x, gpr_clock_type clock_type); +typedef gpr_timespec(*gpr_time_from_nanos_type)(int64_t x, gpr_clock_type clock_type); extern gpr_time_from_nanos_type gpr_time_from_nanos_import; #define gpr_time_from_nanos gpr_time_from_nanos_import -typedef gpr_timespec(*gpr_time_from_millis_type)(long x, gpr_clock_type clock_type); +typedef gpr_timespec(*gpr_time_from_millis_type)(int64_t x, gpr_clock_type clock_type); extern gpr_time_from_millis_type gpr_time_from_millis_import; #define gpr_time_from_millis gpr_time_from_millis_import -typedef gpr_timespec(*gpr_time_from_seconds_type)(long x, gpr_clock_type clock_type); +typedef gpr_timespec(*gpr_time_from_seconds_type)(int64_t x, gpr_clock_type clock_type); extern gpr_time_from_seconds_type gpr_time_from_seconds_import; #define gpr_time_from_seconds gpr_time_from_seconds_import -typedef gpr_timespec(*gpr_time_from_minutes_type)(long x, gpr_clock_type clock_type); +typedef gpr_timespec(*gpr_time_from_minutes_type)(int64_t x, gpr_clock_type clock_type); extern gpr_time_from_minutes_type gpr_time_from_minutes_import; #define gpr_time_from_minutes gpr_time_from_minutes_import -typedef gpr_timespec(*gpr_time_from_hours_type)(long x, gpr_clock_type clock_type); +typedef gpr_timespec(*gpr_time_from_hours_type)(int64_t x, gpr_clock_type clock_type); extern gpr_time_from_hours_type gpr_time_from_hours_import; #define gpr_time_from_hours gpr_time_from_hours_import typedef int32_t(*gpr_time_to_millis_type)(gpr_timespec timespec); diff --git a/src/ruby/ext/grpc/rb_grpc_imports.generated.h b/src/ruby/ext/grpc/rb_grpc_imports.generated.h index 45e9b475743..618ae5e7fcf 100644 --- a/src/ruby/ext/grpc/rb_grpc_imports.generated.h +++ b/src/ruby/ext/grpc/rb_grpc_imports.generated.h @@ -655,22 +655,22 @@ extern gpr_time_add_type gpr_time_add_import; typedef gpr_timespec(*gpr_time_sub_type)(gpr_timespec a, gpr_timespec b); extern gpr_time_sub_type gpr_time_sub_import; #define gpr_time_sub gpr_time_sub_import -typedef gpr_timespec(*gpr_time_from_micros_type)(long x, gpr_clock_type clock_type); +typedef gpr_timespec(*gpr_time_from_micros_type)(int64_t x, gpr_clock_type clock_type); extern gpr_time_from_micros_type gpr_time_from_micros_import; #define gpr_time_from_micros gpr_time_from_micros_import -typedef gpr_timespec(*gpr_time_from_nanos_type)(long x, gpr_clock_type clock_type); +typedef gpr_timespec(*gpr_time_from_nanos_type)(int64_t x, gpr_clock_type clock_type); extern gpr_time_from_nanos_type gpr_time_from_nanos_import; #define gpr_time_from_nanos gpr_time_from_nanos_import -typedef gpr_timespec(*gpr_time_from_millis_type)(long x, gpr_clock_type clock_type); +typedef gpr_timespec(*gpr_time_from_millis_type)(int64_t x, gpr_clock_type clock_type); extern gpr_time_from_millis_type gpr_time_from_millis_import; #define gpr_time_from_millis gpr_time_from_millis_import -typedef gpr_timespec(*gpr_time_from_seconds_type)(long x, gpr_clock_type clock_type); +typedef gpr_timespec(*gpr_time_from_seconds_type)(int64_t x, gpr_clock_type clock_type); extern gpr_time_from_seconds_type gpr_time_from_seconds_import; #define gpr_time_from_seconds gpr_time_from_seconds_import -typedef gpr_timespec(*gpr_time_from_minutes_type)(long x, gpr_clock_type clock_type); +typedef gpr_timespec(*gpr_time_from_minutes_type)(int64_t x, gpr_clock_type clock_type); extern gpr_time_from_minutes_type gpr_time_from_minutes_import; #define gpr_time_from_minutes gpr_time_from_minutes_import -typedef gpr_timespec(*gpr_time_from_hours_type)(long x, gpr_clock_type clock_type); +typedef gpr_timespec(*gpr_time_from_hours_type)(int64_t x, gpr_clock_type clock_type); extern gpr_time_from_hours_type gpr_time_from_hours_import; #define gpr_time_from_hours gpr_time_from_hours_import typedef int32_t(*gpr_time_to_millis_type)(gpr_timespec timespec); diff --git a/test/core/statistics/census_log_tests.c b/test/core/statistics/census_log_tests.c index aac20fd96a2..858aeb9809a 100644 --- a/test/core/statistics/census_log_tests.c +++ b/test/core/statistics/census_log_tests.c @@ -237,7 +237,7 @@ static void reader_thread(void *arg) { gpr_timespec interval; int counter = 0; printf(" Reader starting\n"); - interval = gpr_time_from_micros(args->read_iteration_interval_in_msec * 1000, + interval = gpr_time_from_micros((int64_t)args->read_iteration_interval_in_msec * 1000, GPR_TIMESPAN); gpr_mu_lock(args->mu); while (!args->stop_flag && records_read < args->total_records) { diff --git a/test/core/support/avl_test.c b/test/core/support/avl_test.c index d8d8b36806b..6dae53c1dfe 100644 --- a/test/core/support/avl_test.c +++ b/test/core/support/avl_test.c @@ -48,7 +48,7 @@ static int *box(int x) { return b; } -static long int_compare(void *int1, void *int2) { +static int64_t int_compare(void *int1, void *int2) { return (*(int *)int1) - (*(int *)int2); } static void *int_copy(void *p) { return box(*(int *)p); } diff --git a/test/core/support/sync_test.c b/test/core/support/sync_test.c index 0149bc3afde..acb5101536a 100644 --- a/test/core/support/sync_test.c +++ b/test/core/support/sync_test.c @@ -251,7 +251,7 @@ static void test(const char *name, void (*body)(void *m), gpr_timespec start = gpr_now(GPR_CLOCK_REALTIME); gpr_timespec time_taken; gpr_timespec deadline = gpr_time_add( - start, gpr_time_from_micros(timeout_s * 1000000, GPR_TIMESPAN)); + start, gpr_time_from_micros((int64_t)timeout_s * 1000000, GPR_TIMESPAN)); fprintf(stderr, "%s:", name); while (gpr_time_cmp(gpr_now(GPR_CLOCK_REALTIME), deadline) < 0) { iterations <<= 1; diff --git a/test/core/support/time_test.c b/test/core/support/time_test.c index fc26f94d29a..5285a2c75b7 100644 --- a/test/core/support/time_test.c +++ b/test/core/support/time_test.c @@ -125,15 +125,15 @@ static void test_values(void) { } /* Test possible overflow in conversion of -ve values. */ - x = gpr_time_from_micros(-(LONG_MAX - 999997), GPR_TIMESPAN); + x = gpr_time_from_micros(-(INT64_MAX - 999997), GPR_TIMESPAN); GPR_ASSERT(x.tv_sec < 0); GPR_ASSERT(x.tv_nsec >= 0 && x.tv_nsec < GPR_NS_PER_SEC); - x = gpr_time_from_nanos(-(LONG_MAX - 999999997), GPR_TIMESPAN); + x = gpr_time_from_nanos(-(INT64_MAX - 999999997), GPR_TIMESPAN); GPR_ASSERT(x.tv_sec < 0); GPR_ASSERT(x.tv_nsec >= 0 && x.tv_nsec < GPR_NS_PER_SEC); - x = gpr_time_from_millis(-(LONG_MAX - 997), GPR_TIMESPAN); + x = gpr_time_from_millis(-(INT64_MAX - 997), GPR_TIMESPAN); GPR_ASSERT(x.tv_sec < 0); GPR_ASSERT(x.tv_nsec >= 0 && x.tv_nsec < GPR_NS_PER_SEC); diff --git a/test/core/util/test_config.h b/test/core/util/test_config.h index 15b71747fb5..3872776cb1d 100644 --- a/test/core/util/test_config.h +++ b/test/core/util/test_config.h @@ -57,13 +57,13 @@ extern double g_fixture_slowdown_factor; #define GRPC_TIMEOUT_SECONDS_TO_DEADLINE(x) \ gpr_time_add( \ gpr_now(GPR_CLOCK_MONOTONIC), \ - gpr_time_from_millis((long)(GRPC_TEST_SLOWDOWN_FACTOR * 1e3 * (x)), \ + gpr_time_from_millis((int64_t)(GRPC_TEST_SLOWDOWN_FACTOR * 1e3 * (x)), \ GPR_TIMESPAN)) #define GRPC_TIMEOUT_MILLIS_TO_DEADLINE(x) \ gpr_time_add( \ gpr_now(GPR_CLOCK_MONOTONIC), \ - gpr_time_from_micros((long)(GRPC_TEST_SLOWDOWN_FACTOR * 1e3 * (x)), \ + gpr_time_from_micros((int64_t)(GRPC_TEST_SLOWDOWN_FACTOR * 1e3 * (x)), \ GPR_TIMESPAN)) #ifndef GRPC_TEST_CUSTOM_PICK_PORT diff --git a/test/cpp/util/time_test.cc b/test/cpp/util/time_test.cc index 1e501dfd288..803bd462101 100644 --- a/test/cpp/util/time_test.cc +++ b/test/cpp/util/time_test.cc @@ -45,7 +45,7 @@ namespace { class TimeTest : public ::testing::Test {}; TEST_F(TimeTest, AbsolutePointTest) { - long us = 10000000L; + int64_t us = 10000000L; gpr_timespec ts = gpr_time_from_micros(us, GPR_TIMESPAN); ts.clock_type = GPR_CLOCK_REALTIME; system_clock::time_point tp{microseconds(us)}; From 7a55684a1305c73b0d7924d5cf04a52c093bd1bc Mon Sep 17 00:00:00 2001 From: murgatroid99 Date: Fri, 5 Feb 2016 11:33:30 -0800 Subject: [PATCH 12/55] Clang format and fix copyrights --- include/grpc/impl/codegen/time.h | 6 ++-- src/core/support/avl.c | 2 +- src/core/support/stack_lockfree.c | 2 +- src/core/support/time.c | 2 +- src/node/ext/timeval.cc | 2 +- .../grpcio/grpc/_cython/_cygrpc/grpc.pxi | 2 +- .../grpc/_cython/_cygrpc/records.pyx.pxi | 2 +- src/python/grpcio/grpc/_cython/cygrpc.pyx | 2 +- test/core/statistics/census_log_tests.c | 6 ++-- test/core/support/sync_test.c | 2 +- test/core/support/time_test.c | 2 +- test/core/util/test_config.h | 14 ++++---- test/cpp/qps/client_async.cc | 34 ++++++++----------- test/cpp/qps/driver.h | 2 +- test/cpp/util/time_test.cc | 2 +- test/distrib/python/distribtest.py | 29 ++++++++++++++++ tools/run_tests/build_artifact_python.sh | 2 +- 17 files changed, 69 insertions(+), 44 deletions(-) diff --git a/include/grpc/impl/codegen/time.h b/include/grpc/impl/codegen/time.h index 21fd9dedef9..4ed1c3cbd86 100644 --- a/include/grpc/impl/codegen/time.h +++ b/include/grpc/impl/codegen/time.h @@ -107,8 +107,10 @@ GPR_API gpr_timespec gpr_time_sub(gpr_timespec a, gpr_timespec b); GPR_API gpr_timespec gpr_time_from_micros(int64_t x, gpr_clock_type clock_type); GPR_API gpr_timespec gpr_time_from_nanos(int64_t x, gpr_clock_type clock_type); GPR_API gpr_timespec gpr_time_from_millis(int64_t x, gpr_clock_type clock_type); -GPR_API gpr_timespec gpr_time_from_seconds(int64_t x, gpr_clock_type clock_type); -GPR_API gpr_timespec gpr_time_from_minutes(int64_t x, gpr_clock_type clock_type); +GPR_API gpr_timespec +gpr_time_from_seconds(int64_t x, gpr_clock_type clock_type); +GPR_API gpr_timespec +gpr_time_from_minutes(int64_t x, gpr_clock_type clock_type); GPR_API gpr_timespec gpr_time_from_hours(int64_t x, gpr_clock_type clock_type); GPR_API int32_t gpr_time_to_millis(gpr_timespec timespec); diff --git a/src/core/support/avl.c b/src/core/support/avl.c index 1767fc12b50..78746588f0a 100644 --- a/src/core/support/avl.c +++ b/src/core/support/avl.c @@ -1,6 +1,6 @@ /* * - * Copyright 2015, Google Inc. + * Copyright 2015-2016, Google Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/src/core/support/stack_lockfree.c b/src/core/support/stack_lockfree.c index 2c97ee18be1..9daecd2e18a 100644 --- a/src/core/support/stack_lockfree.c +++ b/src/core/support/stack_lockfree.c @@ -99,7 +99,7 @@ gpr_stack_lockfree *gpr_stack_lockfree_create(size_t entries) { /* Point the head at reserved dummy entry */ stack->head.contents.index = INVALID_ENTRY_INDEX; - /* Fill in the pad and aba_ctr to avoid confusing memcheck tools */ +/* Fill in the pad and aba_ctr to avoid confusing memcheck tools */ #ifdef GPR_ARCH_64 stack->head.contents.pad = 0; #endif diff --git a/src/core/support/time.c b/src/core/support/time.c index 2a1e40c633c..423d12ffc0f 100644 --- a/src/core/support/time.c +++ b/src/core/support/time.c @@ -1,6 +1,6 @@ /* * - * Copyright 2015, Google Inc. + * Copyright 2015-2016, Google Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/src/node/ext/timeval.cc b/src/node/ext/timeval.cc index 9284db62ef6..c8f8534cfa7 100644 --- a/src/node/ext/timeval.cc +++ b/src/node/ext/timeval.cc @@ -1,6 +1,6 @@ /* * - * Copyright 2015, Google Inc. + * Copyright 2015-2016, Google Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/src/python/grpcio/grpc/_cython/_cygrpc/grpc.pxi b/src/python/grpcio/grpc/_cython/_cygrpc/grpc.pxi index 9d6e0170269..9c85e0ee1bd 100644 --- a/src/python/grpcio/grpc/_cython/_cygrpc/grpc.pxi +++ b/src/python/grpcio/grpc/_cython/_cygrpc/grpc.pxi @@ -1,4 +1,4 @@ -# Copyright 2015, Google Inc. +# Copyright 2015-2016, Google Inc. # All rights reserved. # # Redistribution and use in source and binary forms, with or without diff --git a/src/python/grpcio/grpc/_cython/_cygrpc/records.pyx.pxi b/src/python/grpcio/grpc/_cython/_cygrpc/records.pyx.pxi index 9e14b967e0a..fa4ea99ea9e 100644 --- a/src/python/grpcio/grpc/_cython/_cygrpc/records.pyx.pxi +++ b/src/python/grpcio/grpc/_cython/_cygrpc/records.pyx.pxi @@ -1,4 +1,4 @@ -# Copyright 2015, Google Inc. +# Copyright 2015-2016, Google Inc. # All rights reserved. # # Redistribution and use in source and binary forms, with or without diff --git a/src/python/grpcio/grpc/_cython/cygrpc.pyx b/src/python/grpcio/grpc/_cython/cygrpc.pyx index 579bac7b8af..b1836bf5be3 100644 --- a/src/python/grpcio/grpc/_cython/cygrpc.pyx +++ b/src/python/grpcio/grpc/_cython/cygrpc.pyx @@ -1,4 +1,4 @@ -# Copyright 2015, Google Inc. +# Copyright 2015-2016, Google Inc. # All rights reserved. # # Redistribution and use in source and binary forms, with or without diff --git a/test/core/statistics/census_log_tests.c b/test/core/statistics/census_log_tests.c index 858aeb9809a..77cc57d4d63 100644 --- a/test/core/statistics/census_log_tests.c +++ b/test/core/statistics/census_log_tests.c @@ -1,6 +1,6 @@ /* * - * Copyright 2015, Google Inc. + * Copyright 2015-2016, Google Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -237,8 +237,8 @@ static void reader_thread(void *arg) { gpr_timespec interval; int counter = 0; printf(" Reader starting\n"); - interval = gpr_time_from_micros((int64_t)args->read_iteration_interval_in_msec * 1000, - GPR_TIMESPAN); + interval = gpr_time_from_micros( + (int64_t)args->read_iteration_interval_in_msec * 1000, GPR_TIMESPAN); gpr_mu_lock(args->mu); while (!args->stop_flag && records_read < args->total_records) { gpr_cv_wait(&args->stop, args->mu, interval); diff --git a/test/core/support/sync_test.c b/test/core/support/sync_test.c index acb5101536a..d311eb136a6 100644 --- a/test/core/support/sync_test.c +++ b/test/core/support/sync_test.c @@ -1,6 +1,6 @@ /* * - * Copyright 2015, Google Inc. + * Copyright 2015-2016, Google Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/test/core/support/time_test.c b/test/core/support/time_test.c index 5285a2c75b7..6cc3786df12 100644 --- a/test/core/support/time_test.c +++ b/test/core/support/time_test.c @@ -1,6 +1,6 @@ /* * - * Copyright 2015, Google Inc. + * Copyright 2015-2016, Google Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/test/core/util/test_config.h b/test/core/util/test_config.h index 3872776cb1d..f6bb2e1f72a 100644 --- a/test/core/util/test_config.h +++ b/test/core/util/test_config.h @@ -1,6 +1,6 @@ /* * - * Copyright 2015, Google Inc. + * Copyright 2015-2016, Google Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -54,15 +54,15 @@ extern double g_fixture_slowdown_factor; (GRPC_TEST_SLOWDOWN_BUILD_FACTOR * GRPC_TEST_SLOWDOWN_MACHINE_FACTOR * \ g_fixture_slowdown_factor) -#define GRPC_TIMEOUT_SECONDS_TO_DEADLINE(x) \ - gpr_time_add( \ - gpr_now(GPR_CLOCK_MONOTONIC), \ +#define GRPC_TIMEOUT_SECONDS_TO_DEADLINE(x) \ + gpr_time_add( \ + gpr_now(GPR_CLOCK_MONOTONIC), \ gpr_time_from_millis((int64_t)(GRPC_TEST_SLOWDOWN_FACTOR * 1e3 * (x)), \ GPR_TIMESPAN)) -#define GRPC_TIMEOUT_MILLIS_TO_DEADLINE(x) \ - gpr_time_add( \ - gpr_now(GPR_CLOCK_MONOTONIC), \ +#define GRPC_TIMEOUT_MILLIS_TO_DEADLINE(x) \ + gpr_time_add( \ + gpr_now(GPR_CLOCK_MONOTONIC), \ gpr_time_from_micros((int64_t)(GRPC_TEST_SLOWDOWN_FACTOR * 1e3 * (x)), \ GPR_TIMESPAN)) diff --git a/test/cpp/qps/client_async.cc b/test/cpp/qps/client_async.cc index 6b6294ba518..f3f8f37051b 100644 --- a/test/cpp/qps/client_async.cc +++ b/test/cpp/qps/client_async.cc @@ -96,8 +96,7 @@ class ClientRpcContextUnaryImpl : public ClientRpcContext { std::function< std::unique_ptr>( BenchmarkService::Stub*, grpc::ClientContext*, const RequestType&, - CompletionQueue*)> - start_req, + CompletionQueue*)> start_req, std::function on_done) : ClientRpcContext(channel_id), context_(), @@ -143,8 +142,7 @@ class ClientRpcContextUnaryImpl : public ClientRpcContext { std::function callback_; std::function>( BenchmarkService::Stub*, grpc::ClientContext*, const RequestType&, - CompletionQueue*)> - start_req_; + CompletionQueue*)> start_req_; grpc::Status status_; double start_; std::unique_ptr> @@ -164,12 +162,11 @@ class AsyncClient : public ClientImpl { using ClientImpl::cores_; using ClientImpl::channels_; using ClientImpl::request_; - AsyncClient( - const ClientConfig& config, - std::function - setup_ctx, - std::function(std::shared_ptr)> - create_stub) + AsyncClient(const ClientConfig& config, + std::function setup_ctx, + std::function(std::shared_ptr)> + create_stub) : ClientImpl(config, create_stub), num_async_threads_(NumThreads(config)), channel_lock_(new std::mutex[config.client_channels()]), @@ -411,8 +408,7 @@ class ClientRpcContextStreamingImpl : public ClientRpcContext { std::function>( BenchmarkService::Stub*, grpc::ClientContext*, CompletionQueue*, - void*)> - start_req, + void*)> start_req, std::function on_done) : ClientRpcContext(channel_id), context_(), @@ -464,10 +460,10 @@ class ClientRpcContextStreamingImpl : public ClientRpcContext { ResponseType response_; bool (ClientRpcContextStreamingImpl::*next_state_)(bool, Histogram*); std::function callback_; - std::function>( - BenchmarkService::Stub*, grpc::ClientContext*, CompletionQueue*, void*)> - start_req_; + std::function< + std::unique_ptr>( + BenchmarkService::Stub*, grpc::ClientContext*, CompletionQueue*, + void*)> start_req_; grpc::Status status_; double start_; std::unique_ptr> @@ -511,8 +507,7 @@ class ClientRpcContextGenericStreamingImpl : public ClientRpcContext { int channel_id, grpc::GenericStub* stub, const ByteBuffer& req, std::function( grpc::GenericStub*, grpc::ClientContext*, - const grpc::string& method_name, CompletionQueue*, void*)> - start_req, + const grpc::string& method_name, CompletionQueue*, void*)> start_req, std::function on_done) : ClientRpcContext(channel_id), context_(), @@ -569,8 +564,7 @@ class ClientRpcContextGenericStreamingImpl : public ClientRpcContext { std::function callback_; std::function( grpc::GenericStub*, grpc::ClientContext*, const grpc::string&, - CompletionQueue*, void*)> - start_req_; + CompletionQueue*, void*)> start_req_; grpc::Status status_; double start_; std::unique_ptr stream_; diff --git a/test/cpp/qps/driver.h b/test/cpp/qps/driver.h index 4b2b400c0ce..3af61f73917 100644 --- a/test/cpp/qps/driver.h +++ b/test/cpp/qps/driver.h @@ -1,6 +1,6 @@ /* * - * Copyright 2015, Google Inc. + * Copyright 2015-2016, Google Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/test/cpp/util/time_test.cc b/test/cpp/util/time_test.cc index 803bd462101..48c6ce7697c 100644 --- a/test/cpp/util/time_test.cc +++ b/test/cpp/util/time_test.cc @@ -1,6 +1,6 @@ /* * - * Copyright 2015, Google Inc. + * Copyright 2015-2016, Google Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/test/distrib/python/distribtest.py b/test/distrib/python/distribtest.py index 428ffe2b34a..66c1f887964 100644 --- a/test/distrib/python/distribtest.py +++ b/test/distrib/python/distribtest.py @@ -1,3 +1,32 @@ +# Copyright 2015-2016, Google Inc. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following disclaimer +# in the documentation and/or other materials provided with the +# distribution. +# * Neither the name of Google Inc. nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + from grpc.beta import implementations # This code doesn't do much but makes sure the native extension is loaded diff --git a/tools/run_tests/build_artifact_python.sh b/tools/run_tests/build_artifact_python.sh index 48cf390f696..87bc85e8b1f 100755 --- a/tools/run_tests/build_artifact_python.sh +++ b/tools/run_tests/build_artifact_python.sh @@ -46,4 +46,4 @@ GRPC_PYTHON_BUILD_WITH_CYTHON=1 ${SETARCH_CMD} python setup.py \ mkdir -p artifacts -cp -r dist/* artifacts \ No newline at end of file +cp -r dist/* artifacts From 58d98910add14197aec78aad6be15f5911e21fe4 Mon Sep 17 00:00:00 2001 From: Kristopher Wuollett Date: Fri, 5 Feb 2016 15:53:02 -0500 Subject: [PATCH 13/55] Removed unused userAgentPrefix variable --- src/objective-c/GRPCClient/GRPCCall+ChannelArg.m | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/objective-c/GRPCClient/GRPCCall+ChannelArg.m b/src/objective-c/GRPCClient/GRPCCall+ChannelArg.m index f2821f6abc0..5f9932d86dc 100644 --- a/src/objective-c/GRPCClient/GRPCCall+ChannelArg.m +++ b/src/objective-c/GRPCClient/GRPCCall+ChannelArg.m @@ -37,8 +37,6 @@ @implementation GRPCCall (ChannelArg) -static NSString *_userAgentPrefix; - + (void)setUserAgentPrefix:(NSString *)userAgentPrefix forHost:(NSString *)host { if (!host) { [NSException raise:NSInvalidArgumentException From 95060b510e181588a7229ee498594a5864cf9926 Mon Sep 17 00:00:00 2001 From: murgatroid99 Date: Fri, 5 Feb 2016 13:05:31 -0800 Subject: [PATCH 14/55] Make Node examples package self-contained --- examples/node/greeter_client.js | 4 ++-- examples/node/greeter_server.js | 4 ++-- examples/node/package.json | 7 +++++++ examples/node/route_guide/route_guide_client.js | 6 +++--- examples/node/route_guide/route_guide_server.js | 6 +++--- 5 files changed, 17 insertions(+), 10 deletions(-) create mode 100644 examples/node/package.json diff --git a/examples/node/greeter_client.js b/examples/node/greeter_client.js index e0b89bd376a..9b4b0a77829 100644 --- a/examples/node/greeter_client.js +++ b/examples/node/greeter_client.js @@ -1,6 +1,6 @@ /* * - * Copyright 2015, Google Inc. + * Copyright 2015-2016, Google Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -33,7 +33,7 @@ var PROTO_PATH = __dirname + '/helloworld.proto'; -var grpc = require('../../'); +var grpc = require('grpc'); var hello_proto = grpc.load(PROTO_PATH).helloworld; function main() { diff --git a/examples/node/greeter_server.js b/examples/node/greeter_server.js index 3600c8bfbf4..2712b3dd3ad 100644 --- a/examples/node/greeter_server.js +++ b/examples/node/greeter_server.js @@ -1,6 +1,6 @@ /* * - * Copyright 2015, Google Inc. + * Copyright 2015-2016, Google Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -33,7 +33,7 @@ var PROTO_PATH = __dirname + '/helloworld.proto'; -var grpc = require('../../'); +var grpc = require('grpc'); var hello_proto = grpc.load(PROTO_PATH).helloworld; /** diff --git a/examples/node/package.json b/examples/node/package.json new file mode 100644 index 00000000000..65c5789ed7b --- /dev/null +++ b/examples/node/package.json @@ -0,0 +1,7 @@ +{ + "name": "grpc-examples", + "version": "0.1.0", + "dependencies": { + "grpc": "0.12.0" + } +} diff --git a/examples/node/route_guide/route_guide_client.js b/examples/node/route_guide/route_guide_client.js index edeca6ff553..e38a21f4228 100644 --- a/examples/node/route_guide/route_guide_client.js +++ b/examples/node/route_guide/route_guide_client.js @@ -1,6 +1,6 @@ /* * - * Copyright 2015, Google Inc. + * Copyright 2015-2016, Google Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -30,13 +30,13 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ - + var async = require('async'); var fs = require('fs'); var parseArgs = require('minimist'); var path = require('path'); var _ = require('lodash'); -var grpc = require('../../../'); +var grpc = require('grpc'); var routeguide = grpc.load(__dirname + '/route_guide.proto').routeguide; var client = new routeguide.RouteGuide('localhost:50051', grpc.Credentials.createInsecure()); diff --git a/examples/node/route_guide/route_guide_server.js b/examples/node/route_guide/route_guide_server.js index 2090a6a1d2f..06cf2925e1c 100644 --- a/examples/node/route_guide/route_guide_server.js +++ b/examples/node/route_guide/route_guide_server.js @@ -1,6 +1,6 @@ /* * - * Copyright 2015, Google Inc. + * Copyright 2015-2016, Google Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -30,12 +30,12 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ - + var fs = require('fs'); var parseArgs = require('minimist'); var path = require('path'); var _ = require('lodash'); -var grpc = require('../../../'); +var grpc = require('grpc'); var routeguide = grpc.load(__dirname + '/route_guide.proto').routeguide; var COORD_FACTOR = 1e7; From 0a7468a537f3cc22160247ef88968c8c2d5af118 Mon Sep 17 00:00:00 2001 From: Alistair Veitch Date: Fri, 5 Feb 2016 13:13:13 -0800 Subject: [PATCH 15/55] Add timespan support for win32 gpr_cv_wait. --- include/grpc/impl/codegen/sync.h | 3 ++- src/core/support/sync_win32.c | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/include/grpc/impl/codegen/sync.h b/include/grpc/impl/codegen/sync.h index 7086b5d3711..04ff0dc5bf9 100644 --- a/include/grpc/impl/codegen/sync.h +++ b/include/grpc/impl/codegen/sync.h @@ -115,7 +115,8 @@ GPR_API void gpr_cv_destroy(gpr_cv *cv); /* Atomically release *mu and wait on *cv. When the calling thread is woken from *cv or the deadline abs_deadline is exceeded, execute gpr_mu_lock(mu) and return whether the deadline was exceeded. Use - abs_deadline==gpr_inf_future for no deadline. May return even when not + abs_deadline==gpr_inf_future for no deadline. abs_deadline can be either + an absolute deadline, or a GPR_TIMESPAN. May return even when not woken explicitly. Requires: *mu and *cv initialized; the calling thread holds an exclusive lock on *mu. */ GPR_API int gpr_cv_wait(gpr_cv *cv, gpr_mu *mu, gpr_timespec abs_deadline); diff --git a/src/core/support/sync_win32.c b/src/core/support/sync_win32.c index 84d412a75f0..41998ebcb6b 100644 --- a/src/core/support/sync_win32.c +++ b/src/core/support/sync_win32.c @@ -87,6 +87,7 @@ int gpr_cv_wait(gpr_cv *cv, gpr_mu *mu, gpr_timespec abs_deadline) { 0) { SleepConditionVariableCS(cv, &mu->cs, INFINITE); } else { + abs_deadline = gpr_convert_clock_type(abs_deadline, GPR_CLOCK_REALTIME); gpr_timespec now = gpr_now(abs_deadline.clock_type); int64_t now_ms = (int64_t)now.tv_sec * 1000 + now.tv_nsec / 1000000; int64_t deadline_ms = From 5219c6d8e8ae0c584b0014166b7cf73dbfc8d456 Mon Sep 17 00:00:00 2001 From: "Nicolas \"Pixel\" Noble" Date: Fri, 5 Feb 2016 22:22:29 +0100 Subject: [PATCH 16/55] Properly compiling distributable native gems. --- Rakefile | 16 ++++++++++++---- src/ruby/ext/grpc/extconf.rb | 1 + third_party/rake-compiler-dock/Dockerfile | 15 ++++++++++++++- 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/Rakefile b/Rakefile index 3a30920feae..70406969477 100755 --- a/Rakefile +++ b/Rakefile @@ -23,7 +23,15 @@ Rake::ExtensionTask.new('grpc_c', spec) do |ext| ext.ext_dir = File.join('src', 'ruby', 'ext', 'grpc') ext.lib_dir = File.join('src', 'ruby', 'lib', 'grpc') ext.cross_compile = true - ext.cross_platform = ['x86-mingw32', 'x64-mingw32'] + ext.cross_platform = [ + 'x86-mingw32', 'x64-mingw32', + 'x86_64-linux', 'x86-linux', + 'x86_64-darwin-11', + 'x86_64-darwin-12', + 'x86_64-darwin-13', + 'x86_64-darwin-14', + 'x86_64-darwin-15' + ] ext.cross_compiling do |spec| spec.files = %w( etc/roots.pem grpc_c.32.ruby grpc_c.64.ruby ) spec.files += Dir.glob('src/ruby/bin/**/*') @@ -91,8 +99,8 @@ task 'dlls' do end -desc 'Build the gem file under rake_compiler_dock' -task 'gem:windows' do +desc 'Build the native gem file under rake_compiler_dock' +task 'gem:native' do verbose = ENV['V'] || '0' docker_for_windows "bundle && rake cross native gem RUBY_CC_VERSION=2.3.0:2.2.2:2.1.6:2.0.0 V=#{verbose}" @@ -105,7 +113,7 @@ task 'suite:bidi' => 'suite:wrapper' task 'suite:server' => 'suite:wrapper' task 'suite:pb' => 'suite:server' -task 'gem:windows' => 'dlls' +task 'gem:native' => 'dlls' desc 'Compiles the gRPC extension then runs all the tests' task all: ['suite:idiomatic', 'suite:bidi', 'suite:pb', 'suite:server'] diff --git a/src/ruby/ext/grpc/extconf.rb b/src/ruby/ext/grpc/extconf.rb index 426a6e67a08..503403392da 100644 --- a/src/ruby/ext/grpc/extconf.rb +++ b/src/ruby/ext/grpc/extconf.rb @@ -75,6 +75,7 @@ unless File.exist?(File.join(grpc_lib_dir, 'libgrpc.a')) or windows ENV['EMBED_OPENSSL'] = 'true' ENV['EMBED_ZLIB'] = 'true' + ENV['ARCH_FLAGS'] = RbConfig::CONFIG['ARCH_FLAG'] ENV['ARCH_FLAGS'] = '-arch i386 -arch x86_64' if RUBY_PLATFORM =~ /darwin/ output_dir = File.expand_path(RbConfig::CONFIG['topdir']) diff --git a/third_party/rake-compiler-dock/Dockerfile b/third_party/rake-compiler-dock/Dockerfile index 28623c30280..be73e2d8f49 100644 --- a/third_party/rake-compiler-dock/Dockerfile +++ b/third_party/rake-compiler-dock/Dockerfile @@ -1,7 +1,7 @@ FROM ubuntu:14.04 RUN apt-get -y update && \ - apt-get install -y curl git-core mingw-w64 xz-utils build-essential wget unzip + apt-get install -y curl git-core mingw-w64 xz-utils build-essential gcc-multilib wget unzip RUN mkdir -p /opt/mingw && \ curl -SL http://downloads.sourceforge.net/mingw-w64/i686-w64-mingw32-gcc-4.7.2-release-linux64_rubenvb.tar.xz | \ @@ -103,12 +103,25 @@ RUN bash -c "rvm use 2.3.0 --default && \ export MAKE=\"make -j`nproc`\" CFLAGS='-s -O1 -fno-omit-frame-pointer -fno-fast-math' && \ rake-compiler cross-ruby VERSION=2.3.0 HOST=i686-w64-mingw32 && \ rake-compiler cross-ruby VERSION=2.3.0 HOST=x86_64-w64-mingw32 && \ + rake-compiler cross-ruby VERSION=2.3.0 HOST=x86_64-linux-gnu && \ rake-compiler cross-ruby VERSION=2.2.2 HOST=i686-w64-mingw32 && \ rake-compiler cross-ruby VERSION=2.2.2 HOST=x86_64-w64-mingw32 && \ + rake-compiler cross-ruby VERSION=2.2.2 HOST=x86_64-linux-gnu && \ rake-compiler cross-ruby VERSION=2.1.6 HOST=i686-w64-mingw32 && \ rake-compiler cross-ruby VERSION=2.1.6 HOST=x86_64-w64-mingw32 && \ + rake-compiler cross-ruby VERSION=2.1.6 HOST=x86_64-linux-gnu && \ rake-compiler cross-ruby VERSION=2.0.0-p645 HOST=i686-w64-mingw32 && \ rake-compiler cross-ruby VERSION=2.0.0-p645 HOST=x86_64-w64-mingw32 && \ + rake-compiler cross-ruby VERSION=2.0.0-p645 HOST=x86_64-linux-gnu && \ + rm -rf ~/.rake-compiler/tmp/builds ~/.rake-compiler/sources && \ + find /usr/local/rvm -type d -print0 | sudo xargs -0 chmod g+sw " + +RUN bash -c "rvm use 2.3.0 --default && \ + export MAKE=\"make -j`nproc`\" CFLAGS='-m32 -s -O1 -fno-omit-frame-pointer -fno-fast-math' LDFLAGS='-m32' && \ + rake-compiler cross-ruby VERSION=2.3.0 HOST=i686-linux-gnu && \ + rake-compiler cross-ruby VERSION=2.2.2 HOST=i686-linux-gnu && \ + rake-compiler cross-ruby VERSION=2.1.6 HOST=i686-linux-gnu && \ + rake-compiler cross-ruby VERSION=2.0.0-p645 HOST=i686-linux-gnu && \ rm -rf ~/.rake-compiler/tmp/builds ~/.rake-compiler/sources && \ find /usr/local/rvm -type d -print0 | sudo xargs -0 chmod g+sw " From 6c857eab57f241741881b8e8696df44506c6a8fc Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Fri, 5 Feb 2016 12:19:07 -0800 Subject: [PATCH 17/55] allow parallel docker run --- tools/jenkins/build_and_run_docker.sh | 3 --- 1 file changed, 3 deletions(-) diff --git a/tools/jenkins/build_and_run_docker.sh b/tools/jenkins/build_and_run_docker.sh index b77cd0aebbf..92dbbc6f380 100755 --- a/tools/jenkins/build_and_run_docker.sh +++ b/tools/jenkins/build_and_run_docker.sh @@ -37,9 +37,6 @@ cd $(dirname $0)/../.. git_root=$(pwd) cd - -# Create a local branch so the child Docker script won't complain -git branch -f jenkins-docker - # Inputs # DOCKERFILE_DIR - Directory in which Dockerfile file is located. # DOCKER_RUN_SCRIPT - Script to run under docker (relative to grpc repo root) From 92711bbc1271691e9593ee2fd5a7ad27288baa0a Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Fri, 5 Feb 2016 13:10:24 -0800 Subject: [PATCH 18/55] make git clone optional --- tools/jenkins/docker_run.sh | 14 ++++++++++---- tools/run_tests/distribtest_targets.py | 3 ++- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/tools/jenkins/docker_run.sh b/tools/jenkins/docker_run.sh index 49553aae2f7..6fbae40ac2f 100755 --- a/tools/jenkins/docker_run.sh +++ b/tools/jenkins/docker_run.sh @@ -33,16 +33,22 @@ set -e -mkdir -p /var/local/git -git clone --recursive "$EXTERNAL_GIT_ROOT" /var/local/git/grpc +if [ "$RELATIVE_COPY_PATH" == "" ] +then + mkdir -p /var/local/git + git clone --recursive "$EXTERNAL_GIT_ROOT" /var/local/git/grpc +else + mkdir -p "/var/local/git/grpc/$RELATIVE_COPY_PATH" + cp -r "$EXTERNAL_GIT_ROOT/$RELATIVE_COPY_PATH/*" "/var/local/git/grpc/$RELATIVE_COPY_PATH" +fi if [ -x "$(command -v rvm)" ] then rvm use ruby-2.1 fi -cd /var/local/git/grpc - nvm use 4 || true +cd /var/local/git/grpc + $RUN_COMMAND diff --git a/tools/run_tests/distribtest_targets.py b/tools/run_tests/distribtest_targets.py index e9a80d2cf40..a8c90205852 100644 --- a/tools/run_tests/distribtest_targets.py +++ b/tools/run_tests/distribtest_targets.py @@ -43,7 +43,8 @@ def create_docker_jobspec(name, dockerfile_dir, shell_command, environ={}, for k,v in environ.iteritems(): docker_args += ['-e', '%s=%s' % (k, v)] docker_env = {'DOCKERFILE_DIR': dockerfile_dir, - 'DOCKER_RUN_SCRIPT': 'tools/jenkins/docker_run.sh'} + 'DOCKER_RUN_SCRIPT': 'tools/jenkins/docker_run.sh', + 'RELATIVE_COPY_PATH': 'test/distrib'} jobspec = jobset.JobSpec( cmdline=['tools/jenkins/build_and_run_docker.sh'] + docker_args, environ=docker_env, From 5c04760d46f2628a83106d048e732c997fed8801 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Fri, 5 Feb 2016 14:25:56 -0800 Subject: [PATCH 19/55] Change default on Python install option --- src/python/grpcio/commands.py | 2 +- test/distrib/python/run_distrib_test.sh | 3 +-- tools/run_tests/build_artifact_python.sh | 10 ++++++---- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/python/grpcio/commands.py b/src/python/grpcio/commands.py index 490d0f07b3d..31bd00e94ea 100644 --- a/src/python/grpcio/commands.py +++ b/src/python/grpcio/commands.py @@ -135,7 +135,7 @@ class Install(install.install, EggNameMixin): def initialize_options(self): install.install.initialize_options(self) - self.use_grpc_custom_bdist = False + self.use_grpc_custom_bdist = bool(int(os.environ.get('GRPC_PYTHON_USE_CUSTOM_BDIST', '1'))) def finalize_options(self): install.install.finalize_options(self) diff --git a/test/distrib/python/run_distrib_test.sh b/test/distrib/python/run_distrib_test.sh index a185bcbc269..2148be121a2 100755 --- a/test/distrib/python/run_distrib_test.sh +++ b/test/distrib/python/run_distrib_test.sh @@ -52,7 +52,6 @@ pip install --upgrade futures GRPC_PYTHON_BINARIES_REPOSITORY="${BDIST_DIR}" \ pip install \ - "${SDIST_ARCHIVE}" \ - --install-option="--use-grpc-custom-bdist" + "${SDIST_ARCHIVE}" python distribtest.py diff --git a/tools/run_tests/build_artifact_python.sh b/tools/run_tests/build_artifact_python.sh index 48cf390f696..835fad83e14 100755 --- a/tools/run_tests/build_artifact_python.sh +++ b/tools/run_tests/build_artifact_python.sh @@ -39,11 +39,13 @@ then pip install -rrequirements.txt fi -GRPC_PYTHON_BUILD_WITH_CYTHON=1 ${SETARCH_CMD} python setup.py \ - bdist_wheel \ - sdist \ +GRPC_PYTHON_USE_CUSTOM_BDIST=0 \ +GRPC_PYTHON_BUILD_WITH_CYTHON=1 \ +${SETARCH_CMD} python setup.py \ + bdist_wheel \ + sdist \ bdist_egg_grpc_custom mkdir -p artifacts -cp -r dist/* artifacts \ No newline at end of file +cp -r dist/* artifacts From b5f7397b08de46e5241f7bcf74a4662917a42c0d Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Fri, 5 Feb 2016 13:53:47 -0800 Subject: [PATCH 20/55] cleanup distribtest Dockerimages --- tools/dockerfile/distribtest/csharp_centos7_x64/Dockerfile | 1 - tools/dockerfile/distribtest/csharp_jessie_x64/Dockerfile | 2 +- tools/dockerfile/distribtest/csharp_jessie_x86/Dockerfile | 2 +- .../distribtest/csharp_ubuntu1404_x64/Dockerfile | 2 +- .../distribtest/csharp_ubuntu1504_x64/Dockerfile | 2 +- .../distribtest/csharp_ubuntu1510_x64/Dockerfile | 2 +- .../distribtest/csharp_ubuntu1604_x64/Dockerfile | 2 +- tools/dockerfile/distribtest/csharp_wheezy_x64/Dockerfile | 2 +- tools/dockerfile/distribtest/node_centos7_x64/Dockerfile | 1 - tools/dockerfile/distribtest/node_jessie_x64/Dockerfile | 2 +- tools/dockerfile/distribtest/node_jessie_x86/Dockerfile | 2 +- .../dockerfile/distribtest/node_ubuntu1204_x64/Dockerfile | 2 +- .../dockerfile/distribtest/node_ubuntu1404_x64/Dockerfile | 2 +- .../dockerfile/distribtest/node_ubuntu1504_x64/Dockerfile | 2 +- .../dockerfile/distribtest/node_ubuntu1510_x64/Dockerfile | 2 +- .../dockerfile/distribtest/node_ubuntu1604_x64/Dockerfile | 2 +- tools/dockerfile/distribtest/python_arch_x64/Dockerfile | 1 - tools/dockerfile/distribtest/python_centos6_x64/Dockerfile | 1 - tools/dockerfile/distribtest/python_centos7_x64/Dockerfile | 1 - .../dockerfile/distribtest/python_fedora20_x64/Dockerfile | 7 +------ .../dockerfile/distribtest/python_fedora21_x64/Dockerfile | 7 +------ .../dockerfile/distribtest/python_fedora22_x64/Dockerfile | 7 +------ .../dockerfile/distribtest/python_fedora23_x64/Dockerfile | 7 +------ tools/dockerfile/distribtest/python_jessie_x64/Dockerfile | 4 +--- tools/dockerfile/distribtest/python_jessie_x86/Dockerfile | 4 +--- .../dockerfile/distribtest/python_opensuse_x64/Dockerfile | 2 -- .../distribtest/python_ubuntu1204_x64/Dockerfile | 6 +----- .../distribtest/python_ubuntu1404_x64/Dockerfile | 6 +----- .../distribtest/python_ubuntu1504_x64/Dockerfile | 6 +----- .../distribtest/python_ubuntu1510_x64/Dockerfile | 6 +----- .../distribtest/python_ubuntu1604_x64/Dockerfile | 6 +----- tools/dockerfile/distribtest/python_wheezy_x64/Dockerfile | 4 +--- tools/dockerfile/distribtest/ruby_centos6_x64/Dockerfile | 2 -- tools/dockerfile/distribtest/ruby_centos7_x64/Dockerfile | 2 -- tools/dockerfile/distribtest/ruby_fedora20_x64/Dockerfile | 6 +----- tools/dockerfile/distribtest/ruby_fedora21_x64/Dockerfile | 6 +----- tools/dockerfile/distribtest/ruby_fedora22_x64/Dockerfile | 6 +----- tools/dockerfile/distribtest/ruby_fedora23_x64/Dockerfile | 6 +----- tools/dockerfile/distribtest/ruby_jessie_x64/Dockerfile | 5 +---- tools/dockerfile/distribtest/ruby_jessie_x86/Dockerfile | 5 +---- tools/dockerfile/distribtest/ruby_opensuse_x64/Dockerfile | 2 -- .../dockerfile/distribtest/ruby_ubuntu1204_x64/Dockerfile | 5 +---- .../dockerfile/distribtest/ruby_ubuntu1404_x64/Dockerfile | 5 +---- .../dockerfile/distribtest/ruby_ubuntu1504_x64/Dockerfile | 5 +---- .../dockerfile/distribtest/ruby_ubuntu1510_x64/Dockerfile | 5 +---- .../dockerfile/distribtest/ruby_ubuntu1604_x64/Dockerfile | 5 +---- tools/dockerfile/distribtest/ruby_wheezy_x64/Dockerfile | 5 +---- tools/jenkins/docker_run.sh | 4 ++-- tools/run_tests/distribtest_targets.py | 4 ++-- 49 files changed, 42 insertions(+), 141 deletions(-) diff --git a/tools/dockerfile/distribtest/csharp_centos7_x64/Dockerfile b/tools/dockerfile/distribtest/csharp_centos7_x64/Dockerfile index 17e9698904c..03b5b364f8e 100644 --- a/tools/dockerfile/distribtest/csharp_centos7_x64/Dockerfile +++ b/tools/dockerfile/distribtest/csharp_centos7_x64/Dockerfile @@ -33,6 +33,5 @@ RUN rpm --import "http://keyserver.ubuntu.com/pks/lookup?op=get&search=0x3FA7E03 RUN yum-config-manager --add-repo http://download.mono-project.com/repo/centos/ RUN yum install -y mono -RUN yum install -y git RUN yum install -y unzip RUN yum install -y nuget diff --git a/tools/dockerfile/distribtest/csharp_jessie_x64/Dockerfile b/tools/dockerfile/distribtest/csharp_jessie_x64/Dockerfile index 840ecf0fc2f..1cadba3b7b9 100644 --- a/tools/dockerfile/distribtest/csharp_jessie_x64/Dockerfile +++ b/tools/dockerfile/distribtest/csharp_jessie_x64/Dockerfile @@ -40,4 +40,4 @@ RUN apt-get update && apt-get install -y \ ca-certificates-mono \ nuget -RUN apt-get update && apt-get install -y git unzip +RUN apt-get update && apt-get install -y unzip diff --git a/tools/dockerfile/distribtest/csharp_jessie_x86/Dockerfile b/tools/dockerfile/distribtest/csharp_jessie_x86/Dockerfile index 3a50da49367..be962828c28 100644 --- a/tools/dockerfile/distribtest/csharp_jessie_x86/Dockerfile +++ b/tools/dockerfile/distribtest/csharp_jessie_x86/Dockerfile @@ -40,4 +40,4 @@ RUN apt-get update && apt-get install -y \ ca-certificates-mono \ nuget -RUN apt-get update && apt-get install -y git unzip +RUN apt-get update && apt-get install -y unzip diff --git a/tools/dockerfile/distribtest/csharp_ubuntu1404_x64/Dockerfile b/tools/dockerfile/distribtest/csharp_ubuntu1404_x64/Dockerfile index 901c981acb8..3d04d032b5a 100644 --- a/tools/dockerfile/distribtest/csharp_ubuntu1404_x64/Dockerfile +++ b/tools/dockerfile/distribtest/csharp_ubuntu1404_x64/Dockerfile @@ -37,4 +37,4 @@ RUN apt-get update && apt-get install -y \ ca-certificates-mono \ nuget -RUN apt-get update && apt-get install -y git unzip +RUN apt-get update && apt-get install -y unzip diff --git a/tools/dockerfile/distribtest/csharp_ubuntu1504_x64/Dockerfile b/tools/dockerfile/distribtest/csharp_ubuntu1504_x64/Dockerfile index 1b8d4546812..5eec570491c 100644 --- a/tools/dockerfile/distribtest/csharp_ubuntu1504_x64/Dockerfile +++ b/tools/dockerfile/distribtest/csharp_ubuntu1504_x64/Dockerfile @@ -37,4 +37,4 @@ RUN apt-get update && apt-get install -y \ ca-certificates-mono \ nuget -RUN apt-get update && apt-get install -y git unzip +RUN apt-get update && apt-get install -y unzip diff --git a/tools/dockerfile/distribtest/csharp_ubuntu1510_x64/Dockerfile b/tools/dockerfile/distribtest/csharp_ubuntu1510_x64/Dockerfile index a6c26a4b9e3..a6d60fb4b91 100644 --- a/tools/dockerfile/distribtest/csharp_ubuntu1510_x64/Dockerfile +++ b/tools/dockerfile/distribtest/csharp_ubuntu1510_x64/Dockerfile @@ -37,4 +37,4 @@ RUN apt-get update && apt-get install -y \ ca-certificates-mono \ nuget -RUN apt-get update && apt-get install -y git unzip +RUN apt-get update && apt-get install -y unzip diff --git a/tools/dockerfile/distribtest/csharp_ubuntu1604_x64/Dockerfile b/tools/dockerfile/distribtest/csharp_ubuntu1604_x64/Dockerfile index c6a86349372..61472704d7d 100644 --- a/tools/dockerfile/distribtest/csharp_ubuntu1604_x64/Dockerfile +++ b/tools/dockerfile/distribtest/csharp_ubuntu1604_x64/Dockerfile @@ -34,4 +34,4 @@ RUN apt-get update && apt-get install -y \ ca-certificates-mono \ nuget -RUN apt-get update && apt-get install -y git unzip +RUN apt-get update && apt-get install -y unzip diff --git a/tools/dockerfile/distribtest/csharp_wheezy_x64/Dockerfile b/tools/dockerfile/distribtest/csharp_wheezy_x64/Dockerfile index dd865e8bbc5..9039c3c509f 100644 --- a/tools/dockerfile/distribtest/csharp_wheezy_x64/Dockerfile +++ b/tools/dockerfile/distribtest/csharp_wheezy_x64/Dockerfile @@ -29,4 +29,4 @@ FROM mono:4.2.2.30 -RUN apt-get update && apt-get install -y git unzip +RUN apt-get update && apt-get install -y unzip diff --git a/tools/dockerfile/distribtest/node_centos7_x64/Dockerfile b/tools/dockerfile/distribtest/node_centos7_x64/Dockerfile index 9c1f5ee7297..f6e1664086a 100644 --- a/tools/dockerfile/distribtest/node_centos7_x64/Dockerfile +++ b/tools/dockerfile/distribtest/node_centos7_x64/Dockerfile @@ -29,7 +29,6 @@ FROM centos:7 -RUN yum install -y git RUN yum install -y curl # Install nvm diff --git a/tools/dockerfile/distribtest/node_jessie_x64/Dockerfile b/tools/dockerfile/distribtest/node_jessie_x64/Dockerfile index 69a071500ee..4ca5e86563b 100644 --- a/tools/dockerfile/distribtest/node_jessie_x64/Dockerfile +++ b/tools/dockerfile/distribtest/node_jessie_x64/Dockerfile @@ -29,7 +29,7 @@ FROM debian:jessie -RUN apt-get update && apt-get install -y curl git +RUN apt-get update && apt-get install -y curl # Install nvm RUN touch .profile diff --git a/tools/dockerfile/distribtest/node_jessie_x86/Dockerfile b/tools/dockerfile/distribtest/node_jessie_x86/Dockerfile index 173c70360dc..bd40ab2b4cb 100644 --- a/tools/dockerfile/distribtest/node_jessie_x86/Dockerfile +++ b/tools/dockerfile/distribtest/node_jessie_x86/Dockerfile @@ -29,7 +29,7 @@ FROM 32bit/debian:jessie -RUN apt-get update && apt-get install -y curl git +RUN apt-get update && apt-get install -y git # Install nvm RUN touch .profile diff --git a/tools/dockerfile/distribtest/node_ubuntu1204_x64/Dockerfile b/tools/dockerfile/distribtest/node_ubuntu1204_x64/Dockerfile index c53a4aa305d..0134dc964e7 100644 --- a/tools/dockerfile/distribtest/node_ubuntu1204_x64/Dockerfile +++ b/tools/dockerfile/distribtest/node_ubuntu1204_x64/Dockerfile @@ -29,7 +29,7 @@ FROM ubuntu:12.04 -RUN apt-get update && apt-get install -y curl git +RUN apt-get update && apt-get install -y curl # Install nvm RUN touch .profile diff --git a/tools/dockerfile/distribtest/node_ubuntu1404_x64/Dockerfile b/tools/dockerfile/distribtest/node_ubuntu1404_x64/Dockerfile index 8fe6ae1f335..0fae447946d 100644 --- a/tools/dockerfile/distribtest/node_ubuntu1404_x64/Dockerfile +++ b/tools/dockerfile/distribtest/node_ubuntu1404_x64/Dockerfile @@ -29,7 +29,7 @@ FROM ubuntu:14.04 -RUN apt-get update && apt-get install -y curl git +RUN apt-get update && apt-get install -y curl # Install nvm RUN touch .profile diff --git a/tools/dockerfile/distribtest/node_ubuntu1504_x64/Dockerfile b/tools/dockerfile/distribtest/node_ubuntu1504_x64/Dockerfile index 013c2a0c72a..55da46c3be4 100644 --- a/tools/dockerfile/distribtest/node_ubuntu1504_x64/Dockerfile +++ b/tools/dockerfile/distribtest/node_ubuntu1504_x64/Dockerfile @@ -29,7 +29,7 @@ FROM ubuntu:15.04 -RUN apt-get update && apt-get install -y curl git +RUN apt-get update && apt-get install -y curl # Install nvm RUN touch .profile diff --git a/tools/dockerfile/distribtest/node_ubuntu1510_x64/Dockerfile b/tools/dockerfile/distribtest/node_ubuntu1510_x64/Dockerfile index 43b3ae2738a..c050cab7d33 100644 --- a/tools/dockerfile/distribtest/node_ubuntu1510_x64/Dockerfile +++ b/tools/dockerfile/distribtest/node_ubuntu1510_x64/Dockerfile @@ -29,7 +29,7 @@ FROM ubuntu:15.10 -RUN apt-get update && apt-get install -y curl git +RUN apt-get update && apt-get install -y curl # Install nvm RUN touch .profile diff --git a/tools/dockerfile/distribtest/node_ubuntu1604_x64/Dockerfile b/tools/dockerfile/distribtest/node_ubuntu1604_x64/Dockerfile index 3eae75475cd..ab9e8a32e34 100644 --- a/tools/dockerfile/distribtest/node_ubuntu1604_x64/Dockerfile +++ b/tools/dockerfile/distribtest/node_ubuntu1604_x64/Dockerfile @@ -29,7 +29,7 @@ FROM ubuntu:16.04 -RUN apt-get update && apt-get install -y curl git +RUN apt-get update && apt-get install -y curl # Install nvm RUN touch .profile diff --git a/tools/dockerfile/distribtest/python_arch_x64/Dockerfile b/tools/dockerfile/distribtest/python_arch_x64/Dockerfile index 4d10e240c60..53bb8e8708f 100644 --- a/tools/dockerfile/distribtest/python_arch_x64/Dockerfile +++ b/tools/dockerfile/distribtest/python_arch_x64/Dockerfile @@ -30,7 +30,6 @@ FROM base/archlinux RUN pacman --noconfirm -Syy -RUN pacman --noconfirm -S git RUN pacman --noconfirm -S python RUN pacman --noconfirm -S python-pip diff --git a/tools/dockerfile/distribtest/python_centos6_x64/Dockerfile b/tools/dockerfile/distribtest/python_centos6_x64/Dockerfile index 683686c6dbb..3889f8862f9 100644 --- a/tools/dockerfile/distribtest/python_centos6_x64/Dockerfile +++ b/tools/dockerfile/distribtest/python_centos6_x64/Dockerfile @@ -29,7 +29,6 @@ FROM centos:6 -RUN yum install -y git RUN yum install -y python RUN rpm -ivh http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm diff --git a/tools/dockerfile/distribtest/python_centos7_x64/Dockerfile b/tools/dockerfile/distribtest/python_centos7_x64/Dockerfile index 6b70f65f10c..114957b5730 100644 --- a/tools/dockerfile/distribtest/python_centos7_x64/Dockerfile +++ b/tools/dockerfile/distribtest/python_centos7_x64/Dockerfile @@ -29,7 +29,6 @@ FROM centos:7 -RUN yum install -y git RUN yum install -y python RUN yum install -y epel-release RUN yum install -y python-pip diff --git a/tools/dockerfile/distribtest/python_fedora20_x64/Dockerfile b/tools/dockerfile/distribtest/python_fedora20_x64/Dockerfile index 1c915943633..d58036410f6 100644 --- a/tools/dockerfile/distribtest/python_fedora20_x64/Dockerfile +++ b/tools/dockerfile/distribtest/python_fedora20_x64/Dockerfile @@ -29,9 +29,4 @@ FROM fedora:20 -RUN yum clean all -RUN yum update -y -RUN yum install -y git -RUN yum install -y python -RUN yum install -y python-pip - +RUN yum clean all && yum update -y && yum install -y python python-pip diff --git a/tools/dockerfile/distribtest/python_fedora21_x64/Dockerfile b/tools/dockerfile/distribtest/python_fedora21_x64/Dockerfile index e35de109ea3..b44fcff7e31 100644 --- a/tools/dockerfile/distribtest/python_fedora21_x64/Dockerfile +++ b/tools/dockerfile/distribtest/python_fedora21_x64/Dockerfile @@ -29,9 +29,4 @@ FROM fedora:21 -RUN yum clean all -RUN yum update -y -RUN yum install -y git -RUN yum install -y python -RUN yum install -y python-pip - +RUN yum clean all && yum update -y && yum install -y python python-pip diff --git a/tools/dockerfile/distribtest/python_fedora22_x64/Dockerfile b/tools/dockerfile/distribtest/python_fedora22_x64/Dockerfile index 69c3b541d3b..c6415946c3b 100644 --- a/tools/dockerfile/distribtest/python_fedora22_x64/Dockerfile +++ b/tools/dockerfile/distribtest/python_fedora22_x64/Dockerfile @@ -29,9 +29,4 @@ FROM fedora:22 -RUN yum clean all -RUN yum update -y -RUN yum install -y git -RUN yum install -y python -RUN yum install -y python-pip - +RUN yum clean all && yum update -y && yum install -y python python-pip diff --git a/tools/dockerfile/distribtest/python_fedora23_x64/Dockerfile b/tools/dockerfile/distribtest/python_fedora23_x64/Dockerfile index 74639a3118e..6c834d2bc2f 100644 --- a/tools/dockerfile/distribtest/python_fedora23_x64/Dockerfile +++ b/tools/dockerfile/distribtest/python_fedora23_x64/Dockerfile @@ -29,9 +29,4 @@ FROM fedora:23 -RUN yum clean all -RUN yum update -y -RUN yum install -y git -RUN yum install -y python -RUN yum install -y python-pip - +RUN yum clean all && yum update -y && yum install -y python python-pip diff --git a/tools/dockerfile/distribtest/python_jessie_x64/Dockerfile b/tools/dockerfile/distribtest/python_jessie_x64/Dockerfile index 3d511e267a6..5778d604c8e 100644 --- a/tools/dockerfile/distribtest/python_jessie_x64/Dockerfile +++ b/tools/dockerfile/distribtest/python_jessie_x64/Dockerfile @@ -29,6 +29,4 @@ FROM debian:jessie -RUN apt-get update -RUN apt-get install -y git python python-pip - +RUN apt-get update && apt-get install -y python python-pip diff --git a/tools/dockerfile/distribtest/python_jessie_x86/Dockerfile b/tools/dockerfile/distribtest/python_jessie_x86/Dockerfile index 035d56b655b..cb6ec22d0ac 100644 --- a/tools/dockerfile/distribtest/python_jessie_x86/Dockerfile +++ b/tools/dockerfile/distribtest/python_jessie_x86/Dockerfile @@ -29,6 +29,4 @@ FROM 32bit/debian:jessie -RUN apt-get update -RUN apt-get install -y git python python-pip - +RUN apt-get update && apt-get install -y python python-pip diff --git a/tools/dockerfile/distribtest/python_opensuse_x64/Dockerfile b/tools/dockerfile/distribtest/python_opensuse_x64/Dockerfile index 032beb97e59..417d9e0293b 100644 --- a/tools/dockerfile/distribtest/python_opensuse_x64/Dockerfile +++ b/tools/dockerfile/distribtest/python_opensuse_x64/Dockerfile @@ -29,7 +29,5 @@ FROM opensuse:42.1 -RUN zypper --non-interactive install git RUN zypper --non-interactive install python RUN zypper --non-interactive install python-pip - diff --git a/tools/dockerfile/distribtest/python_ubuntu1204_x64/Dockerfile b/tools/dockerfile/distribtest/python_ubuntu1204_x64/Dockerfile index 9dbf90f5115..a48ce0eeefd 100644 --- a/tools/dockerfile/distribtest/python_ubuntu1204_x64/Dockerfile +++ b/tools/dockerfile/distribtest/python_ubuntu1204_x64/Dockerfile @@ -29,8 +29,4 @@ FROM ubuntu:12.04 -RUN apt-get update -y -RUN apt-get install -y git -RUN apt-get install -y python -RUN apt-get install -y python-pip - +RUN apt-get update -y && apt-get install -y python python-pip diff --git a/tools/dockerfile/distribtest/python_ubuntu1404_x64/Dockerfile b/tools/dockerfile/distribtest/python_ubuntu1404_x64/Dockerfile index 3b366a9bb44..18dbfd46573 100644 --- a/tools/dockerfile/distribtest/python_ubuntu1404_x64/Dockerfile +++ b/tools/dockerfile/distribtest/python_ubuntu1404_x64/Dockerfile @@ -29,8 +29,4 @@ FROM ubuntu:14.04 -RUN apt-get update -y -RUN apt-get install -y git -RUN apt-get install -y python -RUN apt-get install -y python-pip - +RUN apt-get update -y && apt-get install -y python python-pip diff --git a/tools/dockerfile/distribtest/python_ubuntu1504_x64/Dockerfile b/tools/dockerfile/distribtest/python_ubuntu1504_x64/Dockerfile index de90b5b7e24..444a54d14ba 100644 --- a/tools/dockerfile/distribtest/python_ubuntu1504_x64/Dockerfile +++ b/tools/dockerfile/distribtest/python_ubuntu1504_x64/Dockerfile @@ -29,8 +29,4 @@ FROM ubuntu:15.04 -RUN apt-get update -y -RUN apt-get install -y git -RUN apt-get install -y python -RUN apt-get install -y python-pip - +RUN apt-get update -y && apt-get install -y python python-pip diff --git a/tools/dockerfile/distribtest/python_ubuntu1510_x64/Dockerfile b/tools/dockerfile/distribtest/python_ubuntu1510_x64/Dockerfile index d10e04aaccf..245ffb94137 100644 --- a/tools/dockerfile/distribtest/python_ubuntu1510_x64/Dockerfile +++ b/tools/dockerfile/distribtest/python_ubuntu1510_x64/Dockerfile @@ -29,8 +29,4 @@ FROM ubuntu:15.10 -RUN apt-get update -y -RUN apt-get install -y git -RUN apt-get install -y python -RUN apt-get install -y python-pip - +RUN apt-get update -y && apt-get install -y python python-pip diff --git a/tools/dockerfile/distribtest/python_ubuntu1604_x64/Dockerfile b/tools/dockerfile/distribtest/python_ubuntu1604_x64/Dockerfile index bc56285a3de..a1ac3051ba9 100644 --- a/tools/dockerfile/distribtest/python_ubuntu1604_x64/Dockerfile +++ b/tools/dockerfile/distribtest/python_ubuntu1604_x64/Dockerfile @@ -29,8 +29,4 @@ FROM ubuntu:16.04 -RUN apt-get update -y -RUN apt-get install -y git -RUN apt-get install -y python -RUN apt-get install -y python-pip - +RUN apt-get update -y && apt-get install -y python python-pip diff --git a/tools/dockerfile/distribtest/python_wheezy_x64/Dockerfile b/tools/dockerfile/distribtest/python_wheezy_x64/Dockerfile index 895dd967473..46353b92d62 100644 --- a/tools/dockerfile/distribtest/python_wheezy_x64/Dockerfile +++ b/tools/dockerfile/distribtest/python_wheezy_x64/Dockerfile @@ -29,6 +29,4 @@ FROM debian:wheezy -RUN apt-get update -RUN apt-get install -y git python python-pip - +RUN apt-get update -y && apt-get install -y python python-pip diff --git a/tools/dockerfile/distribtest/ruby_centos6_x64/Dockerfile b/tools/dockerfile/distribtest/ruby_centos6_x64/Dockerfile index 28a5c4ad716..fd2cf63a59e 100644 --- a/tools/dockerfile/distribtest/ruby_centos6_x64/Dockerfile +++ b/tools/dockerfile/distribtest/ruby_centos6_x64/Dockerfile @@ -29,6 +29,4 @@ FROM centos:6 -RUN yum install -y git RUN yum install -y ruby - diff --git a/tools/dockerfile/distribtest/ruby_centos7_x64/Dockerfile b/tools/dockerfile/distribtest/ruby_centos7_x64/Dockerfile index bdc100ee1cc..5bb9bd6fa64 100644 --- a/tools/dockerfile/distribtest/ruby_centos7_x64/Dockerfile +++ b/tools/dockerfile/distribtest/ruby_centos7_x64/Dockerfile @@ -29,6 +29,4 @@ FROM centos:7 -RUN yum install -y git RUN yum install -y ruby - diff --git a/tools/dockerfile/distribtest/ruby_fedora20_x64/Dockerfile b/tools/dockerfile/distribtest/ruby_fedora20_x64/Dockerfile index 50ff0b038b8..9f23be986f1 100644 --- a/tools/dockerfile/distribtest/ruby_fedora20_x64/Dockerfile +++ b/tools/dockerfile/distribtest/ruby_fedora20_x64/Dockerfile @@ -29,8 +29,4 @@ FROM fedora:20 -RUN yum clean all -RUN yum update -y -RUN yum install -y git -RUN yum install -y ruby - +RUN yum clean all && yum update -y && yum install -y ruby diff --git a/tools/dockerfile/distribtest/ruby_fedora21_x64/Dockerfile b/tools/dockerfile/distribtest/ruby_fedora21_x64/Dockerfile index 219ecc8b532..57106a48946 100644 --- a/tools/dockerfile/distribtest/ruby_fedora21_x64/Dockerfile +++ b/tools/dockerfile/distribtest/ruby_fedora21_x64/Dockerfile @@ -29,8 +29,4 @@ FROM fedora:21 -RUN yum clean all -RUN yum update -y -RUN yum install -y git -RUN yum install -y ruby - +RUN yum clean all && yum update -y && yum install -y ruby diff --git a/tools/dockerfile/distribtest/ruby_fedora22_x64/Dockerfile b/tools/dockerfile/distribtest/ruby_fedora22_x64/Dockerfile index 49d4c7d7f82..d770177381e 100644 --- a/tools/dockerfile/distribtest/ruby_fedora22_x64/Dockerfile +++ b/tools/dockerfile/distribtest/ruby_fedora22_x64/Dockerfile @@ -29,8 +29,4 @@ FROM fedora:22 -RUN yum clean all -RUN yum update -y -RUN yum install -y git -RUN yum install -y ruby - +RUN yum clean all && yum update -y && yum install -y ruby diff --git a/tools/dockerfile/distribtest/ruby_fedora23_x64/Dockerfile b/tools/dockerfile/distribtest/ruby_fedora23_x64/Dockerfile index 3c5363fb63f..2c9b78ed080 100644 --- a/tools/dockerfile/distribtest/ruby_fedora23_x64/Dockerfile +++ b/tools/dockerfile/distribtest/ruby_fedora23_x64/Dockerfile @@ -29,8 +29,4 @@ FROM fedora:23 -RUN yum clean all -RUN yum update -y -RUN yum install -y git -RUN yum install -y ruby - +RUN yum clean all && yum update -y && yum install -y ruby diff --git a/tools/dockerfile/distribtest/ruby_jessie_x64/Dockerfile b/tools/dockerfile/distribtest/ruby_jessie_x64/Dockerfile index 6a3d7edba0d..4784bd73b41 100644 --- a/tools/dockerfile/distribtest/ruby_jessie_x64/Dockerfile +++ b/tools/dockerfile/distribtest/ruby_jessie_x64/Dockerfile @@ -29,7 +29,4 @@ FROM debian:jessie -RUN apt-get update -RUN apt-get install -y git -RUN apt-get install -y ruby-full - +RUN apt-get update && apt-get install -y ruby-full diff --git a/tools/dockerfile/distribtest/ruby_jessie_x86/Dockerfile b/tools/dockerfile/distribtest/ruby_jessie_x86/Dockerfile index ca3b731f569..4f649cbc034 100644 --- a/tools/dockerfile/distribtest/ruby_jessie_x86/Dockerfile +++ b/tools/dockerfile/distribtest/ruby_jessie_x86/Dockerfile @@ -29,7 +29,4 @@ FROM 32bit/debian:jessie -RUN apt-get update -RUN apt-get install -y git -RUN apt-get install -y ruby-full - +RUN apt-get update && apt-get install -y ruby-full diff --git a/tools/dockerfile/distribtest/ruby_opensuse_x64/Dockerfile b/tools/dockerfile/distribtest/ruby_opensuse_x64/Dockerfile index a9423042eaa..a2499509984 100644 --- a/tools/dockerfile/distribtest/ruby_opensuse_x64/Dockerfile +++ b/tools/dockerfile/distribtest/ruby_opensuse_x64/Dockerfile @@ -29,6 +29,4 @@ FROM opensuse:42.1 -RUN zypper --non-interactive install git RUN zypper --non-interactive install ruby - diff --git a/tools/dockerfile/distribtest/ruby_ubuntu1204_x64/Dockerfile b/tools/dockerfile/distribtest/ruby_ubuntu1204_x64/Dockerfile index 66f17100cf8..95b7702afb7 100644 --- a/tools/dockerfile/distribtest/ruby_ubuntu1204_x64/Dockerfile +++ b/tools/dockerfile/distribtest/ruby_ubuntu1204_x64/Dockerfile @@ -29,7 +29,4 @@ FROM ubuntu:12.04 -RUN apt-get update -y -RUN apt-get install -y git -RUN apt-get install -y ruby-full - +RUN apt-get update -y && apt-get install -y ruby-full diff --git a/tools/dockerfile/distribtest/ruby_ubuntu1404_x64/Dockerfile b/tools/dockerfile/distribtest/ruby_ubuntu1404_x64/Dockerfile index dc533a5fcac..66ba01d37ed 100644 --- a/tools/dockerfile/distribtest/ruby_ubuntu1404_x64/Dockerfile +++ b/tools/dockerfile/distribtest/ruby_ubuntu1404_x64/Dockerfile @@ -29,7 +29,4 @@ FROM ubuntu:14.04 -RUN apt-get update -y -RUN apt-get install -y git -RUN apt-get install -y ruby-full - +RUN apt-get update -y && apt-get install -y ruby-full diff --git a/tools/dockerfile/distribtest/ruby_ubuntu1504_x64/Dockerfile b/tools/dockerfile/distribtest/ruby_ubuntu1504_x64/Dockerfile index 7e4f203041e..81e7ca1d3c0 100644 --- a/tools/dockerfile/distribtest/ruby_ubuntu1504_x64/Dockerfile +++ b/tools/dockerfile/distribtest/ruby_ubuntu1504_x64/Dockerfile @@ -29,7 +29,4 @@ FROM ubuntu:15.04 -RUN apt-get update -y -RUN apt-get install -y git -RUN apt-get install -y ruby-full - +RUN apt-get update -y && apt-get install -y ruby-full diff --git a/tools/dockerfile/distribtest/ruby_ubuntu1510_x64/Dockerfile b/tools/dockerfile/distribtest/ruby_ubuntu1510_x64/Dockerfile index 43ef63ec8ca..37b897f0f55 100644 --- a/tools/dockerfile/distribtest/ruby_ubuntu1510_x64/Dockerfile +++ b/tools/dockerfile/distribtest/ruby_ubuntu1510_x64/Dockerfile @@ -29,7 +29,4 @@ FROM ubuntu:15.10 -RUN apt-get update -y -RUN apt-get install -y git -RUN apt-get install -y ruby-full - +RUN apt-get update -y && apt-get install -y ruby-full diff --git a/tools/dockerfile/distribtest/ruby_ubuntu1604_x64/Dockerfile b/tools/dockerfile/distribtest/ruby_ubuntu1604_x64/Dockerfile index 3b63976d3cc..5c54b8f7546 100644 --- a/tools/dockerfile/distribtest/ruby_ubuntu1604_x64/Dockerfile +++ b/tools/dockerfile/distribtest/ruby_ubuntu1604_x64/Dockerfile @@ -29,7 +29,4 @@ FROM ubuntu:16.04 -RUN apt-get update -y -RUN apt-get install -y git -RUN apt-get install -y ruby-full - +RUN apt-get update -y && apt-get install -y ruby-full diff --git a/tools/dockerfile/distribtest/ruby_wheezy_x64/Dockerfile b/tools/dockerfile/distribtest/ruby_wheezy_x64/Dockerfile index 1ff083d43c8..2e6593c230d 100644 --- a/tools/dockerfile/distribtest/ruby_wheezy_x64/Dockerfile +++ b/tools/dockerfile/distribtest/ruby_wheezy_x64/Dockerfile @@ -29,7 +29,4 @@ FROM debian:wheezy -RUN apt-get update -RUN apt-get install -y git -RUN apt-get install -y ruby-full - +RUN apt-get update && apt-get install -y ruby-full diff --git a/tools/jenkins/docker_run.sh b/tools/jenkins/docker_run.sh index 6fbae40ac2f..519dc5cade6 100755 --- a/tools/jenkins/docker_run.sh +++ b/tools/jenkins/docker_run.sh @@ -31,7 +31,7 @@ # This script is invoked by build_docker_* inside a docker # container. You should never need to call this script on your own. -set -e +set -ex if [ "$RELATIVE_COPY_PATH" == "" ] then @@ -39,7 +39,7 @@ then git clone --recursive "$EXTERNAL_GIT_ROOT" /var/local/git/grpc else mkdir -p "/var/local/git/grpc/$RELATIVE_COPY_PATH" - cp -r "$EXTERNAL_GIT_ROOT/$RELATIVE_COPY_PATH/*" "/var/local/git/grpc/$RELATIVE_COPY_PATH" + cp -r "$EXTERNAL_GIT_ROOT/$RELATIVE_COPY_PATH"/* "/var/local/git/grpc/$RELATIVE_COPY_PATH" fi if [ -x "$(command -v rvm)" ] diff --git a/tools/run_tests/distribtest_targets.py b/tools/run_tests/distribtest_targets.py index a8c90205852..a1e45ece9dc 100644 --- a/tools/run_tests/distribtest_targets.py +++ b/tools/run_tests/distribtest_targets.py @@ -38,13 +38,13 @@ def create_docker_jobspec(name, dockerfile_dir, shell_command, environ={}, """Creates jobspec for a task running under docker.""" environ = environ.copy() environ['RUN_COMMAND'] = shell_command + environ['RELATIVE_COPY_PATH'] = 'test/distrib' docker_args=[] for k,v in environ.iteritems(): docker_args += ['-e', '%s=%s' % (k, v)] docker_env = {'DOCKERFILE_DIR': dockerfile_dir, - 'DOCKER_RUN_SCRIPT': 'tools/jenkins/docker_run.sh', - 'RELATIVE_COPY_PATH': 'test/distrib'} + 'DOCKER_RUN_SCRIPT': 'tools/jenkins/docker_run.sh'} jobspec = jobset.JobSpec( cmdline=['tools/jenkins/build_and_run_docker.sh'] + docker_args, environ=docker_env, From a7f3e057605586eec0c496c5c600146289703926 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Fri, 5 Feb 2016 15:02:39 -0800 Subject: [PATCH 21/55] Actually use compiler flags --- setup.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/setup.py b/setup.py index 720e4f75f6c..80828a3b4a9 100644 --- a/setup.py +++ b/setup.py @@ -118,6 +118,8 @@ def cython_extensions(package_names, module_names, extra_sources, include_dirs, sources=[module_file] + extra_sources, include_dirs=include_dirs, libraries=libraries, define_macros=define_macros, + extra_compile_args=list(CFLAGS), + extra_link_args=list(LDFLAGS), ) for (module_name, module_file) in zip(module_names, module_files) ] if build_with_cython: From b3ac991d9e0f27141718b3e44daa071feba5fc4e Mon Sep 17 00:00:00 2001 From: murgatroid99 Date: Fri, 5 Feb 2016 14:40:04 -0800 Subject: [PATCH 22/55] Fix function pointer type in timeout_encoding_test --- test/core/transport/chttp2/timeout_encoding_test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/core/transport/chttp2/timeout_encoding_test.c b/test/core/transport/chttp2/timeout_encoding_test.c index f0e8ec386fc..483e79fb253 100644 --- a/test/core/transport/chttp2/timeout_encoding_test.c +++ b/test/core/transport/chttp2/timeout_encoding_test.c @@ -93,7 +93,7 @@ static void assert_decodes_as(const char *buffer, gpr_timespec expected) { } void decode_suite(char ext, - gpr_timespec (*answer)(long x, gpr_clock_type clock)) { + gpr_timespec (*answer)(int64_t x, gpr_clock_type clock)) { long test_vals[] = {1, 12, 123, 1234, 12345, 123456, 1234567, 12345678, 123456789, 98765432, 9876543, 987654, 98765, 9876, 987, 98, 9}; From 86cbe3087ca5817416f9045047c9bb478dff8cb6 Mon Sep 17 00:00:00 2001 From: Nicolas Noble Date: Fri, 5 Feb 2016 15:08:12 -0800 Subject: [PATCH 23/55] Fixing Mac build for Ruby. --- Rakefile | 18 ++++++++++-------- src/ruby/ext/grpc/extconf.rb | 2 ++ src/ruby/ext/grpc/rb_channel.c | 2 +- src/ruby/ext/grpc/rb_server_credentials.c | 2 +- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/Rakefile b/Rakefile index 70406969477..1f9bbcf7f64 100755 --- a/Rakefile +++ b/Rakefile @@ -3,6 +3,7 @@ require 'rake/extensiontask' require 'rspec/core/rake_task' require 'rubocop/rake_task' require 'bundler/gem_tasks' +require 'fileutils' load 'tools/distrib/docker_for_windows.rb' @@ -26,11 +27,7 @@ Rake::ExtensionTask.new('grpc_c', spec) do |ext| ext.cross_platform = [ 'x86-mingw32', 'x64-mingw32', 'x86_64-linux', 'x86-linux', - 'x86_64-darwin-11', - 'x86_64-darwin-12', - 'x86_64-darwin-13', - 'x86_64-darwin-14', - 'x86_64-darwin-15' + 'universal-darwin' ] ext.cross_compiling do |spec| spec.files = %w( etc/roots.pem grpc_c.32.ruby grpc_c.64.ruby ) @@ -103,7 +100,14 @@ desc 'Build the native gem file under rake_compiler_dock' task 'gem:native' do verbose = ENV['V'] || '0' - docker_for_windows "bundle && rake cross native gem RUBY_CC_VERSION=2.3.0:2.2.2:2.1.6:2.0.0 V=#{verbose}" + if RUBY_PLATFORM =~ /darwin/ + FileUtils.touch 'grpc_c.32.ruby' + FileUtils.touch 'grpc_c.64.ruby' + system "rake cross native gem RUBY_CC_VERSION=2.3.0:2.2.2:2.1.6:2.0.0 V=#{verbose}" + else + Rake::Task['dlls'].execute + docker_for_windows "bundle && rake cross native gem RUBY_CC_VERSION=2.3.0:2.2.2:2.1.6:2.0.0 V=#{verbose}" + end end # Define dependencies between the suites. @@ -113,8 +117,6 @@ task 'suite:bidi' => 'suite:wrapper' task 'suite:server' => 'suite:wrapper' task 'suite:pb' => 'suite:server' -task 'gem:native' => 'dlls' - desc 'Compiles the gRPC extension then runs all the tests' task all: ['suite:idiomatic', 'suite:bidi', 'suite:pb', 'suite:server'] task default: :all diff --git a/src/ruby/ext/grpc/extconf.rb b/src/ruby/ext/grpc/extconf.rb index 503403392da..b7c6cb3d7ea 100644 --- a/src/ruby/ext/grpc/extconf.rb +++ b/src/ruby/ext/grpc/extconf.rb @@ -66,6 +66,8 @@ else grpc_lib_dir = File.join(grpc_root, 'libs', grpc_config) end +ENV['MACOSX_DEPLOYMENT_TARGET'] = '10.7' + unless File.exist?(File.join(grpc_lib_dir, 'libgrpc.a')) or windows ENV['AR'] = RbConfig::CONFIG['AR'] + ' rcs' ENV['CC'] = RbConfig::CONFIG['CC'] diff --git a/src/ruby/ext/grpc/rb_channel.c b/src/ruby/ext/grpc/rb_channel.c index d1e48753f27..0e6badbdaf0 100644 --- a/src/ruby/ext/grpc/rb_channel.c +++ b/src/ruby/ext/grpc/rb_channel.c @@ -229,7 +229,7 @@ static VALUE grpc_rb_channel_watch_connectivity_state(VALUE self, } grpc_channel_watch_connectivity_state( ch, - NUM2LONG(last_state), + (grpc_connectivity_state)NUM2LONG(last_state), grpc_rb_time_timeval(deadline, /* absolute time */ 0), cq, ROBJECT(tag)); diff --git a/src/ruby/ext/grpc/rb_server_credentials.c b/src/ruby/ext/grpc/rb_server_credentials.c index f866aecd289..4ea59b6b27f 100644 --- a/src/ruby/ext/grpc/rb_server_credentials.c +++ b/src/ruby/ext/grpc/rb_server_credentials.c @@ -177,7 +177,7 @@ static VALUE grpc_rb_server_credentials_init(VALUE self, VALUE pem_root_certs, VALUE key = Qnil; VALUE key_cert = Qnil; int auth_client = 0; - int num_key_certs = 0; + long num_key_certs = 0; int i; if (NIL_P(force_client_auth) || From 85474df7b3f4ba2060d2c9a9debfb3829b2131d9 Mon Sep 17 00:00:00 2001 From: murgatroid99 Date: Fri, 5 Feb 2016 15:51:47 -0800 Subject: [PATCH 24/55] Reverse changes to AVL code --- include/grpc/support/avl.h | 4 ++-- src/core/support/avl.c | 12 ++++++------ test/core/support/avl_test.c | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/include/grpc/support/avl.h b/include/grpc/support/avl.h index 623da6698c4..3433124c6fa 100644 --- a/include/grpc/support/avl.h +++ b/include/grpc/support/avl.h @@ -43,7 +43,7 @@ typedef struct gpr_avl_node { void *value; struct gpr_avl_node *left; struct gpr_avl_node *right; - int64_t height; + long height; } gpr_avl_node; typedef struct gpr_avl_vtable { @@ -53,7 +53,7 @@ typedef struct gpr_avl_vtable { void *(*copy_key)(void *key); /** compare key1, key2; return <0 if key1 < key2, >0 if key1 > key2, 0 if key1 == key2 */ - int64_t (*compare_keys)(void *key1, void *key2); + long (*compare_keys)(void *key1, void *key2); /** destroy a value */ void (*destroy_value)(void *value); /** copy a value */ diff --git a/src/core/support/avl.c b/src/core/support/avl.c index 78746588f0a..9734c9987fe 100644 --- a/src/core/support/avl.c +++ b/src/core/support/avl.c @@ -1,6 +1,6 @@ /* * - * Copyright 2015-2016, Google Inc. + * Copyright 2015, Google Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -67,12 +67,12 @@ static void unref_node(const gpr_avl_vtable *vtable, gpr_avl_node *node) { } } -static int64_t node_height(gpr_avl_node *node) { +static long node_height(gpr_avl_node *node) { return node == NULL ? 0 : node->height; } #ifndef NDEBUG -static int64_t calculate_height(gpr_avl_node *node) { +static long calculate_height(gpr_avl_node *node) { return node == NULL ? 0 : 1 + GPR_MAX(calculate_height(node->left), calculate_height(node->right)); } @@ -103,7 +103,7 @@ gpr_avl_node *new_node(void *key, void *value, gpr_avl_node *left, static gpr_avl_node *get(const gpr_avl_vtable *vtable, gpr_avl_node *node, void *key) { - int64_t cmp; + long cmp; if (node == NULL) { return NULL; @@ -198,7 +198,7 @@ static gpr_avl_node *rebalance(const gpr_avl_vtable *vtable, void *key, static gpr_avl_node *add(const gpr_avl_vtable *vtable, gpr_avl_node *node, void *key, void *value) { - int64_t cmp; + long cmp; if (node == NULL) { return new_node(key, value, NULL, NULL); } @@ -240,7 +240,7 @@ static gpr_avl_node *in_order_tail(gpr_avl_node *node) { static gpr_avl_node *remove(const gpr_avl_vtable *vtable, gpr_avl_node *node, void *key) { - int64_t cmp; + long cmp; if (node == NULL) { return NULL; } diff --git a/test/core/support/avl_test.c b/test/core/support/avl_test.c index 6dae53c1dfe..d8d8b36806b 100644 --- a/test/core/support/avl_test.c +++ b/test/core/support/avl_test.c @@ -48,7 +48,7 @@ static int *box(int x) { return b; } -static int64_t int_compare(void *int1, void *int2) { +static long int_compare(void *int1, void *int2) { return (*(int *)int1) - (*(int *)int2); } static void *int_copy(void *p) { return box(*(int *)p); } From 6b5555ead1a0a7141d28bec505f5421a4101763d Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Fri, 5 Feb 2016 16:07:18 -0800 Subject: [PATCH 25/55] Fix docker files, distrib test script --- test/distrib/python/run_distrib_test.sh | 17 +++++++++-------- .../distribtest/python_arch_x64/Dockerfile | 5 +++-- .../distribtest/python_centos6_x64/Dockerfile | 2 ++ 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/test/distrib/python/run_distrib_test.sh b/test/distrib/python/run_distrib_test.sh index 2148be121a2..08856ad388a 100755 --- a/test/distrib/python/run_distrib_test.sh +++ b/test/distrib/python/run_distrib_test.sh @@ -42,16 +42,17 @@ then exit 1 fi -# TODO(jtattermusch): this shouldn't be required -pip install --upgrade six +PIP=pip2 +which $PIP || PIP=pip +PYTHON=python2 +which $PYTHON || PYTHON=python -# TODO(jtattermusch): if these don't get preinstalled, pip tries to install them -# with --use-grpc-custom-bdist option, which obviously fails. -pip install --upgrade enum34 -pip install --upgrade futures +# TODO(jtattermusch): this shouldn't be required +$PIP install --upgrade six GRPC_PYTHON_BINARIES_REPOSITORY="${BDIST_DIR}" \ - pip install \ + $PIP install \ "${SDIST_ARCHIVE}" -python distribtest.py +$PYTHON distribtest.py + diff --git a/tools/dockerfile/distribtest/python_arch_x64/Dockerfile b/tools/dockerfile/distribtest/python_arch_x64/Dockerfile index 4d10e240c60..536ad86d53a 100644 --- a/tools/dockerfile/distribtest/python_arch_x64/Dockerfile +++ b/tools/dockerfile/distribtest/python_arch_x64/Dockerfile @@ -31,6 +31,7 @@ FROM base/archlinux RUN pacman --noconfirm -Syy RUN pacman --noconfirm -S git -RUN pacman --noconfirm -S python -RUN pacman --noconfirm -S python-pip +RUN pacman --noconfirm -S openssl +RUN pacman --noconfirm -S python2 +RUN pacman --noconfirm -S python2-pip diff --git a/tools/dockerfile/distribtest/python_centos6_x64/Dockerfile b/tools/dockerfile/distribtest/python_centos6_x64/Dockerfile index 683686c6dbb..55677fc10cc 100644 --- a/tools/dockerfile/distribtest/python_centos6_x64/Dockerfile +++ b/tools/dockerfile/distribtest/python_centos6_x64/Dockerfile @@ -35,3 +35,5 @@ RUN yum install -y python RUN rpm -ivh http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm RUN yum install -y python-pip +RUN pip install --upgrade pip + From 524d7ed6723aefd78cc980ccae432959b10cc7b5 Mon Sep 17 00:00:00 2001 From: Nicolas Noble Date: Fri, 5 Feb 2016 16:35:48 -0800 Subject: [PATCH 26/55] Adding a script to spawn MacOS's build environment. --- tools/distrib/build_ruby_environment_macos.sh | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 tools/distrib/build_ruby_environment_macos.sh diff --git a/tools/distrib/build_ruby_environment_macos.sh b/tools/distrib/build_ruby_environment_macos.sh new file mode 100644 index 00000000000..b2be86f6f39 --- /dev/null +++ b/tools/distrib/build_ruby_environment_macos.sh @@ -0,0 +1,59 @@ +#!/bin/bash +# Copyright 2015-2016, Google Inc. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following disclaimer +# in the documentation and/or other materials provided with the +# distribution. +# * Neither the name of Google Inc. nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +set -ex + +CROSS_RUBY=`mktemp` + +curl https://raw.githubusercontent.com/rake-compiler/rake-compiler/v0.9.5/tasks/bin/cross-ruby.rake > $CROSS_RUBY + +patch $CROSS_RUBY << EOF +--- cross-ruby.rake 2016-02-05 16:26:53.000000000 -0800 ++++ cross-ruby.rake.patched 2016-02-05 16:27:33.000000000 -0800 +@@ -133,7 +133,8 @@ + "--host=#{MINGW_HOST}", + "--target=#{MINGW_TARGET}", + "--build=#{RUBY_BUILD}", +- '--enable-shared', ++ '--enable-static', ++ '--disable-shared', + '--disable-install-doc', + '--without-tk', + '--without-tcl' +EOF + +MAKE="make -j8" + +for v in 2.3.0 2.2.2 2.1.6 2.0.0-p645 ; do + rake -f $CROSS_RUBY cross-ruby VERSION=$v HOST=x86_64-darwin11 +done + +sed 's/x86_64-darwin-11/universal-darwin/' ~/.rake-compiler/config.yaml > $CROSS_RUBY +mv $CROSS_RUBY > ~/.rake-compiler/config.yaml From ec187ce677fdfd9114d82c63ee73c5ec60fac97a Mon Sep 17 00:00:00 2001 From: "Nicolas \"Pixel\" Noble" Date: Sat, 6 Feb 2016 01:45:46 +0100 Subject: [PATCH 27/55] Updating the ruby artifact build script. --- tools/run_tests/build_artifact_ruby.sh | 37 ++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/tools/run_tests/build_artifact_ruby.sh b/tools/run_tests/build_artifact_ruby.sh index 482d128be3b..8033c3157a1 100755 --- a/tools/run_tests/build_artifact_ruby.sh +++ b/tools/run_tests/build_artifact_ruby.sh @@ -27,16 +27,43 @@ # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - set -ex - cd $(dirname $0)/../.. +set +ex +[[ -s /etc/profile.d/rvm.sh ]] && . /etc/profile.d/rvm.sh +set -ex + +SYSTEM=`uname | cut -f 1 -d_` +if [ "$SYSTEM" == "MSYS" ] ; then + SYSTEM=MINGW32 +fi +if [ "$SYSTEM" == "MINGW64" ] ; then + SYSTEM=MINGW32 +fi -${SETARCH_CMD} bundle install +if [ "$SYSTEM" == "MINGW32" ] ; then + echo "Need Linux to build the Windows ruby gem." + exit 1 +fi -${SETARCH_CMD} rake native gem +if [ "$SYSTEM" == "Darwin" ] ; then + set +ex + rvm use ruby-head + set -ex +fi + +if [ "$SYSTEM" == "Linux" ] ; then + set +ex + ${SETARCH_CMD} bundle install + set -ex +fi + +${SETARCH_CMD} rake gem:native + +if [ "$SYSTEM" == "Darwin" ] ; then + rm pkg/`ls pkg/*.gem | grep -v darwin` +fi mkdir -p artifacts cp pkg/*.gem artifacts - From da46a701c4c48f49943b3f9ba06bb9f983b24709 Mon Sep 17 00:00:00 2001 From: "Nicolas \"Pixel\" Noble" Date: Sat, 6 Feb 2016 01:52:02 +0100 Subject: [PATCH 28/55] 2.1.6 doesn't work on MacOS (wheee...) --- Rakefile | 4 ++-- third_party/rake-compiler-dock/Dockerfile | 10 +++++----- tools/distrib/build_ruby_environment_macos.sh | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Rakefile b/Rakefile index 1f9bbcf7f64..f208a24fd33 100755 --- a/Rakefile +++ b/Rakefile @@ -103,10 +103,10 @@ task 'gem:native' do if RUBY_PLATFORM =~ /darwin/ FileUtils.touch 'grpc_c.32.ruby' FileUtils.touch 'grpc_c.64.ruby' - system "rake cross native gem RUBY_CC_VERSION=2.3.0:2.2.2:2.1.6:2.0.0 V=#{verbose}" + system "rake cross native gem RUBY_CC_VERSION=2.3.0:2.2.2:2.1.5:2.0.0 V=#{verbose}" else Rake::Task['dlls'].execute - docker_for_windows "bundle && rake cross native gem RUBY_CC_VERSION=2.3.0:2.2.2:2.1.6:2.0.0 V=#{verbose}" + docker_for_windows "bundle && rake cross native gem RUBY_CC_VERSION=2.3.0:2.2.2:2.1.5:2.0.0 V=#{verbose}" end end diff --git a/third_party/rake-compiler-dock/Dockerfile b/third_party/rake-compiler-dock/Dockerfile index be73e2d8f49..a8f5b8a1165 100644 --- a/third_party/rake-compiler-dock/Dockerfile +++ b/third_party/rake-compiler-dock/Dockerfile @@ -107,9 +107,9 @@ RUN bash -c "rvm use 2.3.0 --default && \ rake-compiler cross-ruby VERSION=2.2.2 HOST=i686-w64-mingw32 && \ rake-compiler cross-ruby VERSION=2.2.2 HOST=x86_64-w64-mingw32 && \ rake-compiler cross-ruby VERSION=2.2.2 HOST=x86_64-linux-gnu && \ - rake-compiler cross-ruby VERSION=2.1.6 HOST=i686-w64-mingw32 && \ - rake-compiler cross-ruby VERSION=2.1.6 HOST=x86_64-w64-mingw32 && \ - rake-compiler cross-ruby VERSION=2.1.6 HOST=x86_64-linux-gnu && \ + rake-compiler cross-ruby VERSION=2.1.5 HOST=i686-w64-mingw32 && \ + rake-compiler cross-ruby VERSION=2.1.5 HOST=x86_64-w64-mingw32 && \ + rake-compiler cross-ruby VERSION=2.1.5 HOST=x86_64-linux-gnu && \ rake-compiler cross-ruby VERSION=2.0.0-p645 HOST=i686-w64-mingw32 && \ rake-compiler cross-ruby VERSION=2.0.0-p645 HOST=x86_64-w64-mingw32 && \ rake-compiler cross-ruby VERSION=2.0.0-p645 HOST=x86_64-linux-gnu && \ @@ -120,7 +120,7 @@ RUN bash -c "rvm use 2.3.0 --default && \ export MAKE=\"make -j`nproc`\" CFLAGS='-m32 -s -O1 -fno-omit-frame-pointer -fno-fast-math' LDFLAGS='-m32' && \ rake-compiler cross-ruby VERSION=2.3.0 HOST=i686-linux-gnu && \ rake-compiler cross-ruby VERSION=2.2.2 HOST=i686-linux-gnu && \ - rake-compiler cross-ruby VERSION=2.1.6 HOST=i686-linux-gnu && \ + rake-compiler cross-ruby VERSION=2.1.5 HOST=i686-linux-gnu && \ rake-compiler cross-ruby VERSION=2.0.0-p645 HOST=i686-linux-gnu && \ rm -rf ~/.rake-compiler/tmp/builds ~/.rake-compiler/sources && \ find /usr/local/rvm -type d -print0 | sudo xargs -0 chmod g+sw " @@ -164,6 +164,6 @@ RUN cp /tmp/build/runas /usr/local/bin/ # Install sudoers configuration RUN cp /tmp/build/sudoers /etc/sudoers.d/rake-compiler-dock -ENV RUBY_CC_VERSION 2.3.0:2.2.2:2.1.6:2.0.0 +ENV RUBY_CC_VERSION 2.3.0:2.2.2:2.1.5:2.0.0 CMD bash diff --git a/tools/distrib/build_ruby_environment_macos.sh b/tools/distrib/build_ruby_environment_macos.sh index b2be86f6f39..ccc5e20713e 100644 --- a/tools/distrib/build_ruby_environment_macos.sh +++ b/tools/distrib/build_ruby_environment_macos.sh @@ -51,7 +51,7 @@ EOF MAKE="make -j8" -for v in 2.3.0 2.2.2 2.1.6 2.0.0-p645 ; do +for v in 2.3.0 2.2.2 2.1.5 2.0.0-p645 ; do rake -f $CROSS_RUBY cross-ruby VERSION=$v HOST=x86_64-darwin11 done From 700cae3b9eb3559cb52a3f2d6c19f852d565d89b Mon Sep 17 00:00:00 2001 From: "Nicolas \"Pixel\" Noble" Date: Sat, 6 Feb 2016 01:52:38 +0100 Subject: [PATCH 29/55] Typo. --- tools/distrib/build_ruby_environment_macos.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/distrib/build_ruby_environment_macos.sh b/tools/distrib/build_ruby_environment_macos.sh index ccc5e20713e..a876990b985 100644 --- a/tools/distrib/build_ruby_environment_macos.sh +++ b/tools/distrib/build_ruby_environment_macos.sh @@ -55,5 +55,5 @@ for v in 2.3.0 2.2.2 2.1.5 2.0.0-p645 ; do rake -f $CROSS_RUBY cross-ruby VERSION=$v HOST=x86_64-darwin11 done -sed 's/x86_64-darwin-11/universal-darwin/' ~/.rake-compiler/config.yaml > $CROSS_RUBY -mv $CROSS_RUBY > ~/.rake-compiler/config.yaml +sed 's/x86_64-darwin-11/universal-darwin/' ~/.rake-compiler/config.yml > $CROSS_RUBY +mv $CROSS_RUBY > ~/.rake-compiler/config.yml From 4bb713b84daef1b5a2737c004c7f39c26eae3bc1 Mon Sep 17 00:00:00 2001 From: "Nicolas \"Pixel\" Noble" Date: Sat, 6 Feb 2016 02:09:11 +0100 Subject: [PATCH 30/55] Last changes to build_artifact_ruby.sh --- tools/run_tests/build_artifact_ruby.sh | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/tools/run_tests/build_artifact_ruby.sh b/tools/run_tests/build_artifact_ruby.sh index 8033c3157a1..69e4dcf85ac 100755 --- a/tools/run_tests/build_artifact_ruby.sh +++ b/tools/run_tests/build_artifact_ruby.sh @@ -28,12 +28,17 @@ # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. set -ex + +SYSTEM=`uname | cut -f 1 -d_` + cd $(dirname $0)/../.. +if [ "$SYSTEM" == "Darwin" ] ; then + ./tools/distrib/build_ruby_environment_macos.sh +fi set +ex [[ -s /etc/profile.d/rvm.sh ]] && . /etc/profile.d/rvm.sh set -ex -SYSTEM=`uname | cut -f 1 -d_` if [ "$SYSTEM" == "MSYS" ] ; then SYSTEM=MINGW32 fi @@ -52,11 +57,9 @@ if [ "$SYSTEM" == "Darwin" ] ; then set -ex fi -if [ "$SYSTEM" == "Linux" ] ; then - set +ex - ${SETARCH_CMD} bundle install - set -ex -fi +set +ex +${SETARCH_CMD} bundle install +set -ex ${SETARCH_CMD} rake gem:native From 5bb9a916e29aee275378511ca38ab4fd9c5333b4 Mon Sep 17 00:00:00 2001 From: Nicolas Noble Date: Fri, 5 Feb 2016 17:38:04 -0800 Subject: [PATCH 31/55] Update build_artifact_ruby.sh --- tools/run_tests/build_artifact_ruby.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/run_tests/build_artifact_ruby.sh b/tools/run_tests/build_artifact_ruby.sh index 69e4dcf85ac..015f54f026a 100755 --- a/tools/run_tests/build_artifact_ruby.sh +++ b/tools/run_tests/build_artifact_ruby.sh @@ -33,7 +33,7 @@ SYSTEM=`uname | cut -f 1 -d_` cd $(dirname $0)/../.. if [ "$SYSTEM" == "Darwin" ] ; then - ./tools/distrib/build_ruby_environment_macos.sh + /bin/bash ./tools/distrib/build_ruby_environment_macos.sh fi set +ex [[ -s /etc/profile.d/rvm.sh ]] && . /etc/profile.d/rvm.sh From 07854f7baa0f53f7fabf8edb9fa7c73bede4ca1a Mon Sep 17 00:00:00 2001 From: Nicolas Noble Date: Fri, 5 Feb 2016 17:51:48 -0800 Subject: [PATCH 32/55] Update build_ruby_environment_macos.sh --- tools/distrib/build_ruby_environment_macos.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/distrib/build_ruby_environment_macos.sh b/tools/distrib/build_ruby_environment_macos.sh index a876990b985..b6dec68c7fc 100644 --- a/tools/distrib/build_ruby_environment_macos.sh +++ b/tools/distrib/build_ruby_environment_macos.sh @@ -30,7 +30,7 @@ set -ex -CROSS_RUBY=`mktemp` +CROSS_RUBY=`mktemp tmpfile.XXXXXXXX` curl https://raw.githubusercontent.com/rake-compiler/rake-compiler/v0.9.5/tasks/bin/cross-ruby.rake > $CROSS_RUBY From 3c6039222fd6493cfbde4d349d9722ccb3b452a4 Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Fri, 5 Feb 2016 18:17:55 -0800 Subject: [PATCH 33/55] add build_package collector targets for python and ruby --- tools/run_tests/build_package_python.sh | 43 +++++++++++++++++++++ tools/run_tests/build_package_ruby.sh | 43 +++++++++++++++++++++ tools/run_tests/package_targets.py | 51 ++++++++++++++++++++++--- 3 files changed, 131 insertions(+), 6 deletions(-) create mode 100755 tools/run_tests/build_package_python.sh create mode 100755 tools/run_tests/build_package_ruby.sh diff --git a/tools/run_tests/build_package_python.sh b/tools/run_tests/build_package_python.sh new file mode 100755 index 00000000000..2511a6ae465 --- /dev/null +++ b/tools/run_tests/build_package_python.sh @@ -0,0 +1,43 @@ +#!/bin/bash +# Copyright 2016, Google Inc. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following disclaimer +# in the documentation and/or other materials provided with the +# distribution. +# * Neither the name of Google Inc. nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +set -ex + +cd $(dirname $0)/../.. + +mkdir -p artifacts/ + +# All the python packages have been built in the artifact phase already +# and we only collect them here to deliver them to the distribtest phase. +cp -r $EXTERNAL_GIT_ROOT/architecture={x86,x64},language=python,platform={windows,linux,macos}/artifacts/* artifacts/ || true + +# TODO: all the artifact builder configurations generate a grpcio-VERSION.tar.gz +# source distribution package, and only one of them will end up +# in the artifacts/ directory. They should be all equivalent though. diff --git a/tools/run_tests/build_package_ruby.sh b/tools/run_tests/build_package_ruby.sh new file mode 100755 index 00000000000..1a5b94348d8 --- /dev/null +++ b/tools/run_tests/build_package_ruby.sh @@ -0,0 +1,43 @@ +#!/bin/bash +# Copyright 2016, Google Inc. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following disclaimer +# in the documentation and/or other materials provided with the +# distribution. +# * Neither the name of Google Inc. nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +set -ex + +cd $(dirname $0)/../.. + +mkdir -p artifacts/ + +# All the ruby packages have been built in the artifact phase already +# and we only collect them here to deliver them to the distribtest phase. +cp -r $EXTERNAL_GIT_ROOT/architecture={x86,x64},language=ruby,platform={windows,linux,macos}/artifacts/* artifacts/ || true + +# TODO: all the artifact builder configurations generate a grpc-VERSION.gem +# source distribution package, and only one of them will end up +# in the artifacts/ directory. They should be all equivalent though. diff --git a/tools/run_tests/package_targets.py b/tools/run_tests/package_targets.py index 997bc57cc5a..4ca8279f1bf 100644 --- a/tools/run_tests/package_targets.py +++ b/tools/run_tests/package_targets.py @@ -68,11 +68,11 @@ def create_jobspec(name, cmdline, environ=None, cwd=None, shell=False, return jobspec -class CSharpNugetTarget: +class CSharpPackage: """Builds C# nuget packages.""" def __init__(self): - self.name = 'csharp_nuget' + self.name = 'csharp_package' self.labels = ['package', 'csharp', 'windows'] def pre_build_jobspecs(self): @@ -87,11 +87,12 @@ class CSharpNugetTarget: def __str__(self): return self.name -class NodeNpmBinaryTarget: - """Builds Node NPM package and collects binaries""" + +class NodePackage: + """Builds Node NPM package and collects precompiled binaries""" def __init__(self): - self.name = 'node_npm_binary' + self.name = 'node_package' self.labels = ['package', 'node', 'linux'] def pre_build_jobspecs(self): @@ -103,6 +104,44 @@ class NodeNpmBinaryTarget: 'tools/dockerfile/grpc_artifact_linux_x64', 'tools/run_tests/build_package_node.sh') + +class RubyPackage: + """Collects ruby gems created in the artifact phase""" + + def __init__(self): + self.name = 'ruby_package' + self.labels = ['package', 'ruby', 'linux'] + + def pre_build_jobspecs(self): + return [] + + def build_jobspec(self): + return create_docker_jobspec( + self.name, + 'tools/dockerfile/grpc_artifact_linux_x64', + 'tools/run_tests/build_package_ruby.sh') + + +class PythonPackage: + """Collects python eggs and wheels created in the artifact phase""" + + def __init__(self): + self.name = 'python_package' + self.labels = ['package', 'python', 'linux'] + + def pre_build_jobspecs(self): + return [] + + def build_jobspec(self): + return create_docker_jobspec( + self.name, + 'tools/dockerfile/grpc_artifact_linux_x64', + 'tools/run_tests/build_package_python.sh') + + def targets(): """Gets list of supported targets""" - return [CSharpNugetTarget(), NodeNpmBinaryTarget()] + return [CSharpPackage(), + NodePackage(), + RubyPackage(), + PythonPackage()] From 9d6de14fcfa85c380c6b342ea54baf6cb24f1dc6 Mon Sep 17 00:00:00 2001 From: "Nicolas \"Pixel\" Noble" Date: Sat, 6 Feb 2016 03:31:16 +0100 Subject: [PATCH 34/55] Typos. --- tools/distrib/build_ruby_environment_macos.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/distrib/build_ruby_environment_macos.sh b/tools/distrib/build_ruby_environment_macos.sh index b6dec68c7fc..317c2721c27 100644 --- a/tools/distrib/build_ruby_environment_macos.sh +++ b/tools/distrib/build_ruby_environment_macos.sh @@ -56,4 +56,4 @@ for v in 2.3.0 2.2.2 2.1.5 2.0.0-p645 ; do done sed 's/x86_64-darwin-11/universal-darwin/' ~/.rake-compiler/config.yml > $CROSS_RUBY -mv $CROSS_RUBY > ~/.rake-compiler/config.yml +mv $CROSS_RUBY ~/.rake-compiler/config.yml From ff2e76e286224306b08f77b264338cfb7be7cb3e Mon Sep 17 00:00:00 2001 From: "Nicolas \"Pixel\" Noble" Date: Sat, 6 Feb 2016 03:36:18 +0100 Subject: [PATCH 35/55] rake-compiler builds aren't repeatable after all. --- tools/distrib/build_ruby_environment_macos.sh | 2 ++ tools/run_tests/build_artifact_ruby.sh | 3 --- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/tools/distrib/build_ruby_environment_macos.sh b/tools/distrib/build_ruby_environment_macos.sh index 317c2721c27..ff3a388eaf6 100644 --- a/tools/distrib/build_ruby_environment_macos.sh +++ b/tools/distrib/build_ruby_environment_macos.sh @@ -30,6 +30,8 @@ set -ex +rm -rf ~/.rake-compiler + CROSS_RUBY=`mktemp tmpfile.XXXXXXXX` curl https://raw.githubusercontent.com/rake-compiler/rake-compiler/v0.9.5/tasks/bin/cross-ruby.rake > $CROSS_RUBY diff --git a/tools/run_tests/build_artifact_ruby.sh b/tools/run_tests/build_artifact_ruby.sh index 015f54f026a..21daee73513 100755 --- a/tools/run_tests/build_artifact_ruby.sh +++ b/tools/run_tests/build_artifact_ruby.sh @@ -32,9 +32,6 @@ set -ex SYSTEM=`uname | cut -f 1 -d_` cd $(dirname $0)/../.. -if [ "$SYSTEM" == "Darwin" ] ; then - /bin/bash ./tools/distrib/build_ruby_environment_macos.sh -fi set +ex [[ -s /etc/profile.d/rvm.sh ]] && . /etc/profile.d/rvm.sh set -ex From cd7411466e3a434bc14cb3f2d2fc46f1f5754046 Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Fri, 5 Feb 2016 19:52:36 -0800 Subject: [PATCH 36/55] make python jessie x86 distribtest pass --- tools/dockerfile/distribtest/python_jessie_x86/Dockerfile | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tools/dockerfile/distribtest/python_jessie_x86/Dockerfile b/tools/dockerfile/distribtest/python_jessie_x86/Dockerfile index cb6ec22d0ac..e9cf99142b8 100644 --- a/tools/dockerfile/distribtest/python_jessie_x86/Dockerfile +++ b/tools/dockerfile/distribtest/python_jessie_x86/Dockerfile @@ -30,3 +30,8 @@ FROM 32bit/debian:jessie RUN apt-get update && apt-get install -y python python-pip + +# docker is running on a 64-bit machine, so we need to +# override "uname -m" to report i686 instead of x86_64, otherwise +# python will choose a wrong binary package to install. +ENTRYPOINT ["linux32"] From 0bd1da55936bae4bdd82ef40526b5de6105c8624 Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Fri, 5 Feb 2016 20:21:17 -0800 Subject: [PATCH 37/55] fix some node distribtests --- test/distrib/node/run_distrib_test.sh | 7 ++++++- tools/dockerfile/distribtest/node_jessie_x86/Dockerfile | 2 +- tools/run_tests/distribtest_targets.py | 3 +-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/test/distrib/node/run_distrib_test.sh b/test/distrib/node/run_distrib_test.sh index 90637cc01d0..ac9e7d70907 100755 --- a/test/distrib/node/run_distrib_test.sh +++ b/test/distrib/node/run_distrib_test.sh @@ -32,7 +32,12 @@ set -ex cd $(dirname $0) -nvm install $1 +NODE_VERSION="$1" + +# make sure nvm is available +source ~/.nvm/nvm.sh || true + +nvm install $NODE_VERSION npm install -g node-static diff --git a/tools/dockerfile/distribtest/node_jessie_x86/Dockerfile b/tools/dockerfile/distribtest/node_jessie_x86/Dockerfile index bd40ab2b4cb..0408cbeeb09 100644 --- a/tools/dockerfile/distribtest/node_jessie_x86/Dockerfile +++ b/tools/dockerfile/distribtest/node_jessie_x86/Dockerfile @@ -29,7 +29,7 @@ FROM 32bit/debian:jessie -RUN apt-get update && apt-get install -y git +RUN apt-get update && apt-get install -y curl # Install nvm RUN touch .profile diff --git a/tools/run_tests/distribtest_targets.py b/tools/run_tests/distribtest_targets.py index a1e45ece9dc..f3ebc00b4ef 100644 --- a/tools/run_tests/distribtest_targets.py +++ b/tools/run_tests/distribtest_targets.py @@ -105,8 +105,7 @@ class NodeDistribTest(object): 'tools/dockerfile/distribtest/node_%s_%s' % ( self.docker_suffix, self.arch), - # bash -l needed to make nvm available - 'bash -l test/distrib/node/run_distrib_test.sh %s' % ( + 'test/distrib/node/run_distrib_test.sh %s' % ( self.node_version)) def __str__(self): return self.name From b9e66cd283b5ec6b4cdaee6c0146f91c6c1e5387 Mon Sep 17 00:00:00 2001 From: "Nicolas \"Pixel\" Noble" Date: Sat, 6 Feb 2016 06:24:16 +0100 Subject: [PATCH 38/55] Removing architecture commands, and updating the bundler gem. --- tools/run_tests/build_artifact_ruby.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tools/run_tests/build_artifact_ruby.sh b/tools/run_tests/build_artifact_ruby.sh index 21daee73513..10fc997a836 100755 --- a/tools/run_tests/build_artifact_ruby.sh +++ b/tools/run_tests/build_artifact_ruby.sh @@ -55,10 +55,11 @@ if [ "$SYSTEM" == "Darwin" ] ; then fi set +ex -${SETARCH_CMD} bundle install +gem install bundle --update +bundle install set -ex -${SETARCH_CMD} rake gem:native +rake gem:native if [ "$SYSTEM" == "Darwin" ] ; then rm pkg/`ls pkg/*.gem | grep -v darwin` From bb439efb9db0aa83444f2f8f65fc069a175db9e3 Mon Sep 17 00:00:00 2001 From: "Nicolas \"Pixel\" Noble" Date: Sat, 6 Feb 2016 06:27:00 +0100 Subject: [PATCH 39/55] Typo. --- tools/run_tests/build_artifact_ruby.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/run_tests/build_artifact_ruby.sh b/tools/run_tests/build_artifact_ruby.sh index 10fc997a836..f7504a9614a 100755 --- a/tools/run_tests/build_artifact_ruby.sh +++ b/tools/run_tests/build_artifact_ruby.sh @@ -55,7 +55,7 @@ if [ "$SYSTEM" == "Darwin" ] ; then fi set +ex -gem install bundle --update +gem install bundler --update bundle install set -ex From a677208073b4fc6e443e311caf2a8c51e20f5f98 Mon Sep 17 00:00:00 2001 From: "Nicolas \"Pixel\" Noble" Date: Sat, 6 Feb 2016 06:35:29 +0100 Subject: [PATCH 40/55] Typo. --- tools/run_tests/build_artifact_ruby.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/run_tests/build_artifact_ruby.sh b/tools/run_tests/build_artifact_ruby.sh index f7504a9614a..7709fe12b1d 100755 --- a/tools/run_tests/build_artifact_ruby.sh +++ b/tools/run_tests/build_artifact_ruby.sh @@ -62,7 +62,7 @@ set -ex rake gem:native if [ "$SYSTEM" == "Darwin" ] ; then - rm pkg/`ls pkg/*.gem | grep -v darwin` + rm `ls pkg/*.gem | grep -v darwin` fi mkdir -p artifacts From 412a39875e3a6039bc5fcd5dde82c3cd18cd5bf0 Mon Sep 17 00:00:00 2001 From: "Nicolas \"Pixel\" Noble" Date: Sat, 6 Feb 2016 07:25:32 +0100 Subject: [PATCH 41/55] Shortcut the artifact builder early. --- tools/jenkins/build_artifacts.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tools/jenkins/build_artifacts.sh b/tools/jenkins/build_artifacts.sh index 9af553ae48d..c0acbdfb276 100755 --- a/tools/jenkins/build_artifacts.sh +++ b/tools/jenkins/build_artifacts.sh @@ -39,4 +39,8 @@ set -ex -o igncr || set -ex curr_platform="$platform" unset platform # variable named 'platform' breaks the windows build -python tools/run_tests/task_runner.py -f artifact $language $curr_platform $architecture +if [ "$curr_platform" == "linux" ] && [ "$language" == "ruby" ] ; then + ./tools/run_tests/build_artifact_ruby.sh +else + python tools/run_tests/task_runner.py -f artifact $language $curr_platform $architecture +fi From 32ee36d9800945535a87efdd0b57a64b3fe1b239 Mon Sep 17 00:00:00 2001 From: "Nicolas \"Pixel\" Noble" Date: Sat, 6 Feb 2016 07:45:04 +0100 Subject: [PATCH 42/55] Better to always use rvm. --- tools/run_tests/build_artifact_ruby.sh | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/tools/run_tests/build_artifact_ruby.sh b/tools/run_tests/build_artifact_ruby.sh index 7709fe12b1d..727899db5e6 100755 --- a/tools/run_tests/build_artifact_ruby.sh +++ b/tools/run_tests/build_artifact_ruby.sh @@ -48,13 +48,8 @@ if [ "$SYSTEM" == "MINGW32" ] ; then exit 1 fi -if [ "$SYSTEM" == "Darwin" ] ; then - set +ex - rvm use ruby-head - set -ex -fi - set +ex +rvm use default gem install bundler --update bundle install set -ex From 2cbc545f163281c4a784ebadbcfa5c395597a2a2 Mon Sep 17 00:00:00 2001 From: "Nicolas \"Pixel\" Noble" Date: Sat, 6 Feb 2016 07:47:32 +0100 Subject: [PATCH 43/55] Load RVM on Linux too... --- tools/run_tests/build_artifact_ruby.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/run_tests/build_artifact_ruby.sh b/tools/run_tests/build_artifact_ruby.sh index 727899db5e6..2d97b4068bc 100755 --- a/tools/run_tests/build_artifact_ruby.sh +++ b/tools/run_tests/build_artifact_ruby.sh @@ -34,6 +34,7 @@ SYSTEM=`uname | cut -f 1 -d_` cd $(dirname $0)/../.. set +ex [[ -s /etc/profile.d/rvm.sh ]] && . /etc/profile.d/rvm.sh +[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" set -ex if [ "$SYSTEM" == "MSYS" ] ; then From 6494e8bf9567d045ab2fd1e76193178c50c8f515 Mon Sep 17 00:00:00 2001 From: yang-g Date: Fri, 5 Feb 2016 23:54:03 -0800 Subject: [PATCH 44/55] flush the stalled list after the window is updated --- src/core/transport/chttp2/writing.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/core/transport/chttp2/writing.c b/src/core/transport/chttp2/writing.c index 095883c66da..cafecf10465 100644 --- a/src/core/transport/chttp2/writing.c +++ b/src/core/transport/chttp2/writing.c @@ -75,6 +75,9 @@ int grpc_chttp2_unlocking_check_writes( GRPC_CHTTP2_FLOW_MOVE_TRANSPORT("write", transport_writing, outgoing_window, transport_global, outgoing_window); + bool is_window_available = transport_writing->outgoing_window > 0; + grpc_chttp2_list_flush_writing_stalled_by_transport(transport_writing, + is_window_available); /* for each grpc_chttp2_stream that's become writable, frame it's data (according to available window sizes) and add to the output buffer */ @@ -329,10 +332,6 @@ void grpc_chttp2_cleanup_writing( grpc_chttp2_transport_writing *transport_writing) { grpc_chttp2_stream_writing *stream_writing; grpc_chttp2_stream_global *stream_global; - bool is_window_available = transport_writing->outgoing_window > 0; - - grpc_chttp2_list_flush_writing_stalled_by_transport(transport_writing, - is_window_available); while (grpc_chttp2_list_pop_written_stream( transport_global, transport_writing, &stream_global, &stream_writing)) { From 1be92658ef0a66108fa997b2f8b857f387fb8662 Mon Sep 17 00:00:00 2001 From: "Nicolas \"Pixel\" Noble" Date: Sat, 6 Feb 2016 09:30:19 +0100 Subject: [PATCH 45/55] Versionning Ruby from build.yaml, and regenerating broken files after census merge. --- .../grpcio/grpc/_cython/imports.generated.c | 36 +++++------- .../grpcio/grpc/_cython/imports.generated.h | 58 +++++++++---------- src/ruby/lib/grpc/version.rb | 2 +- .../src/ruby/lib/grpc/version.rb.template | 35 +++++++++++ 4 files changed, 78 insertions(+), 53 deletions(-) create mode 100644 templates/src/ruby/lib/grpc/version.rb.template diff --git a/src/python/grpcio/grpc/_cython/imports.generated.c b/src/python/grpcio/grpc/_cython/imports.generated.c index b818f3491bf..817303c8a4a 100644 --- a/src/python/grpcio/grpc/_cython/imports.generated.c +++ b/src/python/grpcio/grpc/_cython/imports.generated.c @@ -41,7 +41,14 @@ census_initialize_type census_initialize_import; census_shutdown_type census_shutdown_import; census_supported_type census_supported_import; census_enabled_type census_enabled_import; -census_context_serialize_type census_context_serialize_import; +census_context_create_type census_context_create_import; +census_context_destroy_type census_context_destroy_import; +census_context_get_status_type census_context_get_status_import; +census_context_initialize_iterator_type census_context_initialize_iterator_import; +census_context_next_tag_type census_context_next_tag_import; +census_context_get_tag_type census_context_get_tag_import; +census_context_encode_type census_context_encode_import; +census_context_decode_type census_context_decode_import; census_trace_mask_type census_trace_mask_import; census_set_trace_mask_type census_set_trace_mask_import; census_start_rpc_op_timestamp_type census_start_rpc_op_timestamp_import; @@ -54,15 +61,6 @@ census_trace_print_type census_trace_print_import; census_trace_scan_start_type census_trace_scan_start_import; census_get_trace_record_type census_get_trace_record_import; census_trace_scan_end_type census_trace_scan_end_import; -census_tag_set_create_type census_tag_set_create_import; -census_tag_set_destroy_type census_tag_set_destroy_import; -census_tag_set_get_create_status_type census_tag_set_get_create_status_import; -census_tag_set_initialize_iterator_type census_tag_set_initialize_iterator_import; -census_tag_set_next_tag_type census_tag_set_next_tag_import; -census_tag_set_get_tag_by_key_type census_tag_set_get_tag_by_key_import; -census_tag_set_encode_type census_tag_set_encode_import; -census_tag_set_decode_type census_tag_set_decode_import; -census_context_tag_set_type census_context_tag_set_import; census_record_values_type census_record_values_import; census_view_create_type census_view_create_import; census_view_delete_type census_view_delete_import; @@ -303,7 +301,14 @@ void pygrpc_load_imports(HMODULE library) { census_shutdown_import = (census_shutdown_type) GetProcAddress(library, "census_shutdown"); census_supported_import = (census_supported_type) GetProcAddress(library, "census_supported"); census_enabled_import = (census_enabled_type) GetProcAddress(library, "census_enabled"); - census_context_serialize_import = (census_context_serialize_type) GetProcAddress(library, "census_context_serialize"); + census_context_create_import = (census_context_create_type) GetProcAddress(library, "census_context_create"); + census_context_destroy_import = (census_context_destroy_type) GetProcAddress(library, "census_context_destroy"); + census_context_get_status_import = (census_context_get_status_type) GetProcAddress(library, "census_context_get_status"); + census_context_initialize_iterator_import = (census_context_initialize_iterator_type) GetProcAddress(library, "census_context_initialize_iterator"); + census_context_next_tag_import = (census_context_next_tag_type) GetProcAddress(library, "census_context_next_tag"); + census_context_get_tag_import = (census_context_get_tag_type) GetProcAddress(library, "census_context_get_tag"); + census_context_encode_import = (census_context_encode_type) GetProcAddress(library, "census_context_encode"); + census_context_decode_import = (census_context_decode_type) GetProcAddress(library, "census_context_decode"); census_trace_mask_import = (census_trace_mask_type) GetProcAddress(library, "census_trace_mask"); census_set_trace_mask_import = (census_set_trace_mask_type) GetProcAddress(library, "census_set_trace_mask"); census_start_rpc_op_timestamp_import = (census_start_rpc_op_timestamp_type) GetProcAddress(library, "census_start_rpc_op_timestamp"); @@ -316,15 +321,6 @@ void pygrpc_load_imports(HMODULE library) { census_trace_scan_start_import = (census_trace_scan_start_type) GetProcAddress(library, "census_trace_scan_start"); census_get_trace_record_import = (census_get_trace_record_type) GetProcAddress(library, "census_get_trace_record"); census_trace_scan_end_import = (census_trace_scan_end_type) GetProcAddress(library, "census_trace_scan_end"); - census_tag_set_create_import = (census_tag_set_create_type) GetProcAddress(library, "census_tag_set_create"); - census_tag_set_destroy_import = (census_tag_set_destroy_type) GetProcAddress(library, "census_tag_set_destroy"); - census_tag_set_get_create_status_import = (census_tag_set_get_create_status_type) GetProcAddress(library, "census_tag_set_get_create_status"); - census_tag_set_initialize_iterator_import = (census_tag_set_initialize_iterator_type) GetProcAddress(library, "census_tag_set_initialize_iterator"); - census_tag_set_next_tag_import = (census_tag_set_next_tag_type) GetProcAddress(library, "census_tag_set_next_tag"); - census_tag_set_get_tag_by_key_import = (census_tag_set_get_tag_by_key_type) GetProcAddress(library, "census_tag_set_get_tag_by_key"); - census_tag_set_encode_import = (census_tag_set_encode_type) GetProcAddress(library, "census_tag_set_encode"); - census_tag_set_decode_import = (census_tag_set_decode_type) GetProcAddress(library, "census_tag_set_decode"); - census_context_tag_set_import = (census_context_tag_set_type) GetProcAddress(library, "census_context_tag_set"); census_record_values_import = (census_record_values_type) GetProcAddress(library, "census_record_values"); census_view_create_import = (census_view_create_type) GetProcAddress(library, "census_view_create"); census_view_delete_import = (census_view_delete_type) GetProcAddress(library, "census_view_delete"); diff --git a/src/python/grpcio/grpc/_cython/imports.generated.h b/src/python/grpcio/grpc/_cython/imports.generated.h index 2a8a910055a..f85d416db8f 100644 --- a/src/python/grpcio/grpc/_cython/imports.generated.h +++ b/src/python/grpcio/grpc/_cython/imports.generated.h @@ -73,9 +73,30 @@ extern census_supported_type census_supported_import; typedef int(*census_enabled_type)(void); extern census_enabled_type census_enabled_import; #define census_enabled census_enabled_import -typedef size_t(*census_context_serialize_type)(const census_context *context, char *buffer, size_t buf_size); -extern census_context_serialize_type census_context_serialize_import; -#define census_context_serialize census_context_serialize_import +typedef census_context *(*census_context_create_type)(const census_context *base, const census_tag *tags, int ntags, census_context_status const **status); +extern census_context_create_type census_context_create_import; +#define census_context_create census_context_create_import +typedef void(*census_context_destroy_type)(census_context *context); +extern census_context_destroy_type census_context_destroy_import; +#define census_context_destroy census_context_destroy_import +typedef const census_context_status *(*census_context_get_status_type)(const census_context *context); +extern census_context_get_status_type census_context_get_status_import; +#define census_context_get_status census_context_get_status_import +typedef void(*census_context_initialize_iterator_type)(const census_context *context, census_context_iterator *iterator); +extern census_context_initialize_iterator_type census_context_initialize_iterator_import; +#define census_context_initialize_iterator census_context_initialize_iterator_import +typedef int(*census_context_next_tag_type)(census_context_iterator *iterator, census_tag *tag); +extern census_context_next_tag_type census_context_next_tag_import; +#define census_context_next_tag census_context_next_tag_import +typedef int(*census_context_get_tag_type)(const census_context *context, const char *key, census_tag *tag); +extern census_context_get_tag_type census_context_get_tag_import; +#define census_context_get_tag census_context_get_tag_import +typedef char *(*census_context_encode_type)(const census_context *context, char *buffer, size_t buf_size, size_t *print_buf_size, size_t *bin_buf_size); +extern census_context_encode_type census_context_encode_import; +#define census_context_encode census_context_encode_import +typedef census_context *(*census_context_decode_type)(const char *buffer, size_t size, const char *bin_buffer, size_t bin_size); +extern census_context_decode_type census_context_decode_import; +#define census_context_decode census_context_decode_import typedef int(*census_trace_mask_type)(const census_context *context); extern census_trace_mask_type census_trace_mask_import; #define census_trace_mask census_trace_mask_import @@ -112,37 +133,10 @@ extern census_get_trace_record_type census_get_trace_record_import; typedef void(*census_trace_scan_end_type)(); extern census_trace_scan_end_type census_trace_scan_end_import; #define census_trace_scan_end census_trace_scan_end_import -typedef census_tag_set *(*census_tag_set_create_type)(const census_tag_set *base, const census_tag *tags, int ntags, census_tag_set_create_status const **status); -extern census_tag_set_create_type census_tag_set_create_import; -#define census_tag_set_create census_tag_set_create_import -typedef void(*census_tag_set_destroy_type)(census_tag_set *tags); -extern census_tag_set_destroy_type census_tag_set_destroy_import; -#define census_tag_set_destroy census_tag_set_destroy_import -typedef const census_tag_set_create_status *(*census_tag_set_get_create_status_type)(const census_tag_set *tags); -extern census_tag_set_get_create_status_type census_tag_set_get_create_status_import; -#define census_tag_set_get_create_status census_tag_set_get_create_status_import -typedef void(*census_tag_set_initialize_iterator_type)(const census_tag_set *tags, census_tag_set_iterator *iterator); -extern census_tag_set_initialize_iterator_type census_tag_set_initialize_iterator_import; -#define census_tag_set_initialize_iterator census_tag_set_initialize_iterator_import -typedef int(*census_tag_set_next_tag_type)(census_tag_set_iterator *iterator, census_tag *tag); -extern census_tag_set_next_tag_type census_tag_set_next_tag_import; -#define census_tag_set_next_tag census_tag_set_next_tag_import -typedef int(*census_tag_set_get_tag_by_key_type)(const census_tag_set *tags, const char *key, census_tag *tag); -extern census_tag_set_get_tag_by_key_type census_tag_set_get_tag_by_key_import; -#define census_tag_set_get_tag_by_key census_tag_set_get_tag_by_key_import -typedef char *(*census_tag_set_encode_type)(const census_tag_set *tags, char *buffer, size_t buf_size, size_t *print_buf_size, size_t *bin_buf_size); -extern census_tag_set_encode_type census_tag_set_encode_import; -#define census_tag_set_encode census_tag_set_encode_import -typedef census_tag_set *(*census_tag_set_decode_type)(const char *buffer, size_t size, const char *bin_buffer, size_t bin_size); -extern census_tag_set_decode_type census_tag_set_decode_import; -#define census_tag_set_decode census_tag_set_decode_import -typedef census_tag_set *(*census_context_tag_set_type)(census_context *context); -extern census_context_tag_set_type census_context_tag_set_import; -#define census_context_tag_set census_context_tag_set_import typedef void(*census_record_values_type)(census_context *context, census_value *values, size_t nvalues); extern census_record_values_type census_record_values_import; #define census_record_values census_record_values_import -typedef census_view *(*census_view_create_type)(uint32_t metric_id, const census_tag_set *tags, const census_aggregation *aggregations, size_t naggregations); +typedef census_view *(*census_view_create_type)(uint32_t metric_id, const census_context *tags, const census_aggregation *aggregations, size_t naggregations); extern census_view_create_type census_view_create_import; #define census_view_create census_view_create_import typedef void(*census_view_delete_type)(census_view *view); @@ -154,7 +148,7 @@ extern census_view_metric_type census_view_metric_import; typedef size_t(*census_view_naggregations_type)(const census_view *view); extern census_view_naggregations_type census_view_naggregations_import; #define census_view_naggregations census_view_naggregations_import -typedef const census_tag_set *(*census_view_tags_type)(const census_view *view); +typedef const census_context *(*census_view_tags_type)(const census_view *view); extern census_view_tags_type census_view_tags_import; #define census_view_tags census_view_tags_import typedef const census_aggregation *(*census_view_aggregrations_type)(const census_view *view); diff --git a/src/ruby/lib/grpc/version.rb b/src/ruby/lib/grpc/version.rb index 956e0222dfe..89ff882916c 100644 --- a/src/ruby/lib/grpc/version.rb +++ b/src/ruby/lib/grpc/version.rb @@ -29,5 +29,5 @@ # GRPC contains the General RPC module. module GRPC - VERSION = '0.12.0' + VERSION = '0.13.0.0' end diff --git a/templates/src/ruby/lib/grpc/version.rb.template b/templates/src/ruby/lib/grpc/version.rb.template new file mode 100644 index 00000000000..4859d2f8834 --- /dev/null +++ b/templates/src/ruby/lib/grpc/version.rb.template @@ -0,0 +1,35 @@ +%YAML 1.2 +--- | + # Copyright 2015-2016, Google Inc. + # All rights reserved. + # + # Redistribution and use in source and binary forms, with or without + # modification, are permitted provided that the following conditions are + # met: + # + # * Redistributions of source code must retain the above copyright + # notice, this list of conditions and the following disclaimer. + # * Redistributions in binary form must reproduce the above + # copyright notice, this list of conditions and the following disclaimer + # in the documentation and/or other materials provided with the + # distribution. + # * Neither the name of Google Inc. nor the names of its + # contributors may be used to endorse or promote products derived from + # this software without specific prior written permission. + # + # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + # GRPC contains the General RPC module. + module GRPC + VERSION = '${settings.version.major}.${settings.version.minor}.${settings.version.micro}.${settings.version.build}' + end From 23dadd920449634ae5a04ac7c1bb4b78d735ff96 Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Sat, 6 Feb 2016 08:51:10 -0800 Subject: [PATCH 46/55] Try to make npm available on jessie x86 --- tools/dockerfile/distribtest/node_jessie_x86/Dockerfile | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tools/dockerfile/distribtest/node_jessie_x86/Dockerfile b/tools/dockerfile/distribtest/node_jessie_x86/Dockerfile index 0408cbeeb09..ca92b1923a3 100644 --- a/tools/dockerfile/distribtest/node_jessie_x86/Dockerfile +++ b/tools/dockerfile/distribtest/node_jessie_x86/Dockerfile @@ -33,4 +33,8 @@ RUN apt-get update && apt-get install -y curl # Install nvm RUN touch .profile -RUN curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.30.2/install.sh | bash \ No newline at end of file +RUN curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.30.2/install.sh | bash + +# Install node 4, as on 32bit system, npm will be missing after nvm install +RUN curl -sL https://deb.nodesource.com/setup_4.x | bash - +RUN apt-get update && apt-get install -y nodejs From c83a9c01870c21ee0632342fe58b69d33cea7fb3 Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Sat, 6 Feb 2016 14:53:28 -0800 Subject: [PATCH 47/55] enable C# distribtest on macos --- test/distrib/csharp/run_distrib_test.sh | 2 +- test/distrib/csharp/update_version.sh | 2 +- tools/run_tests/distribtest_targets.py | 36 ++++++++++++++++++++----- 3 files changed, 31 insertions(+), 9 deletions(-) diff --git a/test/distrib/csharp/run_distrib_test.sh b/test/distrib/csharp/run_distrib_test.sh index 5a01c918757..8ddb4c4bffe 100755 --- a/test/distrib/csharp/run_distrib_test.sh +++ b/test/distrib/csharp/run_distrib_test.sh @@ -32,7 +32,7 @@ set -ex cd $(dirname $0) -unzip "$EXTERNAL_GIT_ROOT/input_artifacts/csharp_nugets.zip" -d TestNugetFeed +unzip -o "$EXTERNAL_GIT_ROOT/input_artifacts/csharp_nugets.zip" -d TestNugetFeed # TODO(jtattermusch): replace the version number ./update_version.sh 0.13.0 diff --git a/test/distrib/csharp/update_version.sh b/test/distrib/csharp/update_version.sh index 569f7ff4bd5..f2554e89981 100755 --- a/test/distrib/csharp/update_version.sh +++ b/test/distrib/csharp/update_version.sh @@ -33,4 +33,4 @@ set -e cd $(dirname $0) # Replaces version placeholder with value provided as first argument. -sed -i "s/__GRPC_NUGET_VERSION__/$1/g" DistribTest/packages.config DistribTest/DistribTest.csproj +sed -ibak "s/__GRPC_NUGET_VERSION__/$1/g" DistribTest/packages.config DistribTest/DistribTest.csproj diff --git a/tools/run_tests/distribtest_targets.py b/tools/run_tests/distribtest_targets.py index a1e45ece9dc..965c7f8316e 100644 --- a/tools/run_tests/distribtest_targets.py +++ b/tools/run_tests/distribtest_targets.py @@ -55,28 +55,49 @@ def create_docker_jobspec(name, dockerfile_dir, shell_command, environ={}, return jobspec +def create_jobspec(name, cmdline, environ=None, shell=False, + flake_retries=0, timeout_retries=0): + """Creates jobspec.""" + jobspec = jobset.JobSpec( + cmdline=cmdline, + environ=environ, + shortname='distribtest.%s' % (name), + timeout_seconds=10*60, + flake_retries=flake_retries, + timeout_retries=timeout_retries, + shell=shell) + return jobspec + + class CSharpDistribTest(object): """Tests C# NuGet package""" - def __init__(self, platform, arch, docker_suffix): - self.name = 'csharp_nuget_%s_%s_%s' % (platform, arch, docker_suffix) + def __init__(self, platform, arch, docker_suffix=None): + self.name = 'csharp_nuget_%s_%s' % (platform, arch) self.platform = platform self.arch = arch self.docker_suffix = docker_suffix - self.labels = ['distribtest', 'csharp', platform, arch, docker_suffix] + self.labels = ['distribtest', 'csharp', platform, arch] + if docker_suffix: + self.name += '_%s' % docker_suffix + self.labels.append(docker_suffix) def pre_build_jobspecs(self): return [] def build_jobspec(self): - if not self.platform == 'linux': - raise Exception("Not supported yet.") - - return create_docker_jobspec(self.name, + if self.platform == 'linux': + return create_docker_jobspec(self.name, 'tools/dockerfile/distribtest/csharp_%s_%s' % ( self.docker_suffix, self.arch), 'test/distrib/csharp/run_distrib_test.sh') + elif self.platform == 'macos': + return create_jobspec(self.name, + ['test/distrib/csharp/run_distrib_test.sh'], + environ={'EXTERNAL_GIT_ROOT': '../../..'}) + else: + raise Exception("Not supported yet.") def __str__(self): return self.name @@ -176,6 +197,7 @@ def targets(): CSharpDistribTest('linux', 'x64', 'ubuntu1504'), CSharpDistribTest('linux', 'x64', 'ubuntu1510'), CSharpDistribTest('linux', 'x64', 'ubuntu1604'), + CSharpDistribTest('macos', 'x86'), PythonDistribTest('linux', 'x64', 'wheezy'), PythonDistribTest('linux', 'x64', 'jessie'), PythonDistribTest('linux', 'x86', 'jessie'), From e477b84c92c7655d1dc11fa1e687de7b60836927 Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Sat, 6 Feb 2016 22:19:01 -0800 Subject: [PATCH 48/55] make node tests pass on macos --- tools/jenkins/docker_run_tests.sh | 2 -- tools/run_tests/build_node.sh | 4 ++++ tools/run_tests/pre_build_node.sh | 4 ++++ tools/run_tests/run_node.sh | 4 ++++ tools/run_tests/run_tests.py | 10 +++++++--- 5 files changed, 19 insertions(+), 5 deletions(-) diff --git a/tools/jenkins/docker_run_tests.sh b/tools/jenkins/docker_run_tests.sh index 26e5585d2d8..12874386a3c 100755 --- a/tools/jenkins/docker_run_tests.sh +++ b/tools/jenkins/docker_run_tests.sh @@ -43,8 +43,6 @@ chown `whoami` $XDG_CACHE_HOME mkdir -p /var/local/git git clone --recursive /var/local/jenkins/grpc /var/local/git/grpc -nvm use 0.12 || true - if [ -x "$(command -v rvm)" ] then rvm use ruby-2.1 diff --git a/tools/run_tests/build_node.sh b/tools/run_tests/build_node.sh index 8f2ab4413a2..9c4af071856 100755 --- a/tools/run_tests/build_node.sh +++ b/tools/run_tests/build_node.sh @@ -29,8 +29,12 @@ # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +NODE_VERSION=$1 +source ~/.nvm/nvm.sh set -ex +nvm use $NODE_VERSION + CONFIG=${CONFIG:-opt} # change to grpc repo root diff --git a/tools/run_tests/pre_build_node.sh b/tools/run_tests/pre_build_node.sh index 28ce354f276..40213b859ad 100755 --- a/tools/run_tests/pre_build_node.sh +++ b/tools/run_tests/pre_build_node.sh @@ -29,8 +29,12 @@ # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +NODE_VERSION=$1 +source ~/.nvm/nvm.sh set -ex +nvm use $NODE_VERSION + export GRPC_CONFIG=${CONFIG:-opt} # Expire cache after 1 week diff --git a/tools/run_tests/run_node.sh b/tools/run_tests/run_node.sh index f93c9c30cbe..40f61d77cc9 100755 --- a/tools/run_tests/run_node.sh +++ b/tools/run_tests/run_node.sh @@ -28,8 +28,12 @@ # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +NODE_VERSION=$1 +source ~/.nvm/nvm.sh set -ex +nvm use $NODE_VERSION + CONFIG=${CONFIG:-opt} # change to grpc repo root diff --git a/tools/run_tests/run_tests.py b/tools/run_tests/run_tests.py index 9e7b97c6a21..6dfdc705bec 100755 --- a/tools/run_tests/run_tests.py +++ b/tools/run_tests/run_tests.py @@ -194,13 +194,17 @@ class CLanguage(object): class NodeLanguage(object): + def __init__(self): + self.node_version = '0.12' + def test_specs(self, config, args): - return [config.job_spec(['tools/run_tests/run_node.sh'], None, + return [config.job_spec(['tools/run_tests/run_node.sh', self.node_version], + None, environ=_FORCE_ENVIRON_FOR_WRAPPERS)] def pre_build_steps(self): # Default to 1 week cache expiration - return [['tools/run_tests/pre_build_node.sh']] + return [['tools/run_tests/pre_build_node.sh', self.node_version]] def make_targets(self, test_regex): return [] @@ -209,7 +213,7 @@ class NodeLanguage(object): return [] def build_steps(self): - return [['tools/run_tests/build_node.sh']] + return [['tools/run_tests/build_node.sh', self.node_version]] def post_tests_steps(self): return [] From 823b8a2ce2610d694ee5a2d0a7e4066c38253849 Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Sat, 6 Feb 2016 22:34:13 -0800 Subject: [PATCH 49/55] fix copyright --- tools/run_tests/pre_build_node.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/run_tests/pre_build_node.sh b/tools/run_tests/pre_build_node.sh index 40213b859ad..11f46d60fc2 100755 --- a/tools/run_tests/pre_build_node.sh +++ b/tools/run_tests/pre_build_node.sh @@ -1,6 +1,6 @@ #!/bin/bash -# Copyright 2015, Google Inc. +# Copyright 2015-2016, Google Inc. # All rights reserved. # # Redistribution and use in source and binary forms, with or without From 766fa227e00b9e3fd299a207bde0e4040ffa0f82 Mon Sep 17 00:00:00 2001 From: yang-g Date: Mon, 8 Feb 2016 09:46:52 -0800 Subject: [PATCH 50/55] missed newline --- tools/run_tests/build_artifact_python.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/run_tests/build_artifact_python.sh b/tools/run_tests/build_artifact_python.sh index 48cf390f696..87bc85e8b1f 100755 --- a/tools/run_tests/build_artifact_python.sh +++ b/tools/run_tests/build_artifact_python.sh @@ -46,4 +46,4 @@ GRPC_PYTHON_BUILD_WITH_CYTHON=1 ${SETARCH_CMD} python setup.py \ mkdir -p artifacts -cp -r dist/* artifacts \ No newline at end of file +cp -r dist/* artifacts From b9e66cc551b1480e363667bac1d2162f7da7f27d Mon Sep 17 00:00:00 2001 From: Adele Zhou Date: Wed, 3 Feb 2016 13:12:23 -0800 Subject: [PATCH 51/55] Added test cases for Cloud gateway. --- tools/run_tests/interop_html_report.template | 42 ++++++---- tools/run_tests/report_utils.py | 4 +- tools/run_tests/run_interop_tests.py | 88 +++++++++++++------- 3 files changed, 89 insertions(+), 45 deletions(-) diff --git a/tools/run_tests/interop_html_report.template b/tools/run_tests/interop_html_report.template index 114a508c319..46cce426b7a 100644 --- a/tools/run_tests/interop_html_report.template +++ b/tools/run_tests/interop_html_report.template @@ -64,17 +64,8 @@ % endif -% if num_failures > 1: -

${num_failures} tests failed!

-% elif num_failures: -

${num_failures} test failed!

-% else: -

All tests passed!

-% endif - -% if cloud_to_prod: +<%def name="display_cloud_to_prod_result(prod_server)"> ## Each column header is the client language. -

Cloud to Prod

@@ -87,15 +78,32 @@ % for client_lang in client_langs: <% if test_case in auth_test_cases: - shortname = 'cloud_to_prod_auth:%s:%s' % (client_lang, test_case) + shortname = 'cloud_to_prod_auth:%s:%s:%s' % ( + prod_server, client_lang, test_case) else: - shortname = 'cloud_to_prod:%s:%s' % (client_lang, test_case) + shortname = 'cloud_to_prod:%s:%s:%s' % ( + prod_server, client_lang, test_case) %> ${fill_one_test_result(shortname, resultset)} % endfor % endfor
Client languages ►
Test Cases ▼
+ + +% if num_failures > 1: +

${num_failures} tests failed!

+% elif num_failures: +

${num_failures} test failed!

+% else: +

All tests passed!

+% endif + +% if cloud_to_prod: + % for prod_server in prod_servers: +

Cloud to ${prod_server}

+ ${display_cloud_to_prod_result(prod_server)} + % endfor % endif % if http2_interop: @@ -108,7 +116,9 @@ ${server_lang} % endfor % if cloud_to_prod: - prod + % for prod_server in prod_servers: + ${prod_server} + % endfor % endif % for test_case in http2_cases: @@ -122,8 +132,10 @@ ${fill_one_http2_test_result(shortname, resultset)} % endfor % if cloud_to_prod: - <% shortname = 'cloud_to_prod:http2:%s' % test_case %> - ${fill_one_http2_test_result(shortname, resultset)} + % for prod_server in prod_servers: + <% shortname = 'cloud_to_prod:%s:http2:%s' % (prod_server, test_case) %> + ${fill_one_http2_test_result(shortname, resultset)} + % endfor % endif % endfor diff --git a/tools/run_tests/report_utils.py b/tools/run_tests/report_utils.py index 35f2069beea..437c4693a52 100644 --- a/tools/run_tests/report_utils.py +++ b/tools/run_tests/report_utils.py @@ -77,7 +77,7 @@ def render_junit_xml_report(resultset, xml_report): def render_interop_html_report( client_langs, server_langs, test_cases, auth_test_cases, http2_cases, - resultset, num_failures, cloud_to_prod, http2_interop): + resultset, num_failures, cloud_to_prod, prod_servers, http2_interop): """Generate HTML report for interop tests.""" template_file = 'tools/run_tests/interop_html_report.template' try: @@ -94,6 +94,7 @@ def render_interop_html_report( sorted_http2_cases = sorted(http2_cases) sorted_client_langs = sorted(client_langs) sorted_server_langs = sorted(server_langs) + sorted_prod_servers = sorted(prod_servers) args = {'client_langs': sorted_client_langs, 'server_langs': sorted_server_langs, @@ -103,6 +104,7 @@ def render_interop_html_report( 'resultset': resultset, 'num_failures': num_failures, 'cloud_to_prod': cloud_to_prod, + 'prod_servers': sorted_prod_servers, 'http2_interop': http2_interop} html_report_out_dir = 'reports' diff --git a/tools/run_tests/run_interop_tests.py b/tools/run_tests/run_interop_tests.py index fbc3b3cdf6f..4a670e0c9db 100755 --- a/tools/run_tests/run_interop_tests.py +++ b/tools/run_tests/run_interop_tests.py @@ -422,12 +422,13 @@ def _job_kill_handler(job): time.sleep(2) -def cloud_to_prod_jobspec(language, test_case, docker_image=None, auth=False): +def cloud_to_prod_jobspec(language, test_case, server_host_name, + server_host_detail, docker_image=None, auth=False): """Creates jobspec for cloud-to-prod interop test""" container_name = None cmdargs = [ - '--server_host_override=grpc-test.sandbox.googleapis.com', - '--server_host=grpc-test.sandbox.googleapis.com', + '--server_host=%s' % server_host_detail[0], + '--server_host_override=%s' % server_host_detail[1], '--server_port=443', '--use_tls=true', '--test_case=%s' % test_case] @@ -440,7 +441,8 @@ def cloud_to_prod_jobspec(language, test_case, docker_image=None, auth=False): cwd = language.client_cwd if docker_image: - container_name = dockerjob.random_name('interop_client_%s' % language.safename) + container_name = dockerjob.random_name('interop_client_%s' % + language.safename) cmdline = docker_run_cmdline(cmdline, image=docker_image, cwd=cwd, @@ -455,7 +457,8 @@ def cloud_to_prod_jobspec(language, test_case, docker_image=None, auth=False): cmdline=cmdline, cwd=cwd, environ=environ, - shortname='%s:%s:%s' % (suite_name, language, test_case), + shortname='%s:%s:%s:%s' % (suite_name, server_host_name, language, + test_case), timeout_seconds=90, flake_retries=5 if args.allow_flakes else 0, timeout_retries=2 if args.allow_flakes else 0, @@ -491,7 +494,7 @@ def cloud_to_cloud_jobspec(language, test_case, server_name, server_host, cwd=cwd, environ=environ, shortname='cloud_to_cloud:%s:%s_server:%s' % (language, server_name, - test_case), + test_case), timeout_seconds=90, flake_retries=5 if args.allow_flakes else 0, timeout_retries=2 if args.allow_flakes else 0, @@ -572,6 +575,21 @@ def aggregate_http2_results(stdout): 'percent': 1.0 * passed / (passed + failed) } +# A dictionary of prod servers to test. +# Format: server_name: (server_host, server_host_override, errors_allowed) +# TODO(adelez): implement logic for errors_allowed where if the indicated tests +# fail, they don't impact the overall test result. +prod_servers = { + 'default': ('grpc-test.sandbox.googleapis.com', + 'grpc-test.sandbox.googleapis.com', False), + 'gateway_v2': ('grpc-test2.sandbox.googleapis.com', + 'grpc-test2.sandbox.googleapis.com', True), + 'cloud_gateway': ('216.239.32.255', 'grpc-test.sandbox.googleapis.com', + False), + 'cloud_gateway_v2': ('216.239.32.255', 'grpc-test2.sandbox.googleapis.com', + True) +} + argp = argparse.ArgumentParser(description='Run interop tests.') argp.add_argument('-l', '--language', choices=['all'] + sorted(_LANGUAGES), @@ -589,6 +607,12 @@ argp.add_argument('--cloud_to_prod_auth', action='store_const', const=True, help='Run cloud_to_prod_auth tests.') +argp.add_argument('--prod_servers', + choices=prod_servers.keys(), + default=['default'], + nargs='+', + help=('The servers to run cloud_to_prod and ' + 'cloud_to_prod_auth tests against.')) argp.add_argument('-s', '--server', choices=['all'] + sorted(_SERVERS), action='append', @@ -688,32 +712,37 @@ try: server_jobs[lang] = job server_addresses[lang] = ('localhost', job.mapped_port(_DEFAULT_SERVER_PORT)) - jobs = [] if args.cloud_to_prod: - for language in languages: - for test_case in _TEST_CASES: - if not test_case in language.unimplemented_test_cases(): - if not test_case in _SKIP_ADVANCED + _SKIP_COMPRESSION: - test_job = cloud_to_prod_jobspec(language, test_case, - docker_image=docker_images.get(str(language))) - jobs.append(test_job) - - if args.http2_interop: - for test_case in _HTTP2_TEST_CASES: - test_job = cloud_to_prod_jobspec(http2Interop, test_case, - docker_image=docker_images.get(str(http2Interop))) - jobs.append(test_job) - + for server_host_name in args.prod_servers: + for language in languages: + for test_case in _TEST_CASES: + if not test_case in language.unimplemented_test_cases(): + if not test_case in _SKIP_ADVANCED + _SKIP_COMPRESSION: + test_job = cloud_to_prod_jobspec( + language, test_case, server_host_name, + prod_servers[server_host_name], + docker_image=docker_images.get(str(language))) + jobs.append(test_job) + + if args.http2_interop: + for test_case in _HTTP2_TEST_CASES: + test_job = cloud_to_prod_jobspec( + http2Interop, test_case, server_host_name, + prod_servers[server_host_name], + docker_image=docker_images.get(str(http2Interop))) + jobs.append(test_job) if args.cloud_to_prod_auth: - for language in languages: - for test_case in _AUTH_TEST_CASES: - if not test_case in language.unimplemented_test_cases(): - test_job = cloud_to_prod_jobspec(language, test_case, - docker_image=docker_images.get(str(language)), - auth=True) - jobs.append(test_job) + for server_host_name in args.prod_servers: + for language in languages: + for test_case in _AUTH_TEST_CASES: + if not test_case in language.unimplemented_test_cases(): + test_job = cloud_to_prod_jobspec( + language, test_case, server_host_name, + prod_servers[server_host_name], + docker_image=docker_images.get(str(language)), auth=True) + jobs.append(test_job) for server in args.override_server: server_name = server[0] @@ -773,7 +802,8 @@ try: report_utils.render_interop_html_report( set([str(l) for l in languages]), servers, _TEST_CASES, _AUTH_TEST_CASES, _HTTP2_TEST_CASES, resultset, num_failures, - args.cloud_to_prod_auth or args.cloud_to_prod, args.http2_interop) + args.cloud_to_prod_auth or args.cloud_to_prod, args.prod_servers, + args.http2_interop) finally: # Check if servers are still running. From 474ccfcaedad31ce896a59b8100174a2c7d25ac7 Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Mon, 8 Feb 2016 10:17:19 -0800 Subject: [PATCH 52/55] revert suspicious change to node_jessie_x86 --- tools/dockerfile/distribtest/node_jessie_x86/Dockerfile | 4 ---- 1 file changed, 4 deletions(-) diff --git a/tools/dockerfile/distribtest/node_jessie_x86/Dockerfile b/tools/dockerfile/distribtest/node_jessie_x86/Dockerfile index ca92b1923a3..8b97d8bb5a3 100644 --- a/tools/dockerfile/distribtest/node_jessie_x86/Dockerfile +++ b/tools/dockerfile/distribtest/node_jessie_x86/Dockerfile @@ -34,7 +34,3 @@ RUN apt-get update && apt-get install -y curl # Install nvm RUN touch .profile RUN curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.30.2/install.sh | bash - -# Install node 4, as on 32bit system, npm will be missing after nvm install -RUN curl -sL https://deb.nodesource.com/setup_4.x | bash - -RUN apt-get update && apt-get install -y nodejs From 6c90d898b625d9e52233328b41eb44a684d32aef Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Mon, 8 Feb 2016 10:27:50 -0800 Subject: [PATCH 53/55] Fix sanity --- examples/objective-c/helloworld/main.m | 2 +- src/objective-c/GRPCClient/private/GRPCChannel.h | 2 +- src/objective-c/GRPCClient/private/GRPCChannel.m | 2 +- src/objective-c/GRPCClient/private/GRPCHost.h | 2 +- src/objective-c/GRPCClient/private/GRPCHost.m | 2 +- tools/run_tests/report_utils.py | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/objective-c/helloworld/main.m b/examples/objective-c/helloworld/main.m index 755dce33df9..bf357990a56 100644 --- a/examples/objective-c/helloworld/main.m +++ b/examples/objective-c/helloworld/main.m @@ -1,6 +1,6 @@ /* * - * Copyright 2015, Google Inc. + * Copyright 2015-2016, Google Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/src/objective-c/GRPCClient/private/GRPCChannel.h b/src/objective-c/GRPCClient/private/GRPCChannel.h index 1888dea1b47..8661ae6f972 100644 --- a/src/objective-c/GRPCClient/private/GRPCChannel.h +++ b/src/objective-c/GRPCClient/private/GRPCChannel.h @@ -1,6 +1,6 @@ /* * - * Copyright 2015, Google Inc. + * Copyright 2015-2016, Google Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/src/objective-c/GRPCClient/private/GRPCChannel.m b/src/objective-c/GRPCClient/private/GRPCChannel.m index 7a676060c16..7e55a473d74 100644 --- a/src/objective-c/GRPCClient/private/GRPCChannel.m +++ b/src/objective-c/GRPCClient/private/GRPCChannel.m @@ -1,6 +1,6 @@ /* * - * Copyright 2015, Google Inc. + * Copyright 2015-2016, Google Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/src/objective-c/GRPCClient/private/GRPCHost.h b/src/objective-c/GRPCClient/private/GRPCHost.h index 69a115e88cf..82c0ad6cf63 100644 --- a/src/objective-c/GRPCClient/private/GRPCHost.h +++ b/src/objective-c/GRPCClient/private/GRPCHost.h @@ -1,6 +1,6 @@ /* * - * Copyright 2015, Google Inc. + * Copyright 2015-2016, Google Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/src/objective-c/GRPCClient/private/GRPCHost.m b/src/objective-c/GRPCClient/private/GRPCHost.m index f750841a446..eb1db899b70 100644 --- a/src/objective-c/GRPCClient/private/GRPCHost.m +++ b/src/objective-c/GRPCClient/private/GRPCHost.m @@ -1,6 +1,6 @@ /* * - * Copyright 2015, Google Inc. + * Copyright 2015-2016, Google Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/tools/run_tests/report_utils.py b/tools/run_tests/report_utils.py index 437c4693a52..0032a985232 100644 --- a/tools/run_tests/report_utils.py +++ b/tools/run_tests/report_utils.py @@ -1,4 +1,4 @@ -# Copyright 2015, Google Inc. +# Copyright 2015-2016, Google Inc. # All rights reserved. # # Redistribution and use in source and binary forms, with or without From d271dd400f194425e7dcc5a4a3a77bca16661615 Mon Sep 17 00:00:00 2001 From: "Nicolas \"Pixel\" Noble" Date: Mon, 8 Feb 2016 19:32:05 +0100 Subject: [PATCH 54/55] Nope. --- grpc.gemspec | 1 - templates/grpc.gemspec.template | 1 - 2 files changed, 2 deletions(-) diff --git a/grpc.gemspec b/grpc.gemspec index e305ea57ef3..e990948edf6 100755 --- a/grpc.gemspec +++ b/grpc.gemspec @@ -14,7 +14,6 @@ Gem::Specification.new do |s| s.license = 'BSD-3-Clause' s.required_ruby_version = '>= 2.0.0' - s.requirements << 'libgrpc ~> 0.11.0 needs to be installed' s.files = %w( Makefile ) s.files += %w( etc/roots.pem ) diff --git a/templates/grpc.gemspec.template b/templates/grpc.gemspec.template index 9d034ddba12..c4987a6725f 100644 --- a/templates/grpc.gemspec.template +++ b/templates/grpc.gemspec.template @@ -16,7 +16,6 @@ s.license = 'BSD-3-Clause' s.required_ruby_version = '>= 2.0.0' - s.requirements << 'libgrpc ~> 0.11.0 needs to be installed' s.files = %w( Makefile ) s.files += %w( etc/roots.pem ) From 001db590ffb68c8e7051273f7fe9ccd6a9572e10 Mon Sep 17 00:00:00 2001 From: Sree Kuchibhotla Date: Mon, 8 Feb 2016 10:54:57 -0800 Subject: [PATCH 55/55] Modify the test to have large number of threads receiving the RPCs and a smaller number of threads sending the RPCs. This increases the likelyhood of race-conditions on receiving threads. --- test/cpp/end2end/thread_stress_test.cc | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/test/cpp/end2end/thread_stress_test.cc b/test/cpp/end2end/thread_stress_test.cc index 4c7caa9b878..dd7a8e5ed2c 100644 --- a/test/cpp/end2end/thread_stress_test.cc +++ b/test/cpp/end2end/thread_stress_test.cc @@ -55,7 +55,9 @@ using grpc::testing::EchoRequest; using grpc::testing::EchoResponse; using std::chrono::system_clock; -const int kNumThreads = 100; // Number of threads +const int kNumThreads = 100; // Number of threads +const int kNumAsyncSendThreads = 2; +const int kNumAsyncReceiveThreads = 50; const int kNumRpcs = 1000; // Number of RPCs per thread namespace grpc { @@ -273,7 +275,7 @@ class AsyncClientEnd2endTest : public ::testing::Test { for (int i = 0; i < num_rpcs; ++i) { AsyncClientCall* call = new AsyncClientCall; EchoRequest request; - request.set_message("Hello"); + request.set_message("Hello: " + std::to_string(i)); call->response_reader = common_.GetStub()->AsyncEcho(&call->context, request, &cq_); call->response_reader->Finish(&call->response, &call->status, @@ -290,7 +292,9 @@ class AsyncClientEnd2endTest : public ::testing::Test { bool ok = false; if (!cq_.Next(&got_tag, &ok)) break; AsyncClientCall* call = static_cast(got_tag); - GPR_ASSERT(ok); + if (!ok) { + gpr_log(GPR_DEBUG, "Error: %d", call->status.error_code()); + } delete call; bool notify; @@ -315,22 +319,22 @@ class AsyncClientEnd2endTest : public ::testing::Test { TEST_F(AsyncClientEnd2endTest, ThreadStress) { common_.ResetStub(); std::vector send_threads, completion_threads; - for (int i = 0; i < kNumThreads / 2; ++i) { + for (int i = 0; i < kNumAsyncReceiveThreads; ++i) { completion_threads.push_back(new std::thread( &AsyncClientEnd2endTest_ThreadStress_Test::AsyncCompleteRpc, this)); } - for (int i = 0; i < kNumThreads / 2; ++i) { + for (int i = 0; i < kNumAsyncSendThreads; ++i) { send_threads.push_back( new std::thread(&AsyncClientEnd2endTest_ThreadStress_Test::AsyncSendRpc, this, kNumRpcs)); } - for (int i = 0; i < kNumThreads / 2; ++i) { + for (int i = 0; i < kNumAsyncSendThreads; ++i) { send_threads[i]->join(); delete send_threads[i]; } Wait(); - for (int i = 0; i < kNumThreads / 2; ++i) { + for (int i = 0; i < kNumAsyncReceiveThreads; ++i) { completion_threads[i]->join(); delete completion_threads[i]; }