-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
File digests are now additionally keyed by ctime for supported file system implementations. Since Bazel has a non-zero default for `--cache_computed_file_digests`, this may be required for correctness in cases where different files have identical mtime and inode number. For example, this can happen on Linux when files are extracted from a tar file with fixed mtime and are then replaced with `mv`, which preserves inodes.
- Loading branch information
Showing
3 changed files
with
108 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
#!/bin/bash | ||
# | ||
# Copyright 2020 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. | ||
|
||
# --- begin runfiles.bash initialization --- | ||
# Copy-pasted from Bazel's Bash runfiles library (tools/bash/runfiles/runfiles.bash). | ||
set -euo pipefail | ||
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; } | ||
|
||
# Regression test for https://github.com/bazelbuild/bazel/issues/14723 | ||
function test_fixed_mtime_move_detected_as_change() { | ||
mkdir -p pkg | ||
cat > pkg/BUILD <<'EOF' | ||
load("rules.bzl", "my_expand") | ||
genrule( | ||
name = "my_templates", | ||
srcs = ["template_archive.tar"], | ||
outs = ["template1"], | ||
cmd = "tar -C $(RULEDIR) -xf $<", | ||
) | ||
my_expand( | ||
name = "expand1", | ||
input = "template1", | ||
output = "expanded1", | ||
to_sub = {"test":"foo"} | ||
) | ||
EOF | ||
cat > pkg/rules.bzl <<'EOF' | ||
def _my_expand_impl(ctx): | ||
ctx.actions.expand_template( | ||
template = ctx.file.input, | ||
output = ctx.outputs.output, | ||
substitutions = ctx.attr.to_sub | ||
) | ||
my_expand = rule( | ||
implementation = _my_expand_impl, | ||
attrs = { | ||
"input": attr.label(allow_single_file=True), | ||
"output": attr.output(), | ||
"to_sub" : attr.string_dict(), | ||
} | ||
) | ||
EOF | ||
|
||
echo "test : alpha" > template1 | ||
tar -cf pkg/template_archive_alpha.tar --mtime='1970-01-01' template1 | ||
echo "test : delta" > template1 | ||
tar -cf pkg/template_archive_delta.tar --mtime='1970-01-01' template1 | ||
|
||
mv pkg/template_archive_alpha.tar pkg/template_archive.tar | ||
bazel build //pkg:expand1 || fail "Expected success" | ||
assert_equals "foo : alpha" "$(cat bazel-bin/pkg/expanded1)" | ||
|
||
mv pkg/template_archive_delta.tar pkg/template_archive.tar | ||
bazel build //pkg:expand1 || fail "Expected success" | ||
assert_equals "foo : delta" "$(cat bazel-bin/pkg/expanded1)" | ||
} | ||
|
||
run_suite "digest cache invalidation test" |