make kube::util::find-binary not dependent on bazel-out/ structure

Implement an aspect that outputs go_build_mode metadata for go binaries,
and use that during binary selection.
This commit is contained in:
Mike Danese
2020-09-09 17:44:05 -07:00
parent d182ecc1f9
commit bdadb2a187
3 changed files with 77 additions and 14 deletions

View File

@@ -207,19 +207,16 @@ kube::util::find-binary-for-platform() {
"${KUBE_ROOT}/_output/dockerized/go/bin/${lookfor}"
);
fi
# Also search for binary in bazel build tree.
# The bazel go rules place some binaries in subtrees like
# "bazel-bin/source/path/linux_amd64_pure_stripped/binaryname", so make sure
# the platform name is matched in the path.
while IFS=$'\n' read -r location; do
locations+=("$location");
done < <(find "${KUBE_ROOT}/bazel-bin/" -type f -executable \
\( -path "*/${platform/\//_}*/${lookfor}" -o -path "*/${lookfor}" \) 2>/dev/null || true)
# search for executables for non-GNU versions of find (eg. BSD)
while IFS=$'\n' read -r location; do
locations+=("$location");
done < <(find "${KUBE_ROOT}/bazel-bin/" -type f -perm -111 \
\( -path "*/${platform/\//_}*/${lookfor}" -o -path "*/${lookfor}" \) 2>/dev/null || true)
# Also search for binary in bazel build tree if bazel-out/ exists.
if [[ -d "${KUBE_ROOT}/bazel-out" ]]; then
while IFS=$'\n' read -r bin_build_mode; do
if grep -q "${platform}" "${bin_build_mode}"; then
# drop the extension to get the real binary path.
locations+=("${bin_build_mode%.*}")
fi
done < <(find "${KUBE_ROOT}/bazel-out/" -name "${lookfor}.go_build_mode")
fi
# List most recently-updated location.
local -r bin=$( (ls -t "${locations[@]}" 2>/dev/null || true) | head -1 )