Lukacs Berki | 840acb1 | 2017-01-25 14:01:33 +0000 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # |
| 3 | # Copyright 2016 The Bazel Authors. All rights reserved. |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | # |
| 17 | # Load the test setup defined in the parent directory |
| 18 | CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
| 19 | source "${CURRENT_DIR}/../integration_test_setup.sh" \ |
| 20 | || { echo "integration_test_setup.sh not found!" >&2; exit 1; } |
| 21 | |
| 22 | #### SETUP ############################################################# |
| 23 | |
| 24 | set -e |
| 25 | |
| 26 | #### TESTS ############################################################# |
| 27 | |
| 28 | function test_no_rebuild_on_irrelevant_header_change() { |
| 29 | mkdir -p a |
| 30 | cat > a/BUILD <<EOF |
| 31 | cc_binary(name="a", srcs=["a.cc"], deps=["b"]) |
| 32 | cc_library(name="b", srcs=["b1.h", "b2.h"]) |
| 33 | EOF |
| 34 | |
| 35 | cat > a/a.cc <<EOF |
| 36 | #include "a/b1.h" |
| 37 | |
| 38 | int main(void) { |
| 39 | return B_RETURN_VALUE; |
| 40 | } |
| 41 | EOF |
| 42 | |
| 43 | cat > a/b1.h <<EOF |
| 44 | #define B_RETURN_VALUE 31 |
| 45 | EOF |
| 46 | |
| 47 | cat > a/b2.h <<EOF |
| 48 | === BANANA === |
| 49 | EOF |
| 50 | |
| 51 | bazel build //a || fail "build failed" |
| 52 | echo "CHERRY" > a/b2.h |
| 53 | bazel build //a >& $TEST_log || fail "build failed" |
| 54 | expect_not_log "Compiling a/a.cc" |
| 55 | } |
| 56 | |
| 57 | function test_new_header_is_required() { |
| 58 | mkdir -p a |
| 59 | cat > a/BUILD <<EOF |
| 60 | cc_binary(name="a", srcs=["a.cc"], deps=[":b"]) |
| 61 | cc_library(name="b", srcs=["b1.h", "b2.h"]) |
| 62 | EOF |
| 63 | |
| 64 | cat > a/a.cc << EOF |
| 65 | #include "a/b1.h" |
| 66 | |
| 67 | int main(void) { |
| 68 | return B1; |
| 69 | } |
| 70 | EOF |
| 71 | |
| 72 | cat > a/b1.h <<EOF |
| 73 | #define B1 3 |
| 74 | EOF |
| 75 | |
| 76 | cat > a/b2.h <<EOF |
| 77 | #define B2 4 |
| 78 | EOF |
| 79 | |
| 80 | bazel build //a || fail "build failed" |
| 81 | cat > a/a.cc << EOF |
| 82 | #include "a/b1.h" |
| 83 | #include "a/b2.h" |
| 84 | |
| 85 | int main(void) { |
| 86 | return B1 + B2; |
| 87 | } |
| 88 | EOF |
| 89 | |
| 90 | bazel build //a || fail "build failled" |
| 91 | } |
| 92 | |
George Gensure | abc9332 | 2017-02-27 12:16:39 +0000 | [diff] [blame] | 93 | function test_no_recompile_on_shutdown() { |
| 94 | mkdir -p a |
| 95 | cat > a/BUILD <<EOF |
| 96 | cc_binary(name="a", srcs=["a.cc"], deps=["b"]) |
| 97 | cc_library(name="b", includes=["."], hdrs=["b.h"]) |
| 98 | EOF |
| 99 | |
| 100 | cat > a/a.cc <<EOF |
| 101 | #include "b.h" |
| 102 | |
| 103 | int main(void) { |
| 104 | return B_RETURN_VALUE; |
| 105 | } |
| 106 | EOF |
| 107 | |
| 108 | cat > a/b.h <<EOF |
| 109 | #define B_RETURN_VALUE 31 |
| 110 | EOF |
| 111 | |
| 112 | bazel build -s //a >& $TEST_log || fail "build failed" |
| 113 | expect_log "Compiling a/a.cc" |
| 114 | bazel shutdown >& /dev/null || fail "query failed" |
| 115 | bazel build -s //a >& $TEST_log || fail "build failed" |
| 116 | expect_not_log "Compiling a/a.cc" |
| 117 | } |
| 118 | |
Lukacs Berki | 840acb1 | 2017-01-25 14:01:33 +0000 | [diff] [blame] | 119 | run_suite "Tests for Bazel's C++ rules" |