Skip to content

Commit 0b18494

Browse files
authored
feat(cloudprofiler): generate library (googleapis#8425)
1 parent d549738 commit 0b18494

Some content is hidden

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

43 files changed

+2583
-0
lines changed

BUILD.bazel

+1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ EXPERIMENTAL_LIBRARIES = [
6565
"oslogin",
6666
"policytroubleshooter",
6767
"privateca",
68+
"profiler",
6869
"pubsublite",
6970
"recommender",
7071
"redis",

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ releasing them early in case they elicit some feedback that requires changes.
159159
<br>
160160

161161
* [Apigee Hybrid](https://github.com/googleapis/google-cloud-cpp/blob/main/google/cloud/apigeeconnect/README.md)
162+
* [Cloud Profiler](https://github.com/googleapis/google-cloud-cpp/blob/main/google/cloud/profiler/README.md)
162163
* [Contact Center AI Insights](https://github.com/googleapis/google-cloud-cpp/blob/main/google/cloud/contactcenterinsights/README.md)
163164
* [Data Catalog](https://github.com/googleapis/google-cloud-cpp/blob/main/google/cloud/datacatalog/README.md)
164165
* [Dataproc](https://github.com/googleapis/google-cloud-cpp/blob/main/google/cloud/dataproc/README.md)

ci/etc/expected_install_directories

+6
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,9 @@
208208
./include/google/cloud/privateca
209209
./include/google/cloud/privateca/internal
210210
./include/google/cloud/privateca/mocks
211+
./include/google/cloud/profiler
212+
./include/google/cloud/profiler/internal
213+
./include/google/cloud/profiler/mocks
211214
./include/google/cloud/pubsublite
212215
./include/google/cloud/pubsublite/internal
213216
./include/google/cloud/pubsublite/mocks
@@ -338,6 +341,8 @@
338341
./include/google/devtools/cloudbuild/v1
339342
./include/google/devtools/clouddebugger
340343
./include/google/devtools/clouddebugger/v2
344+
./include/google/devtools/cloudprofiler
345+
./include/google/devtools/cloudprofiler/v2
341346
./include/google/devtools/cloudtrace
342347
./include/google/devtools/cloudtrace/v2
343348
./include/google/devtools/containeranalysis
@@ -419,6 +424,7 @@
419424
./lib64/cmake/google_cloud_cpp_oslogin
420425
./lib64/cmake/google_cloud_cpp_policytroubleshooter
421426
./lib64/cmake/google_cloud_cpp_privateca
427+
./lib64/cmake/google_cloud_cpp_profiler
422428
./lib64/cmake/google_cloud_cpp_pubsublite
423429
./lib64/cmake/google_cloud_cpp_recommender
424430
./lib64/cmake/google_cloud_cpp_redis

ci/etc/full_feature_list

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ osconfig
4444
oslogin
4545
policytroubleshooter
4646
privateca
47+
profiler
4748
pubsublite
4849
recommender
4950
redis
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@com_google_googleapis//google/api:annotations_proto
2+
@com_google_googleapis//google/api:client_proto
3+
@com_google_googleapis//google/api:http_proto
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@com_google_googleapis//google/devtools/cloudprofiler/v2:profiler.proto

external/googleapis/update_libraries.sh

+1
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ declare -A -r LIBRARIES=(
122122
)"
123123
["policytroubleshooter"]="@com_google_googleapis//google/cloud/policytroubleshooter/v1:policytroubleshooter_cc_grpc"
124124
["privateca"]="@com_google_googleapis//google/cloud/security/privateca/v1:privateca_cc_grpc"
125+
["profiler"]="@com_google_googleapis//google/devtools/cloudprofiler/v2:cloudprofiler_cc_grpc"
125126
["pubsub"]="@com_google_googleapis//google/pubsub/v1:pubsub_cc_grpc"
126127
["pubsublite"]="@com_google_googleapis//google/cloud/pubsublite/v1:pubsublite_cc_grpc"
127128
["recommender"]="$(

generator/generator_config.textproto

+8
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,14 @@ service {
621621
retryable_status_codes: ["kDeadlineExceeded", "kUnavailable"]
622622
}
623623

624+
# Cloud Profiler
625+
service {
626+
service_proto_path: "google/devtools/cloudprofiler/v2/profiler.proto"
627+
product_path: "google/cloud/profiler"
628+
initial_copyright_year: "2022"
629+
retryable_status_codes: ["kUnavailable"]
630+
}
631+
624632
# Pub/Sub Lite
625633
service {
626634
service_proto_path: "google/cloud/pubsublite/v1/admin.proto"

google/cloud/profiler/BUILD.bazel

+59
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_profiler",
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/devtools/cloudprofiler/v2:cloudprofiler_cc_grpc",
42+
],
43+
)
44+
45+
cc_library(
46+
name = "google_cloud_cpp_profiler_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_profiler",
56+
"//google/cloud:google_cloud_cpp_common",
57+
"//google/cloud:google_cloud_cpp_grpc_utils",
58+
],
59+
)

google/cloud/profiler/CMakeLists.txt

+199
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 Profiler API C++ Client")
19+
set(DOXYGEN_PROJECT_BRIEF "A C++ Client Library for the Cloud Profiler API")
20+
set(DOXYGEN_PROJECT_NUMBER "${PROJECT_VERSION} (Experimental)")
21+
set(DOXYGEN_EXCLUDE_SYMBOLS "internal" "profiler_internal" "profiler_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::profiler_protos)
27+
28+
include(GoogleCloudCppCommon)
29+
30+
set(EXTERNAL_GOOGLEAPIS_SOURCE
31+
"${PROJECT_BINARY_DIR}/external/googleapis/src/googleapis_download")
32+
find_path(PROTO_INCLUDE_DIR google/protobuf/descriptor.proto)
33+
if (PROTO_INCLUDE_DIR)
34+
list(INSERT PROTOBUF_IMPORT_DIRS 0 "${PROTO_INCLUDE_DIR}")
35+
endif ()
36+
37+
include(CompileProtos)
38+
google_cloud_cpp_grpcpp_library(
39+
google_cloud_cpp_profiler_protos
40+
# cmake-format: sort
41+
${EXTERNAL_GOOGLEAPIS_SOURCE}/google/devtools/cloudprofiler/v2/profiler.proto
42+
PROTO_PATH_DIRECTORIES
43+
"${EXTERNAL_GOOGLEAPIS_SOURCE}"
44+
"${PROTO_INCLUDE_DIR}")
45+
external_googleapis_set_version_and_alias(profiler_protos)
46+
target_link_libraries(
47+
google_cloud_cpp_profiler_protos
48+
PUBLIC #
49+
google-cloud-cpp::api_annotations_protos
50+
google-cloud-cpp::api_client_protos
51+
google-cloud-cpp::api_http_protos)
52+
53+
file(
54+
GLOB source_files
55+
RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}"
56+
"*.h" "*.cc" "internal/*.h" "internal/*.cc")
57+
list(SORT source_files)
58+
add_library(google_cloud_cpp_profiler ${source_files})
59+
target_include_directories(
60+
google_cloud_cpp_profiler
61+
PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>
62+
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}>
63+
$<INSTALL_INTERFACE:include>)
64+
target_link_libraries(
65+
google_cloud_cpp_profiler
66+
PUBLIC google-cloud-cpp::grpc_utils google-cloud-cpp::common
67+
google-cloud-cpp::profiler_protos)
68+
google_cloud_cpp_add_common_options(google_cloud_cpp_profiler)
69+
set_target_properties(
70+
google_cloud_cpp_profiler
71+
PROPERTIES EXPORT_NAME google-cloud-cpp::experimental-profiler
72+
VERSION "${PROJECT_VERSION}" SOVERSION
73+
"${PROJECT_VERSION_MAJOR}")
74+
target_compile_options(google_cloud_cpp_profiler
75+
PUBLIC ${GOOGLE_CLOUD_CPP_EXCEPTIONS_FLAG})
76+
77+
add_library(google-cloud-cpp::experimental-profiler ALIAS
78+
google_cloud_cpp_profiler)
79+
80+
# Create a header-only library for the mocks. We use a CMake `INTERFACE` library
81+
# for these, a regular library would not work on macOS (where the library needs
82+
# at least one .o file). Unfortunately INTERFACE libraries are a bit weird in
83+
# that they need absolute paths for their sources.
84+
file(
85+
GLOB relative_mock_files
86+
RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}"
87+
"mocks/*.h")
88+
list(SORT relative_mock_files)
89+
set(mock_files)
90+
foreach (file IN LISTS relative_mock_files)
91+
list(APPEND mock_files "${CMAKE_CURRENT_SOURCE_DIR}/${file}")
92+
endforeach ()
93+
add_library(google_cloud_cpp_profiler_mocks INTERFACE)
94+
target_sources(google_cloud_cpp_profiler_mocks INTERFACE ${mock_files})
95+
target_link_libraries(
96+
google_cloud_cpp_profiler_mocks
97+
INTERFACE google-cloud-cpp::experimental-profiler GTest::gmock_main
98+
GTest::gmock GTest::gtest)
99+
set_target_properties(
100+
google_cloud_cpp_profiler_mocks
101+
PROPERTIES EXPORT_NAME google-cloud-cpp::experimental-profiler_mocks)
102+
target_include_directories(
103+
google_cloud_cpp_profiler_mocks
104+
INTERFACE $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>
105+
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}>
106+
$<INSTALL_INTERFACE:include>)
107+
target_compile_options(google_cloud_cpp_profiler_mocks
108+
INTERFACE ${GOOGLE_CLOUD_CPP_EXCEPTIONS_FLAG})
109+
110+
include(CTest)
111+
if (BUILD_TESTING)
112+
add_executable(profiler_quickstart "quickstart/quickstart.cc")
113+
target_link_libraries(profiler_quickstart
114+
PRIVATE google-cloud-cpp::experimental-profiler)
115+
google_cloud_cpp_add_common_options(profiler_quickstart)
116+
add_test(
117+
NAME profiler_quickstart
118+
COMMAND cmake -P "${PROJECT_SOURCE_DIR}/cmake/quickstart-runner.cmake"
119+
$<TARGET_FILE:profiler_quickstart> GOOGLE_CLOUD_PROJECT)
120+
set_tests_properties(profiler_quickstart
121+
PROPERTIES LABELS "integration-test;quickstart")
122+
endif ()
123+
124+
# Get the destination directories based on the GNU recommendations.
125+
include(GNUInstallDirs)
126+
127+
# Export the CMake targets to make it easy to create configuration files.
128+
install(
129+
EXPORT google_cloud_cpp_profiler-targets
130+
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/google_cloud_cpp_profiler"
131+
COMPONENT google_cloud_cpp_development)
132+
133+
# Install the libraries and headers in the locations determined by
134+
# GNUInstallDirs
135+
install(
136+
TARGETS google_cloud_cpp_profiler google_cloud_cpp_profiler_protos
137+
EXPORT google_cloud_cpp_profiler-targets
138+
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
139+
COMPONENT google_cloud_cpp_runtime
140+
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
141+
COMPONENT google_cloud_cpp_runtime
142+
NAMELINK_SKIP
143+
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
144+
COMPONENT google_cloud_cpp_development)
145+
# With CMake-3.12 and higher we could avoid this separate command (and the
146+
# duplication).
147+
install(
148+
TARGETS google_cloud_cpp_profiler google_cloud_cpp_profiler_protos
149+
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
150+
COMPONENT google_cloud_cpp_development
151+
NAMELINK_ONLY
152+
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
153+
COMPONENT google_cloud_cpp_development)
154+
155+
google_cloud_cpp_install_proto_library_protos("google_cloud_cpp_profiler_protos"
156+
"${EXTERNAL_GOOGLEAPIS_SOURCE}")
157+
google_cloud_cpp_install_proto_library_headers(
158+
"google_cloud_cpp_profiler_protos")
159+
google_cloud_cpp_install_headers("google_cloud_cpp_profiler"
160+
"include/google/cloud/profiler")
161+
google_cloud_cpp_install_headers("google_cloud_cpp_profiler_mocks"
162+
"include/google/cloud/profiler")
163+
164+
# Setup global variables used in the following *.in files.
165+
set(GOOGLE_CLOUD_CONFIG_VERSION_MAJOR ${PROJECT_VERSION_MAJOR})
166+
set(GOOGLE_CLOUD_CONFIG_VERSION_MINOR ${PROJECT_VERSION_MINOR})
167+
set(GOOGLE_CLOUD_CONFIG_VERSION_PATCH ${PROJECT_VERSION_PATCH})
168+
set(GOOGLE_CLOUD_PC_NAME "The Cloud Profiler API C++ Client Library")
169+
set(GOOGLE_CLOUD_PC_DESCRIPTION
170+
"Provides C++ APIs to use the Cloud Profiler API.")
171+
set(GOOGLE_CLOUD_PC_LIBS "-lgoogle_cloud_cpp_profiler")
172+
string(CONCAT GOOGLE_CLOUD_PC_REQUIRES "google_cloud_cpp_grpc_utils"
173+
" google_cloud_cpp_common" " google_cloud_cpp_profiler_protos")
174+
175+
# Create and install the pkg-config files.
176+
configure_file("${PROJECT_SOURCE_DIR}/google/cloud/profiler/config.pc.in"
177+
"google_cloud_cpp_profiler.pc" @ONLY)
178+
install(
179+
FILES "${CMAKE_CURRENT_BINARY_DIR}/google_cloud_cpp_profiler.pc"
180+
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig"
181+
COMPONENT google_cloud_cpp_development)
182+
183+
# Create and install the CMake configuration files.
184+
include(CMakePackageConfigHelpers)
185+
configure_file("config.cmake.in" "google_cloud_cpp_profiler-config.cmake" @ONLY)
186+
write_basic_package_version_file(
187+
"google_cloud_cpp_profiler-config-version.cmake"
188+
VERSION ${PROJECT_VERSION}
189+
COMPATIBILITY ExactVersion)
190+
191+
install(
192+
FILES
193+
"${CMAKE_CURRENT_BINARY_DIR}/google_cloud_cpp_profiler-config.cmake"
194+
"${CMAKE_CURRENT_BINARY_DIR}/google_cloud_cpp_profiler-config-version.cmake"
195+
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/google_cloud_cpp_profiler"
196+
COMPONENT google_cloud_cpp_development)
197+
198+
external_googleapis_install_pc("google_cloud_cpp_profiler_protos"
199+
"${PROJECT_SOURCE_DIR}/external/googleapis")

0 commit comments

Comments
 (0)