Move the IfnDefGuard from third_party/protobuf/io/cpp_utils to the existing third_party/protobuf/compiler/cpp, which is a more logical location.

PiperOrigin-RevId: 618485105
pull/16276/head
Protobuf Team Bot 1 year ago committed by Copybara-Service
parent 7cf02389b3
commit 87b1c592a3
  1. 1
      pkg/BUILD.bazel
  2. 19
      src/google/protobuf/compiler/cpp/BUILD.bazel
  3. 6
      src/google/protobuf/compiler/cpp/ifndef_guard.cc
  4. 17
      src/google/protobuf/compiler/cpp/ifndef_guard.h
  5. 18
      src/google/protobuf/compiler/cpp/ifndef_guard_unittest.cc
  6. 58
      src/google/protobuf/io/cpp_utils/BUILD.bazel

@ -174,7 +174,6 @@ cc_dist_library(
"//src/google/protobuf:arena_align",
"//src/google/protobuf:cmake_wkt_cc_proto",
"//src/google/protobuf/compiler:importer",
"//src/google/protobuf/io/cpp_utils:ifndef_guard",
"//src/google/protobuf/json",
"//src/google/protobuf/util:delimited_message_util",
"//src/google/protobuf/util:differencer",

@ -69,6 +69,7 @@ cc_library(
"field_generators/string_view_field.cc",
"file.cc",
"generator.cc",
"ifndef_guard.cc",
"message.cc",
"padding_optimizer.cc",
"parse_function_generator.cc",
@ -82,6 +83,7 @@ cc_library(
"field_generators/generators.h",
"file.h",
"generator.h",
"ifndef_guard.h",
"message.h",
"message_layout_helper.h",
"padding_optimizer.h",
@ -115,6 +117,7 @@ cc_library(
"@com_google_absl//absl/functional:any_invocable",
"@com_google_absl//absl/log:absl_check",
"@com_google_absl//absl/log:absl_log",
"@com_google_absl//absl/log:die_if_null",
"@com_google_absl//absl/memory",
"@com_google_absl//absl/status",
"@com_google_absl//absl/strings",
@ -340,6 +343,22 @@ cc_test(
],
)
cc_test(
name = "ifndef_guard_unittest",
srcs = ["ifndef_guard_unittest.cc"],
deps = [
":cpp",
"//:protobuf",
"//src/google/protobuf/io",
"//src/google/protobuf/io:printer",
"@com_google_absl//absl/log:absl_check",
"@com_google_absl//absl/strings:string_view",
"@com_google_absl//absl/types:optional",
"@com_google_googletest//:gtest",
"@com_google_googletest//:gtest_main",
],
)
################################################################################
# Distribution packaging
################################################################################

@ -5,7 +5,7 @@
// license that can be found in the LICENSE file or at
// https://developers.google.com/open-source/licenses/bsd
#include "google/protobuf/io/cpp_utils/ifndef_guard.h"
#include "google/protobuf/compiler/cpp/ifndef_guard.h"
#include <string>
@ -20,7 +20,7 @@
namespace google {
namespace protobuf {
namespace io {
namespace compiler {
namespace cpp {
namespace {
@ -66,6 +66,6 @@ IfdefGuardPrinter::~IfdefGuardPrinter() {
}
} // namespace cpp
} // namespace io
} // namespace compiler
} // namespace protobuf
} // namespace google

@ -23,8 +23,8 @@
// '.' characters with '_'. If a different transformation is required, an
// optional transformation function can be provided.
#ifndef GOOGLE_PROTOBUF_IO_CPP_UTILS_IFNDEF_GUARD_H__
#define GOOGLE_PROTOBUF_IO_CPP_UTILS_IFNDEF_GUARD_H__
#ifndef GOOGLE_PROTOBUF_COMPILER_CPP_IFNDEF_GUARD_H__
#define GOOGLE_PROTOBUF_COMPILER_CPP_IFNDEF_GUARD_H__
#include <string>
@ -32,12 +32,15 @@
#include "absl/strings/string_view.h"
#include "google/protobuf/io/printer.h"
// Must be included last.
#include "google/protobuf/port_def.inc"
namespace google {
namespace protobuf {
namespace io {
namespace compiler {
namespace cpp {
class IfdefGuardPrinter final {
class PROTOC_EXPORT IfdefGuardPrinter final {
public:
explicit IfdefGuardPrinter(google::protobuf::io::Printer* p,
absl::string_view filename);
@ -53,9 +56,11 @@ class IfdefGuardPrinter final {
const std::string ifdef_identifier_;
};
#include "google/protobuf/port_undef.inc"
} // namespace cpp
} // namespace io
} // namespace compiler
} // namespace protobuf
} // namespace google
#endif // GOOGLE_PROTOBUF_IO_CPP_UTILS_IFNDEF_GUARD_H__
#endif // GOOGLE_PROTOBUF_COMPILER_CPP_IFNDEF_GUARD_H__

@ -1,4 +1,4 @@
#include "google/protobuf/io/cpp_utils/ifndef_guard.h"
#include "google/protobuf/compiler/cpp/ifndef_guard.h"
#include <string>
@ -12,14 +12,14 @@
namespace google {
namespace protobuf {
namespace io {
namespace compiler {
namespace cpp {
namespace {
class IfnDefGuardTest : public testing::Test {
protected:
ZeroCopyOutputStream* output() {
io::ZeroCopyOutputStream* output() {
ABSL_CHECK(stream_.has_value());
return &*stream_;
}
@ -29,12 +29,12 @@ class IfnDefGuardTest : public testing::Test {
}
std::string out_;
absl::optional<StringOutputStream> stream_{&out_};
absl::optional<io::StringOutputStream> stream_{&out_};
};
TEST_F(IfnDefGuardTest, Basic) {
{
Printer printer(output(), '$');
io::Printer printer(output(), '$');
const IfdefGuardPrinter ifdef_guard(&printer, "A/B/E/alpha");
@ -51,7 +51,7 @@ TEST_F(IfnDefGuardTest, Basic) {
TEST_F(IfnDefGuardTest, DifferentDelim) {
{
Printer printer(output(), '\0');
io::Printer printer(output(), '\0');
const IfdefGuardPrinter ifdef_guard(&printer, "A/B/E/alpha");
@ -68,7 +68,7 @@ TEST_F(IfnDefGuardTest, DifferentDelim) {
TEST_F(IfnDefGuardTest, DifferentSubstitutionFunction) {
{
Printer printer(output(), '$');
io::Printer printer(output(), '$');
const IfdefGuardPrinter ifdef_guard(
&printer, "A/B/E/alpha", [](absl::string_view) { return "FOO_BAR_"; });
@ -85,8 +85,8 @@ TEST_F(IfnDefGuardTest, DifferentSubstitutionFunction) {
}
} // namespace
} // namespace cpp
} // namespace io
} // namespace cpp
} // namespace compiler
} // namespace protobuf
} // namespace google

@ -1,58 +0,0 @@
# Utilities for generating C++ code
load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test")
load("@rules_pkg//pkg:mappings.bzl", "pkg_files", "strip_prefix")
load("//build_defs:cpp_opts.bzl", "COPTS")
package(
default_visibility = ["//visibility:public"],
)
cc_library(
name = "ifndef_guard",
srcs = ["ifndef_guard.cc"],
hdrs = ["ifndef_guard.h"],
copts = COPTS,
strip_include_prefix = "/src",
deps = [
"//src/google/protobuf/io:printer",
"@com_google_absl//absl/functional:any_invocable",
"@com_google_absl//absl/log:die_if_null",
"@com_google_absl//absl/strings",
"@com_google_absl//absl/strings:string_view",
],
)
cc_test(
name = "ifndef_guard_unittest",
srcs = ["ifndef_guard_unittest.cc"],
deps = [
":ifndef_guard",
"//src/google/protobuf/io",
"//src/google/protobuf/io:printer",
"@com_google_absl//absl/log:absl_check",
"@com_google_absl//absl/strings:string_view",
"@com_google_absl//absl/types:optional",
"@com_google_googletest//:gtest",
"@com_google_googletest//:gtest_main",
],
)
################################################################################
# Distribution packaging
################################################################################
pkg_files(
name = "dist_files",
srcs = glob(["**/*"]),
strip_prefix = strip_prefix.from_root(""),
visibility = ["//src:__pkg__"],
)
filegroup(
name = "test_srcs",
srcs = glob([
"*unittest.cc",
]),
visibility = ["//pkg:__pkg__"],
)
Loading…
Cancel
Save