Skip to content
This repository was archived by the owner on Dec 15, 2021. It is now read-only.

Commit 59d8b85

Browse files
authored
Merge pull request #200 from thomasvl/update
Update deps and add custom framework generation support
2 parents 744114d + 1ff02f3 commit 59d8b85

5 files changed

Lines changed: 41 additions & 15 deletions

File tree

Source/Tools/ServiceGenerator/FHGenerator.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,14 @@ typedef enum {
2929
@property (readonly, retain) GTLDiscoveryRpcDescription* api;
3030
@property (readonly, assign) NSUInteger verboseLevel;
3131
@property (readonly, assign) BOOL allowRootURLOverrides;
32+
@property (readonly, copy) NSString *frameworkName;
3233

3334
+ (instancetype)generatorForApi:(GTLDiscoveryRpcDescription *)api
3435
verboseLevel:(NSUInteger)verboseLevel
3536
allowRootURLOverrides:(BOOL)allowRootURLOverrides
3637
formattedNameOverride:(NSString *)formattedNameOverride
37-
skipIfLikelyREST:(BOOL)skipIfLikelyREST;
38+
skipIfLikelyREST:(BOOL)skipIfLikelyREST
39+
useFrameworkName:(NSString *)frameworkName;
3840

3941
// Keys are the file names; values are the contents of the files.
4042
- (NSDictionary *)generateFilesWithHandler:(void (^)(FHGeneratorHandlerMessageType msgType,

Source/Tools/ServiceGenerator/FHGenerator.m

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,8 @@ - (instancetype)initWithApi:(GTLDiscoveryRpcDescription *)api
177177
verboseLevel:(NSUInteger)verboseLevel
178178
allowRootURLOverrides:(BOOL)allowRootURLOverrides
179179
formattedNameOverride:(NSString *)formattedNameOverride
180-
skipIfLikelyREST:(BOOL)skipIfLikelyREST;
180+
skipIfLikelyREST:(BOOL)skipIfLikelyREST
181+
useFrameworkName:(NSString *)frameworkName;
181182

182183
- (void)adornMethods:(GTLDiscoveryRpcDescriptionMethods *)methods;
183184
- (void)adornSchema:(GTLDiscoveryJsonSchema *)schema
@@ -242,7 +243,8 @@ @implementation FHGenerator
242243

243244
@synthesize api = api_,
244245
verboseLevel = verboseLevel_,
245-
allowRootURLOverrides = allowRootURLOverrides_;
246+
allowRootURLOverrides = allowRootURLOverrides_,
247+
frameworkName = frameworkName_;
246248

247249
@synthesize warnings = warnings_,
248250
infos = infos_;
@@ -251,25 +253,29 @@ + (instancetype)generatorForApi:(GTLDiscoveryRpcDescription *)api
251253
verboseLevel:(NSUInteger)verboseLevel
252254
allowRootURLOverrides:(BOOL)allowRootURLOverrides
253255
formattedNameOverride:(NSString *)formattedNameOverride
254-
skipIfLikelyREST:(BOOL)skipIfLikelyREST {
256+
skipIfLikelyREST:(BOOL)skipIfLikelyREST
257+
useFrameworkName:(NSString *)frameworkName {
255258
return [[[self alloc] initWithApi:api
256259
verboseLevel:verboseLevel
257260
allowRootURLOverrides:allowRootURLOverrides
258261
formattedNameOverride:formattedNameOverride
259-
skipIfLikelyREST:skipIfLikelyREST] autorelease];
262+
skipIfLikelyREST:skipIfLikelyREST
263+
useFrameworkName:frameworkName] autorelease];
260264
}
261265

262266
- (instancetype)initWithApi:(GTLDiscoveryRpcDescription *)api
263267
verboseLevel:(NSUInteger)verboseLevel
264268
allowRootURLOverrides:(BOOL)allowRootURLOverrides
265269
formattedNameOverride:(NSString *)formattedNameOverride
266-
skipIfLikelyREST:(BOOL)skipIfLikelyREST {
270+
skipIfLikelyREST:(BOOL)skipIfLikelyREST
271+
useFrameworkName:(NSString *)frameworkName {
267272
self = [super init];
268273
if (self != nil) {
269274
api_ = [api retain];
270275
verboseLevel_ = verboseLevel;
271276
allowRootURLOverrides_ = allowRootURLOverrides;
272277
formattedName_ = [formattedNameOverride copy];
278+
frameworkName_ = [frameworkName copy];
273279
if (!api) {
274280
[self release];
275281
self = nil;
@@ -2473,11 +2479,15 @@ - (NSString *)authorizationScopeToConstant:(NSString *)scope {
24732479

24742480
- (NSString *)frameworkedImport:(NSString *)headerName {
24752481
NSMutableString *result = [NSMutableString string];
2476-
[result appendFormat:@"#if %@\n", kFrameworkIncludeGate];
2477-
[result appendFormat:@" #import \"%@/%@.h\"\n", kProjectPrefix, headerName];
2478-
[result appendString:@"#else\n"];
2479-
[result appendFormat:@" #import \"%@.h\"\n", headerName];
2480-
[result appendString:@"#endif\n"];
2482+
if (self.frameworkName) {
2483+
[result appendFormat:@"#import <%@/%@.h>\n", self.frameworkName, headerName];
2484+
} else {
2485+
[result appendFormat:@"#if %@\n", kFrameworkIncludeGate];
2486+
[result appendFormat:@" #import \"%@/%@.h\"\n", kProjectPrefix, headerName];
2487+
[result appendString:@"#else\n"];
2488+
[result appendFormat:@" #import \"%@.h\"\n", headerName];
2489+
[result appendString:@"#endif\n"];
2490+
}
24812491
return result;
24822492
}
24832493

Source/Tools/ServiceGenerator/FHMain.m

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@
4747
" to send the JSON-RPC requests. This is useful for running against a"
4848
" custom or prerelease server."
4949
},
50+
{ "--gtlFrameworkName NAME",
51+
"Will generate sources that include GTL's headers as if they are in a"
52+
" framework with the given name. If you are using GTL via CocoaPods,"
53+
" you'll likely want to pass \"GoogleAPIClient\" as the value for this."
54+
},
5055
{ "--apiLogDir DIR",
5156
"Write out a file into DIR for each JSON API description processed. These"
5257
" can be useful for reporting bugs if generation fails with an error."
@@ -103,7 +108,7 @@
103108
" the files for it are generated. When using --generatePreferred"
104109
" version can be '-' to skip generating the name service." },
105110
{ "http[s]://url/to/rpc_description_json",
106-
"A URL to download containing the descripiton of a service to"
111+
"A URL to download containing the description of a service to"
107112
" generate." },
108113
{ "path/to/rpc_description.json",
109114
"The path to a text file containing the description of a service to"
@@ -159,6 +164,7 @@ @interface FHMain ()
159164
@property (copy) NSString *appName;
160165
@property (copy) NSString *outputDir;
161166
@property (copy) NSString *discoveryServiceURLString;
167+
@property(copy) NSString *gtlFrameworkName;
162168
@property (copy) NSString *apiLogDir;
163169
@property (copy) NSString *httpLogDir;
164170
@property (assign) BOOL generatePreferred;
@@ -446,6 +452,7 @@ - (void)stateParseArgs {
446452
struct option longopts[] = {
447453
{ "outputDir", required_argument, NULL, 'o' },
448454
{ "discoveryService", required_argument, NULL, 'd' },
455+
{ "gtlFrameworkName", required_argument, NULL, 'n' },
449456
{ "apiLogDir", required_argument, NULL, 'a' },
450457
{ "httpLogDir", required_argument, NULL, 'h' },
451458
{ "generatePreferred", no_argument, &generatePreferred, 1 },
@@ -469,6 +476,9 @@ - (void)stateParseArgs {
469476
case 'd':
470477
self.discoveryServiceURLString = [NSString stringWithUTF8String:optarg];
471478
break;
479+
case 'n':
480+
self.gtlFrameworkName = @(optarg);
481+
break;
472482
case 'a':
473483
self.apiLogDir = [NSString stringWithUTF8String:optarg];
474484
break;
@@ -562,6 +572,9 @@ - (void)stateParseArgs {
562572
if ([self.discoveryServiceURLString length] == 0) {
563573
self.discoveryServiceURLString = nil;
564574
}
575+
if (self.gtlFrameworkName.length == 0) {
576+
self.gtlFrameworkName = nil;
577+
}
565578

566579
// Make sure output dir exists.
567580
NSFileManager *fm = [NSFileManager defaultManager];
@@ -958,7 +971,8 @@ - (void)stateGenerate {
958971
verboseLevel:self.verboseLevel
959972
allowRootURLOverrides:self.rootURLOverrides
960973
formattedNameOverride:formattedNameOverride
961-
skipIfLikelyREST:fromDiscovery];
974+
skipIfLikelyREST:fromDiscovery
975+
useFrameworkName:self.gtlFrameworkName];
962976
if (fromDiscovery && [aGenerator likelyRESTOnlyAPI]) {
963977
fprintf(stderr,
964978
" %s Skipping this api. It appears to be a REST only and can't be supported via JSON-RPC\n", kWARNING);

0 commit comments

Comments
 (0)