BUILD 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. # Example python binary that uses the dynamic python validation code.
  29. #
  30. # Exactly as example_cc above except different label. Example:
  31. #
  32. # bazel run //:example_py -- $(pwd)/valid.textproto
  33. py_binary(
  34. name = "example_py",
  35. srcs = ["example.py"],
  36. main = "example.py",
  37. srcs_version = "PY3",
  38. deps = [
  39. "@com_google_protobuf//:protobuf_python",
  40. "@com_envoyproxy_protoc_gen_validate//python:validator_py",
  41. "//foo:bar_py_proto",
  42. ],
  43. )
  44. # Test that the example textproto inputs evoke the right responses.
  45. [
  46. sh_test(
  47. name = "example_{lang}_test_{which}".format(lang=lang, which=which),
  48. srcs = ["example_test.sh"],
  49. args = [
  50. "$(location :example_{lang})".format(lang=lang),
  51. str(code),
  52. "$(location :{which})".format(which=which),
  53. ],
  54. data = [
  55. which,
  56. ":example_{lang}".format(lang=lang),
  57. ],
  58. )
  59. for lang in (
  60. "cc",
  61. "py",
  62. )
  63. for (which, code) in (
  64. ("valid.textproto", 0),
  65. ("invalid.textproto", 1),
  66. )
  67. ]