From dde14310f48bf7d67d9f16ab9911837940f020ac Mon Sep 17 00:00:00 2001 From: Thomas Van Lenten Date: Thu, 1 Nov 2018 17:18:24 -0400 Subject: [PATCH] Support suppressing the objc package prefix checks on a list of files. --- .../compiler/objectivec/objectivec_generator.cc | 6 ++++++ .../compiler/objectivec/objectivec_helpers.cc | 13 +++++++++++++ .../compiler/objectivec/objectivec_helpers.h | 1 + 3 files changed, 20 insertions(+) diff --git a/src/google/protobuf/compiler/objectivec/objectivec_generator.cc b/src/google/protobuf/compiler/objectivec/objectivec_generator.cc index e0597cc7ff61..25338ad93962 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_generator.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_generator.cc @@ -89,6 +89,12 @@ bool ObjectiveCGenerator::GenerateAll(const std::vector& // 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 + // exclude from the package prefix validations (expected_prefixes_path). + // This is provided as an "out", to skip some files being checked. + 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 diff --git a/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc b/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc index 0afa6fb06081..5357e94bba80 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc @@ -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 { @@ -1169,6 +1173,15 @@ bool ValidateObjCClassPrefixes(const std::vector& 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) { + continue; + } + bool is_valid = ValidateObjCClassPrefix(files[i], generation_options.expected_prefixes_path, diff --git a/src/google/protobuf/compiler/objectivec/objectivec_helpers.h b/src/google/protobuf/compiler/objectivec/objectivec_helpers.h index e7f21f28610f..3ec465f5e76e 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_helpers.h +++ b/src/google/protobuf/compiler/objectivec/objectivec_helpers.h @@ -50,6 +50,7 @@ namespace objectivec { struct Options { Options(); string expected_prefixes_path; + std::vector expected_prefixes_suppressions; string generate_for_named_framework; string named_framework_to_proto_path_mappings_path; };