| 1 |
#!/bin/sh |
| 2 |
# determines the version of the sources |
| 3 |
# usage: version <source directory> |
| 4 |
|
| 5 |
# set -x |
| 6 |
|
| 7 |
srcdir="$1" |
| 8 |
|
| 9 |
# if we're building via CI from a protected tag, that is our version |
| 10 |
if test "${CI_COMMIT_REF_PROTECTED}" = "true" && ! test -z "${CI_COMMIT_TAG}"; then |
| 11 |
echo "${CI_COMMIT_TAG}" | sed -e s/^v// |
| 12 |
exit 0 |
| 13 |
fi |
| 14 |
|
| 15 |
# set version parts to defaults for CVS snapshot |
| 16 |
major_version=`cat ${srcdir}/major_version` |
| 17 |
minor_version_proto=`cat ${srcdir}/minor_version` |
| •18 |
# Set DATE from SOURCE_DATE_EPOCH to enable reproducible builds: |
| 19 |
# https://reproducible-builds.org/docs/source-date-epoch/ |
| 20 |
DATE_FMT='+%Y%m%d' |
| 21 |
DATE=$(date -u -d "@${SOURCE_DATE_EPOCH}" "${DATE_FMT}" 2>/dev/null || date -u -r "${SOURCE_DATE_EPOCH}" "${DATE_FMT}" 2>/dev/null || date -u "${DATE_FMT}") |
| 22 |
|
| 23 |
#echo $major_version |
| 24 |
#echo $minor_version |
| 25 |
|
| 26 |
bzr_count_revisions() |
| 27 |
{ |
| 28 |
srcdir="$1" |
| 29 |
limit="$2" |
| 30 |
|
| 31 |
test -z "$limit" || limit="-l $limit" |
| 32 |
|
| 33 |
count=$(bzr log -n 0 --line $limit "${srcdir}" 2>/dev/null | wc -l) |
| 34 |
echo $count |
| 35 |
} |
| 36 |
|
| 37 |
# *TODO* once we get our superproject up on launchpad (and thus get saner branch nicks), use branch nicks for $major_version |
| 38 |
# Check if bzr is installed, and if the path is versionned |
| 39 |
bzr >/dev/null 2>&1 |
| 40 |
# But for now, ignore it |
| 41 |
if test $? -eq 0 && test -d ${srcdir}/.bzr |
| 42 |
#if test 1 -eq 0 |
| 43 |
then |
| 44 |
# Crappily, we can't rely on revision numbers to do anything |
| 45 |
# ( ie. when one merges then pushes, the last revno might be lower than originally) |
| 46 |
# So we count revisions, including merged ones, also including fools which have empty |
| 47 |
# lines with only "revno: 15" in their commit messages |
| 48 |
revno=$( bzr revno ${srcdir} 2>/dev/null) |
| 49 |
revcount=$( bzr_count_revisions ${srcdir} ) |
| 50 |
lca=$revno |
| 51 |
lcaz=$revcount |
| 52 |
versioned=# |
| 53 |
branchurl=$( bzr info ${srcdir} 2>/dev/null | sed -ne 's/^ parent branch: \(.*\)$/\1/p' ) |
| 54 |
|
| 55 |
|
| 56 |
# We will check this branch diverged, and/or if tree changed |
| 57 |
bzrmissingcout=$( cd ${srcdir} && bzr missing --this 2>/dev/null ) |
| 58 |
missing=$? |
| 59 |
bzr diff ${srcdir} --quiet >/dev/null 2>&1 |
| 60 |
changed=$? |
| 61 |
|
| 62 |
|
| 63 |
if test ${missing} -eq 1 |
| 64 |
# if it diverged: |
| 65 |
then |
| 66 |
# Count the revisions we added locally |
| 67 |
localrevisions=$( echo "${bzrmissingcout}" | sed -ne '2,1s/[^0-9]//gp' ) |
| 68 |
# See how many steps it is, with the fool's number |
| 69 |
stepsbackwards=$( bzr_count_revisions ${srcdir} ${localrevisions} ) |
| 70 |
# And start dancing. |
| 71 |
minor_version=_alpha_z$(( ${revcount} - ${stepsbackwards} ))_${DATE} |
| 72 |
# Set last common ancestors |
| 73 |
lca=$(( ${revno} - ${localrevisions})) |
| 74 |
lcaz=$(( ${revcount} - ${stepsbackwards} )) |
| 75 |
srcchanged=# |
| 76 |
elif test ${missing} -eq 0 && ( test ${changed} -eq 1 || test ${changed} -eq 2 ) |
| 77 |
then |
| 78 |
# If a change was made and no more revision was added, just use revision fool's number plus build date |
| 79 |
minor_version=_alpha_z${revcount}_${DATE} |
| 80 |
# And this is versionned too |
| 81 |
srcchanged=# |
| 82 |
elif test ${missing} -eq 0 |
| 83 |
then |
| 84 |
# If really no change was made, use the fool's number, with tag if any |
| 85 |
# So check if we have tags |
| 86 |
revno=$(bzr revno ${srcdir}) |
| 87 |
tag=$(bzr tags -r $revno | awk '{ print $1 }' | sed -e s/^v//) |
| 88 |
if test ${tag} |
| 89 |
then |
| 90 |
# If it is tagged, use the tag |
| 91 |
minor_version=_alpha_z${revcount}_${tag} |
| 92 |
else |
| 93 |
# If not, use fool's number only |
| 94 |
minor_version=_alpha_z${revcount} |
| 95 |
fi |
| 96 |
# That's versioned as well |
| 97 |
else |
| 98 |
# Otherwise, this is just not versionned |
| 99 |
versioned= |
| 100 |
fi |
| 101 |
|
| 102 |
if test $versioned |
| 103 |
then |
| 104 |
branchnick=$( cd ${srcdir}; bzr nick ) |
| 105 |
revid=$( bzr testament | sed -ne 's/^revision-id: \(.*\)/\1/p' ) |
| 106 |
fi |
| 107 |
fi |
| 108 |
|
| 109 |
# try to get a good guess about which branch we're on |
| 110 |
GIT_BRANCH="alpha" |
| 111 |
|
| 112 |
if test -e "${srcdir}/.git"; then |
| 113 |
# check for a tag |
| 114 |
cd $srcdir |
| 115 |
|
| 116 |
# todo: once we have make tags, consider just git describe --tags as version ID, like this: |
| 117 |
# git describe --tags | sed -e s/^v// |
| 118 |
# exit 0 |
| 119 |
|
| 120 |
#if tag=`git describe --tags --candidates=0` > /dev/null 2>&1; then |
| 121 |
# major_version=`echo ${tag} | sed -e s/version_// -e s/release_//` -e s/^v// |
| 122 |
# minor_version="" |
| 123 |
# DATE="" |
| 124 |
#else |
| 125 |
git update-index --refresh > /dev/null |
| 126 |
if git diff-index --quiet HEAD --; then |
| 127 |
# local checkout clean, just use revno |
| 128 |
DATE=_z`git rev-list HEAD --count` |
| 129 |
else |
| 130 |
# local changes, add date |
| 131 |
DATE=_z`git rev-list HEAD --count`_$DATE |
| 132 |
fi |
| 133 |
#fi |
| 134 |
|
| 135 |
GIT_BRANCH=`git -C ${srcdir} rev-parse --abbrev-ref HEAD` |
| 136 |
fi |
| 137 |
test -z "${CI_COMMIT_BRANCH}" || GIT_BRANCH=${CI_COMMIT_BRANCH} |
| 138 |
|
| 139 |
if test -z "$minor_version" |
| 140 |
then |
| 141 |
test -z "$DATE" || minor_version=`echo ${minor_version_proto} | sed -e "s,DATE,$DATE," -e "s,YYYYMMDD,$DATE,"` |
| 142 |
fi |
| 143 |
|
| 144 |
if test "${CI_COMMIT_REF_PROTECTED}" = "true"; then |
| 145 |
# determine alpha/beta/rc status based on branch |
| 146 |
if echo ${GIT_BRANCH} | grep -q "^beta"; then |
| 147 |
minor_version=`echo ${minor_version} | sed -e s,alpha,beta,` |
| 148 |
elif echo ${GIT_BRANCH} | grep -q "^release"; then |
| 149 |
minor_version=`echo ${minor_version} | sed -e s,alpha,rc,` |
| 150 |
fi |
| 151 |
fi |
| 152 |
|
| 153 |
echo $major_version$minor_version |