Skip to content

Commit d549738

Browse files
authored
feat(documentai): generate library (googleapis#8426)
Note that the quickstart is disabled.
1 parent 69b1aa7 commit d549738

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

+3007
-0
lines changed

BUILD.bazel

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ EXPERIMENTAL_LIBRARIES = [
4343
"dataproc",
4444
"debugger",
4545
"dlp",
46+
"documentai",
4647
"eventarc",
4748
"filestore",
4849
"functions",

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ releasing them early in case they elicit some feedback that requires changes.
162162
* [Contact Center AI Insights](https://github.com/googleapis/google-cloud-cpp/blob/main/google/cloud/contactcenterinsights/README.md)
163163
* [Data Catalog](https://github.com/googleapis/google-cloud-cpp/blob/main/google/cloud/datacatalog/README.md)
164164
* [Dataproc](https://github.com/googleapis/google-cloud-cpp/blob/main/google/cloud/dataproc/README.md)
165+
* [Document AI](https://github.com/googleapis/google-cloud-cpp/blob/main/google/cloud/documentai/README.md)
165166
* [Managed Service for Microsoft Active Directory](https://github.com/googleapis/google-cloud-cpp/blob/main/google/cloud/managedidentities/README.md)
166167
* [Natural Language AI](https://github.com/googleapis/google-cloud-cpp/blob/main/google/cloud/language/README.md)
167168
* [Resource Settings](https://github.com/googleapis/google-cloud-cpp/blob/main/google/cloud/resourcesettings/README.md)

ci/etc/expected_install_directories

+5
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,10 @@
111111
./include/google/cloud/dlp
112112
./include/google/cloud/dlp/internal
113113
./include/google/cloud/dlp/mocks
114+
./include/google/cloud/documentai
115+
./include/google/cloud/documentai/internal
116+
./include/google/cloud/documentai/mocks
117+
./include/google/cloud/documentai/v1
114118
./include/google/cloud/eventarc
115119
./include/google/cloud/eventarc/internal
116120
./include/google/cloud/eventarc/mocks
@@ -392,6 +396,7 @@
392396
./lib64/cmake/google_cloud_cpp_dataproc
393397
./lib64/cmake/google_cloud_cpp_debugger
394398
./lib64/cmake/google_cloud_cpp_dlp
399+
./lib64/cmake/google_cloud_cpp_documentai
395400
./lib64/cmake/google_cloud_cpp_eventarc
396401
./lib64/cmake/google_cloud_cpp_filestore
397402
./lib64/cmake/google_cloud_cpp_functions

ci/etc/full_feature_list

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ datamigration
2121
dataproc
2222
debugger
2323
dlp
24+
documentai
2425
eventarc
2526
filestore
2627
functions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
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/longrunning:operations_proto
7+
@com_google_googleapis//google/rpc:status_proto
8+
@com_google_googleapis//google/type:color_proto
9+
@com_google_googleapis//google/type:date_proto
10+
@com_google_googleapis//google/type:datetime_proto
11+
@com_google_googleapis//google/type:money_proto
12+
@com_google_googleapis//google/type:postal_address_proto
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@com_google_googleapis//google/cloud/documentai/v1:document.proto
2+
@com_google_googleapis//google/cloud/documentai/v1:document_io.proto
3+
@com_google_googleapis//google/cloud/documentai/v1:document_processor_service.proto
4+
@com_google_googleapis//google/cloud/documentai/v1:geometry.proto
5+
@com_google_googleapis//google/cloud/documentai/v1:operation_metadata.proto

external/googleapis/update_libraries.sh

+1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ declare -A -r LIBRARIES=(
7171
["debugger"]="@com_google_googleapis//google/devtools/clouddebugger/v2:clouddebugger_cc_grpc"
7272
["dialogflow"]="@com_google_googleapis//google/cloud/dialogflow/v2:dialogflow_cc_grpc"
7373
["dlp"]="@com_google_googleapis//google/privacy/dlp/v2:dlp_cc_grpc"
74+
["documentai"]="@com_google_googleapis//google/cloud/documentai/v1:documentai_cc_grpc"
7475
["eventarc"]="$(
7576
printf ",%s" \
7677
"@com_google_googleapis//google/cloud/eventarc/v1:eventarc_cc_grpc" \

generator/generator_config.textproto

+7
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,13 @@ service {
342342
retryable_status_codes: ["kDeadlineExceeded", "kUnavailable"]
343343
}
344344

345+
# Document AI
346+
service {
347+
service_proto_path: "google/cloud/documentai/v1/document_processor_service.proto"
348+
product_path: "google/cloud/documentai"
349+
initial_copyright_year: "2022"
350+
retryable_status_codes: ["kUnavailable"]
351+
}
345352

346353
# Eventarc
347354
service {

google/cloud/documentai/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_documentai",
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/documentai/v1:documentai_cc_grpc",
42+
],
43+
)
44+
45+
cc_library(
46+
name = "google_cloud_cpp_documentai_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_documentai",
56+
"//google/cloud:google_cloud_cpp_common",
57+
"//google/cloud:google_cloud_cpp_grpc_utils",
58+
],
59+
)
+217
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,217 @@
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 Document AI API C++ Client")
19+
set(DOXYGEN_PROJECT_BRIEF "A C++ Client Library for the Cloud Document AI API")
20+
set(DOXYGEN_PROJECT_NUMBER "${PROJECT_VERSION} (Experimental)")
21+
set(DOXYGEN_EXCLUDE_SYMBOLS "internal" "documentai_internal"
22+
"documentai_testing" "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::documentai_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_documentai_protos
40+
# cmake-format: sort
41+
${EXTERNAL_GOOGLEAPIS_SOURCE}/google/cloud/documentai/v1/document.proto
42+
${EXTERNAL_GOOGLEAPIS_SOURCE}/google/cloud/documentai/v1/document_io.proto
43+
${EXTERNAL_GOOGLEAPIS_SOURCE}/google/cloud/documentai/v1/document_processor_service.proto
44+
${EXTERNAL_GOOGLEAPIS_SOURCE}/google/cloud/documentai/v1/geometry.proto
45+
${EXTERNAL_GOOGLEAPIS_SOURCE}/google/cloud/documentai/v1/operation_metadata.proto
46+
PROTO_PATH_DIRECTORIES
47+
"${EXTERNAL_GOOGLEAPIS_SOURCE}"
48+
"${PROTO_INCLUDE_DIR}")
49+
external_googleapis_set_version_and_alias(documentai_protos)
50+
target_link_libraries(
51+
google_cloud_cpp_documentai_protos
52+
PUBLIC #
53+
google-cloud-cpp::api_annotations_protos
54+
google-cloud-cpp::api_client_protos
55+
google-cloud-cpp::api_field_behavior_protos
56+
google-cloud-cpp::api_http_protos
57+
google-cloud-cpp::api_resource_protos
58+
google-cloud-cpp::longrunning_operations_protos
59+
google-cloud-cpp::rpc_status_protos
60+
google-cloud-cpp::type_color_protos
61+
google-cloud-cpp::type_date_protos
62+
google-cloud-cpp::type_datetime_protos
63+
google-cloud-cpp::type_money_protos
64+
google-cloud-cpp::type_postal_address_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_documentai ${source_files})
72+
target_include_directories(
73+
google_cloud_cpp_documentai
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_documentai
79+
PUBLIC google-cloud-cpp::grpc_utils google-cloud-cpp::common
80+
google-cloud-cpp::documentai_protos)
81+
google_cloud_cpp_add_common_options(google_cloud_cpp_documentai)
82+
set_target_properties(
83+
google_cloud_cpp_documentai
84+
PROPERTIES EXPORT_NAME google-cloud-cpp::experimental-documentai
85+
VERSION "${PROJECT_VERSION}" SOVERSION
86+
"${PROJECT_VERSION_MAJOR}")
87+
target_compile_options(google_cloud_cpp_documentai
88+
PUBLIC ${GOOGLE_CLOUD_CPP_EXCEPTIONS_FLAG})
89+
90+
add_library(google-cloud-cpp::experimental-documentai ALIAS
91+
google_cloud_cpp_documentai)
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_documentai_mocks INTERFACE)
107+
target_sources(google_cloud_cpp_documentai_mocks INTERFACE ${mock_files})
108+
target_link_libraries(
109+
google_cloud_cpp_documentai_mocks
110+
INTERFACE google-cloud-cpp::experimental-documentai GTest::gmock_main
111+
GTest::gmock GTest::gtest)
112+
set_target_properties(
113+
google_cloud_cpp_documentai_mocks
114+
PROPERTIES EXPORT_NAME google-cloud-cpp::experimental-documentai_mocks)
115+
target_include_directories(
116+
google_cloud_cpp_documentai_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_documentai_mocks
121+
INTERFACE ${GOOGLE_CLOUD_CPP_EXCEPTIONS_FLAG})
122+
123+
include(CTest)
124+
if (BUILD_TESTING)
125+
add_executable(documentai_quickstart "quickstart/quickstart.cc")
126+
target_link_libraries(documentai_quickstart
127+
PRIVATE google-cloud-cpp::experimental-documentai)
128+
google_cloud_cpp_add_common_options(documentai_quickstart)
129+
add_test(
130+
NAME documentai_quickstart
131+
COMMAND
132+
cmake -P "${PROJECT_SOURCE_DIR}/cmake/quickstart-runner.cmake"
133+
$<TARGET_FILE:documentai_quickstart> GOOGLE_CLOUD_PROJECT
134+
# TODO(#7976): Enable this quickstart and make it run.
135+
)
136+
set_tests_properties(
137+
documentai_quickstart PROPERTIES DISABLED true LABELS
138+
"integration-test;quickstart")
139+
endif ()
140+
141+
# Get the destination directories based on the GNU recommendations.
142+
include(GNUInstallDirs)
143+
144+
# Export the CMake targets to make it easy to create configuration files.
145+
install(
146+
EXPORT google_cloud_cpp_documentai-targets
147+
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/google_cloud_cpp_documentai"
148+
COMPONENT google_cloud_cpp_development)
149+
150+
# Install the libraries and headers in the locations determined by
151+
# GNUInstallDirs
152+
install(
153+
TARGETS google_cloud_cpp_documentai google_cloud_cpp_documentai_protos
154+
EXPORT google_cloud_cpp_documentai-targets
155+
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
156+
COMPONENT google_cloud_cpp_runtime
157+
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
158+
COMPONENT google_cloud_cpp_runtime
159+
NAMELINK_SKIP
160+
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
161+
COMPONENT google_cloud_cpp_development)
162+
# With CMake-3.12 and higher we could avoid this separate command (and the
163+
# duplication).
164+
install(
165+
TARGETS google_cloud_cpp_documentai google_cloud_cpp_documentai_protos
166+
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
167+
COMPONENT google_cloud_cpp_development
168+
NAMELINK_ONLY
169+
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
170+
COMPONENT google_cloud_cpp_development)
171+
172+
google_cloud_cpp_install_proto_library_protos(
173+
"google_cloud_cpp_documentai_protos" "${EXTERNAL_GOOGLEAPIS_SOURCE}")
174+
google_cloud_cpp_install_proto_library_headers(
175+
"google_cloud_cpp_documentai_protos")
176+
google_cloud_cpp_install_headers("google_cloud_cpp_documentai"
177+
"include/google/cloud/documentai")
178+
google_cloud_cpp_install_headers("google_cloud_cpp_documentai_mocks"
179+
"include/google/cloud/documentai")
180+
181+
# Setup global variables used in the following *.in files.
182+
set(GOOGLE_CLOUD_CONFIG_VERSION_MAJOR ${PROJECT_VERSION_MAJOR})
183+
set(GOOGLE_CLOUD_CONFIG_VERSION_MINOR ${PROJECT_VERSION_MINOR})
184+
set(GOOGLE_CLOUD_CONFIG_VERSION_PATCH ${PROJECT_VERSION_PATCH})
185+
set(GOOGLE_CLOUD_PC_NAME "The Cloud Document AI API C++ Client Library")
186+
set(GOOGLE_CLOUD_PC_DESCRIPTION
187+
"Provides C++ APIs to use the Cloud Document AI API.")
188+
set(GOOGLE_CLOUD_PC_LIBS "-lgoogle_cloud_cpp_documentai")
189+
string(CONCAT GOOGLE_CLOUD_PC_REQUIRES "google_cloud_cpp_grpc_utils"
190+
" google_cloud_cpp_common" " google_cloud_cpp_documentai_protos")
191+
192+
# Create and install the pkg-config files.
193+
configure_file("${PROJECT_SOURCE_DIR}/google/cloud/documentai/config.pc.in"
194+
"google_cloud_cpp_documentai.pc" @ONLY)
195+
install(
196+
FILES "${CMAKE_CURRENT_BINARY_DIR}/google_cloud_cpp_documentai.pc"
197+
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig"
198+
COMPONENT google_cloud_cpp_development)
199+
200+
# Create and install the CMake configuration files.
201+
include(CMakePackageConfigHelpers)
202+
configure_file("config.cmake.in" "google_cloud_cpp_documentai-config.cmake"
203+
@ONLY)
204+
write_basic_package_version_file(
205+
"google_cloud_cpp_documentai-config-version.cmake"
206+
VERSION ${PROJECT_VERSION}
207+
COMPATIBILITY ExactVersion)
208+
209+
install(
210+
FILES
211+
"${CMAKE_CURRENT_BINARY_DIR}/google_cloud_cpp_documentai-config.cmake"
212+
"${CMAKE_CURRENT_BINARY_DIR}/google_cloud_cpp_documentai-config-version.cmake"
213+
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/google_cloud_cpp_documentai"
214+
COMPONENT google_cloud_cpp_development)
215+
216+
external_googleapis_install_pc("google_cloud_cpp_documentai_protos"
217+
"${PROJECT_SOURCE_DIR}/external/googleapis")

0 commit comments

Comments
 (0)