xref: /aosp_15_r20/external/sandboxed-api/sandboxed_api/util/BUILD.bazel (revision ec63e07ab9515d95e79c211197c445ef84cefa6a)
1# Copyright 2019 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
15load("//sandboxed_api/bazel:build_defs.bzl", "sapi_platform_copts")
16load("//sandboxed_api/bazel:proto.bzl", "sapi_proto_library")
17
18package(
19    default_visibility = [
20        "//sandboxed_api:__subpackages__",
21        "//security/bedebox:__subpackages__",
22    ],
23)
24
25licenses(["notice"])
26
27# Another helper library with filesystem and path utility functions.
28cc_library(
29    name = "file_base",
30    srcs = ["path.cc"],
31    hdrs = ["path.h"],
32    copts = sapi_platform_copts(),
33    deps = ["@com_google_absl//absl/strings"],
34)
35
36cc_test(
37    name = "file_base_test",
38    size = "small",
39    srcs = ["path_test.cc"],
40    copts = sapi_platform_copts(),
41    deps = [
42        ":file_base",
43        "@com_google_absl//absl/strings",
44        "@com_google_googletest//:gtest_main",
45    ],
46)
47
48# String file routines
49cc_library(
50    name = "file_helpers",
51    srcs = ["file_helpers.cc"],
52    hdrs = ["file_helpers.h"],
53    copts = sapi_platform_copts(),
54    deps = [
55        "@com_google_absl//absl/status",
56        "@com_google_absl//absl/strings",
57    ],
58)
59
60cc_test(
61    name = "file_helpers_test",
62    size = "small",
63    srcs = ["file_helpers_test.cc"],
64    copts = sapi_platform_copts(),
65    deps = [
66        ":file_helpers",
67        ":status_matchers",
68        "@com_google_googletest//:gtest_main",
69    ],
70)
71
72# Portable filesystem and path utility functions
73cc_library(
74    name = "fileops",
75    srcs = ["fileops.cc"],
76    hdrs = ["fileops.h"],
77    copts = sapi_platform_copts(),
78    deps = [
79        ":strerror",
80        "@com_google_absl//absl/strings",
81    ],
82)
83
84cc_test(
85    name = "fileops_test",
86    size = "small",
87    srcs = ["fileops_test.cc"],
88    copts = sapi_platform_copts(),
89    deps = [
90        ":file_helpers",
91        ":fileops",
92        ":status_matchers",
93        "//sandboxed_api:testing",
94        "@com_google_absl//absl/strings",
95        "@com_google_googletest//:gtest_main",
96    ],
97)
98
99# Small support library emulating verbose logging using Abseil's raw logging
100# facility.
101cc_library(
102    name = "raw_logging",
103    srcs = ["raw_logging.cc"],
104    hdrs = ["raw_logging.h"],
105    copts = sapi_platform_copts(),
106    deps = [
107        ":strerror",
108        "@com_google_absl//absl/base:config",
109        "@com_google_absl//absl/base:core_headers",
110        "@com_google_absl//absl/base:log_severity",
111        "@com_google_absl//absl/strings",
112        "@com_google_absl//absl/strings:str_format",
113    ],
114)
115
116cc_library(
117    name = "runfiles",
118    srcs = ["runfiles_bazel.cc"],
119    hdrs = ["runfiles.h"],
120    copts = sapi_platform_copts(),
121    visibility = ["//visibility:public"],
122    deps = [
123        ":file_base",
124        ":raw_logging",
125        "@bazel_tools//tools/cpp/runfiles",
126        "@com_google_absl//absl/strings",
127        "@com_google_absl//absl/strings:str_format",
128    ],
129)
130
131sapi_proto_library(
132    name = "status_proto",
133    srcs = ["status.proto"],
134)
135
136# Implementations of utility functions not released with absl::Status.
137cc_library(
138    name = "status",
139    srcs = ["status.cc"],
140    hdrs = [
141        "status.h",
142        "status_macros.h",
143    ],
144    copts = sapi_platform_copts(),
145    visibility = ["//visibility:public"],
146    deps = [
147        ":status_cc_proto",
148        "@com_google_absl//absl/base:core_headers",
149        "@com_google_absl//absl/status",
150        "@com_google_absl//absl/strings",
151        "@com_google_absl//absl/strings:cord",
152    ],
153)
154
155# gMock matchers for absl::Status and absl::StatusOr<T> and a gUnit printer
156# extension. Adapted from the version in Asylo.
157cc_library(
158    name = "status_matchers",
159    testonly = 1,
160    hdrs = ["status_matchers.h"],
161    copts = sapi_platform_copts(),
162    visibility = ["//visibility:public"],
163    deps = [
164        ":status",
165        "@com_google_absl//absl/status",
166        "@com_google_absl//absl/status:statusor",
167        "@com_google_absl//absl/strings:string_view",
168        "@com_google_absl//absl/types:optional",
169        "@com_google_googletest//:gtest",
170    ],
171)
172
173# Tests for the Status utility.
174cc_test(
175    name = "status_test",
176    srcs = ["status_test.cc"],
177    copts = sapi_platform_copts(),
178    deps = [
179        ":status",
180        "@com_google_absl//absl/status",
181        "@com_google_absl//absl/strings:string_view",
182        "@com_google_googletest//:gtest_main",
183    ],
184)
185
186# Tests for the Status macros.
187cc_test(
188    name = "status_macros_test",
189    srcs = ["status_macros_test.cc"],
190    copts = sapi_platform_copts(),
191    deps = [
192        ":status",
193        ":status_matchers",
194        "@com_google_absl//absl/status",
195        "@com_google_absl//absl/status:statusor",
196        "@com_google_absl//absl/strings",
197        "@com_google_googletest//:gtest_main",
198    ],
199)
200
201# Internal thread-safe helper to format system error messages. Mostly
202# equivalent to base/strerror.h.
203cc_library(
204    name = "strerror",
205    srcs = ["strerror.cc"],
206    hdrs = ["strerror.h"],
207    copts = sapi_platform_copts(),
208    deps = [
209        "@com_google_absl//absl/base:core_headers",
210        "@com_google_absl//absl/strings:str_format",
211    ],
212)
213
214cc_test(
215    name = "strerror_test",
216    srcs = ["strerror_test.cc"],
217    copts = sapi_platform_copts(),
218    deps = [
219        ":strerror",
220        "@com_google_absl//absl/strings",
221        "@com_google_googletest//:gtest_main",
222    ],
223)
224
225cc_library(
226    name = "temp_file",
227    srcs = ["temp_file.cc"],
228    hdrs = ["temp_file.h"],
229    copts = sapi_platform_copts(),
230    deps = [
231        ":status",
232        "@com_google_absl//absl/status",
233        "@com_google_absl//absl/status:statusor",
234        "@com_google_absl//absl/strings",
235    ],
236)
237
238cc_test(
239    name = "temp_file_test",
240    srcs = ["temp_file_test.cc"],
241    copts = sapi_platform_copts(),
242    deps = [
243        ":file_base",
244        ":fileops",
245        ":status_matchers",
246        ":temp_file",
247        "//sandboxed_api:testing",
248        "@com_google_absl//absl/status",
249        "@com_google_absl//absl/status:statusor",
250        "@com_google_googletest//:gtest_main",
251    ],
252)
253