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

Run buildifer on Bazel files #797

Merged
merged 2 commits into from
Nov 8, 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
11 changes: 6 additions & 5 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,22 @@ jobs:
- run: dep ensure --vendor-only
- run: go get golang.org/x/lint/golint
- run: make lint
bazel_build:
bazel_lint:
docker:
- image: l.gcr.io/google/bazel:latest
working_directory: /go/src/github.com/grpc-ecosystem/grpc-gateway
steps:
- checkout
- run: bazel --batch --output_base=$HOME/.cache/_grpc_gateway_bazel run //:gazelle_diff
- run: bazel --batch --output_base=$HOME/.cache/_grpc_gateway_bazel build //...
- run: 'bazel --output_base=$HOME/.cache/_grpc_gateway_bazel run //:buildifier_check ||
(echo "Bazel files not formatted, please run \`bazel run :buildifier\`"; exit 1)'
- run: bazel --output_base=$HOME/.cache/_grpc_gateway_bazel run //:gazelle_diff
bazel_test:
docker:
- image: l.gcr.io/google/bazel:latest
working_directory: /go/src/github.com/grpc-ecosystem/grpc-gateway
steps:
- checkout
- run: bazel --batch --output_base=$HOME/.cache/_grpc_gateway_bazel test --test_output=errors --features=race //...
- run: bazel --output_base=$HOME/.cache/_grpc_gateway_bazel test --test_output=errors --features=race //...
build_linux_release:
docker:
- image: jfbrandhorst/grpc-gateway-build-env
Expand Down Expand Up @@ -151,7 +152,7 @@ workflows:
- node_test
- generate
- lint
- bazel_build
- bazel_lint
- bazel_test
- build_linux_release:
filters:
Expand Down
10 changes: 10 additions & 0 deletions BUILD
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
load("@bazel_gazelle//:def.bzl", "gazelle")
load("@com_github_bazelbuild_buildtools//buildifier:def.bzl", "buildifier")

buildifier(
name = "buildifier",
)

buildifier(
name = "buildifier_check",
mode = "check",
)

# gazelle:exclude third_party

Expand Down
29 changes: 20 additions & 9 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,21 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
name = "io_bazel_rules_go",
url = "https://github.com/bazelbuild/rules_go/releases/download/0.12.1/rules_go-0.12.1.tar.gz",
sha256 = "8b68d0630d63d95dacc0016c3bb4b76154fe34fca93efd65d1c366de3fcb4294",
url = "https://github.com/bazelbuild/rules_go/releases/download/0.12.1/rules_go-0.12.1.tar.gz",
)

http_archive(
name = "bazel_gazelle",
url = "https://github.com/bazelbuild/bazel-gazelle/releases/download/0.10.1/bazel-gazelle-0.10.1.tar.gz",
sha256 = "d03625db67e9fb0905bbd206fa97e32ae9da894fe234a493e7517fd25faec914",
url = "https://github.com/bazelbuild/bazel-gazelle/releases/download/0.10.1/bazel-gazelle-0.10.1.tar.gz",
)

http_archive(
name = "com_github_bazelbuild_buildtools",
sha256 = "e4c83a7a5d0712e2cea2077112a5eb6bb1af75a84e34c8c9b77330e322966b8b",
strip_prefix = "buildtools-e90e7cc6ef3e6d08d4ca8a982935c3eed638e058",
url = "https://github.com/bazelbuild/buildtools/archive/e90e7cc6ef3e6d08d4ca8a982935c3eed638e058.tar.gz",
)

load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies")
Expand All @@ -20,7 +27,7 @@ gazelle_dependencies()

load("@bazel_gazelle//:def.bzl", "go_repository")
load("//:repositories.bzl", "repositories")
load("@io_bazel_rules_go//go:def.bzl", "go_rules_dependencies", "go_register_toolchains")
load("@io_bazel_rules_go//go:def.bzl", "go_register_toolchains", "go_rules_dependencies")

# Also define in Gopkg.toml
go_repository(
Expand All @@ -45,20 +52,24 @@ go_repository(

# Also define in Gopkg.toml
go_repository(
name = "com_github_ghodss_yaml",
commit = "0ca9ea5df5451ffdf184b4428c902747c2c11cd7",
importpath = "github.com/ghodss/yaml",
name = "com_github_ghodss_yaml",
commit = "0ca9ea5df5451ffdf184b4428c902747c2c11cd7",
importpath = "github.com/ghodss/yaml",
)

# Also define in Gopkg.toml
go_repository(
name = "in_gopkg_yaml_v2",
commit = "eb3733d160e74a9c7e442f435eb3bea458e1d19f",
importpath = "gopkg.in/yaml.v2",
name = "in_gopkg_yaml_v2",
commit = "eb3733d160e74a9c7e442f435eb3bea458e1d19f",
importpath = "gopkg.in/yaml.v2",
)

repositories()

go_rules_dependencies()

go_register_toolchains()

load("@com_github_bazelbuild_buildtools//buildifier:deps.bzl", "buildifier_dependencies")

buildifier_dependencies()
2 changes: 1 addition & 1 deletion examples/clients/abe/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ go_library(
"//examples/proto/examplepb:go_default_library",
"//examples/proto/pathenum:go_default_library",
"//runtime:go_default_library",
"@com_github_go_resty_resty//:go_default_library"
"@com_github_go_resty_resty//:go_default_library",
],
)
2 changes: 1 addition & 1 deletion examples/proto/examplepb/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ proto_library(
"a_bit_of_everything.proto",
"echo_service.proto",
"flow_combination.proto",
"response_body_service.proto",
"stream.proto",
"unannotated_echo_service.proto",
"wrappers.proto",
"response_body_service.proto",
],
deps = [
"//examples/proto/pathenum:pathenum_proto",
Expand Down
2 changes: 1 addition & 1 deletion examples/server/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ go_library(
"echo.go",
"flow_combination.go",
"main.go",
"unannotatedecho.go",
"responsebody.go",
"unannotatedecho.go",
],
importpath = "github.com/grpc-ecosystem/grpc-gateway/examples/server",
deps = [
Expand Down
58 changes: 29 additions & 29 deletions protoc-gen-swagger/defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -33,34 +33,34 @@ def _collect_includes(gen_dir, srcs):
def _run_proto_gen_swagger(ctx, direct_proto_srcs, transitive_proto_srcs, actions, protoc, protoc_gen_swagger, grpc_api_configuration):
swagger_files = []
for proto in direct_proto_srcs:
swagger_file = actions.declare_file(
"%s.swagger.json" % proto.basename[:-len(".proto")],
sibling = proto,
)
swagger_file = actions.declare_file(
"%s.swagger.json" % proto.basename[:-len(".proto")],
sibling = proto,
)

inputs = direct_proto_srcs + transitive_proto_srcs + [protoc_gen_swagger]
inputs = direct_proto_srcs + transitive_proto_srcs + [protoc_gen_swagger]

options=["logtostderr=true"]
if grpc_api_configuration:
options.append("grpc_api_configuration=%s" % grpc_api_configuration.path)
inputs.append(grpc_api_configuration)
options = ["logtostderr=true"]
if grpc_api_configuration:
options.append("grpc_api_configuration=%s" % grpc_api_configuration.path)
inputs.append(grpc_api_configuration)

includes = _collect_includes(ctx.genfiles_dir.path, direct_proto_srcs + transitive_proto_srcs)
includes = _collect_includes(ctx.genfiles_dir.path, direct_proto_srcs + transitive_proto_srcs)

args = actions.args()
args.add("--plugin=%s" % protoc_gen_swagger.path)
args.add("--swagger_out=%s:%s" % (",".join(options), ctx.bin_dir.path))
args.add(["-I%s" % include for include in includes])
args.add(proto.path)
args = actions.args()
args.add("--plugin=%s" % protoc_gen_swagger.path)
args.add("--swagger_out=%s:%s" % (",".join(options), ctx.bin_dir.path))
args.add(["-I%s" % include for include in includes])
args.add(proto.path)

actions.run(
executable = protoc,
inputs = inputs,
outputs = [swagger_file],
arguments = [args],
)
actions.run(
executable = protoc,
inputs = inputs,
outputs = [swagger_file],
arguments = [args],
)

swagger_files.append(swagger_file)
swagger_files.append(swagger_file)

return swagger_files

Expand All @@ -69,29 +69,29 @@ def _proto_gen_swagger_impl(ctx):
grpc_api_configuration = ctx.file.grpc_api_configuration

return struct(
files=depset(
files = depset(
_run_proto_gen_swagger(
ctx,
direct_proto_srcs = proto.direct_sources,
transitive_proto_srcs = ctx.files._well_known_protos + proto.transitive_sources.to_list(),
actions = ctx.actions,
protoc = ctx.executable._protoc,
protoc_gen_swagger = ctx.executable._protoc_gen_swagger,
grpc_api_configuration = grpc_api_configuration
)
)
grpc_api_configuration = grpc_api_configuration,
),
),
)

protoc_gen_swagger = rule(
attrs = {
"proto": attr.label(
allow_rules = ["proto_library"],
mandatory = True,
providers = ['proto'],
providers = ["proto"],
),
"grpc_api_configuration": attr.label(
allow_single_file=True,
mandatory=False
allow_single_file = True,
mandatory = False,
),
"_protoc": attr.label(
default = "@com_google_protobuf//:protoc",
Expand Down
2 changes: 0 additions & 2 deletions repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,9 @@ def _googleapis_repository_impl(ctx):

ctx.file("google/api/BUILD.bazel", GOOGLEAPIS_GOOGLE_API_BUILD_CONTENTS)


_googleapis_repository = repository_rule(
implementation = _googleapis_repository_impl,
)


def repositories():
_googleapis_repository(name = "com_github_googleapis_googleapis")
2 changes: 1 addition & 1 deletion runtime/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ go_test(
"@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",
"@org_golang_google_genproto//protobuf/field_mask:go_default_library",
"@org_golang_google_genproto//googleapis/rpc/errdetails:go_default_library",
"@org_golang_google_genproto//protobuf/field_mask:go_default_library",
"@org_golang_google_grpc//:go_default_library",
"@org_golang_google_grpc//codes:go_default_library",
"@org_golang_google_grpc//metadata:go_default_library",
Expand Down