Klaus Aehlig | 6afb4fd | 2019-03-04 12:17:19 -0800 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # |
| 3 | # Copyright 2019 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 | # An end-to-end test that Bazel's experimental UI produces reasonable output. |
| 18 | |
| 19 | # --- begin runfiles.bash initialization --- |
| 20 | set -euo pipefail |
| 21 | if [[ ! -d "${RUNFILES_DIR:-/dev/null}" && ! -f "${RUNFILES_MANIFEST_FILE:-/dev/null}" ]]; then |
| 22 | if [[ -f "$0.runfiles_manifest" ]]; then |
| 23 | export RUNFILES_MANIFEST_FILE="$0.runfiles_manifest" |
| 24 | elif [[ -f "$0.runfiles/MANIFEST" ]]; then |
| 25 | export RUNFILES_MANIFEST_FILE="$0.runfiles/MANIFEST" |
| 26 | elif [[ -f "$0.runfiles/bazel_tools/tools/bash/runfiles/runfiles.bash" ]]; then |
| 27 | export RUNFILES_DIR="$0.runfiles" |
| 28 | fi |
| 29 | fi |
| 30 | if [[ -f "${RUNFILES_DIR:-/dev/null}/bazel_tools/tools/bash/runfiles/runfiles.bash" ]]; then |
| 31 | source "${RUNFILES_DIR}/bazel_tools/tools/bash/runfiles/runfiles.bash" |
| 32 | elif [[ -f "${RUNFILES_MANIFEST_FILE:-/dev/null}" ]]; then |
| 33 | source "$(grep -m1 "^bazel_tools/tools/bash/runfiles/runfiles.bash " \ |
| 34 | "$RUNFILES_MANIFEST_FILE" | cut -d ' ' -f 2-)" |
| 35 | else |
| 36 | echo >&2 "ERROR: cannot find @bazel_tools//tools/bash/runfiles:runfiles.bash" |
| 37 | exit 1 |
| 38 | fi |
| 39 | # --- end runfiles.bash initialization --- |
| 40 | |
| 41 | source "$(rlocation "io_bazel/src/test/shell/integration_test_setup.sh")" \ |
| 42 | || { echo "integration_test_setup.sh not found!" >&2; exit 1; } |
| 43 | |
| 44 | case "$(uname -s | tr [:upper:] [:lower:])" in |
| 45 | msys*|mingw*|cygwin*) |
| 46 | declare -r is_windows=true |
| 47 | ;; |
| 48 | *) |
| 49 | declare -r is_windows=false |
| 50 | ;; |
| 51 | esac |
| 52 | |
| 53 | if "$is_windows"; then |
| 54 | export MSYS_NO_PATHCONV=1 |
| 55 | export MSYS2_ARG_CONV_EXCL="*" |
| 56 | fi |
| 57 | |
| 58 | #### SETUP ############################################################# |
| 59 | |
| 60 | test_custom_message() { |
| 61 | rm -rf custommessage |
| 62 | mkdir custommessage |
| 63 | cd custommessage |
| 64 | |
oquenchil | 9606887 | 2019-07-08 07:01:39 -0700 | [diff] [blame] | 65 | create_workspace_with_default_repos WORKSPACE |
Klaus Aehlig | 6afb4fd | 2019-03-04 12:17:19 -0800 | [diff] [blame] | 66 | cat > rule.bzl <<'EOF' |
| 67 | def _rule_impl(ctx): |
laurentlb | 5e51c88 | 2019-05-27 11:42:08 -0700 | [diff] [blame] | 68 | out = ctx.actions.declare_file(ctx.label.name + ".txt") |
laurentlb | 213043a | 2020-10-29 04:26:32 -0700 | [diff] [blame] | 69 | ctx.actions.run( |
Klaus Aehlig | 6afb4fd | 2019-03-04 12:17:19 -0800 | [diff] [blame] | 70 | inputs = ctx.files._data, |
| 71 | outputs = [out], |
laurentlb | 213043a | 2020-10-29 04:26:32 -0700 | [diff] [blame] | 72 | executable = "cp", |
| 73 | arguments = [f.path for f in ctx.files._data] + [out.path], |
Klaus Aehlig | 6afb4fd | 2019-03-04 12:17:19 -0800 | [diff] [blame] | 74 | mnemonic = "copying", |
| 75 | progress_message = "Copying implict data dependency for %s" % ctx.label |
| 76 | ) |
| 77 | |
| 78 | implicit_rule = rule( |
| 79 | implementation = _rule_impl, |
| 80 | attrs = { |
| 81 | "_data": attr.label(allow_files=True, default = "//magic/place:data", |
| 82 | doc="You must manually put the data to magic/place.") |
| 83 | }, |
| 84 | ) |
| 85 | EOF |
| 86 | cat > BUILD <<'EOF' |
| 87 | load("//:rule.bzl", "implicit_rule") |
| 88 | |
| 89 | implicit_rule(name = "it") |
| 90 | EOF |
| 91 | mkdir -p magic/place |
| 92 | echo Hello World > magic/place/data |
| 93 | echo 'exports_files(["data"])' > magic/place/BUILD |
| 94 | |
| 95 | bazel build //:it || fail "Rule should work" |
| 96 | |
| 97 | rm -rf magic |
| 98 | |
| 99 | bazel build //:it > "${TEST_log}" 2>&1 \ |
| 100 | && fail "Missing implict dependency should be detected" || : |
| 101 | expect_log 'rule.*implicit_rule.*implicitly depends' |
| 102 | expect_log 'attribute _data of.*implicit_rule' |
| 103 | expect_log 'You must manually put the data to magic/place' |
| 104 | } |
| 105 | |
| 106 | run_suite "Integration tests for reporing missing implicit dependencies" |