Skip to content

Commit

Permalink
Merge pull request #21 from stackb/remove-bazel-at-root
Browse files Browse the repository at this point in the history
Remove bazel files
  • Loading branch information
pcj committed Jun 22, 2023
2 parents 246a60f + 8ac6059 commit b7269c7
Show file tree
Hide file tree
Showing 15 changed files with 112 additions and 201 deletions.
1 change: 0 additions & 1 deletion .bazelrc

This file was deleted.

1 change: 0 additions & 1 deletion .bazelversion

This file was deleted.

8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
/bazel-*
.vscode
/bazel-*
WORKSPACE
MODULE.bazel
**/BUILD.bazel
.bazelrc
.bazelversion
47 changes: 0 additions & 47 deletions BUILD.bazel

This file was deleted.

10 changes: 0 additions & 10 deletions MODULE.bazel

This file was deleted.

11 changes: 0 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,14 +1,3 @@
.PHONY: test
test:
go test github.com/stackb/protoreflecthash

.PHONY: test_protoset
test_protoset:
bazel build //test_protos:protoset
cp -f bazel-bin/test_protos/protoset.pb testdata/

# vendor in the generated files for regular go build process
pb_go:
bazel build //test_protos/schema/proto3:proto3_go_proto //test_protos/schema/proto2:proto2_go_proto
cp -f bazel-bin/test_protos/schema/proto3/proto3_go_proto_/github.com/stackb/protoreflecthash/test_protos/generated/latest/proto3/*.pb.go test_protos/generated/latest/proto3
cp -f bazel-bin/test_protos/schema/proto2/proto2_go_proto_/github.com/stackb/protoreflecthash/test_protos/generated/latest/proto2/*.pb.go test_protos/generated/latest/proto2
5 changes: 0 additions & 5 deletions WORKSPACE

This file was deleted.

Empty file removed WORKSPACE.bzlmod
Empty file.
105 changes: 105 additions & 0 deletions bazel.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
#!/bin/bash

set -euo pipefail

BAZEL='bzl' # or bazelisk

write_workspace() {
cat << EOF > WORKSPACE
workspace(name = "com_github_stackb_protoreflecthash")
EOF
}

write_modulebazel() {
cat << EOF > MODULE.bazel
module(
name = "protoreflecthash",
version = "0.1.0",
repo_name = "com_github_stackb_protoreflecthash",
)
bazel_dep(name = "protobuf", version = "21.7", repo_name = "com_google_protobuf")
bazel_dep(name = "rules_proto", version = "4.0.0")
bazel_dep(name = "rules_go", version = "0.39.1")
bazel_dep(name = "gazelle", version = "0.31.1")
EOF
}

write_bazelversion() {
cat << EOF > .bazelversion
6.2.1
EOF
}

write_bazelrc() {
cat << EOF > .bazelrc
build --experimental_enable_bzlmod
EOF
}

write_bazelbuild() {
cat << EOF > BUILD.bazel
load("@rules_go//go:def.bzl", "go_library", "go_test")
load("@rules_proto//proto:defs.bzl", "proto_descriptor_set")
load("@gazelle//:def.bzl", "gazelle")
# gazelle:prefix github.com/stackb/protoreflecthash
# gazelle:resolve go go github.com/stackb/protoreflecthash/test_protos/generated/latest/proto2 @com_github_stackb_protoreflecthash//test_protos/generated/latest/proto2
# gazelle:resolve go go github.com/stackb/protoreflecthash/test_protos/generated/latest/proto3 @com_github_stackb_protoreflecthash//test_protos/generated/latest/proto3
gazelle(name = "gazelle")
proto_descriptor_set(
name = "protoset",
deps = [
"//test_protos/schema/proto2:proto2_proto",
"//test_protos/schema/proto3:proto3_proto",
],
)
EOF
}

run_gazelle() {
"${BAZEL}" run gazelle
}

build_targets() {
"${BAZEL}" build \
//test_protos/schema/proto3:proto3_go_proto \
//test_protos/schema/proto2:proto2_go_proto \
//:protoset
}

copy_pb_go() {
cp -f bazel-bin/test_protos/schema/proto3/proto3_go_proto_/github.com/stackb/protoreflecthash/test_protos/generated/latest/proto3/*.pb.go \
test_protos/generated/latest/proto3

cp -f bazel-bin/test_protos/schema/proto2/proto2_go_proto_/github.com/stackb/protoreflecthash/test_protos/generated/latest/proto2/*.pb.go \
test_protos/generated/latest/proto2
}

copy_protoset() {
cp -f bazel-bin/protoset.pb \
testdata/
}

clean() {
"${BAZEL}" clean
rm .bazelversion .bazelrc MODULE.bazel WORKSPACE
find . -name 'BUILD.bazel' | xargs rm
}

main() {
write_workspace
write_modulebazel
write_bazelversion
write_bazelrc
write_bazelbuild
run_gazelle
build_targets
copy_pb_go
copy_protoset
}

main
# clean
9 changes: 0 additions & 9 deletions test_protos/BUILD.bazel

This file was deleted.

26 changes: 0 additions & 26 deletions test_protos/generated/latest/proto2/BUILD.bazel

This file was deleted.

26 changes: 0 additions & 26 deletions test_protos/generated/latest/proto3/BUILD.bazel

This file was deleted.

32 changes: 0 additions & 32 deletions test_protos/schema/proto2/BUILD.bazel

This file was deleted.

32 changes: 0 additions & 32 deletions test_protos/schema/proto3/BUILD.bazel

This file was deleted.

Binary file modified testdata/protoset.pb
Binary file not shown.

0 comments on commit b7269c7

Please sign in to comment.