blob: 9f2c8932c43c5cd8b9eb93f375c63c0f0fde8e63 [file] [log] [blame]
Klaus Aehlig6afb4fd2019-03-04 12:17:19 -08001#!/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 ---
20set -euo pipefail
21if [[ ! -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
29fi
30if [[ -f "${RUNFILES_DIR:-/dev/null}/bazel_tools/tools/bash/runfiles/runfiles.bash" ]]; then
31 source "${RUNFILES_DIR}/bazel_tools/tools/bash/runfiles/runfiles.bash"
32elif [[ -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-)"
35else
36 echo >&2 "ERROR: cannot find @bazel_tools//tools/bash/runfiles:runfiles.bash"
37 exit 1
38fi
39# --- end runfiles.bash initialization ---
40
41source "$(rlocation "io_bazel/src/test/shell/integration_test_setup.sh")" \
42 || { echo "integration_test_setup.sh not found!" >&2; exit 1; }
43
44case "$(uname -s | tr [:upper:] [:lower:])" in
45msys*|mingw*|cygwin*)
46 declare -r is_windows=true
47 ;;
48*)
49 declare -r is_windows=false
50 ;;
51esac
52
53if "$is_windows"; then
54 export MSYS_NO_PATHCONV=1
55 export MSYS2_ARG_CONV_EXCL="*"
56fi
57
58#### SETUP #############################################################
59
60test_custom_message() {
61 rm -rf custommessage
62 mkdir custommessage
63 cd custommessage
64
oquenchil96068872019-07-08 07:01:39 -070065 create_workspace_with_default_repos WORKSPACE
Klaus Aehlig6afb4fd2019-03-04 12:17:19 -080066 cat > rule.bzl <<'EOF'
67def _rule_impl(ctx):
laurentlb5e51c882019-05-27 11:42:08 -070068 out = ctx.actions.declare_file(ctx.label.name + ".txt")
laurentlb213043a2020-10-29 04:26:32 -070069 ctx.actions.run(
Klaus Aehlig6afb4fd2019-03-04 12:17:19 -080070 inputs = ctx.files._data,
71 outputs = [out],
laurentlb213043a2020-10-29 04:26:32 -070072 executable = "cp",
73 arguments = [f.path for f in ctx.files._data] + [out.path],
Klaus Aehlig6afb4fd2019-03-04 12:17:19 -080074 mnemonic = "copying",
75 progress_message = "Copying implict data dependency for %s" % ctx.label
76 )
77
78implicit_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)
85EOF
86 cat > BUILD <<'EOF'
87load("//:rule.bzl", "implicit_rule")
88
89implicit_rule(name = "it")
90EOF
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
106run_suite "Integration tests for reporing missing implicit dependencies"