twerth | a1a57a5 | 2018-07-18 05:34:13 -0700 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # |
| 3 | # Copyright 2018 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 | |
Laszlo Csomor | 3e0ede4 | 2018-08-09 07:52:41 -0700 | [diff] [blame] | 17 | # --- begin runfiles.bash initialization --- |
| 18 | # Copy-pasted from Bazel's Bash runfiles library (tools/bash/runfiles/runfiles.bash). |
| 19 | set -euo pipefail |
| 20 | if [[ ! -d "${RUNFILES_DIR:-/dev/null}" && ! -f "${RUNFILES_MANIFEST_FILE:-/dev/null}" ]]; then |
| 21 | if [[ -f "$0.runfiles_manifest" ]]; then |
| 22 | export RUNFILES_MANIFEST_FILE="$0.runfiles_manifest" |
| 23 | elif [[ -f "$0.runfiles/MANIFEST" ]]; then |
| 24 | export RUNFILES_MANIFEST_FILE="$0.runfiles/MANIFEST" |
| 25 | elif [[ -f "$0.runfiles/bazel_tools/tools/bash/runfiles/runfiles.bash" ]]; then |
| 26 | export RUNFILES_DIR="$0.runfiles" |
| 27 | fi |
| 28 | fi |
| 29 | if [[ -f "${RUNFILES_DIR:-/dev/null}/bazel_tools/tools/bash/runfiles/runfiles.bash" ]]; then |
| 30 | source "${RUNFILES_DIR}/bazel_tools/tools/bash/runfiles/runfiles.bash" |
| 31 | elif [[ -f "${RUNFILES_MANIFEST_FILE:-/dev/null}" ]]; then |
| 32 | source "$(grep -m1 "^bazel_tools/tools/bash/runfiles/runfiles.bash " \ |
| 33 | "$RUNFILES_MANIFEST_FILE" | cut -d ' ' -f 2-)" |
| 34 | else |
| 35 | echo >&2 "ERROR: cannot find @bazel_tools//tools/bash/runfiles:runfiles.bash" |
| 36 | exit 1 |
| 37 | fi |
| 38 | # --- end runfiles.bash initialization --- |
| 39 | |
| 40 | source "$(rlocation "io_bazel/src/test/shell/integration_test_setup.sh")" \ |
twerth | a1a57a5 | 2018-07-18 05:34:13 -0700 | [diff] [blame] | 41 | || { echo "integration_test_setup.sh not found!" >&2; exit 1; } |
| 42 | |
Laszlo Csomor | 3e0ede4 | 2018-08-09 07:52:41 -0700 | [diff] [blame] | 43 | case "$(uname -s | tr [:upper:] [:lower:])" in |
| 44 | msys*|mingw*|cygwin*) |
| 45 | declare -r is_windows=true |
| 46 | ;; |
| 47 | *) |
| 48 | declare -r is_windows=false |
| 49 | ;; |
| 50 | esac |
| 51 | |
| 52 | if "$is_windows"; then |
| 53 | export MSYS_NO_PATHCONV=1 |
| 54 | export MSYS2_ARG_CONV_EXCL="*" |
| 55 | fi |
| 56 | |
twerth | a1a57a5 | 2018-07-18 05:34:13 -0700 | [diff] [blame] | 57 | add_to_bazelrc "build --package_path=%workspace%" |
| 58 | |
| 59 | function test_basic_aquery() { |
| 60 | local pkg="${FUNCNAME[0]}" |
| 61 | mkdir -p "$pkg" || fail "mkdir -p $pkg" |
| 62 | cat > "$pkg/BUILD" <<'EOF' |
| 63 | genrule( |
| 64 | name = "foo", |
twerth | 66a2063 | 2018-07-31 08:29:27 -0700 | [diff] [blame] | 65 | srcs = [":bar"], |
twerth | a1a57a5 | 2018-07-18 05:34:13 -0700 | [diff] [blame] | 66 | outs = ["foo_out.txt"], |
| 67 | cmd = "cat $(SRCS) > $(OUTS)", |
| 68 | ) |
| 69 | |
| 70 | genrule( |
| 71 | name = "bar", |
| 72 | srcs = ["dummy.txt"], |
| 73 | outs = ["bar_out.txt"], |
| 74 | cmd = "echo unused > $(OUTS)", |
| 75 | ) |
| 76 | EOF |
| 77 | echo "hello aquery" > "$pkg/in.txt" |
| 78 | |
| 79 | bazel aquery "//$pkg:foo" > output 2> "$TEST_log" || fail "Expected success" |
twerth | 66a2063 | 2018-07-31 08:29:27 -0700 | [diff] [blame] | 80 | assert_contains "//$pkg:foo" output |
| 81 | assert_not_contains "//$pkg:bar" output |
twerth | a1a57a5 | 2018-07-18 05:34:13 -0700 | [diff] [blame] | 82 | |
twerth | f621bbe | 2018-08-02 07:30:30 -0700 | [diff] [blame] | 83 | bazel aquery "deps(//$pkg:foo)" > output 2> "$TEST_log" \ |
| 84 | || fail "Expected success" |
twerth | 66a2063 | 2018-07-31 08:29:27 -0700 | [diff] [blame] | 85 | assert_contains "//$pkg:foo" output |
| 86 | assert_contains "//$pkg:bar" output |
twerth | a1a57a5 | 2018-07-18 05:34:13 -0700 | [diff] [blame] | 87 | } |
twerth | 66a2063 | 2018-07-31 08:29:27 -0700 | [diff] [blame] | 88 | |
twerth | f621bbe | 2018-08-02 07:30:30 -0700 | [diff] [blame] | 89 | function test_aquery_text() { |
| 90 | local pkg="${FUNCNAME[0]}" |
| 91 | mkdir -p "$pkg" || fail "mkdir -p $pkg" |
| 92 | cat > "$pkg/BUILD" <<'EOF' |
| 93 | genrule( |
| 94 | name = "bar", |
| 95 | srcs = ["dummy.txt"], |
| 96 | outs = ["bar_out.txt"], |
| 97 | cmd = "echo unused > $(OUTS)", |
| 98 | ) |
| 99 | EOF |
| 100 | echo "hello aquery" > "$pkg/in.txt" |
| 101 | |
| 102 | bazel aquery --output=text "//$pkg:bar" > output 2> "$TEST_log" \ |
| 103 | || fail "Expected success" |
| 104 | cat output >> "$TEST_log" |
| 105 | assert_contains "action 'Executing genrule //$pkg:bar'" output |
| 106 | assert_contains "Mnemonic: Genrule" output |
| 107 | assert_contains "Owner: //$pkg:bar" output |
| 108 | assert_contains "Configuration: .*-fastbuild" output |
| 109 | # Only check that the inputs/outputs/command line/environment exist, but not |
| 110 | # their actual contents since that would be too much. |
| 111 | assert_contains "Inputs: \[" output |
| 112 | assert_contains "Outputs: \[" output |
Laszlo Csomor | 3e0ede4 | 2018-08-09 07:52:41 -0700 | [diff] [blame] | 113 | if is_windows; then |
| 114 | assert_contains "Command Line: .*bash\.exe" output |
| 115 | else |
| 116 | assert_contains "Command Line: (" output |
| 117 | fi |
twerth | 50ea2dd | 2018-09-06 04:58:19 -0700 | [diff] [blame^] | 118 | } |
twerth | f621bbe | 2018-08-02 07:30:30 -0700 | [diff] [blame] | 119 | |
twerth | 50ea2dd | 2018-09-06 04:58:19 -0700 | [diff] [blame^] | 120 | function test_aquery_skylark_env() { |
| 121 | local pkg="${FUNCNAME[0]}" |
| 122 | mkdir -p "$pkg" || fail "mkdir -p $pkg" |
| 123 | cat > "$pkg/rule.bzl" <<'EOF' |
| 124 | def _impl(ctx): |
| 125 | output = ctx.outputs.out |
| 126 | input = ctx.file.source |
| 127 | env = {} |
| 128 | env["foo"] = "bar" |
| 129 | |
| 130 | ctx.actions.run_shell( |
| 131 | inputs = [input], |
| 132 | outputs = [output], |
| 133 | command = "cat '%s' > '%s'" % (input.path, output.path), |
| 134 | env = env, |
| 135 | ) |
| 136 | |
| 137 | copy = rule( |
| 138 | implementation = _impl, |
| 139 | attrs = {"source": attr.label(mandatory = True, allow_single_file = True)}, |
| 140 | outputs = {"out": "%{name}.copy"}, |
| 141 | ) |
| 142 | EOF |
| 143 | |
| 144 | cat > "$pkg/BUILD" <<'EOF' |
| 145 | load(":rule.bzl", "copy") |
| 146 | copy( |
| 147 | name = "goo", |
| 148 | source = "dummy.txt", |
| 149 | ) |
| 150 | EOF |
| 151 | echo "hello aquery" > "$pkg/dummy.txt" |
| 152 | |
| 153 | bazel aquery --output=text "//$pkg:goo" > output 2> "$TEST_log" \ |
| 154 | || fail "Expected success" |
| 155 | cat output >> "$TEST_log" |
| 156 | assert_contains "Mnemonic: SkylarkAction" output |
| 157 | assert_contains "Owner: //$pkg:goo" output |
| 158 | assert_contains "Environment: \[.*foo=bar" output |
twerth | f621bbe | 2018-08-02 07:30:30 -0700 | [diff] [blame] | 159 | } |
| 160 | |
twerth | 66a2063 | 2018-07-31 08:29:27 -0700 | [diff] [blame] | 161 | run_suite "${PRODUCT_NAME} action graph query tests" |