Skip to content

Commit

Permalink
feat(run): generate library (#9460)
Browse files Browse the repository at this point in the history
  • Loading branch information
dbolduc authored Jul 13, 2022
1 parent 4be7b7e commit dc0fb06
Show file tree
Hide file tree
Showing 67 changed files with 5,808 additions and 11 deletions.
2 changes: 2 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ exports_files([
])

EXPERIMENTAL_LIBRARIES = [
# Introduced circa 2022-07-12
"run",
# Introduced circa 2022-06-22
"video",
# Introduced in 2022-05
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,14 @@ For status on this, see https://github.com/googleapis/google-cloud-cpp/issues/88

## v2.1.0 - TBD

### New Libraries

We are introducing a new client library for [Cloud Run]. While we do not
anticipate any API changes to this library before declaring it GA, we are
releasing it early in case it elicits some feedback that requires changes.

[Cloud Run]: https://github.com/googleapis/google-cloud-cpp/blob/main/google/cloud/run/README.md

## v2.0.0 - 2022-07

**BREAKING CHANGES**
Expand Down
5 changes: 5 additions & 0 deletions ci/etc/expected_install_directories
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,10 @@
./include/google/cloud/retail/internal
./include/google/cloud/retail/mocks
./include/google/cloud/retail/v2
./include/google/cloud/run
./include/google/cloud/run/internal
./include/google/cloud/run/mocks
./include/google/cloud/run/v2
./include/google/cloud/scheduler
./include/google/cloud/scheduler/internal
./include/google/cloud/scheduler/mocks
Expand Down Expand Up @@ -471,6 +475,7 @@
./lib64/cmake/google_cloud_cpp_resourcemanager
./lib64/cmake/google_cloud_cpp_resourcesettings
./lib64/cmake/google_cloud_cpp_retail
./lib64/cmake/google_cloud_cpp_run
./lib64/cmake/google_cloud_cpp_scheduler
./lib64/cmake/google_cloud_cpp_secretmanager
./lib64/cmake/google_cloud_cpp_securitycenter
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 @@ -57,6 +57,7 @@ redis
resourcemanager
resourcesettings
retail
run
scheduler
secretmanager
securitycenter
Expand Down
25 changes: 14 additions & 11 deletions cmake/CompileProtos.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,10 @@ function (google_cloud_cpp_generate_proto SRCS)
foreach (file_path ${_opt_UNPARSED_ARGUMENTS})
get_filename_component(file_directory "${file_path}" DIRECTORY)
get_filename_component(file_name "${file_path}" NAME)
# This gets the filename without the extension, analogous to $(basename
# "${file_path}" .proto)
get_filename_component(file_stem "${file_path}" NAME_WE)
# This gets the file name without the ".proto" extension. We would like
# to use get_filename_component with the option NAME_WLE, but that is
# not available until CMake 3.14
string(REPLACE ".proto" "" file_stem "${file_name}")

# Strip all the prefixes in ${_opt_PROTO_PATH_DIRECTORIES} from the
# source proto directory
Expand Down Expand Up @@ -175,11 +176,13 @@ function (google_cloud_cpp_generate_grpcpp SRCS)
endforeach ()

set(${SRCS})
foreach (filename ${_opt_UNPARSED_ARGUMENTS})
get_filename_component(file_directory "${filename}" DIRECTORY)
# This gets the filename without the extension, analogous to $(basename
# "${filename}" .proto)
get_filename_component(file_stem "${filename}" NAME_WE)
foreach (file_path ${_opt_UNPARSED_ARGUMENTS})
get_filename_component(file_directory "${file_path}" DIRECTORY)
get_filename_component(file_name "${file_path}" NAME)
# This gets the file name without the ".proto" extension. We would like
# to use get_filename_component with the option NAME_WLE, but that is
# not available until CMake 3.14
string(REPLACE ".proto" "" file_stem "${file_name}")

# Strip all the prefixes in ${_opt_PROTO_PATH_DIRECTORIES} from the
# source proto directory
Expand All @@ -201,9 +204,9 @@ function (google_cloud_cpp_generate_grpcpp SRCS)
--plugin=protoc-gen-grpc=$<TARGET_FILE:gRPC::grpc_cpp_plugin>
"--grpc_out=${CMAKE_CURRENT_BINARY_DIR}"
"--cpp_out=${CMAKE_CURRENT_BINARY_DIR}" ${protobuf_include_path}
"${filename}"
DEPENDS "${filename}" protobuf::protoc gRPC::grpc_cpp_plugin
COMMENT "Running gRPC C++ protocol buffer compiler on ${filename}"
"${file_path}"
DEPENDS "${file_path}" protobuf::protoc gRPC::grpc_cpp_plugin
COMMENT "Running gRPC C++ protocol buffer compiler on ${file_path}"
VERBATIM)
endforeach ()

Expand Down
13 changes: 13 additions & 0 deletions external/googleapis/protodeps/run.deps
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
@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/api:routing_proto
@com_google_googleapis//google/iam/v1:iam_policy_proto
@com_google_googleapis//google/iam/v1:options_proto
@com_google_googleapis//google/iam/v1:policy_proto
@com_google_googleapis//google/longrunning:operations_proto
@com_google_googleapis//google/rpc:status_proto
@com_google_googleapis//google/type:expr_proto
7 changes: 7 additions & 0 deletions external/googleapis/protolists/run.list
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@com_google_googleapis//google/cloud/run/v2:condition.proto
@com_google_googleapis//google/cloud/run/v2:k8s.min.proto
@com_google_googleapis//google/cloud/run/v2:revision.proto
@com_google_googleapis//google/cloud/run/v2:revision_template.proto
@com_google_googleapis//google/cloud/run/v2:service.proto
@com_google_googleapis//google/cloud/run/v2:traffic_target.proto
@com_google_googleapis//google/cloud/run/v2:vendor_settings.proto
1 change: 1 addition & 0 deletions external/googleapis/update_libraries.sh
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ declare -A -r LIBRARIES=(
["resourcemanager"]="@com_google_googleapis//google/cloud/resourcemanager/v3:resourcemanager_cc_grpc"
["resourcesettings"]="@com_google_googleapis//google/cloud/resourcesettings/v1:resourcesettings_cc_grpc"
["retail"]="@com_google_googleapis//google/cloud/retail/v2:retail_cc_grpc"
["run"]="@com_google_googleapis//google/cloud/run/v2:run_cc_grpc"
["scheduler"]="@com_google_googleapis//google/cloud/scheduler/v1:scheduler_cc_grpc"
["secretmanager"]="$(
printf ",%s" \
Expand Down
16 changes: 16 additions & 0 deletions generator/generator_config.textproto
Original file line number Diff line number Diff line change
Expand Up @@ -1082,6 +1082,22 @@ service {
retryable_status_codes: ["kUnavailable"]
}

# Cloud Run
service {
service_proto_path: "google/cloud/run/v2/revision.proto"
product_path: "google/cloud/run"
initial_copyright_year: "2022"
retryable_status_codes: ["kUnavailable"]
}

service {
service_proto_path: "google/cloud/run/v2/service.proto"
product_path: "google/cloud/run"
initial_copyright_year: "2022"
service_endpoint_env_var: "GOOGLE_CLOUD_CPP_RUN_SERVICES_ENDPOINT"
retryable_status_codes: ["kUnavailable"]
}

# Scheduler
service {
service_proto_path: "google/cloud/scheduler/v1/cloudscheduler.proto"
Expand Down
59 changes: 59 additions & 0 deletions google/cloud/run/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Copyright 2022 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

SOURCE_GLOB = "**/*.cc"

MOCK_SOURCE_GLOB = "mocks/*.cc"

HEADER_GLOB = "**/*.h"

MOCK_HEADER_GLOB = "mocks/*.h"

cc_library(
name = "google_cloud_cpp_run",
srcs = glob(
include = [SOURCE_GLOB],
exclude = [MOCK_SOURCE_GLOB],
),
hdrs = glob(
include = [HEADER_GLOB],
exclude = [MOCK_HEADER_GLOB],
),
visibility = ["//:__pkg__"],
deps = [
"//:common",
"//:grpc_utils",
"@com_google_googleapis//google/cloud/run/v2:run_cc_grpc",
],
)

cc_library(
name = "google_cloud_cpp_run_mocks",
srcs = glob(
include = [MOCK_SOURCE_GLOB],
),
hdrs = glob(
include = [MOCK_HEADER_GLOB],
),
visibility = ["//:__pkg__"],
deps = [
":google_cloud_cpp_run",
"//:common",
"//:grpc_utils",
],
)
182 changes: 182 additions & 0 deletions google/cloud/run/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
# ~~~
# Copyright 2022 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 "Cloud Run Admin API C++ Client")
set(DOXYGEN_PROJECT_BRIEF "A C++ Client Library for the Cloud Run Admin API")
set(DOXYGEN_PROJECT_NUMBER "${PROJECT_VERSION} (Experimental)")
set(DOXYGEN_EXCLUDE_SYMBOLS "internal" "run_internal" "run_testing" "examples")
set(DOXYGEN_EXAMPLE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/quickstart)

# Creates the proto headers needed by doxygen.
set(GOOGLE_CLOUD_CPP_DOXYGEN_DEPS google-cloud-cpp::run_protos)

include(GoogleCloudCppCommon)

set(EXTERNAL_GOOGLEAPIS_SOURCE
"${PROJECT_BINARY_DIR}/external/googleapis/src/googleapis_download")
find_path(PROTO_INCLUDE_DIR google/protobuf/descriptor.proto)
if (PROTO_INCLUDE_DIR)
list(INSERT PROTOBUF_IMPORT_DIRS 0 "${PROTO_INCLUDE_DIR}")
endif ()

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

file(
GLOB source_files
RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}"
"*.h" "*.cc" "internal/*.h" "internal/*.cc")
list(SORT source_files)
add_library(google_cloud_cpp_run ${source_files})
target_include_directories(
google_cloud_cpp_run
PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}>
$<INSTALL_INTERFACE:include>)
target_link_libraries(
google_cloud_cpp_run
PUBLIC google-cloud-cpp::grpc_utils google-cloud-cpp::common
google-cloud-cpp::run_protos)
google_cloud_cpp_add_common_options(google_cloud_cpp_run)
set_target_properties(
google_cloud_cpp_run
PROPERTIES EXPORT_NAME google-cloud-cpp::experimental-run
VERSION "${PROJECT_VERSION}"
SOVERSION "${PROJECT_VERSION_MAJOR}")
target_compile_options(google_cloud_cpp_run
PUBLIC ${GOOGLE_CLOUD_CPP_EXCEPTIONS_FLAG})

add_library(google-cloud-cpp::experimental-run ALIAS google_cloud_cpp_run)

# 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/*.h")
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_run_mocks INTERFACE)
target_sources(google_cloud_cpp_run_mocks INTERFACE ${mock_files})
target_link_libraries(
google_cloud_cpp_run_mocks
INTERFACE google-cloud-cpp::experimental-run GTest::gmock_main GTest::gmock
GTest::gtest)
set_target_properties(
google_cloud_cpp_run_mocks
PROPERTIES EXPORT_NAME google-cloud-cpp::experimental-run_mocks)
target_include_directories(
google_cloud_cpp_run_mocks
INTERFACE $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}>
$<INSTALL_INTERFACE:include>)
target_compile_options(google_cloud_cpp_run_mocks
INTERFACE ${GOOGLE_CLOUD_CPP_EXCEPTIONS_FLAG})

include(CTest)
if (BUILD_TESTING)
add_executable(run_quickstart "quickstart/quickstart.cc")
target_link_libraries(run_quickstart
PRIVATE google-cloud-cpp::experimental-run)
google_cloud_cpp_add_common_options(run_quickstart)
add_test(
NAME run_quickstart
COMMAND
cmake -P "${PROJECT_SOURCE_DIR}/cmake/quickstart-runner.cmake"
$<TARGET_FILE:run_quickstart> GOOGLE_CLOUD_PROJECT
GOOGLE_CLOUD_CPP_TEST_REGION)
set_tests_properties(run_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_run-targets
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/google_cloud_cpp_run"
COMPONENT google_cloud_cpp_development)

# Install the libraries and headers in the locations determined by
# GNUInstallDirs
install(
TARGETS google_cloud_cpp_run google_cloud_cpp_run_protos
EXPORT google_cloud_cpp_run-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_run google_cloud_cpp_run_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_run_protos"
"${EXTERNAL_GOOGLEAPIS_SOURCE}")
google_cloud_cpp_install_proto_library_headers("google_cloud_cpp_run_protos")
google_cloud_cpp_install_headers("google_cloud_cpp_run"
"include/google/cloud/run")
google_cloud_cpp_install_headers("google_cloud_cpp_run_mocks"
"include/google/cloud/run")

google_cloud_cpp_add_pkgconfig(
run
"The Cloud Run Admin API C++ Client Library"
"Provides C++ APIs to use the Cloud Run Admin API."
"google_cloud_cpp_grpc_utils"
" google_cloud_cpp_common"
" google_cloud_cpp_run_protos")

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

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

external_googleapis_install_pc("google_cloud_cpp_run_protos")
Loading

0 comments on commit dc0fb06

Please sign in to comment.