Skip to content

Commit

Permalink
add importpath_aliases to go_proto_library (bazelbuild#2608)
Browse files Browse the repository at this point in the history
It allows go_proto_library to accept importpath_aliases as an argument. It is needed because gazelle generates go_proto_library rules that have importpath_aliases as an argument.

Fixes bazelbuild#2358
  • Loading branch information
tian000 authored Aug 20, 2020
1 parent 1df596c commit 631e26b
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 0 deletions.
1 change: 1 addition & 0 deletions proto/def.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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]),
Expand Down
7 changes: 7 additions & 0 deletions tests/core/go_proto_library/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 6 additions & 0 deletions tests/core/go_proto_library/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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``.
29 changes: 29 additions & 0 deletions tests/core/go_proto_library/protos_alias_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/* 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.
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{})
}

0 comments on commit 631e26b

Please sign in to comment.