Skip to content

Commit

Permalink
Remove nanosecond modification times from Cargo fingerprints
Browse files Browse the repository at this point in the history
  • Loading branch information
shepmaster committed Jul 14, 2016
1 parent af2f7f6 commit 876a49e
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 0 deletions.
2 changes: 2 additions & 0 deletions compiler/base/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ FROM ubuntu:14.04
RUN apt-get update && apt-get install -y \
curl \
gcc \
jq \
libssl-dev \
&& rm -rf /var/lib/apt/lists/*

Expand All @@ -11,3 +12,4 @@ ENV PATH=/root/.cargo/bin:$PATH
RUN curl https://sh.rustup.rs -sSf | sh -s -- -y && rustup toolchain uninstall stable
ADD Cargo.toml /root/Cargo.toml
ADD entrypoint.sh /root/
ADD fix-modification-time.sh /root/
21 changes: 21 additions & 0 deletions compiler/base/fix-modification-time.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash

set -eu -o pipefail

# The docker filesystem layers (at least AUFS) preserve
# nanosecond-level granularity while the container is running, but
# lose that granularity when the image is saved.
#
# This causes spurious rebuilds of any crate that uses file
# modification-based timestamps, as the time appears to have
# changed. See https://github.com/rust-lang/cargo/issues/2874 for some
# further details.
#
# As a terrible, nasty hack, let's just rewrite the fingerprint files
# to set the nanosecond value to 0, matching the filesystem. This
# relies on the unstable internals of the JSON cache files, so this is
# likely quite brittle.

t=$(mktemp)
jq 'if .local.variant == "MtimeBased" then .local.fields[0][1] |= 0 else . end' "$1" > "$t"
mv "$t" "$1"
2 changes: 2 additions & 0 deletions compiler/beta/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ RUN mv /root/Cargo.toml ./Cargo.toml && \
cargo build && \
cargo build --release

RUN find . -name '*.json' -print0 | xargs -0 -n1 /root/fix-modification-time.sh

ENTRYPOINT ["/root/entrypoint.sh"]
2 changes: 2 additions & 0 deletions compiler/nightly/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ RUN mv /root/Cargo.toml ./Cargo.toml && \
cargo build && \
cargo build --release

RUN find . -name '*.json' -print0 | xargs -0 -n1 /root/fix-modification-time.sh

ENTRYPOINT ["/root/entrypoint.sh"]
2 changes: 2 additions & 0 deletions compiler/stable/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ RUN mv /root/Cargo.toml ./Cargo.toml && \
cargo build && \
cargo build --release

RUN find . -name '*.json' -print0 | xargs -0 -n1 /root/fix-modification-time.sh

ENTRYPOINT ["/root/entrypoint.sh"]

0 comments on commit 876a49e

Please sign in to comment.