plymouth/scripts/generate-version.sh
Ray Strode 36cf20c6fa meson: Generate version for reproducibility
Right now we call date directly from meson.build leading to
non-reproducible builds.

This commit makes it only call date when building from git,
otherwise it extracts the version from the tarball name.

script borrowed from accountsservice.

Closes https://gitlab.freedesktop.org/plymouth/plymouth/-/issues/188
2022-11-29 14:40:11 -05:00

26 lines
948 B
Bash
Executable file

#!/bin/sh
exec 3>&2 2> /dev/null
SRCDIR=$(dirname "$0")
cd "$SRCDIR"
CWD=$(realpath "$PWD")
TOPLEVEL_WORKING_DIR=$(realpath "$(git rev-parse --show-toplevel)")
SCRIPTDIR=${SRCDIR#"${TOPLEVEL_WORKING_DIR}/"}
exec 2>&3
# If it's not from a git checkout, assume it's from a tarball
if [ "${TOPLEVEL_WORKING_DIR}/${SCRIPTDIR}" != "$CWD" ]; then
VERSION_FROM_DIR_NAME=$(basename "$CWD" | sed -n 's/^plymouth-\([^-]*\)$/\1/p')
if [ -n "$VERSION_FROM_DIR_NAME" ]; then
echo "$VERSION_FROM_DIR_NAME"
exit 0
fi
echo "Source doesn't appear to come from an plymouth git clone or tarball. Version unknown."
exit 1
fi
# If it is from a git checkout, derive the version from the date of the last commit, and the number
# of commits since the last release.
COMMITS_SINCE_LAST_RELEASE=$(git rev-list $(git describe --abbrev=0)..HEAD --count)
date +%y.%V.${COMMITS_SINCE_LAST_RELEASE} -d "@$(git log -1 --pretty=format:%ct)"