Merge pull request #9233 from thomasvl/package_as_prefix_prefix

Add a envvar to provide a prefix on all proto package prefixed symbols.
This commit is contained in:
Thomas Van Lenten 2021-11-22 11:07:39 -05:00 committed by GitHub
commit ba5eb3a7e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 5 deletions

View File

@ -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) {

View 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);