Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: export headers with top-level Bazel targets #12762

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 47 additions & 14 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ exports_files([
])

load("@bazel_skylib//rules:common_settings.bzl", "bool_flag")
load("//bazel:library_dir_name.bzl", "google_cloud_cpp_library_dir_name")
load("//bazel:library_names.bzl", "hdrs_filegroup_name", "library_dir_name", "mocks_filegroup_name")
load(":libraries.bzl", "GOOGLE_CLOUD_CPP_EXPERIMENTAL_LIBRARIES", "GOOGLE_CLOUD_CPP_GA_LIBRARIES", "GOOGLE_CLOUD_CPP_TRANSITION_LIBRARIES")

EXPERIMENTAL_LIBRARIES = GOOGLE_CLOUD_CPP_EXPERIMENTAL_LIBRARIES
Expand All @@ -34,74 +34,99 @@ NO_MOCK_LIBRARIES = ["oauth2"]

[cc_library(
name = "experimental-{library}".format(library = library),
hdrs = ["//google/cloud/{dir}:{group}".format(
dir = library_dir_name(library),
group = hdrs_filegroup_name(library),
)],
deps = [
"//google/cloud/{library_dir}:google_cloud_cpp_{library}".format(
"//google/cloud/{dir}:google_cloud_cpp_{library}".format(
dir = library_dir_name(library),
library = library,
library_dir = google_cloud_cpp_library_dir_name(library),
),
],
) for library in EXPERIMENTAL_LIBRARIES]

[cc_library(
name = "experimental-{library}_mocks".format(library = library),
testonly = True,
hdrs = ["//google/cloud/{dir}:{group}".format(
dir = library_dir_name(library),
group = mocks_filegroup_name(library),
)],
deps = [
"//google/cloud/{library_dir}:google_cloud_cpp_{library}_mocks".format(
"//google/cloud/{dir}:google_cloud_cpp_{library}_mocks".format(
dir = library_dir_name(library),
library = library,
library_dir = google_cloud_cpp_library_dir_name(library),
),
],
) for library in EXPERIMENTAL_LIBRARIES if library not in NO_MOCK_LIBRARIES]

[cc_library(
name = "experimental-{library}".format(library = library),
hdrs = ["//google/cloud/{dir}:{group}".format(
dir = library_dir_name(library),
group = hdrs_filegroup_name(library),
)],
deprecation = "this library is now GA, please use //:{library} instead.".format(library = library),
tags = ["manual"],
deps = [
"//google/cloud/{library_dir}:google_cloud_cpp_{library}".format(
"//google/cloud/{dir}:google_cloud_cpp_{library}".format(
dir = library_dir_name(library),
library = library,
library_dir = google_cloud_cpp_library_dir_name(library),
),
],
) for library in TRANSITION_LIBRARIES]

[cc_library(
name = "experimental-{library}_mocks".format(library = library),
testonly = True,
hdrs = ["//google/cloud/{dir}:{group}".format(
dir = library_dir_name(library),
group = mocks_filegroup_name(library),
)],
deprecation = "this library is now GA, please use //:{library}_mocks instead.".format(library = library),
tags = ["manual"],
deps = [
"//google/cloud/{library_dir}:google_cloud_cpp_{library}_mocks".format(
"//google/cloud/{dir}:google_cloud_cpp_{library}_mocks".format(
dir = library_dir_name(library),
library = library,
library_dir = google_cloud_cpp_library_dir_name(library),
),
],
) for library in TRANSITION_LIBRARIES]
) for library in TRANSITION_LIBRARIES if library not in NO_MOCK_LIBRARIES]

[cc_library(
name = "{library}".format(library = library),
hdrs = ["//google/cloud/{dir}:{group}".format(
dir = library_dir_name(library),
group = hdrs_filegroup_name(library),
)],
deps = [
"//google/cloud/{library_dir}:google_cloud_cpp_{library}".format(
"//google/cloud/{dir}:google_cloud_cpp_{library}".format(
dir = library_dir_name(library),
library = library,
library_dir = google_cloud_cpp_library_dir_name(library),
),
],
) for library in GA_LIBRARIES + TRANSITION_LIBRARIES]

[cc_library(
name = "{library}_mocks".format(library = library),
testonly = True,
hdrs = ["//google/cloud/{dir}:{group}".format(
dir = library_dir_name(library),
group = mocks_filegroup_name(library),
)],
deps = [
"//google/cloud/{library_dir}:google_cloud_cpp_{library}_mocks".format(
"//google/cloud/{dir}:google_cloud_cpp_{library}_mocks".format(
dir = library_dir_name(library),
library = library,
library_dir = google_cloud_cpp_library_dir_name(library),
),
],
) for library in GA_LIBRARIES + TRANSITION_LIBRARIES if library not in NO_MOCK_LIBRARIES]

cc_library(
name = "bigquery-mocks",
testonly = True,
hdrs = ["//google/cloud/bigquery:mocks"],
deprecation = "please use //:bigquery_mocks instead.",
tags = ["manual"],
deps = [
Expand All @@ -112,6 +137,7 @@ cc_library(
cc_library(
name = "iam-mocks",
testonly = True,
hdrs = ["//google/cloud/iam:mocks"],
deprecation = "please use //:iam_mocks instead.",
tags = ["manual"],
deps = [
Expand All @@ -127,6 +153,7 @@ bool_flag(

cc_library(
name = "experimental-storage_grpc",
hdrs = ["//google/cloud/storage:grpc_hdrs"],
tags = ["manual"],
deps = [
"//google/cloud/storage:google_cloud_cpp_storage_grpc",
Expand All @@ -136,6 +163,7 @@ cc_library(
# TODO(12698) - remove transition name (experimental-storage-grpc)
cc_library(
name = "experimental-storage-grpc",
hdrs = ["//google/cloud/storage:grpc_hdrs"],
tags = ["manual"],
deps = [
":experimental-storage_grpc",
Expand All @@ -144,13 +172,15 @@ cc_library(

cc_library(
name = "common",
hdrs = ["//google/cloud:common_hdrs"],
deps = [
"//google/cloud:google_cloud_cpp_common_private",
],
)

cc_library(
name = "grpc_utils",
hdrs = ["//google/cloud:grpc_utils_hdrs"],
deps = [
"//google/cloud:google_cloud_cpp_grpc_utils_private",
],
Expand All @@ -159,13 +189,15 @@ cc_library(
cc_library(
name = "mocks",
testonly = True,
hdrs = ["//google/cloud:mocks"],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

Both are consistent. I am fine with your choice.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just went with the most commonly used names. I figured we can change them later if we wanted to.

deps = [
"//google/cloud:google_cloud_cpp_mocks",
],
)

cc_library(
name = "experimental-opentelemetry",
hdrs = ["//google/cloud/opentelemetry:hdrs"],
deprecation = "this library is now GA, please use //:opentelemetry instead.",
tags = ["manual"],
deps = [
Expand All @@ -175,6 +207,7 @@ cc_library(

cc_library(
name = "opentelemetry",
hdrs = ["//google/cloud/opentelemetry:hdrs"],
deps = [
"//google/cloud/opentelemetry:google_cloud_cpp_opentelemetry",
],
Expand Down
12 changes: 11 additions & 1 deletion bazel/library_dir_name.bzl → bazel/library_names.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,17 @@
# See the License for the specific language governing permissions and
# limitations under the License.

def google_cloud_cpp_library_dir_name(library):
def library_dir_name(library):
if library.startswith("compute_"):
return "compute"
return library

def mocks_filegroup_name(library):
if library.startswith("compute_"):
return library.removeprefix("compute_") + "_mock_hdrs"
return "mocks"

def hdrs_filegroup_name(library):
if library.startswith("compute_"):
return library.removeprefix("compute_") + "_hdrs"
return "hdrs"
2 changes: 2 additions & 0 deletions generator/internal/scaffold_generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -396,11 +396,13 @@ filegroup(
filegroup(
name = "hdrs",
srcs = glob([d + "*.h" for d in src_dirs]),
visibility = ["//:__pkg__"],
)

filegroup(
name = "mocks",
srcs = glob([d + "mocks/*.h" for d in service_dirs]),
visibility = ["//:__pkg__"],
)

cc_library(
Expand Down
18 changes: 18 additions & 0 deletions google/cloud/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ config_setting(
},
)

filegroup(
name = "common_hdrs",
srcs = [h for h in google_cloud_cpp_common_hdrs if not h.startswith("internal/")],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Observation: we are doing this internal filtering on handwritten libraries. Our fully generated libraries also have internal headers which are picked up by globs.

Do we care to filter both?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. That is one of the reasons why this is "part of" and not "fixes" for that bug.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I included the fixes in this PR. PTAL

visibility = ["//:__pkg__"],
)

cc_library(
name = "google_cloud_cpp_common_private",
srcs = google_cloud_cpp_common_srcs + ["internal/build_info.cc"],
Expand Down Expand Up @@ -161,6 +167,12 @@ cc_library(
],
) for benchmark in google_cloud_cpp_common_benchmarks]

filegroup(
name = "grpc_utils_hdrs",
srcs = [h for h in google_cloud_cpp_grpc_utils_hdrs if ("/internal/" not in h and "grpc_utils/" not in h)],
visibility = ["//:__pkg__"],
)

cc_library(
name = "google_cloud_cpp_grpc_utils_private",
srcs = google_cloud_cpp_grpc_utils_srcs,
Expand Down Expand Up @@ -242,6 +254,12 @@ cc_library(
],
) for test in google_cloud_cpp_grpc_utils_benchmarks]

filegroup(
name = "mocks",
srcs = [h for h in google_cloud_cpp_mocks_hdrs if not h.startswith("internal/")],
visibility = ["//:__pkg__"],
)

cc_library(
name = "google_cloud_cpp_mocks",
testonly = True,
Expand Down
2 changes: 2 additions & 0 deletions google/cloud/accessapproval/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@ filegroup(
filegroup(
name = "hdrs",
srcs = glob([d + "*.h" for d in src_dirs]),
visibility = ["//:__pkg__"],
)

filegroup(
name = "mocks",
srcs = glob([d + "mocks/*.h" for d in service_dirs]),
visibility = ["//:__pkg__"],
)

cc_library(
Expand Down
2 changes: 2 additions & 0 deletions google/cloud/accesscontextmanager/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@ filegroup(
filegroup(
name = "hdrs",
srcs = glob([d + "*.h" for d in src_dirs]),
visibility = ["//:__pkg__"],
)

filegroup(
name = "mocks",
srcs = glob([d + "mocks/*.h" for d in service_dirs]),
visibility = ["//:__pkg__"],
)

cc_library(
Expand Down
2 changes: 2 additions & 0 deletions google/cloud/advisorynotifications/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ filegroup(
filegroup(
name = "hdrs",
srcs = glob([d + "*.h" for d in src_dirs]),
visibility = ["//:__pkg__"],
)

filegroup(
name = "mocks",
srcs = glob([d + "mocks/*.h" for d in service_dirs]),
visibility = ["//:__pkg__"],
)

cc_library(
Expand Down
2 changes: 2 additions & 0 deletions google/cloud/aiplatform/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ filegroup(
filegroup(
name = "hdrs",
srcs = glob([d + "*.h" for d in src_dirs]),
visibility = ["//:__pkg__"],
)

filegroup(
name = "mocks",
srcs = glob([d + "mocks/*.h" for d in service_dirs]),
visibility = ["//:__pkg__"],
)

cc_library(
Expand Down
2 changes: 2 additions & 0 deletions google/cloud/alloydb/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ filegroup(
filegroup(
name = "hdrs",
srcs = glob([d + "*.h" for d in src_dirs]),
visibility = ["//:__pkg__"],
)

filegroup(
name = "mocks",
srcs = glob([d + "mocks/*.h" for d in service_dirs]),
visibility = ["//:__pkg__"],
)

cc_library(
Expand Down
2 changes: 2 additions & 0 deletions google/cloud/apigateway/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@ filegroup(
filegroup(
name = "hdrs",
srcs = glob([d + "*.h" for d in src_dirs]),
visibility = ["//:__pkg__"],
)

filegroup(
name = "mocks",
srcs = glob([d + "mocks/*.h" for d in service_dirs]),
visibility = ["//:__pkg__"],
)

cc_library(
Expand Down
2 changes: 2 additions & 0 deletions google/cloud/apigeeconnect/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@ filegroup(
filegroup(
name = "hdrs",
srcs = glob([d + "*.h" for d in src_dirs]),
visibility = ["//:__pkg__"],
)

filegroup(
name = "mocks",
srcs = glob([d + "mocks/*.h" for d in service_dirs]),
visibility = ["//:__pkg__"],
)

cc_library(
Expand Down
2 changes: 2 additions & 0 deletions google/cloud/apikeys/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@ filegroup(
filegroup(
name = "hdrs",
srcs = glob([d + "*.h" for d in src_dirs]),
visibility = ["//:__pkg__"],
)

filegroup(
name = "mocks",
srcs = glob([d + "mocks/*.h" for d in service_dirs]),
visibility = ["//:__pkg__"],
)

cc_library(
Expand Down
2 changes: 2 additions & 0 deletions google/cloud/appengine/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@ filegroup(
filegroup(
name = "hdrs",
srcs = glob([d + "*.h" for d in src_dirs]),
visibility = ["//:__pkg__"],
)

filegroup(
name = "mocks",
srcs = glob([d + "mocks/*.h" for d in service_dirs]),
visibility = ["//:__pkg__"],
)

cc_library(
Expand Down
2 changes: 2 additions & 0 deletions google/cloud/artifactregistry/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@ filegroup(
filegroup(
name = "hdrs",
srcs = glob([d + "*.h" for d in src_dirs]),
visibility = ["//:__pkg__"],
)

filegroup(
name = "mocks",
srcs = glob([d + "mocks/*.h" for d in service_dirs]),
visibility = ["//:__pkg__"],
)

cc_library(
Expand Down
Loading