Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support suppressing the objc package prefix checks on a list of files. #5309

Merged
merged 2 commits into from
Nov 1, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ bool ObjectiveCGenerator::GenerateAll(const std::vector<const FileDescriptor*>&
// There is no validation that the prefixes are good prefixes, it is
// assumed that they are when you create the file.
generation_options.expected_prefixes_path = options[i].second;
} else if (options[i].first == "expected_prefixes_suppressions") {
// A semicolon delimited string that lists the paths of .proto files to
// skip the package prefix validations (expected_prefixes_path). This is
// provided as an "out", to skip some files being becked.
thomasvl marked this conversation as resolved.
Show resolved Hide resolved
SplitStringUsing(options[i].second, ";",
&generation_options.expected_prefixes_suppressions);
} else if (options[i].first == "generate_for_named_framework") {
// The name of the framework that protos are being generated for. This
// will cause the #import statements to be framework based using this
Expand Down
13 changes: 13 additions & 0 deletions src/google/protobuf/compiler/objectivec/objectivec_helpers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ Options::Options() {
if (file_path) {
expected_prefixes_path = file_path;
}
const char* suppressions = getenv("GPB_OBJC_EXPECTED_PACKAGE_PREFIXES_SUPPRESSIONS");
if (suppressions) {
SplitStringUsing(suppressions, ";", &expected_prefixes_suppressions);
}
}

namespace {
Expand Down Expand Up @@ -1169,6 +1173,15 @@ bool ValidateObjCClassPrefixes(const std::vector<const FileDescriptor*>& files,
}

for (int i = 0; i < files.size(); i++) {
bool should_skip =
(std::find(generation_options.expected_prefixes_suppressions.begin(),
generation_options.expected_prefixes_suppressions.end(),
files[i]->name())
!= generation_options.expected_prefixes_suppressions.end());
if (should_skip) {
return true;
thomasvl marked this conversation as resolved.
Show resolved Hide resolved
}

bool is_valid =
ValidateObjCClassPrefix(files[i],
generation_options.expected_prefixes_path,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ namespace objectivec {
struct Options {
Options();
string expected_prefixes_path;
std::vector<string> expected_prefixes_suppressions;
string generate_for_named_framework;
string named_framework_to_proto_path_mappings_path;
};
Expand Down