diff options
author | Thomas Van Lenten <thomasvl@google.com> | 2016-05-09 13:53:20 -0400 |
---|---|---|
committer | Thomas Van Lenten <thomasvl@google.com> | 2016-05-24 09:25:02 -0400 |
commit | 7da023b892ccd7135b6c9762d7618ccf414a4cd7 (patch) | |
tree | 04eb21f4a5a59ce61be4dc974d2e7cd6857f296a /src/google/protobuf/compiler/objectivec/objectivec_helpers.cc | |
parent | 2131b2d544bf6eeb789c128ef3e9e04fc299237a (diff) | |
download | protobuf-7da023b892ccd7135b6c9762d7618ccf414a4cd7.tar.gz protobuf-7da023b892ccd7135b6c9762d7618ccf414a4cd7.tar.bz2 protobuf-7da023b892ccd7135b6c9762d7618ccf414a4cd7.zip |
Better support for using the proto library from a framework.
- Add generator constant for the default framework name.
- Add generator api for making the CPP symbol from the name.
- Add generator api to see if it is a bundled proto file.
- Output a CPP conditional and two imports for the core library headers.
- Add helper for generating the #import for file headers to deal with the
framework imports.
- Add a reference from the unittests to a WKT to use that to inspect how
imports generate.
- Update the podspec to define the CPP symbol and require pods 1.0 (or later).
Fixes https://github.com/google/protobuf/issues/1457
Diffstat (limited to 'src/google/protobuf/compiler/objectivec/objectivec_helpers.cc')
-rw-r--r-- | src/google/protobuf/compiler/objectivec/objectivec_helpers.cc | 54 |
1 files changed, 47 insertions, 7 deletions
diff --git a/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc b/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc index 196b39dd..65bf8348 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc @@ -293,13 +293,6 @@ string BaseFileName(const FileDescriptor* file) { return basename; } -string FileName(const FileDescriptor* file) { - string path = FilePath(file); - string basename; - PathSplit(path, NULL, &basename); - return basename; -} - string FilePath(const FileDescriptor* file) { string output; string basename; @@ -317,6 +310,19 @@ string FilePath(const FileDescriptor* file) { return output; } +string FilePathBasename(const FileDescriptor* file) { + string output; + string basename; + string directory; + PathSplit(file->name(), &directory, &basename); + basename = StripProto(basename); + + // CamelCase to be more ObjC friendly. + output = UnderscoresToCamelCase(basename, true); + + return output; +} + string FileClassPrefix(const FileDescriptor* file) { // Default is empty string, no need to check has_objc_class_prefix. string result = file->options().objc_class_prefix(); @@ -831,6 +837,40 @@ string BuildCommentsString(const SourceLocation& location) { return final_comments; } +// Making these a generator option for folks that don't use CocoaPods, but do +// want to put the library in a framework is an interesting question. The +// problem is it means changing sources shipped with the library to actually +// use a different value; so it isn't as simple as a option. +const char* const ProtobufLibraryFrameworkName = "Protobuf"; + +string ProtobufFrameworkImportSymbol(const string& framework_name) { + // GPB_USE_[framework_name]_FRAMEWORK_IMPORTS + string result = string("GPB_USE_"); + result += ToUpper(framework_name); + result += "_FRAMEWORK_IMPORTS"; + return result; +} + +bool IsProtobufLibraryBundledProtoFile(const FileDescriptor* file) { + // We don't check the name prefix or proto package because some files + // (descriptor.proto), aren't shipped generated by the library, so this + // seems to be the safest way to only catch the ones shipped. + const string name = file->name(); + if (name == "google/protobuf/any.proto" || + name == "google/protobuf/api.proto" || + name == "google/protobuf/duration.proto" || + name == "google/protobuf/empty.proto" || + name == "google/protobuf/field_mask.proto" || + name == "google/protobuf/source_context.proto" || + name == "google/protobuf/struct.proto" || + name == "google/protobuf/timestamp.proto" || + name == "google/protobuf/type.proto" || + name == "google/protobuf/wrappers.proto") { + return true; + } + return false; +} + namespace { // Internal helper class that parses the expected package to prefix mappings |