rockbox/tools/version.sh
Skye 85c1ff8667 change build scripts to make reproducible builds possible
- makes SOURCE_DATE_EPOCH affect BUILDDATE and version string
- makes wpsbuild.pl output deterministic
- omits unnecessary extended metadata from zip files
- runs strip-nondeterminism on zip files if REPRODUCIBLE_ZIP is set

Change-Id: I1617e3f5233b2bc356fcfa6457be1a7785c303f9
2026-08-09 10:29:48 -04:00

60 lines
1.6 KiB
Bash
Executable file

#!/bin/sh
# __________ __ ___.
# Open \______ \ ____ ____ | | _\_ |__ _______ ___
# Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
# Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
# Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
# \/ \/ \/ \/ \/
#
# Usage: version.sh [source-root]
# Prints the revision of the repository.
#
# The format is rNNNNNNNNNN[M]-YYMMDD
#
# The M indicates the revision has been locally modified
#
# This logic is pulled from the Linux's scripts/setlocalversion (also GPL)
# and tweaked for rockbox.
gitversion() {
# This verifies we are in a git directory
if head=`git -C "$1" rev-parse --verify --short=10 HEAD 2>/dev/null`; then
# Are there uncommitted changes?
export GIT_WORK_TREE="$1"
if git -C "$1" diff --name-only HEAD | read dummy; then
mod="M"
elif git -C "$1" diff --name-only --cached HEAD | read dummy; then
mod="M"
fi
echo "${head}${mod}"
# All done with git
exit
fi
}
#
# First locate the top of the src tree (passed in usually)
#
if [ -n "$1" ]; then TOP=$1; else TOP=..; fi
# setting VERSION var on commandline has precedence
if [ -z $VERSION ]; then
# If the VERSIONFILE exisits we use that
VERSIONFILE=docs/VERSION
if [ -r $TOP/$VERSIONFILE ]; then
VER=`cat $TOP/$VERSIONFILE`;
else
# Ok, we need to derive it from the Version Control system
VER=`gitversion $TOP`
fi
if [ -z $SOURCE_DATE_EPOCH ]; then
VERSION=$VER-`date -u +%y%m%d`
else
VERSION=$VER-`date -d @$SOURCE_DATE_EPOCH -u +%y%m%d`
fi
fi
echo $VERSION