BUILD 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. # gRPC Bazel BUILD file.
  2. #
  3. # Copyright 2019 The gRPC authors.
  4. #
  5. # Licensed under the Apache License, Version 2.0 (the "License");
  6. # you may not use this file except in compliance with the License.
  7. # You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing, software
  12. # distributed under the License is distributed on an "AS IS" BASIS,
  13. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. # See the License for the specific language governing permissions and
  15. # limitations under the License.
  16. load("@rules_proto//proto:defs.bzl", "proto_library")
  17. load(
  18. "@com_github_grpc_grpc//bazel:python_rules.bzl",
  19. "py_grpc_library",
  20. "py_proto_library",
  21. )
  22. package(
  23. default_testonly = 1,
  24. )
  25. proto_library(
  26. name = "helloworld_proto",
  27. srcs = ["helloworld.proto"],
  28. deps = [
  29. ":hello_dep_proto",
  30. "@com_google_protobuf//:duration_proto",
  31. "@com_google_protobuf//:timestamp_proto",
  32. ],
  33. )
  34. # Test that .proto files can be located in strict subdiretories of the package.
  35. proto_library(
  36. name = "hello_dep_proto",
  37. srcs = ["subdir/hello_dep.proto"],
  38. )
  39. py_proto_library(
  40. name = "helloworld_py_pb2",
  41. deps = [":helloworld_proto"],
  42. )
  43. py_grpc_library(
  44. name = "helloworld_py_pb2_grpc",
  45. srcs = [":helloworld_proto"],
  46. deps = [":helloworld_py_pb2"],
  47. )
  48. py_proto_library(
  49. name = "duration_py_pb2",
  50. deps = ["@com_google_protobuf//:duration_proto"],
  51. )
  52. py_proto_library(
  53. name = "timestamp_py_pb2",
  54. deps = ["@com_google_protobuf//:timestamp_proto"],
  55. )
  56. py_test(
  57. name = "import_test",
  58. srcs = ["helloworld.py"],
  59. main = "helloworld.py",
  60. python_version = "PY3",
  61. deps = [
  62. ":duration_py_pb2",
  63. ":helloworld_py_pb2",
  64. ":helloworld_py_pb2_grpc",
  65. ":timestamp_py_pb2",
  66. ],
  67. )
  68. # Test compatibility of py_proto_library and py_grpc_library rules with
  69. # proto_library targets as deps when the latter use import_prefix and/or
  70. # strip_import_prefix arguments
  71. #
  72. # See namespaced/upper/example for more encompassing tests.
  73. proto_library(
  74. name = "helloworld_moved_proto",
  75. srcs = ["helloworld.proto"],
  76. import_prefix = "google/cloud",
  77. strip_import_prefix = "",
  78. deps = [
  79. ":hello_dep_proto",
  80. "@com_google_protobuf//:duration_proto",
  81. "@com_google_protobuf//:timestamp_proto",
  82. ],
  83. )
  84. py_proto_library(
  85. name = "helloworld_moved_py_pb2",
  86. deps = [":helloworld_moved_proto"],
  87. )
  88. py_grpc_library(
  89. name = "helloworld_moved_py_pb2_grpc",
  90. srcs = [":helloworld_moved_proto"],
  91. deps = [":helloworld_moved_py_pb2"],
  92. )
  93. py_test(
  94. name = "import_moved_test",
  95. srcs = ["helloworld_moved.py"],
  96. main = "helloworld_moved.py",
  97. python_version = "PY3",
  98. deps = [
  99. ":duration_py_pb2",
  100. ":helloworld_moved_py_pb2",
  101. ":helloworld_moved_py_pb2_grpc",
  102. ":timestamp_py_pb2",
  103. ],
  104. )
  105. # Test that a py_proto_library wrapping a proto_library in another package can
  106. # be imported from the package that contains the py_proto_library *AND* from
  107. # the package that contains the proto_library.
  108. py_proto_library(
  109. name = "subpackage_py_pb2",
  110. deps = ["//in_subpackage:subpackage_proto"],
  111. )
  112. py_test(
  113. name = "import_from_this_package_subpackage_test",
  114. srcs = ["import_from_this_package.py"],
  115. main = "import_from_this_package.py",
  116. python_version = "PY3",
  117. deps = [
  118. ":subpackage_py_pb2",
  119. ],
  120. )
  121. py_test(
  122. name = "import_from_proto_library_package_test",
  123. srcs = ["import_from_proto_library_package.py"],
  124. main = "import_from_proto_library_package.py",
  125. python_version = "PY3",
  126. deps = [
  127. ":subpackage_py_pb2",
  128. ],
  129. )
  130. # Test that a py_proto_library can be successfully imported without requiring
  131. # explicit dependencies on unused dependencies of the generated code.
  132. py_test(
  133. name = "transitive_proto_dep_test",
  134. srcs = ["transitive_proto_dep.py"],
  135. main = "transitive_proto_dep.py",
  136. python_version = "PY3",
  137. deps = [
  138. ":helloworld_py_pb2",
  139. ],
  140. )