Skip to content

Commit 9e4eaa9

Browse files
authored
feat(functions): generate library (googleapis#8149)
* feat(functions): generate library * Run generators and format their outputs * Manually update READMEs, quickstart, and top-level stuff
1 parent 77ea634 commit 9e4eaa9

42 files changed

Lines changed: 4185 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

BUILD.bazel

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,20 @@ cc_library(
283283
],
284284
)
285285

286+
cc_library(
287+
name = "experimental-functions",
288+
deps = [
289+
"//google/cloud/functions:google_cloud_cpp_functions",
290+
],
291+
)
292+
293+
cc_library(
294+
name = "experimental-functions_mocks",
295+
deps = [
296+
"//google/cloud/functions:google_cloud_cpp_functions_mocks",
297+
],
298+
)
299+
286300
cc_library(
287301
name = "experimental-eventarc",
288302
deps = [

ci/etc/expected_install_directories

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@
8787
./include/google/cloud/eventarc/publishing
8888
./include/google/cloud/eventarc/publishing/v1
8989
./include/google/cloud/eventarc/v1
90+
./include/google/cloud/functions
91+
./include/google/cloud/functions/internal
92+
./include/google/cloud/functions/mocks
93+
./include/google/cloud/functions/v1
9094
./include/google/cloud/gameservices
9195
./include/google/cloud/gameservices/internal
9296
./include/google/cloud/gameservices/mocks
@@ -305,6 +309,7 @@
305309
./lib64/cmake/google_cloud_cpp_debugger
306310
./lib64/cmake/google_cloud_cpp_dlp
307311
./lib64/cmake/google_cloud_cpp_eventarc
312+
./lib64/cmake/google_cloud_cpp_functions
308313
./lib64/cmake/google_cloud_cpp_gameservices
309314
./lib64/cmake/google_cloud_cpp_gkehub
310315
./lib64/cmake/google_cloud_cpp_iam

ci/etc/full_feature_list

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ datamigration
1616
debugger
1717
dlp
1818
eventarc
19+
functions
1920
gameservices
2021
gkehub
2122
iam
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
@com_google_googleapis//google/api:annotations_proto
2+
@com_google_googleapis//google/api:client_proto
3+
@com_google_googleapis//google/api:field_behavior_proto
4+
@com_google_googleapis//google/api:http_proto
5+
@com_google_googleapis//google/api:resource_proto
6+
@com_google_googleapis//google/iam/v1:iam_policy_proto
7+
@com_google_googleapis//google/iam/v1:options_proto
8+
@com_google_googleapis//google/iam/v1:policy_proto
9+
@com_google_googleapis//google/longrunning:operations_proto
10+
@com_google_googleapis//google/rpc:status_proto
11+
@com_google_googleapis//google/type:expr_proto
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
@com_google_googleapis//google/cloud/functions/v1:functions.proto
2+
@com_google_googleapis//google/cloud/functions/v1:operations.proto

external/googleapis/update_libraries.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ declare -A -r LIBRARIES=(
6969
"@com_google_googleapis//google/cloud/eventarc/v1:eventarc_cc_grpc" \
7070
"@com_google_googleapis//google/cloud/eventarc/publishing/v1:publishing_cc_grpc"
7171
)"
72+
["functions"]="@com_google_googleapis//google/cloud/functions/v1:functions_cc_grpc"
7273
["gameservices"]="@com_google_googleapis//google/cloud/gaming/v1:gaming_cc_grpc"
7374
["gkehub"]="$(
7475
printf ",%s" \

generator/generator_config.textproto

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,15 @@ service {
235235
retryable_status_codes: ["kUnavailable"]
236236
}
237237

238+
# Functions
239+
service {
240+
service_proto_path: "google/cloud/functions/v1/functions.proto"
241+
additional_proto_files: ["google/cloud/functions/v1/operations.proto"]
242+
product_path: "google/cloud/functions"
243+
initial_copyright_year: "2022"
244+
retryable_status_codes: ["kDeadlineExceeded", "kUnavailable"]
245+
}
246+
238247
# Game Services
239248
service {
240249
service_proto_path: "google/cloud/gaming/v1/game_server_clusters_service.proto"

google/cloud/functions/BUILD.bazel

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Copyright 2022 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
package(default_visibility = ["//visibility:private"])
16+
17+
licenses(["notice"]) # Apache 2.0
18+
19+
SOURCE_GLOB = "**/*.cc"
20+
21+
MOCK_SOURCE_GLOB = "mocks/*.cc"
22+
23+
HEADER_GLOB = "**/*.h"
24+
25+
MOCK_HEADER_GLOB = "mocks/*.h"
26+
27+
cc_library(
28+
name = "google_cloud_cpp_functions",
29+
srcs = glob(
30+
include = [SOURCE_GLOB],
31+
exclude = [MOCK_SOURCE_GLOB],
32+
),
33+
hdrs = glob(
34+
include = [HEADER_GLOB],
35+
exclude = [MOCK_HEADER_GLOB],
36+
),
37+
visibility = ["//:__pkg__"],
38+
deps = [
39+
"//google/cloud:google_cloud_cpp_common",
40+
"//google/cloud:google_cloud_cpp_grpc_utils",
41+
"@com_google_googleapis//google/cloud/functions/v1:functions_cc_grpc",
42+
],
43+
)
44+
45+
cc_library(
46+
name = "google_cloud_cpp_functions_mocks",
47+
srcs = glob(
48+
include = [MOCK_SOURCE_GLOB],
49+
),
50+
hdrs = glob(
51+
include = [MOCK_HEADER_GLOB],
52+
),
53+
visibility = ["//:__pkg__"],
54+
deps = [
55+
":google_cloud_cpp_functions",
56+
"//google/cloud:google_cloud_cpp_common",
57+
"//google/cloud:google_cloud_cpp_grpc_utils",
58+
],
59+
)
Lines changed: 199 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
1+
# ~~~
2+
# Copyright 2022 Google LLC
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# https://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
# ~~~
16+
17+
include(GoogleapisConfig)
18+
set(DOXYGEN_PROJECT_NAME "Cloud Functions API C++ Client")
19+
set(DOXYGEN_PROJECT_BRIEF "A C++ Client Library for the Cloud Functions API")
20+
set(DOXYGEN_PROJECT_NUMBER "${PROJECT_VERSION} (Experimental)")
21+
set(DOXYGEN_EXCLUDE_SYMBOLS "internal" "functions_internal" "functions_testing"
22+
"examples")
23+
set(DOXYGEN_EXAMPLE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/quickstart)
24+
25+
# Creates the proto headers needed by doxygen.
26+
set(GOOGLE_CLOUD_CPP_DOXYGEN_DEPS google-cloud-cpp::functions_protos)
27+
28+
find_package(gRPC REQUIRED)
29+
find_package(ProtobufWithTargets REQUIRED)
30+
find_package(absl CONFIG REQUIRED)
31+
32+
include(GoogleCloudCppCommon)
33+
34+
set(EXTERNAL_GOOGLEAPIS_SOURCE
35+
"${PROJECT_BINARY_DIR}/external/googleapis/src/googleapis_download")
36+
find_path(PROTO_INCLUDE_DIR google/protobuf/descriptor.proto)
37+
if (PROTO_INCLUDE_DIR)
38+
list(INSERT PROTOBUF_IMPORT_DIRS 0 "${PROTO_INCLUDE_DIR}")
39+
endif ()
40+
41+
include(CompileProtos)
42+
google_cloud_cpp_grpcpp_library(
43+
google_cloud_cpp_functions_protos
44+
# cmake-format: sort
45+
${EXTERNAL_GOOGLEAPIS_SOURCE}/google/cloud/functions/v1/functions.proto
46+
${EXTERNAL_GOOGLEAPIS_SOURCE}/google/cloud/functions/v1/operations.proto
47+
PROTO_PATH_DIRECTORIES
48+
"${EXTERNAL_GOOGLEAPIS_SOURCE}"
49+
"${PROTO_INCLUDE_DIR}")
50+
external_googleapis_set_version_and_alias(functions_protos)
51+
target_link_libraries(
52+
google_cloud_cpp_functions_protos
53+
PUBLIC #
54+
google-cloud-cpp::api_annotations_protos
55+
google-cloud-cpp::api_client_protos
56+
google-cloud-cpp::api_field_behavior_protos
57+
google-cloud-cpp::api_http_protos
58+
google-cloud-cpp::api_resource_protos
59+
google-cloud-cpp::iam_v1_iam_policy_protos
60+
google-cloud-cpp::iam_v1_options_protos
61+
google-cloud-cpp::iam_v1_policy_protos
62+
google-cloud-cpp::longrunning_operations_protos
63+
google-cloud-cpp::rpc_status_protos
64+
google-cloud-cpp::type_expr_protos)
65+
66+
file(
67+
GLOB source_files
68+
RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}"
69+
"*.h" "*.cc" "internal/*.h" "internal/*.cc")
70+
list(SORT source_files)
71+
add_library(google_cloud_cpp_functions ${source_files})
72+
target_include_directories(
73+
google_cloud_cpp_functions
74+
PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>
75+
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}>
76+
$<INSTALL_INTERFACE:include>)
77+
target_link_libraries(
78+
google_cloud_cpp_functions
79+
PUBLIC google-cloud-cpp::grpc_utils google-cloud-cpp::common
80+
google-cloud-cpp::functions_protos)
81+
google_cloud_cpp_add_common_options(google_cloud_cpp_functions)
82+
set_target_properties(
83+
google_cloud_cpp_functions
84+
PROPERTIES EXPORT_NAME google-cloud-cpp::experimental-functions
85+
VERSION "${PROJECT_VERSION}" SOVERSION
86+
"${PROJECT_VERSION_MAJOR}")
87+
target_compile_options(google_cloud_cpp_functions
88+
PUBLIC ${GOOGLE_CLOUD_CPP_EXCEPTIONS_FLAG})
89+
90+
add_library(google-cloud-cpp::experimental-functions ALIAS
91+
google_cloud_cpp_functions)
92+
93+
# Create a header-only library for the mocks. We use a CMake `INTERFACE` library
94+
# for these, a regular library would not work on macOS (where the library needs
95+
# at least one .o file). Unfortunately INTERFACE libraries are a bit weird in
96+
# that they need absolute paths for their sources.
97+
file(
98+
GLOB relative_mock_files
99+
RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}"
100+
"mocks/*.h")
101+
list(SORT relative_mock_files)
102+
set(mock_files)
103+
foreach (file IN LISTS relative_mock_files)
104+
list(APPEND mock_files "${CMAKE_CURRENT_SOURCE_DIR}/${file}")
105+
endforeach ()
106+
add_library(google_cloud_cpp_functions_mocks INTERFACE)
107+
target_sources(google_cloud_cpp_functions_mocks INTERFACE ${mock_files})
108+
target_link_libraries(
109+
google_cloud_cpp_functions_mocks
110+
INTERFACE google-cloud-cpp::experimental-functions GTest::gmock_main
111+
GTest::gmock GTest::gtest)
112+
set_target_properties(
113+
google_cloud_cpp_functions_mocks
114+
PROPERTIES EXPORT_NAME google-cloud-cpp::experimental-functions_mocks)
115+
target_include_directories(
116+
google_cloud_cpp_functions_mocks
117+
INTERFACE $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>
118+
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}>
119+
$<INSTALL_INTERFACE:include>)
120+
target_compile_options(google_cloud_cpp_functions_mocks
121+
INTERFACE ${GOOGLE_CLOUD_CPP_EXCEPTIONS_FLAG})
122+
123+
# Get the destination directories based on the GNU recommendations.
124+
include(GNUInstallDirs)
125+
126+
# Export the CMake targets to make it easy to create configuration files.
127+
install(
128+
EXPORT google_cloud_cpp_functions-targets
129+
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/google_cloud_cpp_functions"
130+
COMPONENT google_cloud_cpp_development)
131+
132+
# Install the libraries and headers in the locations determined by
133+
# GNUInstallDirs
134+
install(
135+
TARGETS google_cloud_cpp_functions google_cloud_cpp_functions_protos
136+
EXPORT google_cloud_cpp_functions-targets
137+
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
138+
COMPONENT google_cloud_cpp_runtime
139+
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
140+
COMPONENT google_cloud_cpp_runtime
141+
NAMELINK_SKIP
142+
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
143+
COMPONENT google_cloud_cpp_development)
144+
# With CMake-3.12 and higher we could avoid this separate command (and the
145+
# duplication).
146+
install(
147+
TARGETS google_cloud_cpp_functions google_cloud_cpp_functions_protos
148+
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
149+
COMPONENT google_cloud_cpp_development
150+
NAMELINK_ONLY
151+
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
152+
COMPONENT google_cloud_cpp_development)
153+
154+
google_cloud_cpp_install_proto_library_protos(
155+
"google_cloud_cpp_functions_protos" "${EXTERNAL_GOOGLEAPIS_SOURCE}")
156+
google_cloud_cpp_install_proto_library_headers(
157+
"google_cloud_cpp_functions_protos")
158+
google_cloud_cpp_install_headers("google_cloud_cpp_functions"
159+
"include/google/cloud/functions")
160+
google_cloud_cpp_install_headers("google_cloud_cpp_functions_mocks"
161+
"include/google/cloud/functions")
162+
163+
# Setup global variables used in the following *.in files.
164+
set(GOOGLE_CLOUD_CONFIG_VERSION_MAJOR ${PROJECT_VERSION_MAJOR})
165+
set(GOOGLE_CLOUD_CONFIG_VERSION_MINOR ${PROJECT_VERSION_MINOR})
166+
set(GOOGLE_CLOUD_CONFIG_VERSION_PATCH ${PROJECT_VERSION_PATCH})
167+
set(GOOGLE_CLOUD_PC_NAME "The Cloud Functions API C++ Client Library")
168+
set(GOOGLE_CLOUD_PC_DESCRIPTION
169+
"Provides C++ APIs to use the Cloud Functions API.")
170+
set(GOOGLE_CLOUD_PC_LIBS "-lgoogle_cloud_cpp_functions")
171+
string(CONCAT GOOGLE_CLOUD_PC_REQUIRES "google_cloud_cpp_grpc_utils"
172+
" google_cloud_cpp_common" " google_cloud_cpp_functions_protos")
173+
174+
# Create and install the pkg-config files.
175+
configure_file("${PROJECT_SOURCE_DIR}/google/cloud/functions/config.pc.in"
176+
"google_cloud_cpp_functions.pc" @ONLY)
177+
install(
178+
FILES "${CMAKE_CURRENT_BINARY_DIR}/google_cloud_cpp_functions.pc"
179+
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig"
180+
COMPONENT google_cloud_cpp_development)
181+
182+
# Create and install the CMake configuration files.
183+
include(CMakePackageConfigHelpers)
184+
configure_file("config.cmake.in" "google_cloud_cpp_functions-config.cmake"
185+
@ONLY)
186+
write_basic_package_version_file(
187+
"google_cloud_cpp_functions-config-version.cmake"
188+
VERSION ${PROJECT_VERSION}
189+
COMPATIBILITY ExactVersion)
190+
191+
install(
192+
FILES
193+
"${CMAKE_CURRENT_BINARY_DIR}/google_cloud_cpp_functions-config.cmake"
194+
"${CMAKE_CURRENT_BINARY_DIR}/google_cloud_cpp_functions-config-version.cmake"
195+
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/google_cloud_cpp_functions"
196+
COMPONENT google_cloud_cpp_development)
197+
198+
external_googleapis_install_pc("google_cloud_cpp_functions_protos"
199+
"${PROJECT_SOURCE_DIR}/external/googleapis")

0 commit comments

Comments
 (0)