Skip to content

Commit

Permalink
Switch to new_go_repository.
Browse files Browse the repository at this point in the history
    - Updates targets for go-related code.
    - Removes old custom BUILD files.
    - deps.bzl file cleanup.
    - Remove dangling third_part trunk.
    - Simplify travis to test //...
    - Apply buildifier.

Support proto_library rules in external workspaces.

    - Fixes up the code to shift the execdir into the external workspace,
      then adjust all other paths relative to that.
    - Add prefix attribute to proto_compile rule. This fixes several bugs
      bug related to improper propogation of the go_prefix.
    - Fix descriptor_set path (was previously not offset).
    - Don't offset adjust import paths.

Bump to v0.7.0.
  • Loading branch information
pcj committed Oct 6, 2016
1 parent e3cb432 commit 4b2d8fe
Show file tree
Hide file tree
Showing 41 changed files with 293 additions and 938 deletions.
13 changes: 7 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,13 @@ script:
--spawn_strategy=standalone \
--genrule_strategy=standalone \
--local_resources=400,1,1.0 \
examples/helloworld/cpp/... \
examples/helloworld/go/... \
examples/helloworld/java/... \
examples/helloworld/closure/... \
examples/wkt/... \
tests/... \
//examples/helloworld/closure/... \
//examples/helloworld/cpp/... \
//examples/helloworld/go/... \
//examples/helloworld/grpc_gateway/... \
//examples/helloworld/java/... \
//examples/wkt/... \
//tests/... \
$FLAGS
notifications:
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
buildify_all:
fmt:
buildifier WORKSPACE
find bzl/build_file/ -name '*.BUILD' | xargs buildifier
find third_party/ -name BUILD | xargs buildifier
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ language-specific `*_proto_repositories` rule(s):
git_repository(
name = "org_pubref_rules_protobuf",
remote = "https://github.com/pubref/rules_protobuf",
tag = "v0.6.4",
tag = "v0.7.0",
)

load("@org_pubref_rules_protobuf//java:rules.bzl", "java_proto_repositories")
Expand Down
73 changes: 66 additions & 7 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ closure_repositories()

git_repository(
name = "io_bazel_rules_dotnet",
commit = "b23e796dd0be27f35867590309d79ffe278d4eeb",
remote = "https://github.com/pcj/rules_dotnet.git",
commit = "9283e4596fbadd7fed237b5c462dfd687c15d301",
remote = "https://github.com/bazelbuild/rules_dotnet.git",
)

load("@io_bazel_rules_dotnet//dotnet:csharp.bzl", "csharp_repositories")
Expand All @@ -46,11 +46,6 @@ csharp_repositories(use_local_mono = False)
# node_proto_library support requires rules_node
# ================================================================

# local_repository(
# name = "org_pubref_rules_node",
# path = "/Users/pcj/github/rules_node",
# )

git_repository(
name = "org_pubref_rules_node",
commit = "d93a80ac4920c52da8adccbca66a3118a27018fd", # Oct 2, 2016
Expand All @@ -66,35 +61,99 @@ node_repositories()
# ================================================================

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

proto_repositories()

load("//cpp:rules.bzl", "cpp_proto_repositories")

cpp_proto_repositories()

load("//csharp:rules.bzl", "csharp_proto_repositories")

csharp_proto_repositories()

load("//java:rules.bzl", "java_proto_repositories", "nano_proto_repositories")

java_proto_repositories()

nano_proto_repositories()

load("//go:rules.bzl", "go_proto_repositories")

go_proto_repositories()

load("//gogo:rules.bzl", "gogo_proto_repositories")

gogo_proto_repositories()

load("//grpc_gateway:rules.bzl", "grpc_gateway_proto_repositories")

grpc_gateway_proto_repositories()

load("//node:rules.bzl", "node_proto_repositories")

node_proto_repositories()

load("//objc:rules.bzl", "objc_proto_repositories")

objc_proto_repositories()

load("//python:rules.bzl", "py_proto_repositories")

py_proto_repositories()

load("//ruby:rules.bzl", "ruby_proto_repositories")

ruby_proto_repositories()

# ================================================================
# This is for testing
# ================================================================

local_repository(
name = "org_pubref_rules_protobuf",
path = ".",
)

GOOGLEAPIS_BUILD_FILE = """
package(default_visibility = ["//visibility:public"])
load("@io_bazel_rules_go//go:def.bzl", "go_prefix")
go_prefix("github.com/googleapis/googleapis")
load("@org_pubref_rules_protobuf//cpp:rules.bzl", "cc_proto_library")
load("@org_pubref_rules_protobuf//java:rules.bzl", "java_proto_library")
load("@org_pubref_rules_protobuf//go:rules.bzl", "go_proto_library")
cc_proto_library(
name = "cc_label_proto",
protos = [
"google/api/label.proto",
],
verbose = 0,
)
java_proto_library(
name = "java_label_proto",
protos = [
"google/api/label.proto",
],
# Neither seem to be necessary, for either 3 langs
#imports = ["../../external/com_github_google_protobuf/src", "."],
#inputs = ["@com_github_google_protobuf//:well_known_protos"],
verbose = 0,
)
go_proto_library(
name = "go_label_proto",
protos = [
"google/api/label.proto",
],
verbose = 0,
)
"""

new_git_repository(
name = "com_github_googleapis_googleapis",
build_file_content = GOOGLEAPIS_BUILD_FILE,
commit = "60c2f9c8d012db35a65539e30fb6364c36f2e96b",
remote = "https://github.com/googleapis/googleapis.git",
)
4 changes: 0 additions & 4 deletions cpp/deps.bzl
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# ****************************************************************
# List of external dependencies
# ****************************************************************

DEPS = {

# Grpc repo is required by multiple languages but we put it here.
Expand Down
9 changes: 5 additions & 4 deletions csharp/deps.bzl
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# ****************************************************************
# List of external dependencies
# ****************************************************************

PROTOBUF_BUILD_FILE = """
load("@io_bazel_rules_dotnet//dotnet:csharp.bzl", "dll_import")
dll_import(
Expand Down Expand Up @@ -48,4 +44,9 @@ DEPS = {
"build_file_content": GRPC_BUILD_FILE,
},

"protoc_gen_grpc_csharp": {
"rule": "bind",
"actual": "@com_github_grpc_grpc//:grpc_csharp_plugin",
},

}
1 change: 1 addition & 0 deletions csharp/rules.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ def csharp_proto_repositories(
omit_cpp_repositories = False,
lang_deps = DEPS,
lang_requires = [
"protoc_gen_grpc_csharp",
"nuget_google_protobuf",
"nuget_grpc",
], **kwargs):
Expand Down
9 changes: 4 additions & 5 deletions examples/helloworld/closure/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ load("//closure:rules.bzl", "closure_proto_library")
closure_proto_library(
name = "protolib",
protos = [
"//examples/proto:protos",
"//examples/helloworld/proto:protos",
"//examples/proto:protos",
],
verbose = 0,
)
Expand All @@ -19,23 +19,22 @@ closure_js_library(
"greeter.js",
#"protolib.pb",
],

deps = [
"protolib",
"@io_bazel_rules_closure//closure/protobuf:jspb",
"@io_bazel_rules_closure//closure/library",
"@io_bazel_rules_closure//closure/protobuf:jspb",
],
)

closure_js_test(
name = "greeter_test",
srcs = ["greeter_test.js"],
pedantic = True,
compilation_level = "SIMPLE",
pedantic = True,
deps = [
"greeter",
"protolib",
"@io_bazel_rules_closure//closure/protobuf:jspb",
"@io_bazel_rules_closure//closure/library:testing",
"@io_bazel_rules_closure//closure/protobuf:jspb",
],
)
3 changes: 2 additions & 1 deletion examples/helloworld/go/client/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ load(
"//go:rules.bzl",
GO_GRPC_COMPILE_DEPS = "GRPC_COMPILE_DEPS",
)
#load("//gogo:rules.bzl", GOGO_GRPC_COMPILE_DEPS = "GRPC_COMPILE_DEPS")

go_binary(
name = "client",
srcs = ["main.go"],
deps = ["//examples/helloworld/proto:go"] + GO_GRPC_COMPILE_DEPS,
)

#load("//gogo:rules.bzl", GOGO_GRPC_COMPILE_DEPS = "GRPC_COMPILE_DEPS")
#
# To enable this, uncomment and change the importpath to 'gogo' in
# main.go.
#
Expand Down
2 changes: 1 addition & 1 deletion examples/helloworld/grpc_gateway/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ go_test(
":gateway",
"//examples/helloworld/go/server:greeter",
"//examples/helloworld/proto:go",
"@com_github_golang_protobuf//:jsonpb",
"@com_github_golang_protobuf//jsonpb:go_default_library",
] + GRPC_GATEWAY_DEPS,
)
31 changes: 15 additions & 16 deletions examples/wkt/go/BUILD
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package(default_visibility = ["//visibility:public"])

load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_test")

load("//go:rules.bzl", "go_proto_library")

#
Expand All @@ -10,23 +9,23 @@ load("//go:rules.bzl", "go_proto_library")

go_proto_library(
name = "protolib",
protos = ["wkt.proto"],
imports = [
'external/com_github_google_protobuf/src',
],
importmap = {
'google/protobuf/descriptor.proto': 'github.com/golang/protobuf/protoc-gen-go/descriptor',
'google/protobuf/compiler/plugin.proto': 'github.com/golang/protobuf/protoc-gen-go/plugin',
"google/protobuf/descriptor.proto": "github.com/golang/protobuf/protoc-gen-go/descriptor",
"google/protobuf/compiler/plugin.proto": "github.com/golang/protobuf/protoc-gen-go/plugin",
},
imports = [
"external/com_github_google_protobuf/src",
],
protos = ["wkt.proto"],
deps = [
"@com_github_golang_protobuf//:ptypes/any",
"@com_github_golang_protobuf//:ptypes/duration",
"@com_github_golang_protobuf//:ptypes/timestamp",
"@com_github_golang_protobuf//:ptypes/empty",
"@com_github_golang_protobuf//:ptypes/struct",
"@com_github_golang_protobuf//:ptypes/wrappers",
"@com_github_golang_protobuf//:protoc-gen-go/descriptor",
"@com_github_golang_protobuf//:protoc-gen-go/plugin",
"@com_github_golang_protobuf//protoc-gen-go/descriptor:go_default_library",
"@com_github_golang_protobuf//protoc-gen-go/plugin: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/empty:go_default_library",
"@com_github_golang_protobuf//ptypes/struct:go_default_library",
"@com_github_golang_protobuf//ptypes/timestamp:go_default_library",
"@com_github_golang_protobuf//ptypes/wrappers:go_default_library",
],
)

Expand All @@ -36,6 +35,6 @@ go_test(
srcs = ["wkt_test.go"],
deps = [
"protolib",
"@com_github_golang_protobuf//:protoc-gen-go/descriptor",
"@com_github_golang_protobuf//protoc-gen-go/descriptor:go_default_library",
],
)
2 changes: 1 addition & 1 deletion go/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ load("//protobuf:rules.bzl", "proto_language")
proto_language(
name = "go",
pb_file_extensions = [".pb.go"],
pb_plugin = "@com_github_golang_protobuf//:protoc_gen_go",
pb_plugin = "@com_github_golang_protobuf//protoc-gen-go",
pb_plugin_implements_grpc = True,
prefix = "//:go_prefix",
)
31 changes: 14 additions & 17 deletions go/deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,29 @@

DEPS = {

"org_golang_x_net": {
"rule": "new_go_repository",
"importpath": "golang.org/x/net",
"commit": "2a35e686583654a1b89ca79c4ac78cb3d6529ca3",
},

"com_github_golang_glog": {
"rule": "new_git_repository",
"remote": "https://github.com/golang/glog.git",
"rule": "new_go_repository",
"importpath": "github.com/golang/glog",
"commit": "23def4e6c14b4da8ac2ed8007337bc5eb5007998", # Jan 25, 2016
"build_file": str(Label("//protobuf:build_file/com_github_golang_glog.BUILD")),
},

"com_github_golang_protobuf": {
"rule": "new_git_repository",
"remote": "https://github.com/golang/protobuf.git",
"rule": "new_go_repository",
"importpath": "github.com/golang/protobuf",
"commit": "c3cefd437628a0b7d31b34fe44b3a7a540e98527", # Jul 27, 2016
"build_file": str(Label("//protobuf:build_file/com_github_golang_protobuf.BUILD")),
#"build_file": str(Label("//protobuf:build_file/com_github_golang_protobuf.BUILD")),
},

"org_golang_google_grpc": {
"rule": "new_git_repository",
"remote": "https://github.com/grpc/grpc-go.git",
"tag": "v1.0.0",
"build_file": str(Label("//protobuf:build_file/org_golang_google_grpc.BUILD")),
},

"org_golang_x_net": {
"rule": "new_git_repository",
"remote": "https://github.com/golang/net.git",
"commit": "2a35e686583654a1b89ca79c4ac78cb3d6529ca3",
"build_file": str(Label("//protobuf:build_file/org_golang_x_net.BUILD")),
"rule": "new_go_repository",
"importpath": "google.golang.org/grpc",
"tag": "v1.0.1-GA",
},

}
6 changes: 4 additions & 2 deletions go/rules.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ def go_proto_repositories(


PB_COMPILE_DEPS = [
"@com_github_golang_protobuf//:proto",
"@com_github_golang_protobuf//proto:go_default_library",
]

GRPC_COMPILE_DEPS = PB_COMPILE_DEPS + [
"@com_github_golang_glog//:go_default_library",
"@org_golang_google_grpc//:go_default_library",
"@org_golang_x_net//:context",
"@org_golang_x_net//context:go_default_library",
]


Expand All @@ -41,6 +41,7 @@ def go_proto_compile(langs = [str(Label("//go"))], **kwargs):
def go_proto_library(
name,
langs = [str(Label("//go"))],
prefix = Label("//:go_prefix", relative_to_caller_repository=True),
protos = [],
importmap = {},
imports = [],
Expand Down Expand Up @@ -72,6 +73,7 @@ def go_proto_library(
proto_compile_args += {
"name": name + ".pb",
"protos": protos,
"prefix": prefix,
"deps": [dep + ".pb" for dep in proto_deps],
"langs": langs,
"importmap": importmap,
Expand Down
Loading

0 comments on commit 4b2d8fe

Please sign in to comment.