Skip to content

Commit

Permalink
Move the IfnDefGuard from third_party/protobuf/io/cpp_utils to the ex…
Browse files Browse the repository at this point in the history
…isting third_party/protobuf/compiler/cpp, which is a more logical location.

PiperOrigin-RevId: 618251685
  • Loading branch information
protobuf-github-bot authored and copybara-github committed Mar 22, 2024
1 parent 500c953 commit 3ae7d39
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 75 deletions.
30 changes: 30 additions & 0 deletions src/google/protobuf/compiler/cpp/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,36 @@ cc_test(
],
)

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
################################################################################
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand All @@ -20,7 +20,7 @@

namespace google {
namespace protobuf {
namespace io {
namespace compiler {
namespace cpp {

namespace {
Expand Down Expand Up @@ -66,6 +66,6 @@ IfdefGuardPrinter::~IfdefGuardPrinter() {
}

} // namespace cpp
} // namespace io
} // namespace compiler
} // namespace protobuf
} // namespace google
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand All @@ -34,7 +34,7 @@

namespace google {
namespace protobuf {
namespace io {
namespace compiler {
namespace cpp {

class IfdefGuardPrinter final {
Expand All @@ -54,8 +54,8 @@ class IfdefGuardPrinter final {
};

} // 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__
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "google/protobuf/io/cpp_utils/ifndef_guard.h"
#include "google/protobuf/compiler/cpp/ifndef_guard.h"

#include <string>

Expand All @@ -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_;
}
Expand All @@ -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");

Expand All @@ -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");

Expand All @@ -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_"; });
Expand All @@ -85,8 +85,8 @@ TEST_F(IfnDefGuardTest, DifferentSubstitutionFunction) {
}

} // namespace
} // namespace cpp
} // namespace io

} // namespace cpp
} // namespace compiler
} // namespace protobuf
} // namespace google
58 changes: 0 additions & 58 deletions src/google/protobuf/io/cpp_utils/BUILD.bazel

This file was deleted.

0 comments on commit 3ae7d39

Please sign in to comment.