Skip to content

Commit

Permalink
Adding Command proto serialization. (bazelbuild#129)
Browse files Browse the repository at this point in the history
As usual, Go proto files need to be checked in to work with go build.
Modeling our pre-commit hooks after the remote-apis repo.
  • Loading branch information
Ola Rozenfeld authored Mar 19, 2020
1 parent 7476b11 commit 656a0d6
Show file tree
Hide file tree
Showing 8 changed files with 1,131 additions and 4 deletions.
13 changes: 10 additions & 3 deletions .githooks/pre-commit
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
#!/bin/sh


########################################################################
# Check that all Go files have been gofmt'd.
########################################################################
# Find all change go files.
gofiles=$(git diff --cached --name-only --diff-filter=ACM | grep '\.go$')
[ -z "$gofiles" ] && exit 0

source ./check-gofmt.sh "$gofiles"
./check-gofmt.sh $gofiles

########################################################################
# Precommit hook to rebuild generated go code. Fails if building or
# copying the files fails.
########################################################################
bazel build go/api/command:command_go_proto
GEN_CMD_PATH="go/api/command/command.pb.go"
cp -f "$(find $(bazel info bazel-bin) -path "*/$GEN_CMD_PATH")" "$GEN_CMD_PATH"
git add "$GEN_CMD_PATH"
6 changes: 5 additions & 1 deletion check-gofmt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

# Source: https://github.com/golang/go/blob/88da9ccb98ffaf84bb06b98c9a24af5d0a7025d2/misc/git/pre-commit

unformatted=$(gofmt -l "$@")
if [ "$#" -lt 1 ]; then
exit 0
fi

unformatted=$(gofmt -l $@)
[ -z "$unformatted" ] && exit 0

# Some files are not gofmt'd. Print message and fail.
Expand Down
24 changes: 24 additions & 0 deletions go/api/command/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
load("@rules_proto//proto:defs.bzl", "proto_library")
load("@io_bazel_rules_go//go:def.bzl", "go_library")
load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library")

proto_library(
name = "command_proto",
srcs = ["command.proto"],
visibility = ["//visibility:public"],
deps = ["@com_google_protobuf//:timestamp_proto"],
)

go_proto_library(
name = "command_go_proto",
importpath = "github.com/bazelbuild/remote-apis-sdks/go/api/command",
proto = ":command_proto",
visibility = ["//visibility:public"],
)

go_library(
name = "go_default_library",
embed = [":command_go_proto"],
importpath = "github.com/bazelbuild/remote-apis-sdks/go/api/command",
visibility = ["//visibility:public"],
)
Loading

0 comments on commit 656a0d6

Please sign in to comment.