Skip to content

Commit 6e9b2d2

Browse files
committed
Make proto-gen targets not rely on GOPATH
Similar to #4135 Since m3 is now a go.mod project, it's no longer necessary to be checked out under GOPATH. This PR makes our code generation reflect that fact. I've switched to use of relative paths in generate.go, which as I understand it is the preferred way of doing things generally. Our proto-gen script now takes in an actual path to proto files vs a logical path. It infers the logical repo path from the actual path. Fixes #4134
1 parent 42e0064 commit 6e9b2d2

24 files changed

Lines changed: 158 additions & 135 deletions

File tree

scripts/proto-gen.sh

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
#!/bin/bash
22

3-
# include poratable readlink
4-
source $(dirname $0)/realpath.sh
3+
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
4+
ROOT="${DIR}/.."
5+
6+
# include portable readlink
7+
source "${DIR}/realpath.sh"
58

69
# paranoia, ftw
710
set -e
8-
911
PROTOC_IMAGE_VERSION=${PROTOC_IMAGE_VERSION:-"znly/protoc:0.2.0"}
1012

1113
# ensure docker is running
@@ -17,21 +19,42 @@ if [[ -n "$BUILDKITE" ]]; then
1719
fi
1820

1921
PROTO_SRC=$1
20-
for i in "${GOPATH}/src/${PROTO_SRC}"/*; do
22+
# Find all protobuf files under ${PROTO_SRC}
23+
for i in "${PROTO_SRC}"/*; do
2124
if ! [ -d $i ]; then
2225
continue
2326
fi
2427

2528
if ls $i/*.proto > /dev/null 2>&1; then
26-
proto_files=$(ls $i/*.proto | sed -e "s@${GOPATH}@@g")
29+
30+
# Find all .proto files in this subdirectory, and return the full import path to them. The import path is:
31+
# github.com/m3db/m3/<path_from_root>
32+
# compute their path relative to the repository root.
33+
proto_files="$(find $i -name \*.proto | while read -r filename; do
34+
full_path="$(realpath ${filename})"
35+
36+
# Relativize it to the root
37+
root_full_path="$(realpath "${ROOT}")"
38+
39+
# Bash substitution:
40+
# https://stackoverflow.com/questions/13210880/replace-one-substring-for-another-string-in-shell-script
41+
path_from_root="${full_path/${root_full_path}}"
42+
# Finally
43+
echo "github.com/m3db/m3${path_from_root}"
44+
done)"
45+
2746
echo "generating from ${proto_files}"
2847
# need the additional m3db_path mount in docker because it's a symlink on the CI.
29-
m3db_path=$(realpath $GOPATH/src/github.com/m3db/m3)
48+
m3db_path=$(realpath "${ROOT}")
3049
resolve_protos="Mgoogle/protobuf/timestamp.proto=github.com/gogo/protobuf/types,Mgoogle/protobuf/wrappers.proto=github.com/gogo/protobuf/types,Mgoogle/protobuf/any.proto=github.com/gogo/protobuf/types,Mgoogle/protobuf/struct.proto=github.com/gogo/protobuf/types"
3150
32-
docker run --rm -w /src -v $GOPATH/src:/src -v ${m3db_path}:/src/github.com/m3db/m3 \
51+
docker run --rm -w /src \
52+
-v "${ROOT}/src:/src" \
53+
-v ${m3db_path}:/src/github.com/m3db/m3 \
3354
$UID_FLAGS $PROTOC_IMAGE_VERSION \
3455
--gogofaster_out=${resolve_protos},plugins=grpc:/src \
35-
-I/src -I/src/github.com/m3db/m3/vendor ${proto_files}
56+
-I/src \
57+
${proto_files}
58+
3659
fi
3760
done

src/aggregator/generated/proto/generate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@
1818
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
1919
// THE SOFTWARE.
2020

21-
//go:generate sh -c "$GOPATH/src/github.com/m3db/m3/scripts/proto-gen.sh github.com/m3db/m3/src/aggregator/generated/proto"
21+
//go:generate sh -c "../../../../scripts/proto-gen.sh ."
2222

2323
package proto

src/cluster/generated/proto/changesetpb/changeset.pb.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/cluster/generated/proto/changesettest/changesettest.pb.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/cluster/generated/proto/commonpb/common.pb.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/cluster/generated/proto/generate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@
1818
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
1919
// THE SOFTWARE.
2020

21-
//go:generate sh -c "$GOPATH/src/github.com/m3db/m3/scripts/proto-gen.sh github.com/m3db/m3/src/cluster/generated/proto"
21+
//go:generate sh -c "../../../../scripts/proto-gen.sh ."
2222

2323
package proto

src/cluster/generated/proto/kvpb/kv.pb.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/cluster/generated/proto/kvtest/kvtest.pb.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/cluster/generated/proto/metadatapb/metadata.pb.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/cluster/generated/proto/placementpb/placement.pb.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)