From 4c7c5813087c577efa9184ecd966644ce2c1dfa1 Mon Sep 17 00:00:00 2001 From: Marek Siarkowicz Date: Fri, 25 Oct 2019 19:18:20 +0200 Subject: [PATCH] Handle bazel >= 0.25 in stable metric static analysis Check both "bazel-genfiles" and "bazel-bin" due https://github.com/bazelbuild/bazel/issues/6761 --- test/instrumentation/update-stable-metrics.sh | 12 +++++++++++- test/instrumentation/verify-stable-metrics.sh | 14 ++++++++++++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/test/instrumentation/update-stable-metrics.sh b/test/instrumentation/update-stable-metrics.sh index 99d5be53aef..4cd2c7e2226 100755 --- a/test/instrumentation/update-stable-metrics.sh +++ b/test/instrumentation/update-stable-metrics.sh @@ -19,6 +19,16 @@ set -o nounset set -o pipefail KUBE_ROOT=$(dirname "${BASH_SOURCE[0]}")/../.. +BAZEL_OUT_DIR="$KUBE_ROOT/bazel-bin" +BAZEL_GEN_DIR="$KUBE_ROOT/bazel-genfiles" +METRICS_LIST_PATH="test/instrumentation/stable-metrics-list.yaml" bazel build //test/instrumentation:list_stable_metrics -cp "$KUBE_ROOT/bazel-genfiles/test/instrumentation/stable-metrics-list.yaml" "$KUBE_ROOT/test/instrumentation/testdata/stable-metrics-list.yaml" +if [ -d "$BAZEL_OUT_DIR" ]; then + cp "$BAZEL_OUT_DIR/$METRICS_LIST_PATH" "$KUBE_ROOT/test/instrumentation/testdata/stable-metrics-list.yaml" +else + # Handle bazel < 0.25 + # https://github.com/bazelbuild/bazel/issues/6761 + echo "$BAZEL_OUT_DIR not found trying $BAZEL_GEN_DIR" + cp "$BAZEL_GEN_DIR/$METRICS_LIST_PATH" "$KUBE_ROOT/test/instrumentation/testdata/stable-metrics-list.yaml" +fi diff --git a/test/instrumentation/verify-stable-metrics.sh b/test/instrumentation/verify-stable-metrics.sh index 89d761b1f5e..d0e4cbc26d8 100755 --- a/test/instrumentation/verify-stable-metrics.sh +++ b/test/instrumentation/verify-stable-metrics.sh @@ -18,13 +18,23 @@ set -o errexit set -o pipefail KUBE_ROOT=$(dirname "${BASH_SOURCE[0]}")/../.. +BAZEL_OUT_DIR="$KUBE_ROOT/bazel-bin" +BAZEL_GEN_DIR="$KUBE_ROOT/bazel-genfiles" +METRICS_LIST_PATH="test/instrumentation/stable-metrics-list.yaml" # detect if run from bazel if [ -z "${TEST_BINARY}" ]; then bazel build //test/instrumentation:list_stable_metrics - OUTPUT_FILE="$KUBE_ROOT/bazel-genfiles/test/instrumentation/stable-metrics-list.yaml" + + if [ -d "$BAZEL_OUT_DIR" ]; then + OUTPUT_FILE="$BAZEL_OUT_DIR/$METRICS_LIST_PATH" + else + # Handle bazel < 0.25 + # https://github.com/bazelbuild/bazel/issues/6761 + OUTPUT_FILE="$BAZEL_GEN_DIR/$METRICS_LIST_PATH" + fi else - OUTPUT_FILE="$KUBE_ROOT/test/instrumentation/stable-metrics-list.yaml" + OUTPUT_FILE="$KUBE_ROOT/$METRICS_LIST_PATH" fi if diff -u "$KUBE_ROOT/test/instrumentation/testdata/stable-metrics-list.yaml" "$OUTPUT_FILE"; then