|
| 1 | +#!/usr/bin/env bash |
| 2 | +set -euxo pipefail |
| 3 | + |
| 4 | +# Script to generate a tarball of source code and vendored (downloaded) Rust dependencies |
| 5 | +# and the cargo configuration to ensure they are used |
| 6 | + |
| 7 | +# Get the current directory, which we'll use for telling Cargo where to find the sources |
| 8 | +wd="$PWD" |
| 9 | + |
| 10 | +# Get the version from git-describe |
| 11 | +#VERSION=$(git describe --dirty 2>/dev/null) |
| 12 | +VERSION="0.10" |
| 13 | + |
| 14 | +# The path where we will output the tar file |
| 15 | +path=$wd/moss-$VERSION-vendored.tar.zst |
| 16 | + |
| 17 | +# Clean up stuff we've written before |
| 18 | +rm -f "$path" |
| 19 | + |
| 20 | +# Make sure cargo lock files are in sync with cargo.toml |
| 21 | +cargo check --locked |
| 22 | + |
| 23 | +PREFIX_TMPDIR=$(mktemp -d) |
| 24 | +pushd "$PREFIX_TMPDIR" |
| 25 | + |
| 26 | +# Enable dotglob so we copy over files/folders starting with . |
| 27 | +shopt -s dotglob |
| 28 | +cp -ra "$wd"/* . |
| 29 | + |
| 30 | +function get_commit_time() { |
| 31 | + TZ=UTC0 git log -1 \ |
| 32 | + --format=tformat:%cd \ |
| 33 | + --date=format:%Y-%m-%dT%H:%M:%SZ \ |
| 34 | + "$@" |
| 35 | +} |
| 36 | + |
| 37 | +# Set each file mtime to that of it's latest commit |
| 38 | +# Set each source file timestamp to that of its latest commit. |
| 39 | +git ls-files | while read -r file; do |
| 40 | + commit_time=$(get_commit_time "$file") && |
| 41 | + touch -md "$commit_time" "$file" |
| 42 | +done |
| 43 | + |
| 44 | +# Set timestamp of each directory under $FILES |
| 45 | +# to the latest timestamp of any descendant. |
| 46 | +find . -depth -type d -exec sh -c \ |
| 47 | + 'touch -r "$0/$(ls -At "$0" | head -n 1)" "$0"' \ |
| 48 | + {} ';' |
| 49 | + |
| 50 | +SOURCE_EPOCH=$(get_commit_time) |
| 51 | + |
| 52 | +# Cleanup repo |
| 53 | +git reset --hard |
| 54 | +git clean -xdf |
| 55 | +git clean -df |
| 56 | +rm -rf .git |
| 57 | +rm -rf serpent-style |
| 58 | + |
| 59 | +# Generate vendored dependencies and the configuration to use them |
| 60 | +mkdir .cargo |
| 61 | +cargo vendor --manifest-path "$wd/Cargo.toml" > .cargo/config |
| 62 | + |
| 63 | +# Cleanup static libraries that support non-Linux platforms |
| 64 | +find vendor -name "*.a" -type f -print -delete |
| 65 | + |
| 66 | +# Reproducible tar flags |
| 67 | +TARFLAGS=" |
| 68 | + --sort=name --format=posix |
| 69 | + --pax-option=exthdr.name=%d/PaxHeaders/%f |
| 70 | + --pax-option=delete=atime,delete=ctime |
| 71 | + --clamp-mtime --mtime=$SOURCE_EPOCH |
| 72 | + --numeric-owner --owner=0 --group=0 |
| 73 | + --mode=go+u,go-w |
| 74 | +" |
| 75 | +ZSTDFLAGS="-19 -T0" |
| 76 | + |
| 77 | +# shellcheck disable=SC2086 |
| 78 | +LC_ALL=C tar $TARFLAGS -C $PREFIX_TMPDIR -cf - . | |
| 79 | + zstd $ZSTDFLAGS > $path |
| 80 | + |
| 81 | +popd |
| 82 | +rm -rf "$PREFIX_TMPDIR" |
| 83 | + |
| 84 | +checksum=$(sha256sum "$path") |
| 85 | +echo "Release tar checksum $checksum" |
0 commit comments