diff --git a/Deps/gtm-session-fetcher b/Deps/gtm-session-fetcher index d1e244908..db8121f51 160000 --- a/Deps/gtm-session-fetcher +++ b/Deps/gtm-session-fetcher @@ -1 +1 @@ -Subproject commit d1e24490818c432185535d859a0c5f476792dd00 +Subproject commit db8121f51358bdfcaebb195e9b081ab48b962068 diff --git a/Source/Tools/ServiceGenerator/SGGenerator.h b/Source/Tools/ServiceGenerator/SGGenerator.h index 572235340..c46e214be 100644 --- a/Source/Tools/ServiceGenerator/SGGenerator.h +++ b/Source/Tools/ServiceGenerator/SGGenerator.h @@ -31,6 +31,7 @@ typedef NS_OPTIONS(NSUInteger, SGGeneratorOptions) { kSGGeneratorOptionAllowRootOverride = 1 << 1, kSGGeneratorOptionAllowGuessFormattedName = 1 << 2, kSGGeneratorOptionLegacyObjectNaming = 1 << 3, + kSGGeneratorOptionImportPrefixIsFramework = 1 << 4, }; @interface SGGenerator : NSObject @@ -38,7 +39,7 @@ typedef NS_OPTIONS(NSUInteger, SGGeneratorOptions) { @property(readonly) GTLRDiscovery_RestDescription* api; @property(readonly) SGGeneratorOptions options; @property(readonly) NSUInteger verboseLevel; -@property(readonly) NSString *frameworkName; +@property(readonly) NSString *importPrefix; // The API name formatted for use as a directory name. @property (readonly) NSString *formattedAPIName; @@ -47,7 +48,7 @@ typedef NS_OPTIONS(NSUInteger, SGGeneratorOptions) { options:(SGGeneratorOptions)options verboseLevel:(NSUInteger)verboseLevel formattedNameOverride:(NSString *)formattedNameOverride - useFrameworkName:(NSString *)frameworkName; + importPrefix:(NSString *)importPrefix; // Keys are the file names; values are the contents of the files. - (NSDictionary *)generateFilesWithHandler:(SGGeneratorMessageHandler)messageHandler; diff --git a/Source/Tools/ServiceGenerator/SGGenerator.m b/Source/Tools/ServiceGenerator/SGGenerator.m index 735da490b..0f225eb10 100644 --- a/Source/Tools/ServiceGenerator/SGGenerator.m +++ b/Source/Tools/ServiceGenerator/SGGenerator.m @@ -248,7 +248,7 @@ @implementation SGGenerator { @synthesize api = _api, options = _options, verboseLevel = _verboseLevel, - frameworkName = _frameworkName; + importPrefix = _importPrefix; @synthesize warnings = _warnings, infos = _infos; @@ -257,26 +257,26 @@ + (instancetype)generatorForApi:(GTLRDiscovery_RestDescription *)api options:(SGGeneratorOptions)options verboseLevel:(NSUInteger)verboseLevel formattedNameOverride:(NSString *)formattedNameOverride - useFrameworkName:(NSString *)frameworkName { + importPrefix:(NSString *)importPrefix { return [[self alloc] initWithApi:api options:options verboseLevel:verboseLevel formattedNameOverride:formattedNameOverride - useFrameworkName:frameworkName]; + importPrefix:importPrefix]; } - (instancetype)initWithApi:(GTLRDiscovery_RestDescription *)api options:(SGGeneratorOptions)options verboseLevel:(NSUInteger)verboseLevel formattedNameOverride:(NSString *)formattedNameOverride - useFrameworkName:(NSString *)frameworkName { + importPrefix:(NSString *)importPrefix { self = [super init]; if (self != nil) { _api = api; _options = options; _verboseLevel = verboseLevel; _formattedName = [formattedNameOverride copy]; - _frameworkName = [frameworkName copy]; + _importPrefix = [importPrefix copy]; if (api) { NSValue *generatorAsValue = [NSValue valueWithNonretainedObject:self]; [self.api sg_setProperty:generatorAsValue forKey:kWrappedGeneratorKey]; @@ -2830,18 +2830,21 @@ - (NSString *)authorizationScopeToConstant:(NSString *)scope { } - (NSString *)frameworkedImport:(NSString *)headerName { - NSMutableString *result = [NSMutableString string]; - if (self.frameworkName) { - [result appendFormat:@"#import <%@/%@.h>\n", self.frameworkName, headerName]; - } else { - [result appendFormat:@"#if %@\n", kFrameworkIncludeGate]; - [result appendFormat:@" #import \"%@/%@.h\"\n", kProjectPrefix, headerName]; - [result appendString:@"#else\n"]; - [result appendFormat:@" #import \"%@.h\"\n", headerName]; - [result appendString:@"#endif\n"]; + if (self.importPrefix) { + if ((_options & kSGGeneratorOptionImportPrefixIsFramework) != 0) { + return [NSString stringWithFormat:@"#import <%@/%@.h>\n", self.importPrefix, headerName]; + } else { + return [NSString stringWithFormat:@"#import \"%@/%@.h\"\n", self.importPrefix, headerName]; + } } + NSMutableString *result = [NSMutableString string]; + [result appendFormat:@"#if %@\n", kFrameworkIncludeGate]; + [result appendFormat:@" #import \"%@/%@.h\"\n", kProjectPrefix, headerName]; + [result appendString:@"#else\n"]; + [result appendFormat:@" #import \"%@.h\"\n", headerName]; + [result appendString:@"#endif\n"]; return result; } diff --git a/Source/Tools/ServiceGenerator/SGMain.m b/Source/Tools/ServiceGenerator/SGMain.m index 391523660..bedee165d 100644 --- a/Source/Tools/ServiceGenerator/SGMain.m +++ b/Source/Tools/ServiceGenerator/SGMain.m @@ -63,6 +63,10 @@ " you'll likely want to pass \"GoogleApiClientForRest\" as the value for" " this." }, + { "--gtlrImportPrefix PREFIX", + "Will generate sources that include GTLR's headers as if they are in the" + " given directory." + }, { "--apiLogDir DIR", "Write out a file into DIR for each JSON API description processed. These" " can be useful for reporting bugs if generation fails with an error." @@ -204,6 +208,7 @@ @interface SGMain () @property(copy) NSString *outputDir; @property(copy) NSString *discoveryRootURLString; @property(copy) NSString *gtlrFrameworkName; +@property(copy) NSString *gtlrImportPrefix; @property(copy) NSString *apiLogDir; @property(copy) NSString *httpLogDir; @property(copy) NSString *messageFilterPath; @@ -278,6 +283,7 @@ @implementation SGMain { outputDir = _outputDir, discoveryRootURLString = _discoveryRootURLString, gtlrFrameworkName = _gtlrFrameworkName, + gtlrImportPrefix = _gtlrImportPrefix, apiLogDir = _apiLogDir, httpLogDir = _httpLogDir, messageFilterPath = _messageFilterPath, @@ -743,6 +749,7 @@ - (void)stateParseArgs { { "outputDir", required_argument, NULL, 'o' }, { "discoveryRootURL", required_argument, NULL, 'd' }, { "gtlrFrameworkName", required_argument, NULL, 'n' }, + { "gtlrImportPrefix", required_argument, NULL, 'i' }, { "apiLogDir", required_argument, NULL, 'a' }, { "httpLogDir", required_argument, NULL, 'h' }, { "generatePreferred", no_argument, &generatePreferred, 1 }, @@ -773,6 +780,9 @@ - (void)stateParseArgs { case 'n': self.gtlrFrameworkName = @(optarg); break; + case 'i': + self.gtlrImportPrefix = @(optarg); + break; case 'a': self.apiLogDir = @(optarg); break; @@ -887,6 +897,18 @@ - (void)stateParseArgs { if (self.gtlrFrameworkName.length == 0) { self.gtlrFrameworkName = nil; } + while ([self.gtlrImportPrefix hasSuffix:@"/"]) { + self.gtlrImportPrefix = [self.gtlrImportPrefix substringToIndex:self.gtlrImportPrefix.length - 1]; + } + if (self.gtlrImportPrefix.length == 0) { + self.gtlrImportPrefix = nil; + } + + if (self.gtlrFrameworkName && self.gtlrImportPrefix) { + [self reportError:@"Cannot use both --gtlrFrameworkName and --gtlrImportPrefix."]; + [self printUsage:stderr brief:NO]; + return; + } // Make sure output dir exists. NSFileManager *fm = [NSFileManager defaultManager]; @@ -1339,11 +1361,17 @@ - (void)stateGenerate { options |= kSGGeneratorOptionLegacyObjectNaming; } + NSString *importPrefix = self.gtlrImportPrefix; + if (self.gtlrFrameworkName) { + importPrefix = self.gtlrFrameworkName; + options |= kSGGeneratorOptionImportPrefixIsFramework; + } + SGGenerator *aGenerator = [SGGenerator generatorForApi:api options:options verboseLevel:self.verboseLevel formattedNameOverride:formattedNameOverride - useFrameworkName:self.gtlrFrameworkName]; + importPrefix:importPrefix]; NSDictionary *generatedFiles = [aGenerator generateFilesWithHandler:^(SGGeneratorHandlerMessageType msgType,