| 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 |
|
| 17 |
load("@rules_proto//proto:defs.bzl", "proto_library") |
| 18 |
load( |
| 19 |
"@com_github_grpc_grpc//bazel:python_rules.bzl", |
| 20 |
"py_grpc_library", |
| 21 |
"py_proto_library", |
| 22 |
) |
| 23 |
|
| 24 |
package( |
| 25 |
default_testonly = 1, |
| 26 |
) |
| 27 |
|
| 28 |
proto_library( |
| 29 |
name = "helloworld_proto", |
| 30 |
srcs = ["helloworld.proto"], |
| 31 |
deps = [ |
| 32 |
":hello_dep_proto", |
| 33 |
"@com_google_protobuf//:duration_proto", |
| 34 |
"@com_google_protobuf//:timestamp_proto", |
| 35 |
], |
| 36 |
) |
| 37 |
|
| 38 |
# Test that .proto files can be located in strict subdiretories of the package. |
| 39 |
proto_library( |
| 40 |
name = "hello_dep_proto", |
| 41 |
srcs = ["subdir/hello_dep.proto"], |
| 42 |
) |
| 43 |
|
| 44 |
py_proto_library( |
| 45 |
name = "helloworld_py_pb2", |
| 46 |
deps = [":helloworld_proto"], |
| 47 |
) |
| 48 |
|
| 49 |
py_grpc_library( |
| 50 |
name = "helloworld_py_pb2_grpc", |
| 51 |
srcs = [":helloworld_proto"], |
| 52 |
deps = [":helloworld_py_pb2"], |
| 53 |
) |
| 54 |
|
| 55 |
py_proto_library( |
| 56 |
name = "duration_py_pb2", |
| 57 |
deps = ["@com_google_protobuf//:duration_proto"], |
| 58 |
) |
| 59 |
|
| 60 |
py_proto_library( |
| 61 |
name = "timestamp_py_pb2", |
| 62 |
deps = ["@com_google_protobuf//:timestamp_proto"], |
| 63 |
) |
| 64 |
|
| 65 |
py_test( |
| 66 |
name = "import_test", |
| 67 |
srcs = ["helloworld.py"], |
| 68 |
main = "helloworld.py", |
| 69 |
python_version = "PY3", |
| 70 |
deps = [ |
| 71 |
":duration_py_pb2", |
| 72 |
":helloworld_py_pb2", |
| 73 |
":helloworld_py_pb2_grpc", |
| 74 |
":timestamp_py_pb2", |
| 75 |
], |
| 76 |
) |
| 77 |
|
| 78 |
# Test compatibility of py_proto_library and py_grpc_library rules with |
| 79 |
# proto_library targets as deps when the latter use import_prefix and/or |
| 80 |
# strip_import_prefix arguments |
| 81 |
# |
| 82 |
# See namespaced/upper/example for more encompassing tests. |
| 83 |
proto_library( |
| 84 |
name = "helloworld_moved_proto", |
| 85 |
srcs = ["helloworld.proto"], |
| 86 |
import_prefix = "google/cloud", |
| 87 |
strip_import_prefix = "", |
| 88 |
deps = [ |
| 89 |
":hello_dep_proto", |
| 90 |
"@com_google_protobuf//:duration_proto", |
| 91 |
"@com_google_protobuf//:timestamp_proto", |
| 92 |
], |
| 93 |
) |
| 94 |
|
| 95 |
py_proto_library( |
| 96 |
name = "helloworld_moved_py_pb2", |
| 97 |
deps = [":helloworld_moved_proto"], |
| 98 |
) |
| 99 |
|
| 100 |
py_grpc_library( |
| 101 |
name = "helloworld_moved_py_pb2_grpc", |
| 102 |
srcs = [":helloworld_moved_proto"], |
| 103 |
deps = [":helloworld_moved_py_pb2"], |
| 104 |
) |
| 105 |
|
| 106 |
py_test( |
| 107 |
name = "import_moved_test", |
| 108 |
srcs = ["helloworld_moved.py"], |
| 109 |
main = "helloworld_moved.py", |
| 110 |
python_version = "PY3", |
| 111 |
deps = [ |
| 112 |
":duration_py_pb2", |
| 113 |
":helloworld_moved_py_pb2", |
| 114 |
":helloworld_moved_py_pb2_grpc", |
| 115 |
":timestamp_py_pb2", |
| 116 |
], |
| 117 |
) |
| 118 |
|
| 119 |
# Test that a py_proto_library wrapping a proto_library in another package can |
| 120 |
# be imported from the package that contains the py_proto_library *AND* from |
| 121 |
# the package that contains the proto_library. |
| 122 |
py_proto_library( |
| 123 |
name = "subpackage_py_pb2", |
| 124 |
deps = ["//in_subpackage:subpackage_proto"], |
| 125 |
) |
| 126 |
|
| 127 |
py_test( |
| 128 |
name = "import_from_this_package_subpackage_test", |
| 129 |
srcs = ["import_from_this_package.py"], |
| 130 |
main = "import_from_this_package.py", |
| 131 |
python_version = "PY3", |
| 132 |
deps = [ |
| 133 |
":subpackage_py_pb2", |
| 134 |
], |
| 135 |
) |
| 136 |
|
| 137 |
py_test( |
| 138 |
name = "import_from_proto_library_package_test", |
| 139 |
srcs = ["import_from_proto_library_package.py"], |
| 140 |
main = "import_from_proto_library_package.py", |
| 141 |
python_version = "PY3", |
| 142 |
deps = [ |
| 143 |
":subpackage_py_pb2", |
| 144 |
], |
| 145 |
) |
| 146 |
|
| 147 |
# Test that a py_proto_library can be successfully imported without requiring |
| 148 |
# explicit dependencies on unused dependencies of the generated code. |
| 149 |
py_test( |
| 150 |
name = "transitive_proto_dep_test", |
| 151 |
srcs = ["transitive_proto_dep.py"], |
| 152 |
main = "transitive_proto_dep.py", |
| 153 |
python_version = "PY3", |
| 154 |
deps = [ |
| 155 |
":helloworld_py_pb2", |
| 156 |
], |
| 157 |
) |