Internal changes

PiperOrigin-RevId: 544769979
pull/13181/head
Mike Kruskal 2 years ago committed by Copybara-Service
parent 528344245e
commit 32828d843b
  1. 1
      src/google/protobuf/compiler/BUILD.bazel
  2. 12
      src/google/protobuf/compiler/allowlists/BUILD.bazel
  3. 20
      src/google/protobuf/compiler/allowlists/allowlist.h
  4. 6
      src/google/protobuf/compiler/cpp/extension.cc
  5. 2
      src/google/protobuf/compiler/cpp/generator_unittest.cc

@ -431,6 +431,7 @@ filegroup(
],
allow_empty = True,
) + [
"//src/google/protobuf/compiler/allowlists:test_srcs",
"//src/google/protobuf/compiler/cpp:test_srcs",
"//src/google/protobuf/compiler/csharp:test_srcs",
"//src/google/protobuf/compiler/java:test_srcs",

@ -46,3 +46,15 @@ cc_test(
"@com_google_googletest//:gtest_main",
],
)
filegroup(
name = "test_srcs",
srcs = glob(
[
"*_test.cc",
"*unittest.cc",
],
allow_empty = True,
),
visibility = ["//src/google/protobuf/compiler:__pkg__"],
)

@ -33,6 +33,7 @@
#include <cstddef>
#include <cstring>
#include <type_traits>
#include "absl/algorithm/container.h"
#include "google/protobuf/stubs/common.h"
@ -40,6 +41,9 @@
#include "absl/strings/string_view.h"
#include "absl/types/span.h"
// Must be included last.
#include "google/protobuf/port_def.inc"
namespace google {
namespace protobuf {
namespace compiler {
@ -50,6 +54,16 @@ enum AllowlistFlags : unsigned int {
kAllowAllInOss = 1 << 2,
};
#if !defined(__GNUC__) || defined(__clang__) || PROTOBUF_GNUC_MIN(9, 1)
using maybe_string_view = absl::string_view;
#else
// In GCC versions before 9.1, template substitution fails because of the
// implicit conversion between `const char*` and absl::string_view. In these
// cases we can just use a raw string and convert later. See
// https://godbolt.org/z/r57fx37d1 for an example of the failure.
using maybe_string_view = const char*;
#endif
// An allowlist of things (messages, files, targets) that are allowed to violate
// some constraint.
//
@ -63,7 +77,7 @@ template <size_t n>
class Allowlist final {
public:
template <size_t m = n, typename = std::enable_if_t<m != 0>>
constexpr Allowlist(const absl::string_view (&list)[n], AllowlistFlags flags)
constexpr Allowlist(const maybe_string_view (&list)[n], AllowlistFlags flags)
: flags_(flags) {
for (size_t i = 0; i < n; ++i) {
list_[i] = list[i];
@ -135,7 +149,7 @@ constexpr Allowlist<0> MakeAllowlist(
template <size_t n>
constexpr Allowlist<n> MakeAllowlist(
const absl::string_view (&list)[n],
const maybe_string_view (&list)[n],
AllowlistFlags flags = AllowlistFlags::kNone) {
return Allowlist<n>(list, flags);
}
@ -145,4 +159,6 @@ constexpr Allowlist<n> MakeAllowlist(
} // namespace protobuf
} // namespace google
#include "google/protobuf/port_undef.inc"
#endif // GOOGLE_PROTOBUF_COMPILER_ALLOWLISTS_ALLOWLIST_H__

@ -89,6 +89,7 @@ ExtensionGenerator::ExtensionGenerator(const FieldDescriptor* descriptor,
variables_["field_type"] =
absl::StrCat(static_cast<int>(descriptor_->type()));
variables_["packed"] = descriptor_->is_packed() ? "true" : "false";
variables_["dllexport_decl"] = options.dllexport_decl;
std::string scope;
if (IsScoped()) {
@ -177,13 +178,14 @@ void ExtensionGenerator::GenerateDefinition(io::Printer* printer) {
if (IsLazilyInitializedFile(descriptor_->file()->name())) {
format(
"PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_INIT_PRIORITY2\n"
"PROTOBUF_CONSTINIT$ dllexport_decl$ "
"PROTOBUF_ATTRIBUTE_INIT_PRIORITY2\n"
"::$proto_ns$::internal::ExtensionIdentifier< $extendee$,\n"
" ::$proto_ns$::internal::$type_traits$, $field_type$, $packed$>\n"
" $scoped_name$($constant_name$);\n");
} else {
format(
"PROTOBUF_ATTRIBUTE_INIT_PRIORITY2 "
"$dllexport_decl $PROTOBUF_ATTRIBUTE_INIT_PRIORITY2 "
"::$proto_ns$::internal::ExtensionIdentifier< $extendee$,\n"
" ::$proto_ns$::internal::$type_traits$, $field_type$, $packed$>\n"
" $scoped_name$($constant_name$, $1$, $verify_fn$);\n",

@ -50,7 +50,7 @@ class CppGeneratorTest : public CommandLineInterfaceTester {
// Generate built-in protos.
CreateTempFile(
"net/proto2/proto/descriptor.proto",
"google/protobuf/descriptor.proto",
google::protobuf::DescriptorProto::descriptor()->file()->DebugString());
}
};

Loading…
Cancel
Save