diff --git a/bazel/gapic.bzl b/bazel/gapic.bzl index 5b02eaa81925d..d3b30f21c8fa0 100644 --- a/bazel/gapic.bzl +++ b/bazel/gapic.bzl @@ -14,7 +14,7 @@ """A definition for the typical C++ GAPIC library.""" -def cc_gapic_library(name, service_dirs = [], googleapis_deps = []): +def cc_gapic_library(name, service_dirs = [], googleapis_deps = [], additional_deps = []): """Defines targets for the typical fully generated GAPIC library Args: @@ -63,7 +63,7 @@ def cc_gapic_library(name, service_dirs = [], googleapis_deps = []): srcs = [":srcs"], hdrs = [":hdrs"], visibility = ["//:__pkg__"], - deps = ["//:common", "//:grpc_utils"] + googleapis_deps, + deps = ["//:common", "//:grpc_utils"] + googleapis_deps + additional_deps, ) native.cc_library( diff --git a/google/cloud/bigquerycontrol/BUILD.bazel b/google/cloud/bigquerycontrol/BUILD.bazel index d9d346a8052aa..b14edb09ad7c2 100644 --- a/google/cloud/bigquerycontrol/BUILD.bazel +++ b/google/cloud/bigquerycontrol/BUILD.bazel @@ -12,6 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +load("//bazel:gapic.bzl", "cc_gapic_library") + package(default_visibility = ["//visibility:private"]) licenses(["notice"]) # Apache 2.0 @@ -20,71 +22,18 @@ service_dirs = [ "v2/", ] -code_glob = [d + i + f for d in service_dirs for i in [ - "", - "internal/", -] for f in [ - "*.h", - "*.cc", -]] - -sources_glob = [d + "internal/*_sources.cc" for d in service_dirs] - -filegroup( - name = "srcs", - srcs = glob(sources_glob), -) - -filegroup( - name = "hdrs", - srcs = glob( - include = code_glob, - exclude = sources_glob, - ), -) - -filegroup( - name = "public_hdrs", - srcs = glob([d + "*.h" for d in service_dirs]), - visibility = ["//:__pkg__"], -) +src_dirs = service_dirs + [d + "internal/" for d in service_dirs] -filegroup( - name = "mocks", - srcs = glob([d + "mocks/*.h" for d in service_dirs]), - visibility = ["//:__pkg__"], -) +googleapis_deps = [ + "@com_google_googleapis//google/cloud/bigquery/v2:bigquery_cc_proto", +] -cc_library( - name = "google_cloud_cpp_bigquerycontrol", - srcs = [":srcs"], - hdrs = [":hdrs"], - visibility = ["//:__pkg__"], - deps = [ - "//:common", - "//:grpc_utils", +cc_gapic_library( + name = "bigquerycontrol", + additional_deps = [ "//google/cloud:google_cloud_cpp_rest_internal", "//google/cloud:google_cloud_cpp_rest_protobuf_internal", - "@com_google_googleapis//google/cloud/bigquery/v2:bigquery_cc_proto", ], + googleapis_deps = googleapis_deps, + service_dirs = service_dirs, ) - -cc_library( - name = "google_cloud_cpp_bigquerycontrol_mocks", - hdrs = [":mocks"], - visibility = ["//:__pkg__"], - deps = [ - ":google_cloud_cpp_bigquerycontrol", - "@com_google_googletest//:gtest", - ], -) - -[cc_test( - name = sample.replace("/", "_").replace(".cc", ""), - srcs = [sample], - tags = ["integration-test"], - deps = [ - "//:bigquerycontrol", - "//google/cloud/testing_util:google_cloud_cpp_testing_private", - ], -) for sample in glob([d + "samples/*.cc" for d in service_dirs])] diff --git a/google/cloud/sql/BUILD.bazel b/google/cloud/sql/BUILD.bazel index 31e9574a1bcbf..8bcbb6aa9c84f 100644 --- a/google/cloud/sql/BUILD.bazel +++ b/google/cloud/sql/BUILD.bazel @@ -12,77 +12,26 @@ # See the License for the specific language governing permissions and # limitations under the License. +load("//bazel:gapic.bzl", "cc_gapic_library") + package(default_visibility = ["//visibility:private"]) licenses(["notice"]) # Apache 2.0 service_dirs = ["v1/"] -code_glob = [d + i + f for d in service_dirs for i in [ - "", - "internal/", -] for f in [ - "*.h", - "*.cc", -]] - -sources_glob = [d + "internal/*_sources.cc" for d in service_dirs] - -filegroup( - name = "srcs", - srcs = glob(sources_glob), -) - -filegroup( - name = "hdrs", - srcs = glob( - include = code_glob, - exclude = sources_glob, - ), -) - -filegroup( - name = "public_hdrs", - srcs = glob([d + "*.h" for d in service_dirs]), - visibility = ["//:__pkg__"], -) +src_dirs = service_dirs + [d + "internal/" for d in service_dirs] -filegroup( - name = "mocks", - srcs = glob([d + "mocks/*.h" for d in service_dirs]), - visibility = ["//:__pkg__"], -) +googleapis_deps = [ + "@com_google_googleapis//google/cloud/sql/v1:sql_cc_proto", +] -cc_library( - name = "google_cloud_cpp_sql", - srcs = [":srcs"], - hdrs = [":hdrs"], - visibility = ["//:__pkg__"], - deps = [ - "//:common", - "//:grpc_utils", +cc_gapic_library( + name = "sql", + additional_deps = [ "//google/cloud:google_cloud_cpp_rest_internal", "//google/cloud:google_cloud_cpp_rest_protobuf_internal", - "@com_google_googleapis//google/cloud/sql/v1:sql_cc_proto", ], + googleapis_deps = googleapis_deps, + service_dirs = service_dirs, ) - -cc_library( - name = "google_cloud_cpp_sql_mocks", - hdrs = [":mocks"], - visibility = ["//:__pkg__"], - deps = [ - ":google_cloud_cpp_sql", - "@com_google_googletest//:gtest", - ], -) - -[cc_test( - name = sample.replace("/", "_").replace(".cc", ""), - srcs = [sample], - tags = ["integration-test"], - deps = [ - "//:sql", - "//google/cloud/testing_util:google_cloud_cpp_testing_private", - ], -) for sample in glob([d + "samples/*.cc" for d in service_dirs])]