Skip to content

Instantly share code, notes, and snippets.

@kalbasit
Last active September 6, 2019 06:10
Show Gist options
  • Save kalbasit/3c9607333f5f3c794d2bd96114184301 to your computer and use it in GitHub Desktop.
Save kalbasit/3c9607333f5f3c794d2bd96114184301 to your computer and use it in GitHub Desktop.
#! /usr/bin/env bash
set -euo pipefail
OS="$(go env GOHOSTOS)"
ARCH="$(go env GOARCH)"
echo -e ">>> Compiling the Go proto"
for label in $(bazel query 'kind(go_proto_library, //...)'); do
package="${label%%:*}"
package="${package##//}"
target="${label##*:}"
# do not continue if the package does not exist
[[ -d "${package}" ]] || continue
# compute the path where bazel put the files
# TODO: the _static_pure_stripped comes from a .bazelrc option `build --features=pure`, `build --features=static`.
out_path="bazel-bin/${package}/${OS}_${ARCH}_static_pure_stripped/${target}%/github.com/org/repo/${package}"
# compute the relative_path to the
count_paths="$(echo -n "${package}" | tr '/' '\n' | wc -l)"
relative_path=""
for i in $(seq 0 ${count_paths}); do
relative_path="../${relative_path}"
done
bazel build "${label}"
found=0
for f in ${out_path}/*.pb.go; do
if [[ -f "${f}" ]]; then
found=1
ln -nsf "${relative_path}${f}" "${package}/"
fi
done
if [[ "${found}" == "0" ]]; then
echo "ERR: no .pb.go file was found inside $out_path for the package ${package}"
exit 1
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment