Commit Graph

28 Commits

Author SHA1 Message Date
Lidi Zheng c34bef4ca4 Format all Bazel files with buildifier 2019-11-05 14:03:52 -08:00
vam-google 5d9eeb34fc Address PR feedback. Also add a dummy plugin. 2019-10-29 16:23:57 -07:00
vam-google d27cbe443a Add an ability to call an optional custom plugin for py_proto_library and py_grpc_library. This is needed for googleapis (it uses a special doc formatter plugin to fix and pritify the docs (comments) in the generated stubs). 2019-10-28 14:47:47 -07:00
vam-google 564dc771dc Return PyInfo provider with imports from _gen rules and pass that as deps in py_library. This allows hiding _virtual_imports include path from the surface. 2019-10-15 17:47:02 -07:00
vam-google 9e6e57bfba Merge remote-tracking branch 'upstream/master' 2019-10-15 17:34:58 -07:00
Richard Belleville 1d1aebb920 Remove unused import 2019-09-17 14:26:49 -07:00
Juanli Shen 0a3b333c04 Fix internal warning 2019-09-09 11:49:06 -07:00
Richard Belleville 3d4f905775
Merge pull request #20141 from gnossen/python_strip_prefixes
Add strip_prefix to python protoc plugin and py_grpc_library
2019-09-06 11:55:58 -05:00
Richard Belleville c11539f79e Document kwargs 2019-09-05 12:32:58 -07:00
Richard Belleville ecf7274aaa Add docstring to py2and3_test 2019-09-05 11:41:36 -07:00
vam 461c053c37 [bazel][python] Support _virtual_imports input for py_proto_library and py_grpc_library rules
`proto_library` targets are used as deps for `py_proto_library` and `py_grpc_library` rules. The `proto_library` targets can be configured using `import_prefix` and/or `strip_import_prefix` (which essentially move original location of the proto file and, as result, affects import path within proto files themselves and in the generated language-specific stubs).

The biggest question to answer when generating stubs from moved protos is where to put result (this decision affects all downstream rules as well, because the location of file affects its import path).

This PR tries to follow same logic as the native `cc_proto_library` (created and maintained by Bazel team). For example, if we have `firestore.proto` file, which is located under `google/firestore/v1beta1` Bazel package and want to move it under `google/cloud/firestore_v1beta1/proto` (this is axactly what happens in googleapis repository), it can be configured the following way:

```bzl
proto_library(
    name = "firestore_moved_proto",
    srcs = ["firestore.proto"],
    import_prefix = "google/cloud/firestore_v1beta1/proto",
    strip_import_prefix = "google/firestore/v1beta1",
)
```

The rule above will first generate virtual `.proto` files (under new location) and only after that generate a binary descriptor from them.
Specifically it will generate the following "virtual" file under `_virtual_imports` subdirectory of same package:

```
bazel-bin/google/firestore/v1beta1/_virtual_imports/firestore_moved_proto/google/cloud/firestore_v1beta1/proto/common.proto
```

When supplied to `cc_proto_library`, like the following:

```bzl
cc_proto_library(
    name = "firestore_moved_cc_proto",
    deps = ["firestore_moved_proto"],
)
```

The rule will generate .cc and .h files like the following:
```
bazel-bin/google/firestore/v1beta1/_virtual_imports/firestore_moved_proto/google/cloud/firestore_v1beta1/proto/firestore.pb.h
bazel-bin/google/firestore/v1beta1/_virtual_imports/firestore_moved_proto/google/cloud/firestore_v1beta1/proto/firestore.pb.cc
```

Notice, that each generated `.cc` and `.h` file is prefixed with `_virtual_imports/<name_of_proto_library_target>`.

The python rules try to do same thing, so for the following py_proto_library rule:

```bzl
py_proto_library(
    name = "firestore_moved_py_proto",
    deps = [":firestore_moved_proto"],
)
```

It wil generate the following file:
```
bazel-bin/google/firestore/v1beta1/_virtual_imports/firestore_moved_proto/google/cloud/firestore_v1beta1/proto/firestore_pb2.py
```

I.e in same path as cc_proto_library.

This all woks, but an annoying part is that to use the generated library in some other py_library, in needs to specify the "_virtual_imports/proto_target" path as its "includes" parameter (and I can't make it better than that).

Another option would be to skeep the `_virtual_imports/<name_of_proto_library_target>` the suffix for the generated python stubs, which will make the path look like the following:
```
bazel-bin/google/firestore/v1beta1/google/cloud/firestore_v1beta1/proto/firestore_pb2.py
```

That will make using generated stubs simpler and cleaner (no need to specify imports argument), but it will make it inconsistent with the other rules (like cc_proto_library) and also more susseptible to naming conflicts (if there is already something under the generated path).
2019-09-02 18:00:40 -07:00
Richard Belleville d649880044 Add strip_prefix to python protoc plugin and py_grpc_library 2019-08-30 16:47:22 -07:00
Richard Belleville 1444cd1dd3 Revert "Revert "Merge pull request #20097 from gnossen/dual_version_python_tests""
This reverts commit 24c562dbaa.
2019-08-29 10:51:36 -07:00
Richard Belleville 24c562dbaa Revert "Merge pull request #20097 from gnossen/dual_version_python_tests"
This reverts commit c9c847f334, reversing
changes made to 07ba4de392.
2019-08-29 10:47:44 -07:00
Richard Belleville 426450cd82 Implement dual testing 2019-08-27 17:22:45 -07:00
Richard Belleville 8ce740cfe0 Switch py_proto_library from using src to deps to conform with google3 2019-08-21 14:24:06 -07:00
Richard Belleville b26b25113f Make soruce file validation exact 2019-08-07 11:22:01 -07:00
Richard Belleville 5fd25f3c7c Refactor rule. 2019-08-06 11:00:54 -07:00
Richard Belleville 4f13303ec4 Validate length of deps in py_grpc_library 2019-08-05 16:46:29 -07:00
Richard Belleville 7b2c8c27b0 Separate py_grpc_library and py_proto_library.
By popular demand, we'll now be offering separate py_grpc_library and
py_proto_library targets sharing the same interface as within google3.
This change necessitated some modifications to how we pull in our own
Python-level dependencies and how we make those available to those
pulling in our project via Bazel.

There is now a grpc_python_deps() Bazel workspace rule that pulls in the
appropriate dependencies, which should be called from the client
project's WORKSPACE file. A test has been added to the bazel/test/
directory to verify that this behavior works as intended.

It's worth noting that the protobuf repository's usage of Starlark
bind() caused a great deal of trouble in ensuring that we could also
pull in six.

This change also required a change in the way generated proto code is
imported in the channelz and health-check modules, as well as in their
associated tests. We were importing them two different ways, each
relative. This resulted in two different module objects being imported
into the process, which were incompatible. I am not sure exactly what
caused this behavior to begin, as this should have been possible before
this PR. As a workaround, I am simply trying two different absolute
imports and using the one that works. This should function both inside
and outside of Bazel environments.
2019-08-01 15:16:22 -07:00
Esun Kim bd5ed4fddd Move compiler targets from /BUILD to /src/compiler/BUILD 2019-07-10 10:53:07 -07:00
Marcel Hlopko ecf04ccf4d Require ProtoInfo in attributes, not "proto" 2019-06-20 18:57:33 +02:00
Marcel Hlopko 49f0fb9035 Migrate from dep.proto to dep[ProtoInfo] 2019-06-20 18:55:56 +02:00
Keith Smiley f131adf89c Fix bazel incompatible changes
When building grpc with the upcoming `--incompatible_depset_is_not_iterable` flag, these violations were found
2019-05-21 17:13:07 -07:00
vam 4c0d9e2f6b Fix well_known_protos issue 2019-05-06 14:29:08 -07:00
Richard Belleville 930cec4e27 Revert "Merge pull request #18912 from grpc/revert-bazel-changes"
This reverts commit c9a259aa3a, reversing
changes made to 9c882bc725.
2019-04-30 11:17:11 -07:00
Richard Belleville 50b5240d0a Revert "Merge pull request #18859 from grpc/internal_py_proto_library"
This reverts commit 5b720f19c1, reversing
changes made to a64ae3c0d5.
2019-04-29 17:47:56 -07:00
Richard Belleville 05f37c8143 Remove dependency on pubref/rules_proto.
This commit resolves #18331.
This commit resolves #18256.
This commit resolves... another TODO that apparently didn't have an
associated github issue.

We swap out pubref's implementation of py_proto_library with our own,
which more closely mirrors the interface of the internal
py_proto_library, taking the descriptor file output of a proto_library
rule as input.

One minor change in behavior was introduced for simplicity. When a
py_proto_library depends on a proto_library with a source proto file in
a subdirectory of the bazel package, the import module of the resultant
python library will reflect the package, *not* the full directory of the
proto file, including both the bazel package and the subdirectories, as
pubref did previously. This behavior also more closely mirrors google
internal behavior.

This commit also introduces a slightly more stringent bazel format
script. Buildifier on its own will not take care of long lines, but by
running yapf first, we end up with a more legible file. At the moment,
there is no sanity check associated with this formatter.
2019-04-24 17:36:08 -07:00