Skip to content

Commit becfb65

Browse files
dmitriplotnikovcopybara-github
authored andcommitted
[cel-types] Add YAML encoding and decoding for CEL TypeDef and aspects.
Introduce `AspectYaml` and `AspectYamlRegistry` in `common/typedef/aspect_yaml` for pluggable YAML encoding and decoding of aspects (e.g. target-schema-specific properties). Implement `TypeDefFromYaml`, `TypeDefsFromYaml`, `TypeDefToYaml`, and `TypeDefsToYaml` in `common/typedef/typedef_yaml`, supporting both concise type signatures (`list<string>`) and structured `TypeSpec` representations as well as delegating `aspects` blocks to registered `AspectYaml` codecs. PiperOrigin-RevId: 993955156
1 parent d10bc43 commit becfb65

34 files changed

Lines changed: 8096 additions & 0 deletions

‎common/typedef/BUILD‎

Lines changed: 313 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,313 @@
1+
# Copyright 2026 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+
load("@com_google_protobuf//bazel:cc_proto_library.bzl", "cc_proto_library")
16+
load("@com_google_protobuf//bazel:proto_library.bzl", "proto_library")
17+
load("@rules_cc//cc:cc_library.bzl", "cc_library")
18+
load("@rules_cc//cc:cc_test.bzl", "cc_test")
19+
20+
package(default_visibility = ["//visibility:public"])
21+
22+
licenses(["notice"])
23+
24+
cc_library(
25+
name = "typedef",
26+
srcs = ["typedef.cc"],
27+
hdrs = ["typedef.h"],
28+
deps = [
29+
"//common:ast",
30+
"//common:constant",
31+
"@com_google_absl//absl/base:core_headers",
32+
"@com_google_absl//absl/base:nullability",
33+
"@com_google_absl//absl/container:flat_hash_map",
34+
"@com_google_absl//absl/functional:overload",
35+
"@com_google_absl//absl/log:absl_check",
36+
"@com_google_absl//absl/status",
37+
"@com_google_absl//absl/strings",
38+
"@com_google_absl//absl/strings:string_view",
39+
],
40+
)
41+
42+
cc_test(
43+
name = "typedef_test",
44+
srcs = ["typedef_test.cc"],
45+
deps = [
46+
":typedef",
47+
"//common:ast",
48+
"//common:constant",
49+
"//internal:testing",
50+
"@com_google_absl//absl/status",
51+
"@com_google_absl//absl/status:status_matchers",
52+
],
53+
)
54+
55+
proto_library(
56+
name = "typedef_protos",
57+
srcs = ["typedef.proto"],
58+
deps = [
59+
"@com_google_cel_spec//proto/cel/expr:checked_proto",
60+
"@com_google_cel_spec//proto/cel/expr:syntax_proto",
61+
],
62+
)
63+
64+
cc_proto_library(
65+
name = "typedef_cc_proto",
66+
deps = [":typedef_protos"],
67+
)
68+
69+
cc_library(
70+
name = "aspect_proto",
71+
srcs = ["aspect_proto.cc"],
72+
hdrs = ["aspect_proto.h"],
73+
deps = [
74+
":typedef_cc_proto",
75+
"@com_google_absl//absl/base:core_headers",
76+
"@com_google_absl//absl/base:nullability",
77+
"@com_google_absl//absl/container:flat_hash_map",
78+
"@com_google_absl//absl/status",
79+
"@com_google_absl//absl/status:statusor",
80+
"@com_google_absl//absl/strings",
81+
"@com_google_absl//absl/strings:string_view",
82+
],
83+
)
84+
85+
cc_test(
86+
name = "aspect_proto_test",
87+
srcs = ["aspect_proto_test.cc"],
88+
deps = [
89+
":aspect_proto",
90+
":typedef_cc_proto",
91+
"//internal:testing",
92+
"@com_google_absl//absl/status",
93+
"@com_google_absl//absl/status:status_matchers",
94+
"@com_google_absl//absl/strings:string_view",
95+
],
96+
)
97+
98+
cc_library(
99+
name = "typedef_proto",
100+
srcs = ["typedef_proto.cc"],
101+
hdrs = ["typedef_proto.h"],
102+
deps = [
103+
":aspect_proto",
104+
":typedef",
105+
":typedef_cc_proto",
106+
"//common:ast",
107+
"//common:constant",
108+
"//common/ast:constant_proto",
109+
"//internal:status_macros",
110+
"@com_google_absl//absl/base:nullability",
111+
"@com_google_absl//absl/container:flat_hash_map",
112+
"@com_google_absl//absl/status",
113+
"@com_google_absl//absl/status:statusor",
114+
"@com_google_absl//absl/types:span",
115+
"@com_google_absl//absl/types:variant",
116+
"@com_google_cel_spec//proto/cel/expr:checked_cc_proto",
117+
"@com_google_protobuf//:struct_cc_proto",
118+
],
119+
)
120+
121+
cc_library(
122+
name = "proto_schema",
123+
hdrs = ["proto_schema.h"],
124+
deps = [
125+
"@com_google_absl//absl/base:core_headers",
126+
"@com_google_absl//absl/strings:string_view",
127+
],
128+
)
129+
130+
proto_library(
131+
name = "proto_schema_protos",
132+
srcs = ["proto_schema.proto"],
133+
deps = [":typedef_protos"],
134+
)
135+
136+
cc_proto_library(
137+
name = "proto_schema_cc_proto",
138+
deps = [":proto_schema_protos"],
139+
)
140+
141+
cc_library(
142+
name = "proto_schema_proto",
143+
srcs = ["proto_schema_proto.cc"],
144+
hdrs = ["proto_schema_proto.h"],
145+
deps = [
146+
":aspect_proto",
147+
":proto_schema",
148+
":proto_schema_cc_proto",
149+
":typedef_cc_proto",
150+
"@com_google_absl//absl/base:nullability",
151+
"@com_google_absl//absl/status",
152+
"@com_google_absl//absl/status:statusor",
153+
"@com_google_absl//absl/strings",
154+
"@com_google_absl//absl/strings:string_view",
155+
],
156+
)
157+
158+
cc_test(
159+
name = "proto_schema_proto_test",
160+
srcs = ["proto_schema_proto_test.cc"],
161+
deps = [
162+
":aspect_proto",
163+
":proto_schema",
164+
":proto_schema_cc_proto",
165+
":proto_schema_proto",
166+
":typedef_cc_proto",
167+
"//internal:testing",
168+
"@com_google_absl//absl/status",
169+
"@com_google_absl//absl/status:status_matchers",
170+
"@com_google_protobuf//:protobuf",
171+
],
172+
)
173+
174+
cc_test(
175+
name = "typedef_proto_test",
176+
srcs = ["typedef_proto_test.cc"],
177+
data = [
178+
"//common/typedef/testdata:typedef_testdata",
179+
],
180+
deps = [
181+
":aspect_proto",
182+
":proto_schema_proto",
183+
":typedef",
184+
":typedef_cc_proto",
185+
":typedef_proto",
186+
"//internal:proto_matchers",
187+
"//internal:runfiles",
188+
"//internal:testing",
189+
"@com_google_absl//absl/status",
190+
"@com_google_absl//absl/status:status_matchers",
191+
"@com_google_absl//absl/status:statusor",
192+
"@com_google_absl//absl/strings",
193+
"@com_google_absl//absl/strings:string_view",
194+
"@com_google_protobuf//:protobuf",
195+
],
196+
)
197+
198+
cc_library(
199+
name = "yaml_helpers",
200+
srcs = ["yaml_helpers.cc"],
201+
hdrs = ["yaml_helpers.h"],
202+
copts = ["-fexceptions"],
203+
features = ["-use_header_modules"],
204+
deps = [
205+
"@com_google_absl//absl/status",
206+
"@com_google_absl//absl/status:statusor",
207+
"@com_google_absl//absl/strings",
208+
"@com_google_absl//absl/strings:string_view",
209+
"@yaml-cpp",
210+
],
211+
)
212+
213+
cc_library(
214+
name = "aspect_yaml",
215+
srcs = ["aspect_yaml.cc"],
216+
hdrs = ["aspect_yaml.h"],
217+
deps = [
218+
":yaml_helpers",
219+
"@com_google_absl//absl/base:nullability",
220+
"@com_google_absl//absl/container:flat_hash_map",
221+
"@com_google_absl//absl/status",
222+
"@com_google_absl//absl/status:statusor",
223+
"@com_google_absl//absl/strings",
224+
"@com_google_absl//absl/strings:string_view",
225+
],
226+
)
227+
228+
cc_test(
229+
name = "aspect_yaml_test",
230+
srcs = ["aspect_yaml_test.cc"],
231+
copts = ["-fexceptions"],
232+
features = ["-use_header_modules"],
233+
deps = [
234+
":aspect_yaml",
235+
"//internal:testing",
236+
"@com_google_absl//absl/status",
237+
"@com_google_absl//absl/status:status_matchers",
238+
"@com_google_absl//absl/strings:string_view",
239+
"@yaml-cpp",
240+
],
241+
)
242+
243+
cc_library(
244+
name = "typedef_yaml",
245+
srcs = ["typedef_yaml.cc"],
246+
hdrs = [
247+
"typedef_yaml.h",
248+
],
249+
copts = ["-fexceptions"],
250+
features = ["-use_header_modules"],
251+
deps = [
252+
":aspect_yaml",
253+
":typedef",
254+
":yaml_helpers",
255+
"//common:ast",
256+
"//common:constant",
257+
"//common:signature",
258+
"//internal:status_macros",
259+
"//internal:strings",
260+
"@com_google_absl//absl/algorithm:container",
261+
"@com_google_absl//absl/base:nullability",
262+
"@com_google_absl//absl/container:flat_hash_map",
263+
"@com_google_absl//absl/status",
264+
"@com_google_absl//absl/status:statusor",
265+
"@com_google_absl//absl/strings",
266+
"@com_google_absl//absl/strings:str_format",
267+
"@com_google_absl//absl/strings:string_view",
268+
"@com_google_absl//absl/time",
269+
"@yaml-cpp",
270+
],
271+
)
272+
273+
cc_test(
274+
name = "typedef_yaml_test",
275+
srcs = ["typedef_yaml_test.cc"],
276+
copts = ["-fexceptions"],
277+
data = [
278+
"//common/typedef/testdata:typedef_testdata",
279+
],
280+
features = ["-use_header_modules"],
281+
deps = [
282+
":aspect_yaml",
283+
":typedef",
284+
":typedef_cc_proto",
285+
":typedef_proto",
286+
":typedef_yaml",
287+
":yaml_helpers",
288+
":yaml_test_helpers",
289+
"//internal:proto_matchers",
290+
"//internal:runfiles",
291+
"//internal:status_macros",
292+
"//internal:testing",
293+
"@com_google_absl//absl/log:absl_log",
294+
"@com_google_absl//absl/status",
295+
"@com_google_absl//absl/status:status_matchers",
296+
"@com_google_absl//absl/status:statusor",
297+
"@com_google_absl//absl/strings",
298+
"@com_google_absl//absl/strings:string_view",
299+
"@com_google_protobuf//:protobuf",
300+
"@yaml-cpp",
301+
],
302+
)
303+
304+
cc_library(
305+
name = "yaml_test_helpers",
306+
testonly = True,
307+
srcs = ["yaml_test_helpers.cc"],
308+
hdrs = ["yaml_test_helpers.h"],
309+
deps = [
310+
"@com_google_absl//absl/strings",
311+
"@com_google_absl//absl/strings:string_view",
312+
],
313+
)

0 commit comments

Comments
 (0)