]> git.ipfire.org Git - thirdparty/plymouth.git/commitdiff
meson: Generate version for reproducibility
authorRay Strode <rstrode@redhat.com>
Tue, 29 Nov 2022 19:26:43 +0000 (14:26 -0500)
committerRay Strode <rstrode@redhat.com>
Tue, 29 Nov 2022 19:40:11 +0000 (14:40 -0500)
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

meson.build
scripts/generate-version.sh [new file with mode: 0755]

index bd55c1c847ee5e719be8a57bedc2e3209b02b565..78b815ad132972312389f3a31e3ed1c6a26d6c8b 100644 (file)
@@ -1,15 +1,6 @@
 project('plymouth', 'c',
   meson_version: '>= 0.61',
-  version: run_command(
-    'date', '+%y.%V.' + run_command(
-      'git', 'rev-list',
-      run_command('git', 'describe', '--abbrev=0', check: true).stdout().strip() + '..HEAD',
-      '--count',
-      check: true,
-    ).stdout().strip(),
-    '-d', '@' + run_command('git', 'log', '-1', '--pretty=format:%ct', check: true).stdout().strip(),
-    check: true,
-  ).stdout().strip(),
+  version: run_command(['scripts/generate-version.sh'], check: true).stdout().strip(),
 )
 
 # Modules
diff --git a/scripts/generate-version.sh b/scripts/generate-version.sh
new file mode 100755 (executable)
index 0000000..83553ad
--- /dev/null
@@ -0,0 +1,26 @@
+#!/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)"