#!/bin/bash # # Copyright 2016 The Bazel Authors. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # # output_filter_test.sh: a couple of end to end tests for the warning # filter functionality. # --- begin runfiles.bash initialization --- # Copy-pasted from Bazel's Bash runfiles library (tools/bash/runfiles/runfiles.bash). set -euo pipefail if [[ ! -d "${RUNFILES_DIR:-/dev/null}" && ! -f "${RUNFILES_MANIFEST_FILE:-/dev/null}" ]]; then if [[ -f "$0.runfiles_manifest" ]]; then export RUNFILES_MANIFEST_FILE="$0.runfiles_manifest" elif [[ -f "$0.runfiles/MANIFEST" ]]; then export RUNFILES_MANIFEST_FILE="$0.runfiles/MANIFEST" elif [[ -f "$0.runfiles/bazel_tools/tools/bash/runfiles/runfiles.bash" ]]; then export RUNFILES_DIR="$0.runfiles" fi fi if [[ -f "${RUNFILES_DIR:-/dev/null}/bazel_tools/tools/bash/runfiles/runfiles.bash" ]]; then source "${RUNFILES_DIR}/bazel_tools/tools/bash/runfiles/runfiles.bash" elif [[ -f "${RUNFILES_MANIFEST_FILE:-/dev/null}" ]]; then source "$(grep -m1 "^bazel_tools/tools/bash/runfiles/runfiles.bash " \ "$RUNFILES_MANIFEST_FILE" | cut -d ' ' -f 2-)" else echo >&2 "ERROR: cannot find @bazel_tools//tools/bash/runfiles:runfiles.bash" exit 1 fi # --- end runfiles.bash initialization --- source "$(rlocation "io_bazel/src/test/shell/integration_test_setup.sh")" \ || { echo "integration_test_setup.sh not found!" >&2; exit 1; } case "$(uname -s | tr [:upper:] [:lower:])" in msys*|mingw*|cygwin*) declare -r is_windows=true ;; *) declare -r is_windows=false ;; esac if "$is_windows"; then export MSYS_NO_PATHCONV=1 export MSYS2_ARG_CONV_EXCL="*" fi function test_output_filter_cc() { # "test warning filter for C compilation" local -r pkg=$FUNCNAME if is_windows; then local -r copts=\"/W3\" else local -r copts="" fi mkdir -p $pkg/cc/main cat > $pkg/cc/main/BUILD <$pkg/cc/main/main.c < int main(void) { #ifdef COMPILER_MSVC // MSVC does not support the #warning directive. int unused_variable__triggers_a_warning; // triggers C4101 #else // not COMPILER_MSVC // GCC/Clang support #warning. #warning("triggers_a_warning") #endif // COMPILER_MSVC printf("%s", "Hello, World!\n"); return 0; } EOF bazel build --output_filter="dummy" $pkg/cc/main:cc >&"$TEST_log" || fail "build failed" expect_not_log "triggers_a_warning" echo "/* adding a comment forces recompilation */" >> $pkg/cc/main/main.c bazel build $pkg/cc/main:cc >&"$TEST_log" || fail "build failed" expect_log "triggers_a_warning" } function test_output_filter_java() { # "test warning filter for Java compilation" local -r pkg=$FUNCNAME mkdir -p $pkg/java/main cat >$pkg/java/main/BUILD <$pkg/java/main/Main.java <$pkg/java/hello_library/BUILD <$pkg/java/hello_library/HelloLibrary.java <&"$TEST_log" || fail "build failed" expect_log "has been deprecated" # check that we do get a deprecation warning if we select the target echo "// add comment to trigger recompilation" >> $pkg/java/hello_library/HelloLibrary.java echo "// add comment to trigger recompilation" >> $pkg/java/main/Main.java bazel build --output_filter=$pkg/java/main //$pkg/java/main:main >&"$TEST_log" \ || fail "build failed" expect_log "has been deprecated" # check that we do not get a deprecation warning if we select another target echo "// add another comment" >> $pkg/java/hello_library/HelloLibrary.java echo "// add another comment" >> $pkg/java/main/Main.java bazel build --output_filter=$pkg/java/hello_library //$pkg/java/main:main >&"$TEST_log" \ || fail "build failed" expect_not_log "has been deprecated" } function test_test_output_printed() { # "test that test output is printed if warnings are disabled" local -r pkg=$FUNCNAME mkdir -p $pkg/foo/bar cat >$pkg/foo/bar/BUILD <$pkg/foo/bar/test.sh <&"$TEST_log" || fail expect_log "PASS: //$pkg/foo/bar:test" } function test_output_filter_build() { # "test output filter for BUILD files" local -r pkg=$FUNCNAME mkdir -p $pkg/foo/bar cat >$pkg/foo/bar/BUILD <&"$TEST_log" || fail "build failed" expect_log "is unexpected here" # check that we do get a deprecation warning if we select the target echo "# add comment to trigger rebuild" >> $pkg/foo/bar/tomato.skin echo "# add comment to trigger rebuild" >> $pkg/foo/bar/tomato.pulp bazel build --output_filter=$pkg/foo/bar:tomato //$pkg/foo/bar:tomato >&"$TEST_log" \ || fail "build failed" expect_log "is unexpected here" # check that we do not get a deprecation warning if we select another target echo "# add another comment" >> $pkg/foo/bar/tomato.skin echo "# add another comment" >> $pkg/foo/bar/tomato.pulp bazel build --output_filter=$pkg/foo/bar/:red //$pkg/foo/bar:tomato >&"$TEST_log" \ || fail "build failed" expect_not_log "is unexpected here" } function test_output_filter_build_hostattribute() { # "test that output filter also applies to host attributes" local -r pkg=$FUNCNAME # What do you get in bars? mkdir -p $pkg/bar cat >$pkg/bar/BUILD < $pkg/bar/vodka # Check that we do get a deprecation warning bazel build //$pkg/bar:bloody_mary >&"$TEST_log" || fail "build failed" expect_log "is unexpected here" # Check that the warning is disabled if we do not want to see it echo "# add comment to trigger rebuild" >> $pkg/bar/tomato.skin echo "# add comment to trigger rebuild" >> $pkg/bar/tomato.pulp bazel build //$pkg/bar:bloody_mary --output_filter='nothing' >&"$TEST_log" \ || fail "build failed" expect_not_log "is unexpected here" } function test_output_filter_does_not_apply_to_test_output() { local -r pkg=$FUNCNAME mkdir -p $pkg/geflugel cat >$pkg/geflugel/BUILD <$pkg/geflugel/mockingbird.sh <$pkg/geflugel/hummingbird.sh < $TEST_log \ && fail "expected tests to fail" expect_log "To kill -9 a mockingbird" expect_log "To kill -9 a hummingbird" } # TODO(mstaib): enable test after deprecation warnings work in bazel function disabled_test_filters_deprecated_targets() { local -r pkg=$FUNCNAME init_test "test that deprecated target warnings are filtered" mkdir -p $pkg/{relativity,ether} cat > $pkg/relativity/BUILD < $pkg/ether/BUILD < $TEST_log || fail "Expected success" expect_log_once "WARNING:.*target '//$pkg/relativity:relativity' depends on \ deprecated target '//$pkg/ether:ether': Disproven." bazel build --nobuild --output_filter="^//pizza" \ //$pkg/relativity &> $TEST_log || fail "Expected success" expect_not_log "WARNING:.*target '//$pkg/relativity:relativity' depends on \ deprecated target '//$pkg/ether:ether': Disproven." } run_suite "Warning Filter tests"