diff --git a/src/test/shell/bazel/BUILD b/src/test/shell/bazel/BUILD index dc45bc99d242b5..ac17d2c8901160 100644 --- a/src/test/shell/bazel/BUILD +++ b/src/test/shell/bazel/BUILD @@ -1300,6 +1300,14 @@ sh_test( deps = ["@bazel_tools//tools/bash/runfiles"], ) +sh_test( + name = "path_mapping_test", + srcs = ["path_mapping_test.sh"], + data = [":test-deps"], + tags = ["no_windows"], + deps = ["@bazel_tools//tools/bash/runfiles"], +) + sh_test( name = "platforms_test", srcs = ["platforms_test.sh"], diff --git a/src/test/shell/bazel/path_mapping_test.sh b/src/test/shell/bazel/path_mapping_test.sh new file mode 100755 index 00000000000000..74d52147c10780 --- /dev/null +++ b/src/test/shell/bazel/path_mapping_test.sh @@ -0,0 +1,130 @@ +#!/bin/bash +# +# Copyright 2023 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. +# +# Tests remote execution and caching. + +set -euo pipefail + +# --- begin runfiles.bash initialization --- +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; } + +function set_up() { + mkdir -p src/main/java/com/example + cat > src/main/java/com/example/BUILD <<'EOF' +java_binary( + name = "Main", + srcs = ["Main.java"], + deps = [":lib"], +) +java_library( + name = "lib", + srcs = ["Lib.java"], +) +EOF + cat > src/main/java/com/example/Main.java <<'EOF' +package com.example; +public class Main { + public static void main(String[] args) { + System.out.println(Lib.getGreeting()); + } +} +EOF + cat > src/main/java/com/example/Lib.java <<'EOF' +package com.example; +public class Lib { + public static String getGreeting() { + return String.format("Hello, %s!", System.getenv("COMPILATION_MODE")); + } +} +EOF +} + +function test_path_stripping_sandboxed() { + cache_dir=$(mktemp -d) + + COMPILATION_MODE=fastbuild \ + bazel run -c fastbuild \ + --disk_cache=$cache_dir \ + --experimental_output_paths=strip \ + --strategy=Javac=sandboxed \ + //src/main/java/com/example:Main &> $TEST_log || fail "run failed unexpectedly" + expect_log "Hello, fastbuild!" + expect_log '5 \(linux\|darwin\|processwrapper\)-sandbox' + expect_not_log "disk cache hit" + + COMPILATION_MODE=opt \ + bazel run -c opt \ + --disk_cache=$cache_dir \ + --experimental_output_paths=strip \ + --strategy=Javac=sandboxed \ + //src/main/java/com/example:Main &> $TEST_log || fail "run failed unexpectedly" + expect_log "Hello, opt!" + expect_log "5 disk cache hit" + expect_not_log '[0-9] \(linux\|darwin\|processwrapper\)-sandbox' +} + +function test_path_stripping_singleplex_worker() { + cache_dir=$(mktemp -d) + + COMPILATION_MODE=fastbuild \ + bazel run -c fastbuild \ + --disk_cache=$cache_dir \ + --experimental_output_paths=strip \ + --strategy=Javac=worker \ + --worker_sandboxing \ + --noexperimental_worker_multiplex \ + //src/main/java/com/example:Main &> $TEST_log || fail "run failed unexpectedly" + expect_log "Hello, fastbuild!" + expect_log '3 \(linux\|darwin\|processwrapper\)-sandbox' + expect_log '2 worker' + expect_not_log "disk cache hit" + + COMPILATION_MODE=opt \ + bazel run -c opt \ + --disk_cache=$cache_dir \ + --experimental_output_paths=strip \ + --strategy=Javac=worker \ + --worker_sandboxing \ + --noexperimental_worker_multiplex \ + //src/main/java/com/example:Main &> $TEST_log || fail "run failed unexpectedly" + expect_log "Hello, opt!" + expect_log "5 disk cache hit" + expect_not_log '[0-9] \(linux\|darwin\|processwrapper\)-sandbox' + expect_not_log '[0-9] worker' +} + +run_suite "path mapping tests" \ No newline at end of file