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

Keep generated go files in the git repo #2907

Merged
merged 1 commit into from
Aug 22, 2019
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
3 changes: 3 additions & 0 deletions .buildkite/steps/test.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
- label: "Check generated go/proto files in git"
command: $BASE/run_step checkgogen
timeout_in_minutes: 10
- label: "Unit tests :bazel:"
command: $BASE/run_step test
artifact_paths:
Expand Down
11 changes: 11 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,17 @@ pkg_tar(
mode = "0755",
)

# This is a package of tools used for generating code that is checked in
# to git (i.e. outside of bazels reach).
pkg_tar(
name = "build-tools",
package_dir = "",
srcs = [
"@com_zombiezen_go_capnproto2//capnpc-go:capnpc-go",
],
mode = "0755",
)

# Nogo - Go code analysis tool
nogo(
name = "nogo",
Expand Down
20 changes: 10 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: all clean goenv gogenlinks gogenlinks_clean vendor mocks bazel bazel_bin_clean gazelle setcap clibs libscion libfilter dispatcher uninstall tags
.PHONY: all clean goenv gogen vendor mocks bazel bazel_bin_clean gazelle setcap clibs libscion libfilter dispatcher uninstall tags

BRACCEPT = bin/braccept

Expand All @@ -8,26 +8,26 @@ SRC_DIRS = c/lib/scion c/lib/filter c/dispatcher

all: tags clibs dispatcher bazel

clean: gogenlinks_clean
clean:
$(foreach var,$(SRC_DIRS),$(MAKE) -C $(var) clean || exit 1;)
bazel clean
rm -f bin/* tags
if [ -e go/vendor ]; then rm -r go/vendor; fi

goenv: vendor gogenlinks
gogen:
ifndef GOGEN_SKIP
$(MAKE) -C go/proto
else
@echo "gogen: skipped"
endif

gogenlinks: gogenlinks_clean
bazel build //go/proto:go_default_library
find bazel-genfiles/go/proto -maxdepth 1 -type f -exec ln -snf ../../{} go/proto \;

gogenlinks_clean:
find ./go/proto -maxdepth 1 -type l -exec rm {} +
goenv: vendor

vendor:
if [ -e go/vendor ]; then rm -r go/vendor; fi
bzlcompat -vendorBase=go

bazel: vendor bazel_bin_clean
bazel: vendor gogen bazel_bin_clean
bazel build //:scion //:scion-ci --workspace_status_command=./tools/bazel-build-env
tar -kxf bazel-bin/scion.tar -C bin
tar -kxf bazel-bin/scion-ci.tar -C bin
Expand Down
2 changes: 1 addition & 1 deletion docker/perapp/base/Dockerfile.builder
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
FROM scion:latest
COPY bazelrc.quiet ~/.bazelrc
RUN make -s all setcap && bazel clean
RUN make -s GOGEN_SKIP=1 all setcap && bazel clean
51 changes: 12 additions & 39 deletions go/proto/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -8,43 +8,7 @@ go_library(
"cereal.go",
"doc.go",
"sign.go",
":structs",
":capnp",
],
importpath = "github.com/scionproto/scion/go/proto",
visibility = ["//visibility:public"],
deps = [
"//go/lib/common:go_default_library",
"//go/lib/scrypto:go_default_library",
"//go/lib/util:go_default_library",
"@com_zombiezen_go_capnproto2//:go_default_library",
"@com_zombiezen_go_capnproto2//encoding/text:go_default_library",
"@com_zombiezen_go_capnproto2//pogs:go_default_library",
"@com_zombiezen_go_capnproto2//schemas:go_default_library",
],
)

genrule(
name = "structs",
srcs = [],
outs = ["structs.gen.go"],
cmd = "./$(location structs_gen_go.sh) > \"$@\"",
tools = ["structs_gen_go.sh"],
visibility = ["//visibility:public"],
)

# TODO(sustrik): At the moment we have a copied version of go.capnp in proto directory.
# Once python is Bazelified we can copy it as part of the build process.
# Specifically we would need to add "@com_zombiezen_go_capnproto2//std:go.capnp" to
# srcs and -I$$(dirname \"$(location @com_zombiezen_go_capnproto2//std:go.capnp)\")
# to the command line. Also "go.capnp" inside individual capnp files should be changed
# to "/go.capnp".
genrule(
name = "capnp",
srcs = [
"//proto:sources",
],
outs = [
"structs.gen.go",
"ack.capnp.go",
"asm_exts.capnp.go",
"cert_mgmt.capnp.go",
Expand All @@ -64,6 +28,15 @@ genrule(
"svc_resolution.capnp.go",
"zkid.capnp.go",
],
cmd = "capnp compile -o$(location @com_zombiezen_go_capnproto2//capnpc-go:capnpc-go):$(@D) --src-prefix=proto $(locations //proto:sources)",
tools = ["@com_zombiezen_go_capnproto2//capnpc-go:capnpc-go"],
importpath = "github.com/scionproto/scion/go/proto",
visibility = ["//visibility:public"],
deps = [
"//go/lib/common:go_default_library",
"//go/lib/scrypto:go_default_library",
"//go/lib/util:go_default_library",
"@com_zombiezen_go_capnproto2//:go_default_library",
"@com_zombiezen_go_capnproto2//encoding/text:go_default_library",
"@com_zombiezen_go_capnproto2//pogs:go_default_library",
"@com_zombiezen_go_capnproto2//schemas:go_default_library",
],
)
19 changes: 19 additions & 0 deletions go/proto/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
.PHONY: all capnp

PROTO_DIR := ../../proto
SRCS := $(wildcard $(PROTO_DIR)/*.capnp)
SRCS := $(filter-out $(PROTO_DIR)/go.capnp, $(SRCS))

all: capnp structs.gen.go

capnp:
set -eu; \
TMPDIR=$$(mktemp -d -t scion-build-tools.XXXXXXXXXX); \
bazel build //:build-tools; \
tar -xf ../../bazel-bin/build-tools.tar -C $$TMPDIR; \
rm -f *.capnp.go; \
capnp compile --verbose -o$$TMPDIR/capnpc-go --src-prefix $(PROTO_DIR) $(SRCS); \
rm -rf $$TMPDIR

structs.gen.go: structs_gen_go.sh
./structs_gen_go.sh > structs.gen.go
170 changes: 170 additions & 0 deletions go/proto/ack.capnp.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading