Skip to content

Commit

Permalink
Add a staleness test for the well-known types
Browse files Browse the repository at this point in the history
This commit adds a staleness test in preparation for setting up
auto-updating of the well-known type generated code. I also went ahead
and updated them manually just to make sure we don't run into any
surprises when this starts happening automatically.

I had to arrange things so that the generated any.pb.cc (for example)
lives at:
//src/google/protobuf:wkt/google/protobuf/any.pb.cc

This is a weird directory structure, but I think it's the only way to
allow the checked-in and generated versions of the file to coexist while
ensuring that Bazel always uses the generated version.
  • Loading branch information
acozzette committed Nov 3, 2022
1 parent 9542560 commit f63f758
Show file tree
Hide file tree
Showing 21 changed files with 701 additions and 617 deletions.
29 changes: 23 additions & 6 deletions src/google/protobuf/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
load("@rules_cc//cc:defs.bzl", "cc_library", "cc_proto_library", "cc_test")
load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix")
load("@rules_proto//proto:defs.bzl", "proto_library")
load("@upb//cmake:build_defs.bzl", "staleness_test")
load("//build_defs:cpp_opts.bzl", "COPTS", "LINK_OPTS")

package(
Expand Down Expand Up @@ -106,28 +107,44 @@ WELL_KNOWN_TYPES = [
"wrappers",
]

# When we generate code for the well-known types, we put the resulting files in
# wkt/google/protobuf and add ./wkt to the include paths below. This is a
# somewhat strange setup but is necessary to satisfy these two constraints:
# - We need to keep the checked-in sources for now, since Cocoapods relies on
# them.
# - The Bazel build should always use the generated sources so that developers
# don't have to worry about manually updating the checked-in sources.
genrule(
name = "gen_wkt_cc_sources",
srcs = [wkt + ".proto" for wkt in WELL_KNOWN_TYPES],
outs =
[wkt + ".pb.h" for wkt in WELL_KNOWN_TYPES] +
[wkt + ".pb.cc" for wkt in WELL_KNOWN_TYPES],
["wkt/google/protobuf/" + wkt + ".pb.h" for wkt in WELL_KNOWN_TYPES] +
["wkt/google/protobuf/" + wkt + ".pb.cc" for wkt in WELL_KNOWN_TYPES],
cmd = """
$(execpath //src/google/protobuf/compiler:protoc_nowkt) \
--cpp_out=$(RULEDIR)/../.. \
--cpp_out=dllexport_decl=PROTOBUF_EXPORT:$(RULEDIR)/wkt \
--proto_path=$$(dirname $$(dirname $$(dirname $(location any.proto)))) \
$(SRCS)
""",
exec_tools = ["//src/google/protobuf/compiler:protoc_nowkt"],
visibility = ["//visibility:private"],
)

staleness_test(
name = "well_known_types_staleness_test",
outs =
[wkt + ".pb.h" for wkt in WELL_KNOWN_TYPES] +
[wkt + ".pb.cc" for wkt in WELL_KNOWN_TYPES],
generated_pattern = "wkt/google/protobuf/%s",
tags = ["manual"],
)

cc_library(
name = "wkt_cc_proto",
srcs = [wkt + ".pb.cc" for wkt in WELL_KNOWN_TYPES],
hdrs = [wkt + ".pb.h" for wkt in WELL_KNOWN_TYPES],
srcs = ["wkt/google/protobuf/" + wkt + ".pb.cc" for wkt in WELL_KNOWN_TYPES],
hdrs = ["wkt/google/protobuf/" + wkt + ".pb.h" for wkt in WELL_KNOWN_TYPES],
copts = COPTS,
include_prefix = "google/protobuf",
includes = ["wkt"],
linkopts = LINK_OPTS,
visibility = ["//pkg:__pkg__"],
deps = [":protobuf_nowkt"],
Expand Down
30 changes: 16 additions & 14 deletions src/google/protobuf/any.pb.cc

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions src/google/protobuf/any.pb.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit f63f758

Please sign in to comment.