Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Bazel build by generating proto code automatically #96

Merged
merged 7 commits into from
Aug 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 27 additions & 7 deletions bazel/pgv_proto_library.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,39 @@ load(":protobuf.bzl", "cc_proto_gen_validate")

def pgv_go_proto_library(name, proto = None, deps = [], **kwargs):
go_proto_compiler(
name = "pgv_plugin",
name = "pgv_plugin_go",
suffix = ".pb.validate.go",
valid_archive = False,
plugin = "//:protoc-gen-validate",
options = ["lang=go"],
)

go_proto_library(name = name,
proto = proto,
deps = ["//validate:go_default_library"] + deps,
compilers = ["@io_bazel_rules_go//proto:go_proto", "pgv_plugin"],
visibility = ["//visibility:public"],
**kwargs)
go_proto_library(
name = name,
proto = proto,
deps = ["//validate:go_default_library"] + deps,
compilers = ["@io_bazel_rules_go//proto:go_proto", "pgv_plugin_go"],
visibility = ["//visibility:public"],
**kwargs
)

def pgv_gogo_proto_library(name, proto = None, deps = [], **kwargs):
go_proto_compiler(
name = "pgv_plugin_gogo",
suffix = ".pb.validate.go",
valid_archive = False,
plugin = "//:protoc-gen-validate",
options = ["lang=gogo"],
)

go_proto_library(
name = name,
proto = proto,
deps = ["//validate:go_default_library"] + deps,
compilers = ["@io_bazel_rules_go//proto:gogo_proto", "pgv_plugin_gogo"],
visibility = ["//visibility:public"],
**kwargs
)

def pgv_cc_proto_library(
name,
Expand Down
26 changes: 20 additions & 6 deletions tests/harness/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library")

proto_library(
name = "harness_proto_target",
name = "harness_proto",
srcs = ["harness.proto"],
deps = [
"@com_google_protobuf//:any_proto",
Expand All @@ -12,22 +12,36 @@ proto_library(
)

go_proto_library(
name = "go_default_library",
proto = ":harness_proto_target",
importpath = "github.com/lyft/protoc-gen-validate/tests/harness",
name = "harness_go_proto",
importpath = "github.com/lyft/protoc-gen-validate/tests/harness/go",
proto = ":harness_proto",
visibility = ["//visibility:public"],
deps = [
"@com_github_golang_protobuf//ptypes/any:go_default_library",
"@com_github_golang_protobuf//ptypes/timestamp:go_default_library",
"@com_github_golang_protobuf//ptypes/wrappers:go_default_library",
"@io_bazel_rules_go//proto/wkt:descriptor_go_proto",
],
)

go_proto_library(
name = "harness_gogo_proto",
compilers = ["@io_bazel_rules_go//proto:gogo_proto"],
importpath = "github.com/lyft/protoc-gen-validate/tests/harness/gogo",
proto = ":harness_proto",
visibility = ["//visibility:public"],
deps = [
"@com_github_golang_protobuf//ptypes/any:go_default_library",
"@com_github_golang_protobuf//ptypes/timestamp:go_default_library",
"@com_github_golang_protobuf//ptypes/wrappers:go_default_library",
"@io_bazel_rules_go//proto/wkt:descriptor_go_proto",
],
)

cc_proto_library(
name = "harness_proto",
name = "harness_cc_proto",
deps = [
":harness_proto_target",
":harness_proto",
],
visibility = ["//visibility:public"],
)
15 changes: 8 additions & 7 deletions tests/harness/cases/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")

load(
"//bazel:pgv_proto_library.bzl",
"pgv_gogo_proto_library",
"pgv_go_proto_library",
"pgv_cc_proto_library",
)
Expand Down Expand Up @@ -48,17 +49,17 @@ pgv_go_proto_library(
],
)

go_library(
pgv_gogo_proto_library(
name = "gogo",
srcs = glob(["gogo/*.go"]),
visibility = ["//visibility:public"],
importpath = "github.com/lyft/protoc-gen-validate/tests/harness/cases/gogo",
proto = ":cases_proto",
deps = [
"//tests/harness/gogo:go_default_library",
"//tests/harness/cases/other_package:gogo",
"//validate:go_default_library",
"//vendor/github.com/gogo/protobuf/proto:go_default_library",
"//vendor/github.com/gogo/protobuf/types:go_default_library",
"@com_github_golang_protobuf//ptypes:go_default_library",
"@com_github_golang_protobuf//ptypes/any:go_default_library",
"@com_github_golang_protobuf//ptypes/duration:go_default_library",
"@com_github_golang_protobuf//ptypes/timestamp:go_default_library",
"@com_github_golang_protobuf//ptypes/wrappers:go_default_library",
],
)

Expand Down
11 changes: 4 additions & 7 deletions tests/harness/cases/other_package/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")
load(
"//bazel:pgv_proto_library.bzl",
"pgv_go_proto_library",
"pgv_gogo_proto_library",
"pgv_cc_proto_library",
)

Expand All @@ -25,16 +26,12 @@ pgv_go_proto_library(
],
)

go_library(
pgv_gogo_proto_library(
name = "gogo",
srcs = glob(["gogo/*.go"]),
visibility = ["//visibility:public"],
importpath = "github.com/lyft/protoc-gen-validate/tests/harness/cases/other_package/gogo",
proto = ":embed_proto",
deps = [
"//tests/harness/gogo:go_default_library",
"//validate:go_default_library",
"//vendor/github.com/gogo/protobuf/proto:go_default_library",
"//vendor/github.com/gogo/protobuf/types:go_default_library",
"@com_github_golang_protobuf//ptypes:go_default_library",
],
)

Expand Down
2 changes: 1 addition & 1 deletion tests/harness/cc/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ cc_binary(
}),
visibility = ["//visibility:public"],
deps = [
"//tests/harness:harness_proto",
"//tests/harness:harness_cc_proto",
"//tests/harness/cases:cc",
],
)
Expand Down
1 change: 1 addition & 0 deletions tests/harness/executor/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ go_library(
importpath = "github.com/lyft/protoc-gen-validate/tests/harness/executor",
visibility = ["//visibility:private"],
deps = [
"//tests/harness:harness_go_proto",
"//tests/harness/cases:go",
"//tests/harness/cases/other_package:go",
"//tests/harness/go:go_default_library",
Expand Down
2 changes: 1 addition & 1 deletion tests/harness/go/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ load("@io_bazel_rules_go//go:def.bzl", "go_library")

go_library(
name = "go_default_library",
srcs = ["harness.pb.go"],
importpath = "github.com/lyft/protoc-gen-validate/tests/harness/go",
visibility = ["//visibility:public"],
deps = [
"//tests/harness:harness_go_proto",
"@com_github_golang_protobuf//proto:go_default_library",
"@com_github_golang_protobuf//ptypes/any:go_default_library",
],
Expand Down
1 change: 1 addition & 0 deletions tests/harness/go/main/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ go_library(
importpath = "github.com/lyft/protoc-gen-validate/tests/harness/go/main",
visibility = ["//visibility:private"],
deps = [
"//tests/harness:harness_go_proto",
"//tests/harness/cases:go",
"//tests/harness/cases/other_package:go",
"//tests/harness/go:go_default_library",
Expand Down
1 change: 0 additions & 1 deletion tests/harness/gogo/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ load("@io_bazel_rules_go//go:def.bzl", "go_library")

go_library(
name = "go_default_library",
srcs = ["harness.pb.go"],
importpath = "github.com/lyft/protoc-gen-validate/tests/harness/gogo",
visibility = ["//visibility:public"],
deps = [
Expand Down
5 changes: 3 additions & 2 deletions tests/harness/gogo/main/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ go_library(
importpath = "github.com/lyft/protoc-gen-validate/tests/harness/gogo/main",
visibility = ["//visibility:private"],
deps = [
"//tests/harness:harness_gogo_proto",
"//tests/harness/cases:gogo",
"//tests/harness/cases/other_package:gogo",
"//tests/harness/gogo:go_default_library",
"//vendor/github.com/gogo/protobuf/proto:go_default_library",
"//vendor/github.com/gogo/protobuf/types:go_default_library",
"@com_github_gogo_protobuf//proto:go_default_library",
"@com_github_gogo_protobuf//types:go_default_library",
],
)

Expand Down
7 changes: 6 additions & 1 deletion tests/kitchensink/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,16 @@ load(
proto_library(
name = "fixed32_proto",
srcs = ["fixed32.proto"],
deps = ["//validate:validate_proto"],
)

pgv_go_proto_library(
name = "fixed32_go",
proto = ":fixed32_proto"
importpath = "github.com/lyft/protoc-gen-validate/tests/kitchensink/fixed32",
proto = ":fixed32_proto",
deps = [
"@com_github_golang_protobuf//ptypes:go_default_library",
],
)

pgv_cc_proto_library(
Expand Down