Skip to content

Commit

Permalink
feat(networkservices): generate library (#11860)
Browse files Browse the repository at this point in the history
  • Loading branch information
coryan committed Jun 12, 2023
1 parent c33459e commit f9cc920
Show file tree
Hide file tree
Showing 56 changed files with 13,177 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ the APIs in these libraries are stable, and are ready for production use.
- [Cloud Domains](/google/cloud/domains/README.md)
- [Essential Contacts](/google/cloud/essentialcontacts/README.md)
- [Timeseries Insights](/google/cloud/timeseriesinsights/README.md)
- [Traffic Director](/google/cloud/networkservices/README.md)
- [Vertex AI](/google/cloud/aiplatform/README.md)

### Cloud Debugger
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,9 @@ See each library's `README.md` file for more information about:
- [Network Management API](google/cloud/networkmanagement/README.md)
[\[quickstart\]](google/cloud/networkmanagement/quickstart/README.md)
[\[reference\]](https://cloud.google.com/cpp/docs/reference/networkmanagement/latest)
- [Network Services API](google/cloud/networkservices/README.md)
[\[quickstart\]](google/cloud/networkservices/quickstart/README.md)
[\[reference\]](https://cloud.google.com/cpp/docs/reference/networkservices/latest)
- [Notebooks API](google/cloud/notebooks/README.md)
[\[quickstart\]](google/cloud/notebooks/quickstart/README.md)
[\[reference\]](https://cloud.google.com/cpp/docs/reference/notebooks/latest)
Expand Down
Binary file not shown.
5 changes: 5 additions & 0 deletions ci/etc/expected_install_directories
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,10 @@
./include/google/cloud/networkmanagement/v1
./include/google/cloud/networkmanagement/v1/internal
./include/google/cloud/networkmanagement/v1/mocks
./include/google/cloud/networkservices
./include/google/cloud/networkservices/v1
./include/google/cloud/networkservices/v1/internal
./include/google/cloud/networkservices/v1/mocks
./include/google/cloud/notebooks
./include/google/cloud/notebooks/mocks
./include/google/cloud/notebooks/v1
Expand Down Expand Up @@ -1136,6 +1140,7 @@
./lib64/cmake/google_cloud_cpp_monitoring
./lib64/cmake/google_cloud_cpp_networkconnectivity
./lib64/cmake/google_cloud_cpp_networkmanagement
./lib64/cmake/google_cloud_cpp_networkservices
./lib64/cmake/google_cloud_cpp_notebooks
./lib64/cmake/google_cloud_cpp_optimization
./lib64/cmake/google_cloud_cpp_orgpolicy
Expand Down
1 change: 1 addition & 0 deletions ci/etc/full_feature_list
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ memcache
monitoring
networkconnectivity
networkmanagement
networkservices
notebooks
optimization
orgpolicy
Expand Down
1 change: 1 addition & 0 deletions cmake/GoogleCloudCppFeatures.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ set(GOOGLE_CLOUD_CPP_GA_LIBRARIES
"monitoring"
"networkconnectivity"
"networkmanagement"
"networkservices"
"notebooks"
"optimization"
"orgpolicy"
Expand Down
8 changes: 8 additions & 0 deletions external/googleapis/protodeps/networkservices.deps
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
@com_google_googleapis//google/api:annotations_proto
@com_google_googleapis//google/api:client_proto
@com_google_googleapis//google/api:field_behavior_proto
@com_google_googleapis//google/api:http_proto
@com_google_googleapis//google/api:launch_stage_proto
@com_google_googleapis//google/api:resource_proto
@com_google_googleapis//google/longrunning:operations_proto
@com_google_googleapis//google/rpc:status_proto
10 changes: 10 additions & 0 deletions external/googleapis/protolists/networkservices.list
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
@com_google_googleapis//google/cloud/networkservices/v1:common.proto
@com_google_googleapis//google/cloud/networkservices/v1:endpoint_policy.proto
@com_google_googleapis//google/cloud/networkservices/v1:gateway.proto
@com_google_googleapis//google/cloud/networkservices/v1:grpc_route.proto
@com_google_googleapis//google/cloud/networkservices/v1:http_route.proto
@com_google_googleapis//google/cloud/networkservices/v1:mesh.proto
@com_google_googleapis//google/cloud/networkservices/v1:network_services.proto
@com_google_googleapis//google/cloud/networkservices/v1:service_binding.proto
@com_google_googleapis//google/cloud/networkservices/v1:tcp_route.proto
@com_google_googleapis//google/cloud/networkservices/v1:tls_route.proto
1 change: 1 addition & 0 deletions external/googleapis/update_libraries.sh
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ declare -A -r LIBRARIES=(
)"
["networkconnectivity"]="@com_google_googleapis//google/cloud/networkconnectivity/v1:networkconnectivity_cc_grpc"
["networkmanagement"]="@com_google_googleapis//google/cloud/networkmanagement/v1:networkmanagement_cc_grpc"
["networkservices"]="@com_google_googleapis//google/cloud/networkservices/v1:networkservices_cc_grpc"
["notebooks"]="@com_google_googleapis//google/cloud/notebooks/v1:notebooks_cc_grpc"
["optimization"]="@com_google_googleapis//google/cloud/optimization/v1:optimization_cc_grpc"
["orgpolicy"]="@com_google_googleapis//google/cloud/orgpolicy/v2:orgpolicy_cc_grpc"
Expand Down
8 changes: 8 additions & 0 deletions generator/generator_config.textproto
Original file line number Diff line number Diff line change
Expand Up @@ -2346,6 +2346,14 @@ service {
retryable_status_codes: ["kUnavailable"]
}
# Network Services (aka Traffic Director)
service {
service_proto_path: "google/cloud/networkservices/v1/network_services.proto"
product_path: "google/cloud/networkservices/v1"
initial_copyright_year: "2023"
retryable_status_codes: ["kUnavailable"]
}
# Notebooks
service {
service_proto_path: "google/cloud/notebooks/v1/managed_service.proto"
Expand Down
68 changes: 68 additions & 0 deletions google/cloud/networkservices/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# Copyright 2023 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

package(default_visibility = ["//visibility:private"])

licenses(["notice"]) # Apache 2.0

service_dirs = ["v1/"]

src_dirs = service_dirs + [d + "internal/" for d in service_dirs]

filegroup(
name = "srcs",
srcs = glob([d + "*.cc" for d in src_dirs]),
)

filegroup(
name = "hdrs",
srcs = glob([d + "*.h" for d in src_dirs]),
)

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

cc_library(
name = "google_cloud_cpp_networkservices",
srcs = [":srcs"],
hdrs = [":hdrs"],
visibility = ["//:__pkg__"],
deps = [
"//:common",
"//:grpc_utils",
"@com_google_googleapis//google/cloud/networkservices/v1:networkservices_cc_grpc",
],
)

cc_library(
name = "google_cloud_cpp_networkservices_mocks",
hdrs = [":mocks"],
visibility = ["//:__pkg__"],
deps = [
":google_cloud_cpp_networkservices",
"@com_google_googletest//:gtest",
],
)

[cc_test(
name = sample.replace("/", "_").replace(".cc", ""),
srcs = [sample],
tags = ["integration-test"],
deps = [
"//:networkservices",
"//google/cloud/testing_util:google_cloud_cpp_testing_private",
],
) for sample in glob([d + "samples/*.cc" for d in service_dirs])]
204 changes: 204 additions & 0 deletions google/cloud/networkservices/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
# ~~~
# Copyright 2023 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ~~~

include(GoogleapisConfig)
set(DOXYGEN_PROJECT_NAME "Network Services API C++ Client")
set(DOXYGEN_PROJECT_BRIEF "A C++ Client Library for the Network Services API")
set(DOXYGEN_PROJECT_NUMBER "${PROJECT_VERSION}")
set(DOXYGEN_EXCLUDE_SYMBOLS "internal")
set(DOXYGEN_EXAMPLE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/quickstart)

unset(mocks_globs)
unset(source_globs)
set(service_dirs "v1/")
foreach (dir IN LISTS service_dirs)
string(REPLACE "/" "_" ns "${dir}")
list(APPEND source_globs "${dir}*.h" "${dir}*.cc" "${dir}internal/*")
list(APPEND mocks_globs "${dir}mocks/*.h")
list(APPEND DOXYGEN_EXAMPLE_PATH
"${CMAKE_CURRENT_SOURCE_DIR}/${dir}samples")
list(APPEND DOXYGEN_EXCLUDE_SYMBOLS "networkservices_${ns}internal")
endforeach ()

include(GoogleCloudCppDoxygen)
google_cloud_cpp_doxygen_targets("networkservices" DEPENDS cloud-docs
google-cloud-cpp::networkservices_protos)

include(GoogleCloudCppCommon)

include(CompileProtos)
google_cloud_cpp_find_proto_include_dir(PROTO_INCLUDE_DIR)
google_cloud_cpp_load_protolist(
proto_list
"${PROJECT_SOURCE_DIR}/external/googleapis/protolists/networkservices.list")
google_cloud_cpp_load_protodeps(
proto_deps
"${PROJECT_SOURCE_DIR}/external/googleapis/protodeps/networkservices.deps")
google_cloud_cpp_grpcpp_library(
google_cloud_cpp_networkservices_protos # cmake-format: sort
${proto_list} PROTO_PATH_DIRECTORIES "${EXTERNAL_GOOGLEAPIS_SOURCE}"
"${PROTO_INCLUDE_DIR}")
external_googleapis_set_version_and_alias(networkservices_protos)
target_link_libraries(google_cloud_cpp_networkservices_protos
PUBLIC ${proto_deps})

file(
GLOB source_files
RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}"
${source_globs})
list(SORT source_files)
add_library(google_cloud_cpp_networkservices ${source_files})
target_include_directories(
google_cloud_cpp_networkservices
PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}>
$<INSTALL_INTERFACE:include>)
target_link_libraries(
google_cloud_cpp_networkservices
PUBLIC google-cloud-cpp::grpc_utils google-cloud-cpp::common
google-cloud-cpp::networkservices_protos)
google_cloud_cpp_add_common_options(google_cloud_cpp_networkservices)
set_target_properties(
google_cloud_cpp_networkservices
PROPERTIES EXPORT_NAME google-cloud-cpp::networkservices
VERSION "${PROJECT_VERSION}"
SOVERSION "${PROJECT_VERSION_MAJOR}")
target_compile_options(google_cloud_cpp_networkservices
PUBLIC ${GOOGLE_CLOUD_CPP_EXCEPTIONS_FLAG})

add_library(google-cloud-cpp::networkservices ALIAS
google_cloud_cpp_networkservices)

# Create a header-only library for the mocks. We use a CMake `INTERFACE` library
# for these, a regular library would not work on macOS (where the library needs
# at least one .o file). Unfortunately INTERFACE libraries are a bit weird in
# that they need absolute paths for their sources.
file(
GLOB relative_mock_files
RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}"
${mocks_globs})
list(SORT relative_mock_files)
set(mock_files)
foreach (file IN LISTS relative_mock_files)
list(APPEND mock_files "${CMAKE_CURRENT_SOURCE_DIR}/${file}")
endforeach ()
add_library(google_cloud_cpp_networkservices_mocks INTERFACE)
target_sources(google_cloud_cpp_networkservices_mocks INTERFACE ${mock_files})
target_link_libraries(
google_cloud_cpp_networkservices_mocks
INTERFACE google-cloud-cpp::networkservices GTest::gmock_main GTest::gmock
GTest::gtest)
set_target_properties(
google_cloud_cpp_networkservices_mocks
PROPERTIES EXPORT_NAME google-cloud-cpp::networkservices_mocks)
target_include_directories(
google_cloud_cpp_networkservices_mocks
INTERFACE $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}>
$<INSTALL_INTERFACE:include>)
target_compile_options(google_cloud_cpp_networkservices_mocks
INTERFACE ${GOOGLE_CLOUD_CPP_EXCEPTIONS_FLAG})

include(CTest)
if (BUILD_TESTING)
add_executable(networkservices_quickstart "quickstart/quickstart.cc")
target_link_libraries(networkservices_quickstart
PRIVATE google-cloud-cpp::networkservices)
google_cloud_cpp_add_common_options(networkservices_quickstart)
add_test(
NAME networkservices_quickstart
COMMAND cmake -P "${PROJECT_SOURCE_DIR}/cmake/quickstart-runner.cmake"
$<TARGET_FILE:networkservices_quickstart> GOOGLE_CLOUD_PROJECT)
set_tests_properties(networkservices_quickstart
PROPERTIES LABELS "integration-test;quickstart")
endif ()

# Get the destination directories based on the GNU recommendations.
include(GNUInstallDirs)

# Export the CMake targets to make it easy to create configuration files.
install(
EXPORT google_cloud_cpp_networkservices-targets
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/google_cloud_cpp_networkservices"
COMPONENT google_cloud_cpp_development)

# Install the libraries and headers in the locations determined by
# GNUInstallDirs
install(
TARGETS google_cloud_cpp_networkservices
google_cloud_cpp_networkservices_protos
EXPORT google_cloud_cpp_networkservices-targets
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
COMPONENT google_cloud_cpp_runtime
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
COMPONENT google_cloud_cpp_runtime
NAMELINK_SKIP
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
COMPONENT google_cloud_cpp_development)
# With CMake-3.12 and higher we could avoid this separate command (and the
# duplication).
install(
TARGETS google_cloud_cpp_networkservices
google_cloud_cpp_networkservices_protos
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
COMPONENT google_cloud_cpp_development
NAMELINK_ONLY
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
COMPONENT google_cloud_cpp_development)

google_cloud_cpp_install_proto_library_protos(
"google_cloud_cpp_networkservices_protos" "${EXTERNAL_GOOGLEAPIS_SOURCE}")
google_cloud_cpp_install_proto_library_headers(
"google_cloud_cpp_networkservices_protos")
google_cloud_cpp_install_headers("google_cloud_cpp_networkservices"
"include/google/cloud/networkservices")
google_cloud_cpp_install_headers("google_cloud_cpp_networkservices_mocks"
"include/google/cloud/networkservices")

google_cloud_cpp_add_pkgconfig(
networkservices
"The Network Services API C++ Client Library"
"Provides C++ APIs to use the Network Services API."
"google_cloud_cpp_grpc_utils"
" google_cloud_cpp_common"
" google_cloud_cpp_networkservices_protos")

# Create and install the CMake configuration files.
include(CMakePackageConfigHelpers)
configure_file("config.cmake.in"
"google_cloud_cpp_networkservices-config.cmake" @ONLY)
write_basic_package_version_file(
"google_cloud_cpp_networkservices-config-version.cmake"
VERSION ${PROJECT_VERSION}
COMPATIBILITY ExactVersion)

install(
FILES
"${CMAKE_CURRENT_BINARY_DIR}/google_cloud_cpp_networkservices-config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/google_cloud_cpp_networkservices-config-version.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/google_cloud_cpp_networkservices"
COMPONENT google_cloud_cpp_development)

external_googleapis_install_pc("google_cloud_cpp_networkservices_protos")

# google-cloud-cpp::networkservices must be defined before we can add the
# samples.
foreach (dir IN LISTS service_dirs)
if (BUILD_TESTING AND GOOGLE_CLOUD_CPP_ENABLE_CXX_EXCEPTIONS)
google_cloud_cpp_add_samples_relative("networkservices"
"${dir}samples/")
endif ()
endforeach ()
Loading

0 comments on commit f9cc920

Please sign in to comment.