diff --git a/.circleci/config.yml b/.circleci/config.yml index 39e326fafa8..30d20053a19 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -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 @@ -151,7 +152,7 @@ workflows: - node_test - generate - lint - - bazel_build + - bazel_lint - bazel_test - build_linux_release: filters: diff --git a/BUILD b/BUILD index 0ab0afa13f7..b72e9743bd8 100644 --- a/BUILD +++ b/BUILD @@ -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 diff --git a/WORKSPACE b/WORKSPACE index 32c20f962c1..5a6545f1103 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -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") @@ -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( @@ -45,16 +52,16 @@ 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() @@ -62,3 +69,7 @@ repositories() go_rules_dependencies() go_register_toolchains() + +load("@com_github_bazelbuild_buildtools//buildifier:deps.bzl", "buildifier_dependencies") + +buildifier_dependencies() diff --git a/examples/clients/abe/BUILD.bazel b/examples/clients/abe/BUILD.bazel index 8603ce20e7f..6b61fa1b3fa 100644 --- a/examples/clients/abe/BUILD.bazel +++ b/examples/clients/abe/BUILD.bazel @@ -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", ], ) diff --git a/examples/proto/examplepb/BUILD.bazel b/examples/proto/examplepb/BUILD.bazel index 7ec13fbe279..0e0c79d38ca 100644 --- a/examples/proto/examplepb/BUILD.bazel +++ b/examples/proto/examplepb/BUILD.bazel @@ -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", diff --git a/examples/server/BUILD.bazel b/examples/server/BUILD.bazel index afd74848a09..10bb44d0641 100644 --- a/examples/server/BUILD.bazel +++ b/examples/server/BUILD.bazel @@ -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 = [ diff --git a/protoc-gen-swagger/defs.bzl b/protoc-gen-swagger/defs.bzl index ada033139c6..a2933cdbeaa 100644 --- a/protoc-gen-swagger/defs.bzl +++ b/protoc-gen-swagger/defs.bzl @@ -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 @@ -69,7 +69,7 @@ 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, @@ -77,9 +77,9 @@ def _proto_gen_swagger_impl(ctx): 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( @@ -87,11 +87,11 @@ protoc_gen_swagger = rule( "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", diff --git a/repositories.bzl b/repositories.bzl index dc49d60eeee..4133986239d 100644 --- a/repositories.bzl +++ b/repositories.bzl @@ -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") diff --git a/runtime/BUILD.bazel b/runtime/BUILD.bazel index 9fce0447165..60c1fec31d9 100644 --- a/runtime/BUILD.bazel +++ b/runtime/BUILD.bazel @@ -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",