Add a envvar to provide a prefix on all proto package prefixed symbols.

While at it, fix a header comment.
pull/9233/head
Thomas Van Lenten 3 years ago
parent edc8a31828
commit f7a58bb060
  1. 18
      src/google/protobuf/compiler/objectivec/objectivec_helpers.cc
  2. 4
      src/google/protobuf/compiler/objectivec/objectivec_helpers.h

@ -102,9 +102,14 @@ class PrefixModeStorage {
bool is_package_exempted(const std::string& package);
// When using a proto package as the prefix, this should be added as the
// prefix in front of it.
const std::string& forced_package_prefix() const { return forced_prefix_; }
private:
bool use_package_name_;
std::string exception_path_;
std::string forced_prefix_;
std::unordered_set<std::string> exceptions_;
};
@ -120,6 +125,13 @@ PrefixModeStorage::PrefixModeStorage() {
if (exception_path) {
exception_path_ = exception_path;
}
// This one is a not expected to be common, so it doesn't get a generation
// option, just the env var.
const char* prefix = getenv("GPB_OBJC_USE_PACKAGE_AS_PREFIX_PREFIX");
if (prefix) {
forced_prefix_ = prefix;
}
}
bool PrefixModeStorage::is_package_exempted(const std::string& package) {
@ -510,8 +522,8 @@ std::string FileClassPrefix(const FileDescriptor* file) {
return file->options().objc_class_prefix();
}
// If package prefix isn't enabled or no package, done.
if (!g_prefix_mode.use_package_name() || file->package().empty()) {
// If package prefix isn't enabled, done.
if (!g_prefix_mode.use_package_name()) {
return "";
}
@ -538,7 +550,7 @@ std::string FileClassPrefix(const FileDescriptor* file) {
if (!result.empty()) {
result.append("_");
}
return result;
return g_prefix_mode.forced_package_prefix() + result;
}
std::string FilePath(const FileDescriptor* file) {

@ -54,8 +54,8 @@ namespace objectivec {
bool PROTOC_EXPORT UseProtoPackageAsDefaultPrefix();
void PROTOC_EXPORT SetUseProtoPackageAsDefaultPrefix(bool on_or_off);
// Get/Set the path to a file to load as exceptions when
// `UseProtoPackageAsDefaultPrefixUseProtoPackageAsDefaultPrefix()` is `true`.
// And empty string means there should be no exceptions loaded.
// `UseProtoPackageAsDefaultPrefix()` is `true`. An empty string means there
// should be no exceptions.
std::string PROTOC_EXPORT GetProtoPackagePrefixExceptionList();
void PROTOC_EXPORT SetProtoPackagePrefixExceptionList(
const std::string& file_path);

Loading…
Cancel
Save