All this mirrors include_prefix / strip_include_prefix in cc_library except that strip_import_prefix will default to the package name if import_prefix is specified. This is to support the common use case of having a proto_library in a package and wanting to tell which directory it should be imported under.
All this mirrors include_prefix / strip_include_prefix in cc_library except that strip_import_prefix will default to the package name if import_prefix is specified. This is to support the common use case of having a proto_library in a package and wanting to tell which directory it should be imported under.Does this mean if I have a file `myservice/proto/main.proto` and I give its target `import_prefix = "github.com/company/team"`, that the resulting proto would be importable at (a) `github.com/company/team/main.proto` or (b) `github.com/company/team/myservice/proto/main.proto` ?If (a), that would be pretty surprising behavior and contrary to what I want in ~all cases.
Given that `package_name()` exists and can be used from BUILD files, it seems like the better approach would be to not change the default behavior of strip_import_prefix, and ask users to explicitly write something like this if they want that behavior:
```proto_library(name = "foo_proto",srcs = ["foo.proto"],import_prefix = "completely/different/prefix",strip_import_prefix = package_name(),)```On Tue, Nov 27, 2018 at 4:14 AM Lukács T. Berki <lbe...@google.com> wrote:Hey there,I'm planning to add two attributes to proto_library:
- strip_import_prefix: if specified, this path is removed from the import paths of the .proto files in the proto_library, e.g. "a/b/c.proto" can be included as "b/c.proto" if strip_import_prefix is set to "a".
- import_prefix: if specified, this path is prepended to the import paths of the .proto files in the proto_library, e.g. "x/y.proto" can be included as "z/x/y.proto" if import_prefix is set to "z".
- If both are set, strip_import_prefix is applied first and then import_prefix.
All this mirrors include_prefix / strip_include_prefix in cc_library except that strip_import_prefix will default to the package name if import_prefix is specified. This is to support the common use case of having a proto_library in a package and wanting to tell which directory it should be imported under.This is implemented in a rudimentary way here: https://github.com/lberki/bazel/commit/0b3653612aa5f13325cc125e586ac2569e80ff48And a Bazel source tree is available for experimenting here: https://github.com/lberki/bazel/This will fix #3867 if all goes well. I'm hoping to land this this week so that it gets into Bazel 0.21, so if you see any horrible flaws in the idea, speak now or keep your peace forever.--Lukács T. Berki | Software Engineer | lbe...@google.com |Google Germany GmbH | Erika-Mann-Str. 33 | 80636 München | Germany | Geschäftsführer: Paul Manicle, Halimah DeLaine Prado | Registergericht und -nummer: Hamburg, HRB 86891
That is useful, thanks.What are the import paths in both of those situations?
import "company/project/proto/whatever.proto";
import "whatever.proto";
On Tue, Nov 27, 2018 at 9:42 PM Dmitry Lomov <dsl...@google.com> wrote:That is useful, thanks.What are the import paths in both of those situations?Language-specific, matching conventions of library imports for whatever the "main language" is. Protobufs written by Go devs have URL-ish prefixes:Protobufs in other languages tend to follow Google's example, where the first couple components are abstract namespaces:import "company/project/proto/whatever.proto";
If you want Protobuf schemas to start following a particular convention then I think that's an admirable goal, but you should not try to enforce those future conventions in today's build system.
Makefile
main.goproto/
types.protoservice.proto
import "proto/types.proto";
proto_library(..., import_prefix = "k8s.io/api")
For (3), we've always used a local_repository to make the vendored workspace be treated as an external dependency with "standard" package resolution rules. This means that vendored BUILD files don't need to be modified, and any .proto import paths are resolved relative to the vendored subdir rather than the top-level workspace.
"how should vendoring be done" .... you had my curiosity, now you have my attention.
--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/CAOu%2B0LVXUFb7e15YGLNmxgARxKUBVvzkWd-16A755JBa%2B%2Bt55A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discuss+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/CAOu%2B0LVXUFb7e15YGLNmxgARxKUBVvzkWd-16A755JBa%2B%2Bt55A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/CAOu%2B0LVXUFb7e15YGLNmxgARxKUBVvzkWd-16A755JBa%2B%2Bt55A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
--Lukács T. Berki | Software Engineer | lbe...@google.com |Google Germany GmbH | Erika-Mann-Str. 33 | 80636 München | Germany | Geschäftsführer: Paul Manicle, Halimah DeLaine Prado | Registergericht und -nummer: Hamburg, HRB 86891
protoc \-Igoogle/protobuf/any.proto=external/com_google_protobuf/src/google/protobuf/any.proto \
-Igoogle/rpc/status.proto=external/com_google_googleapis/google/rpc/status.proto \
-Ik8s.io/api/core/v1/generated.proto=external/com_github_kubernetes_api/core/v1/generated.proto \[...]