Debian Codegraph @

example-workspace/BUILD

raw
1 # Example C++ binary that uses the generated validation code.
2 #
3 # This binary attempts to read files named on the command line as binary protos.
4 # To try it out, first use Bazel to build this binary:
5 #
6 # bazel build //:example_cc
7 #
8 # Now run it on some files. From the repository root directory:
9 #
10 # bazel run //:example_cc -- $(pwd)/example.cc
11 #
12 # The binary will fail because example.cc is not a valid textproto. Luckily
13 # this directory contains two textprotos already: valid.textproto and
14 # invalid.textproto. From the root directory:
15 #
16 # bazel run //:example_cc -- $(pwd)/valid.textproto
17 #
18 # which succeeds, or
19 #
20 # bazel run //:example_cc -- $(pwd)/invalid.textproto
21 #
22 # which fails.
23 cc_binary(
24 name = "example_cc",
25 srcs = ["example.cc"],
26 deps = ["//foo:bar_cc_proto"],
27 )
28
29 # Example python binary that uses the dynamic python validation code.
30 #
31 # Exactly as example_cc above except different label. Example:
32 #
33 # bazel run //:example_py -- $(pwd)/valid.textproto
34
35 py_binary(
36 name = "example_py",
37 srcs = ["example.py"],
38 main = "example.py",
39 srcs_version = "PY3",
40 deps = [
41 "@com_google_protobuf//:protobuf_python",
42 "@com_envoyproxy_protoc_gen_validate//python:validator_py",
43 "//foo:bar_py_proto",
44 ],
45 )
46
47 # Test that the example textproto inputs evoke the right responses.
48 [
49 sh_test(
50 name = "example_{lang}_test_{which}".format(lang=lang, which=which),
51 srcs = ["example_test.sh"],
52 args = [
53 "$(location :example_{lang})".format(lang=lang),
54 str(code),
55 "$(location :{which})".format(which=which),
56 ],
57 data = [
58 which,
59 ":example_{lang}".format(lang=lang),
60 ],
61 )
62 for lang in (
63 "cc",
64 "py",
65 )
66 for (which, code) in (
67 ("valid.textproto", 0),
68 ("invalid.textproto", 1),
69 )
70 ]