Skip to content

Commit

Permalink
Fix and verify full jdeps rewriting
Browse files Browse the repository at this point in the history
  • Loading branch information
fmeum committed Nov 8, 2023
1 parent df95cac commit c52b670
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,11 @@ public ActionResult execute(ActionExecutionContext actionExecutionContext)
.insertDependencies(
outputDepsProto,
readFullOutputDeps(fallbackResults, actionExecutionContext, spawn.getPathMapper()));
} else if (!spawn.getPathMapper().isNoop()){
// As a side effect, readFullOutputDeps rewrites the on-disk .jdeps file from mapped to
// unmapped paths. To make path mapping fully transparent to consumers of this action's
// output, we ensure that the file always contains unmapped paths.
readFullOutputDeps(fallbackResults, actionExecutionContext, spawn.getPathMapper());
}
return ActionResult.create(
ImmutableList.copyOf(Iterables.concat(primaryResults, fallbackResults)));
Expand Down
12 changes: 12 additions & 0 deletions src/test/shell/integration/config_stripped_outputs_lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,15 @@ function assert_paths_stripped() {

assert_equals 1 "$found_identifying_output"
}

# Asserts a file contains no stripped paths.
#
# Arguments:
# Path to the file.
function assert_contains_no_stripped_path() {
# For "bazel-out/x86-fastbuild/bin/...", return "bazel-out".
output_path=$(bazel info | grep '^output_path:')
stripped_bin="${output_path##*/}/bin"

assert_not_contains "$stripped_bin" "$1" "Stripped path found in $1"
}
28 changes: 20 additions & 8 deletions src/test/shell/integration/config_stripped_outputs_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,14 @@ function is_bazel() {
fi
}

# TODO: Remove this check when Javac actions use multiplex worker sandboxing by default.
if is_bazel; then
bazel_bin=bazel-bin
# TODO: Remove these lines when Javac actions use multiplex worker sandboxing by default in Bazel.
add_to_bazelrc "build --strategy=Javac=worker"
add_to_bazelrc "build --worker_sandboxing"
add_to_bazelrc "build --noexperimental_worker_multiplex"
else
bazel_bin=blaze-bin
fi

# Tests built-in Java support for stripping config path prefixes from
Expand Down Expand Up @@ -180,6 +183,15 @@ function test_inmemory_jdeps_support() {
assert_paths_stripped "$TEST_log" "$pkg/java/hello/liba.jar-0.params"
# java_library header jar compilation:
assert_paths_stripped "$TEST_log" "bin/$pkg/java/hello/libb-hjar.jar"
# jdeps files should contain the original paths since they are read by downstream actions that may
# not use path mapping.
assert_contains_no_stripped_path "${bazel_bin}/$pkg/java/hello/liba.jdeps"
assert_contains_no_stripped_path "${bazel_bin}/$pkg/java/hello/libb.jdeps"
assert_contains_no_stripped_path "${bazel_bin}/$pkg/java/hello/libb-hjar.jdeps"
assert_contains_no_stripped_path "${bazel_bin}/$pkg/java/hello/libc.jdeps"
assert_contains_no_stripped_path "${bazel_bin}/$pkg/java/hello/libc-hjar.jdeps"
assert_contains_no_stripped_path "${bazel_bin}/$pkg/java/hello/libd.jdeps"
assert_contains_no_stripped_path "${bazel_bin}/$pkg/java/hello/libd-hjar.jdeps"
}

function test_multiple_configs() {
Expand Down Expand Up @@ -308,13 +320,13 @@ EOF
assert_contains "\(bazel\|blaze\)-out/[^/]\+-fastbuild/bin/$pkg/java/liblib.jar-0.params" "$TEST_log"
# lib header jar compilation should not be stripped due to conflicting paths
assert_contains "--output \(bazel\|blaze\)-out/[^/]\+-fastbuild/bin/$pkg/java/liblib-hjar.jar" "$TEST_log"
# lib full jdeps proto should not be stripped due to conflicting paths
if is_bazel; then
bazel_bin="bazel-bin"
else
bazel_bin="blaze-bin"
fi
assert_contains "\(bazel\|blaze\)-out/[^/]\+-fastbuild/bin/$pkg/java/libbase_lib-hjar.jar" ${bazel_bin}/$pkg/java/liblib.jdeps
# jdeps files should contain the original paths since they are read by downstream actions that may
# not use path mapping.
assert_contains_no_stripped_path "${bazel_bin}/$pkg/java/Main.jdeps"
assert_contains_no_stripped_path "${bazel_bin}/$pkg/java/liblib.jdeps"
assert_contains_no_stripped_path "${bazel_bin}/$pkg/java/liblib-hjar.jdeps"
assert_contains_no_stripped_path "${bazel_bin}/$pkg/java/libbase_lib.jdeps"
assert_contains_no_stripped_path "${bazel_bin}/$pkg/java/libbase_lib-hjar.jdeps"
}

run_suite "Tests stripping config prefixes from output paths for better action caching"

0 comments on commit c52b670

Please sign in to comment.