From 3f03418333a62c5cf2ef4a8959b63c5face0f5a3 Mon Sep 17 00:00:00 2001 From: Napas Date: Mon, 17 Aug 2020 11:49:58 -0700 Subject: [PATCH 1/3] add importpath_aliases to go_proto_library --- proto/def.bzl | 1 + 1 file changed, 1 insertion(+) diff --git a/proto/def.bzl b/proto/def.bzl index 0aa7120165..80ba9d5546 100644 --- a/proto/def.bzl +++ b/proto/def.bzl @@ -152,6 +152,7 @@ go_proto_library = go_rule( ), "importpath": attr.string(), "importmap": attr.string(), + "importpath_aliases": attr.string_list(), # experimental, undocumented "embed": attr.label_list(providers = [GoLibrary]), "gc_goopts": attr.string_list(), "compiler": attr.label(providers = [GoProtoCompiler]), From 902b83267446cb3f191a4279a84313f0903bb137 Mon Sep 17 00:00:00 2001 From: Napas Date: Mon, 17 Aug 2020 15:43:46 -0700 Subject: [PATCH 2/3] add test --- tests/core/go_proto_library/BUILD.bazel | 7 +++++ .../go_proto_library/protos_alias_test.go | 29 +++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 tests/core/go_proto_library/protos_alias_test.go diff --git a/tests/core/go_proto_library/BUILD.bazel b/tests/core/go_proto_library/BUILD.bazel index d55ba5dab6..c0f1597b8a 100644 --- a/tests/core/go_proto_library/BUILD.bazel +++ b/tests/core/go_proto_library/BUILD.bazel @@ -117,9 +117,16 @@ go_test( deps = [":protos_go_proto"], ) +go_test( + name = "protos_alias_test", + srcs = ["protos_alias_test.go"], + deps = [":protos_go_proto"], +) + go_proto_library( name = "protos_go_proto", importpath = "github.com/bazelbuild/rules_go/tests/core/go_proto_library/protos", + importpath_aliases = ["myalias/protos"], protos = [ ":protos_a_proto", ":protos_b_proto", diff --git a/tests/core/go_proto_library/protos_alias_test.go b/tests/core/go_proto_library/protos_alias_test.go new file mode 100644 index 0000000000..66a9e52866 --- /dev/null +++ b/tests/core/go_proto_library/protos_alias_test.go @@ -0,0 +1,29 @@ +/* Copyright 2018 The Bazel Authors. All rights reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package protos_alias_test + +import ( + "myalias/protos" // importing based on the alias import path + "testing" +) + +func use(interface{}) {} + +func TestProtos(t *testing.T) { + // just make sure both types exist + use(protos.A{}) + use(protos.B{}) +} From 1f25244479cb58808c8aee87e782373422e8b111 Mon Sep 17 00:00:00 2001 From: Napas Date: Wed, 19 Aug 2020 16:12:14 -0700 Subject: [PATCH 3/3] Fix copyright and add to README.rst --- tests/core/go_proto_library/README.rst | 6 ++++++ tests/core/go_proto_library/protos_alias_test.go | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/core/go_proto_library/README.rst b/tests/core/go_proto_library/README.rst index 4caa7ccd2c..1a5b039d3b 100644 --- a/tests/core/go_proto_library/README.rst +++ b/tests/core/go_proto_library/README.rst @@ -53,3 +53,9 @@ wkt_wrapper_test Checks that most of the well known types in ``//proto/wkt`` are wrappers for packages in ``@org_golang_google_protobuf``. The proto types should be type aliases. + +protos_alias_test +----------------- + +Checks that packages generated by `go_proto_library` can be imported using one of the strings +listed in ``importpath_aliases``. diff --git a/tests/core/go_proto_library/protos_alias_test.go b/tests/core/go_proto_library/protos_alias_test.go index 66a9e52866..1761276522 100644 --- a/tests/core/go_proto_library/protos_alias_test.go +++ b/tests/core/go_proto_library/protos_alias_test.go @@ -1,4 +1,4 @@ -/* Copyright 2018 The Bazel Authors. All rights reserved. +/* Copyright 2020 The Bazel Authors. All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.