Skip to content
This repository has been archived by the owner on Oct 27, 2023. It is now read-only.

Commit

Permalink
migrate from go_prefix to go_importpath
Browse files Browse the repository at this point in the history
  • Loading branch information
Rob Figueiredo committed Sep 6, 2018
1 parent 370dfb4 commit 0c31e43
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 45 deletions.
5 changes: 0 additions & 5 deletions BUILD
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
load("@io_bazel_rules_go//go:def.bzl", "go_prefix")

go_prefix("github.com/pubref/rules_protobuf")


load("//protobuf:rules.bzl", "proto_dependencies")

proto_dependencies(
Expand Down
2 changes: 1 addition & 1 deletion go/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ load("//protobuf:rules.bzl", "proto_language")

proto_language(
name = "go",
go_prefix = "//:go_prefix",
go_importpath = "github.com/pubref/rules_protobuf",
pb_file_extensions = [".pb.go"],
pb_plugin = "@com_github_golang_protobuf//protoc-gen-go",
pb_plugin_implements_grpc = True,
Expand Down
5 changes: 0 additions & 5 deletions go/rules.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ def go_proto_compile(langs = [str(Label("//go"))], **kwargs):
def go_proto_library(
name,
langs = [str(Label("//go"))],
go_prefix = Label("//:go_prefix", relative_to_caller_repository=True),
importpath = None,
go_package = None,
protos = [],
Expand Down Expand Up @@ -76,13 +75,9 @@ def go_proto_library(
else:
resolved_go_proto_deps = PB_COMPILE_DEPS

if importpath:
go_prefix = None

proto_compile_args += {
"name": name + ".pb",
"protos": protos,
"go_prefix": go_prefix,
"go_importpath": importpath,
"go_package": go_package,
"deps": [dep + ".pb" for dep in proto_deps],
Expand Down
8 changes: 4 additions & 4 deletions gogo/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,31 @@ load("//protobuf:rules.bzl", "proto_language")

proto_language(
name = "gogo",
go_prefix = "//:go_prefix",
go_importpath = "github.com/pubref/rules_protobuf",
pb_file_extensions = [".pb.go"],
pb_plugin = "@com_github_gogo_protobuf//protoc-gen-gogo",
pb_plugin_implements_grpc = True,
)

proto_language(
name = "gogofast",
go_prefix = "//:go_prefix",
go_importpath = "github.com/pubref/rules_protobuf",
pb_file_extensions = [".pb.go"],
pb_plugin = "@com_github_gogo_protobuf//protoc-gen-gogofast",
pb_plugin_implements_grpc = True,
)

proto_language(
name = "gogofaster",
go_prefix = "//:go_prefix",
go_importpath = "github.com/pubref/rules_protobuf",
pb_file_extensions = [".pb.go"],
pb_plugin = "@com_github_gogo_protobuf//protoc-gen-gogofaster",
pb_plugin_implements_grpc = True,
)

proto_language(
name = "gogoslick",
go_prefix = "//:go_prefix",
go_importpath = "github.com/pubref/rules_protobuf",
pb_file_extensions = [".pb.go"],
pb_plugin = "@com_github_gogo_protobuf//protoc-gen-gogoslick",
pb_plugin_implements_grpc = True,
Expand Down
13 changes: 4 additions & 9 deletions gogo/rules.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ def gogoslick_proto_compile(langs = [str(Label("//gogo:gogoslick"))], **kwargs):
def gogofast_proto_library(
name,
langs = [str(Label("//gogo:gogofast"))],
go_prefix = Label("//:go_prefix", relative_to_caller_repository=True),
protos = [],
importmap = {},
imports = [],
Expand All @@ -66,12 +65,11 @@ def gogofast_proto_library(
go_proto_deps = [],
verbose = 0,
**kwargs):
gogo_proto_library(name, langs, go_prefix, protos, importmap, imports, inputs, proto_deps, output_to_workspace, protoc, pb_plugin, pb_options, grpc_plugin, grpc_options, proto_compile_args, with_grpc, srcs, deps, go_proto_deps, verbose, **kwargs)
gogo_proto_library(name, langs, protos, importmap, imports, inputs, proto_deps, output_to_workspace, protoc, pb_plugin, pb_options, grpc_plugin, grpc_options, proto_compile_args, with_grpc, srcs, deps, go_proto_deps, verbose, **kwargs)

def gogofaster_proto_library(
name,
langs = [str(Label("//gogo:gogofaster"))],
go_prefix = Label("//:go_prefix", relative_to_caller_repository=True),
protos = [],
importmap = {},
imports = [],
Expand All @@ -93,12 +91,11 @@ def gogofaster_proto_library(
go_proto_deps = [],
verbose = 0,
**kwargs):
gogo_proto_library(name, langs, go_prefix, protos, importmap, imports, inputs, proto_deps, output_to_workspace, protoc, pb_plugin, pb_options, grpc_plugin, grpc_options, proto_compile_args, with_grpc, srcs, deps, go_proto_deps, verbose, **kwargs)
gogo_proto_library(name, langs, protos, importmap, imports, inputs, proto_deps, output_to_workspace, protoc, pb_plugin, pb_options, grpc_plugin, grpc_options, proto_compile_args, with_grpc, srcs, deps, go_proto_deps, verbose, **kwargs)

def gogoslick_proto_library(
name,
langs = [str(Label("//gogo:gogoslick"))],
go_prefix = Label("//:go_prefix", relative_to_caller_repository=True),
protos = [],
importmap = {},
imports = [],
Expand All @@ -120,12 +117,11 @@ def gogoslick_proto_library(
go_proto_deps = [],
verbose = 0,
**kwargs):
gogo_proto_library(name, langs, go_prefix, protos, importmap, imports, inputs, proto_deps, output_to_workspace, protoc, pb_plugin, pb_options, grpc_plugin, grpc_options, proto_compile_args, with_grpc, srcs, deps, go_proto_deps, verbose, **kwargs)
gogo_proto_library(name, langs, protos, importmap, imports, inputs, proto_deps, output_to_workspace, protoc, pb_plugin, pb_options, grpc_plugin, grpc_options, proto_compile_args, with_grpc, srcs, deps, go_proto_deps, verbose, **kwargs)

def gogo_proto_library(
name,
langs = [str(Label("//gogo"))],
go_prefix = Label("//:go_prefix", relative_to_caller_repository=True),
protos = [],
importmap = {},
imports = [],
Expand All @@ -149,7 +145,7 @@ def gogo_proto_library(
**kwargs):

gogo_proto_deps = [] + go_proto_deps

if not go_proto_deps:
if with_grpc:
gogo_proto_deps += GRPC_COMPILE_DEPS
Expand All @@ -160,7 +156,6 @@ def gogo_proto_library(
"name": name + ".pb",
"protos": protos,
"deps": [dep + ".pb" for dep in proto_deps],
"go_prefix": go_prefix,
"langs": langs,
"importmap": importmap,
"imports": imports,
Expand Down
6 changes: 3 additions & 3 deletions grpc_gateway/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ load("//protobuf:rules.bzl", "proto_language")

proto_language(
name = "grpc_gateway",
go_prefix = "//:go_prefix",
go_importpath = "github.com/pubref/rules_protobuf",
grpc_file_extensions = [".pb.gw.go"],
grpc_imports = [
"external/com_google_protobuf/src/",
Expand All @@ -26,7 +26,7 @@ proto_language(

proto_language(
name = "pb_gateway",
go_prefix = "//:go_prefix",
go_importpath = "github.com/pubref/rules_protobuf",
importmap = {
"google/api/annotations.proto": "google.golang.org/genproto/googleapis/api/annotations",
},
Expand All @@ -47,7 +47,7 @@ proto_language(

proto_language(
name = "swagger",
go_prefix = "//:go_prefix",
go_importpath = "github.com/pubref/rules_protobuf",
importmap = {
"google/api/annotations.proto": "google.golang.org/genproto/googleapis/api/annotations",
},
Expand Down
5 changes: 1 addition & 4 deletions grpc_gateway/rules.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ def grpc_gateway_proto_library(
name,
pb_gateway = str(Label("//grpc_gateway:pb_gateway")),
langs = [str(Label("//grpc_gateway"))],
go_prefix = Label("//:go_prefix", relative_to_caller_repository=True),
protos = [],
imports = [],
importmap = {},
Expand Down Expand Up @@ -63,15 +62,14 @@ def grpc_gateway_proto_library(
**kwargs):

_go_proto_deps = [] + go_proto_deps

if not go_proto_deps:
_go_proto_deps += GRPC_COMPILE_DEPS

pb_args += {
"name": name + ".pb",
"protos": protos,
"deps": [dep + ".pb" for dep in proto_deps],
"go_prefix": go_prefix,
"langs": [pb_gateway],
"imports": imports,
"importmap": importmap,
Expand Down Expand Up @@ -113,7 +111,6 @@ def grpc_gateway_proto_library(
"name": name + ".gw",
"protos": protos,
"deps": [dep + ".pb" for dep in proto_deps],
"go_prefix": go_prefix,
"langs": langs,
"imports": imports,
"importmap": importmap,
Expand Down
8 changes: 1 addition & 7 deletions protobuf/internal/proto_compile.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,6 @@ def _build_base_namespace(run, builder):
def _build_importmappings(run, builder):
"""Override behavior to add plugin options before building the --go_out option"""
ctx = run.ctx
go_prefix = run.data.go_prefix or run.lang.go_prefix
opts = []

# Build the list of import mappings. Start with any configured on
Expand Down Expand Up @@ -588,9 +587,7 @@ def _proto_compile_impl(ctx):
for unit in dep.proto_compile_result.transitive_units:
transitive_units.append(unit)

if ctx.attr.go_prefix:
go_prefix = ctx.attr.go_prefix.go_prefix
elif ctx.attr.go_importpath:
if ctx.attr.go_importpath:
go_prefix = ctx.attr.go_importpath
else:
go_prefix = ""
Expand Down Expand Up @@ -754,9 +751,6 @@ proto_compile = rule(
cfg = "host",
executable = True,
),
"go_prefix": attr.label(
providers = ["go_prefix"],
),
"go_importpath": attr.string(),
"go_package": attr.string(),
"root": attr.string(),
Expand Down
7 changes: 0 additions & 7 deletions protobuf/internal/proto_language.bzl
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
def _proto_language_impl(ctx):
go_prefix = None
if hasattr(ctx.attr.go_prefix, "go_prefix"):
go_prefix = ctx.attr.go_prefix.go_prefix
#print("pb_compile_deps %s" % ctx.attr.pb_compile_deps)
#print("pb_compile_deps files %s" % ctx.files.pb_compile_deps)
return struct(
Expand Down Expand Up @@ -32,7 +29,6 @@ def _proto_language_impl(ctx):
grpc_plugin = ctx.executable.grpc_plugin,
grpc_compile_deps = ctx.files.grpc_compile_deps,
grpc_runtime_deps = ctx.files.grpc_runtime_deps,
go_prefix = go_prefix,
go_package = ctx.attr.go_package,
go_importpath = ctx.attr.go_importpath,
importmap = ctx.attr.importmap,
Expand Down Expand Up @@ -73,9 +69,6 @@ proto_language_attrs = {
),
"grpc_compile_deps": attr.label_list(),
"grpc_runtime_deps": attr.label_list(),
"go_prefix": attr.label(
providers = ["go_prefix"],
),
"go_importpath": attr.string(
),
"go_package": attr.string(),
Expand Down

0 comments on commit 0c31e43

Please sign in to comment.