Skip to content

Commit 1ddbca7

Browse files
jnthntatumdmitriplotnikov
authored andcommitted
Export policy compiler.
Co-authored-by: Dmitri Plotnikov <dplotnikov@google.com> PiperOrigin-RevId: 930699321
1 parent 9597d49 commit 1ddbca7

42 files changed

Lines changed: 7638 additions & 1 deletion

Some content is hidden

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

MODULE.bazel

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ bazel_dep(
3131
name = "rules_python",
3232
version = "1.6.3",
3333
)
34+
bazel_dep(name = "rules_license", version = "1.0.0")
3435
bazel_dep(
3536
name = "protobuf",
3637
version = "34.1",
@@ -96,3 +97,16 @@ bazel_dep(
9697
name = "yaml-cpp",
9798
version = "0.9.0",
9899
)
100+
101+
_CEL_POLICY_TAG = "ebfb2361f47080af643c14cf4da4c2b551a68740"
102+
103+
_CEL_POLICY_SHA = "ea69e9c6b7bd5bc37d358148aebd2fcca38bc7c45a23feb635de72338e0327c1"
104+
105+
http_archive = use_repo_rule("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
106+
107+
http_archive(
108+
name = "cel_policy",
109+
sha256 = _CEL_POLICY_SHA,
110+
strip_prefix = "cel-policy-%s" % _CEL_POLICY_TAG,
111+
url = "https://github.com/cel-expr/cel-policy/archive/%s.tar.gz" % _CEL_POLICY_TAG,
112+
)

conformance/policy/BUILD

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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("@rules_cc//cc:cc_library.bzl", "cc_library")
16+
load(
17+
"//conformance/policy:policy_conformance_test.bzl",
18+
"cel_policy_conformance_test",
19+
)
20+
21+
package(default_visibility = ["//visibility:public"])
22+
23+
cc_library(
24+
name = "policy_conformance_test_lib",
25+
testonly = True,
26+
srcs = ["policy_conformance_test.cc"],
27+
deps = [
28+
"//common:ast",
29+
"//common:source",
30+
"//common:value",
31+
"//common/internal:value_conversion",
32+
"//compiler",
33+
"//env",
34+
"//env:config",
35+
"//env:env_runtime",
36+
"//env:env_std_extensions",
37+
"//env:env_yaml",
38+
"//env:runtime_std_extensions",
39+
"//extensions/protobuf:bind_proto_to_activation",
40+
"//extensions/protobuf:enum_adapter",
41+
"//internal:runfiles",
42+
"//internal:status_macros",
43+
"//internal:testing_descriptor_pool",
44+
"//internal:testing_no_main",
45+
"//policy:cel_policy",
46+
"//policy:cel_policy_parser",
47+
"//policy:cel_policy_validation_result",
48+
"//policy:compiler",
49+
"//policy:test_util",
50+
"//policy:yaml_policy_parser",
51+
"//runtime",
52+
"//runtime:activation",
53+
"//runtime:function_adapter",
54+
"@com_google_absl//absl/flags:flag",
55+
"@com_google_absl//absl/log:absl_check",
56+
"@com_google_absl//absl/memory",
57+
"@com_google_absl//absl/status",
58+
"@com_google_absl//absl/status:statusor",
59+
"@com_google_absl//absl/strings",
60+
"@com_google_cel_spec//proto/cel/expr:value_cc_proto",
61+
"@com_google_cel_spec//proto/cel/expr/conformance/test:suite_cc_proto",
62+
"@com_google_protobuf//:protobuf",
63+
],
64+
alwayslink = True,
65+
)
66+
67+
cel_policy_conformance_test(
68+
name = "policy_conformance_test",
69+
example = "@cel_policy//conformance:testdata/nested_rule/policy.yaml",
70+
skip_tests = [
71+
# TODO(b/506179116): Fix these.
72+
# Need to add k8s custom yaml parser and mock runtime.
73+
"k8s",
74+
],
75+
test_files = [
76+
"@cel_policy//conformance:testdata",
77+
],
78+
)
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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+
"""
16+
This module contains build rules for generating policy conformance test targets.
17+
"""
18+
19+
load("@rules_cc//cc:cc_test.bzl", "cc_test")
20+
21+
def cel_policy_conformance_test(name, test_files, example, skip_tests = [], **kwargs):
22+
"""Generates a policy conformance test target.
23+
24+
Args:
25+
name: Name of the test target.
26+
test_files: List of targets or files representing the test data.
27+
example: A specific example file from test_files used for runfiles resolution.
28+
skip_tests: List of test cases to skip.
29+
testdata_dir: Path to testdata directory under runfiles.
30+
**kwargs: Additional arguments passed to the underlying cc_test.
31+
"""
32+
args = ["--gunit_fail_if_no_test_linked"]
33+
args.append("--testdata_example='$(rlocationpath {})'".format(example))
34+
35+
if skip_tests:
36+
args.append("--skip_tests=" + ",".join(skip_tests))
37+
38+
cc_test(
39+
name = name,
40+
data = test_files + [example],
41+
deps = [
42+
"//conformance/policy:policy_conformance_test_lib",
43+
],
44+
args = args,
45+
**kwargs
46+
)

0 commit comments

Comments
 (0)