K.I.S.S
Vastly simplify how we determine what version it is. We only support git, nothing else is needed/wanted because of upkeep headaches. tags are now verified with exact-match, NULL otherwise. branches are now populated with the symbolic-ref, NULL otherwise. Fix modification detection. Vastly simplify how we use version data. Fix autorevision.cache file to not be deleted on make clean (before, it would be deleted if you were using a tarball and did make clean) No build modification changes are nessesary, it is backwards compatiable to what we had before. (As long as you use git or use the tarball) closes ticket:4136master
parent
8cba7f3463
commit
cc70e11921
|
@ -16,7 +16,6 @@ usage: ./autorevision {-t output-type | -s symbol} [-o cache-file [-f] ] [-V]
|
|||
-s symbol = specify symbol output
|
||||
-o cache-file = specify cache file location
|
||||
-f = force the use of cache data
|
||||
-U = Check for untracked files in svn
|
||||
-V = emit version and exit
|
||||
-? = help message
|
||||
|
||||
|
@ -24,26 +23,13 @@ The folowing are valid output types:
|
|||
h = Header for use with c/c++
|
||||
xcode = Header useful for populating info.plist files
|
||||
sh = Bash sytax
|
||||
py = Python file
|
||||
pl = Perl file
|
||||
lua = Lua file
|
||||
php = PHP file
|
||||
ini = INI file
|
||||
js = javascript file
|
||||
json = JSON file
|
||||
java = Java file
|
||||
javaprop = Java properties file
|
||||
tex = (La)TeX file
|
||||
m4 = m4 file
|
||||
|
||||
The following are valid symbols:
|
||||
VCS_TYPE
|
||||
VCS_BASENAME
|
||||
VCS_NUM
|
||||
VCS_DATE
|
||||
VCS_BRANCH
|
||||
VCS_TAG
|
||||
VCS_TICK
|
||||
VCS_EXTRA
|
||||
VCS_FULL_HASH
|
||||
VCS_SHORT_HASH
|
||||
VCS_WC_MODIFIED
|
||||
|
@ -52,7 +38,7 @@ EOF
|
|||
}
|
||||
|
||||
# Config
|
||||
ARVERSION="1.6"
|
||||
ARVERSION="1.7-Warzone"
|
||||
TARGETFILE="/dev/stdout"
|
||||
while getopts ":t:o:s:Vf" OPTION; do
|
||||
case "${OPTION}" in
|
||||
|
@ -107,218 +93,22 @@ gitRepo() {
|
|||
cd "$(git rev-parse --show-toplevel)"
|
||||
|
||||
VCS_TYPE="git"
|
||||
|
||||
VCS_BASENAME="$(basename "${PWD}")"
|
||||
|
||||
# Is the working copy clean?
|
||||
test -z "$(git status --untracked-files=normal --porcelain)"
|
||||
test -z "$(git status --untracked-files=no --porcelain)"
|
||||
VCS_WC_MODIFIED="${?}"
|
||||
|
||||
# Enumeration of changesets
|
||||
VCS_NUM="$(git rev-list --count HEAD 2>/dev/null)"
|
||||
if [ -z "${VCS_NUM}" ]; then
|
||||
echo "warning: Counting the number of revisions may be slower due to an outdated git version less than 1.7.2.3. If something breaks, please update it." 1>&2
|
||||
VCS_NUM="$(git rev-list HEAD | wc -l)"
|
||||
fi
|
||||
|
||||
# This may be a git-svn remote. If so, report the Subversion revision.
|
||||
if [ -z "$(git config svn-remote.svn.url 2>/dev/null)" ]
|
||||
then
|
||||
# The full revision hash
|
||||
VCS_FULL_HASH="$(git rev-parse HEAD)"
|
||||
|
||||
# The short hash
|
||||
VCS_SHORT_HASH="$(echo "${VCS_FULL_HASH}" | cut -b 1-7)"
|
||||
else
|
||||
# The git-svn revision number
|
||||
VCS_FULL_HASH="$(git svn find-rev HEAD)"
|
||||
VCS_SHORT_HASH="${VCS_FULL_HASH}"
|
||||
fi
|
||||
|
||||
# Current branch
|
||||
VCS_BRANCH="$(git rev-parse --symbolic-full-name --verify "$(git name-rev --name-only --no-undefined HEAD 2>/dev/null)" 2>/dev/null | sed -e 's:refs/heads/::' | sed -e 's:refs/::')"
|
||||
|
||||
# Cache the description
|
||||
local DESCRIPTION="$(git describe --long --tags 2>/dev/null)"
|
||||
|
||||
# Current or last tag ancestor (empty if no tags)
|
||||
VCS_TAG="$(echo "${DESCRIPTION}" | sed -e "s:-g${VCS_SHORT_HASH}\$::" | sed -e 's:-[0-9]*$::')"
|
||||
|
||||
# Distance to last tag or an alias of VCS_NUM if there is no tag
|
||||
if [ ! -z "${DESCRIPTION}" ]; then
|
||||
VCS_TICK="$(echo "${DESCRIPTION}" | sed -e "s:${VCS_TAG}-::" -e "s:-g${VCS_SHORT_HASH}::")"
|
||||
else
|
||||
VCS_TICK="${VCS_NUM}"
|
||||
fi
|
||||
|
||||
# Date of the current commit
|
||||
VCS_DATE="$(git log -1 --pretty=format:%ci | sed -e 's: :T:' | sed -e 's: ::')"
|
||||
}
|
||||
|
||||
# For hg repos
|
||||
hgRepo() {
|
||||
cd "$(hg root)"
|
||||
|
||||
VCS_TYPE="hg"
|
||||
|
||||
VCS_BASENAME="$(basename "${PWD}")"
|
||||
|
||||
# Is the working copy clean?
|
||||
test -z "$(hg status -duram)"
|
||||
VCS_WC_MODIFIED="${?}"
|
||||
|
||||
# Enumeration of changesets
|
||||
VCS_NUM="$(hg id -n | tr -d '+')"
|
||||
|
||||
# The full revision hash
|
||||
VCS_FULL_HASH="$(hg log -r "${VCS_NUM}" -l 1 --template '{node}\n')"
|
||||
|
||||
VCS_FULL_HASH="$(git rev-parse HEAD)"
|
||||
# The short hash
|
||||
VCS_SHORT_HASH="$(hg id -i | tr -d '+')"
|
||||
|
||||
# Current bookmark (bookmarks are roughly equivalent to git's branches)
|
||||
# or branch if no bookmark
|
||||
VCS_BRANCH="$(hg id -B | cut -d ' ' -f 1)"
|
||||
# Fall back to the branch if there are no bookmarks
|
||||
if [ -z "${VCS_BRANCH}" ]; then
|
||||
VCS_BRANCH="$(hg id -b)"
|
||||
fi
|
||||
|
||||
# Current or last tag ancestor (excluding auto tags, empty if no tags)
|
||||
VCS_TAG="$(hg log -r "${VCS_NUM}" -l 1 --template '{latesttag}\n' 2>/dev/null | sed -e 's:qtip::' -e 's:tip::' -e 's:qbase::' -e 's:qparent::' -e "s:$(hg --config 'extensions.color=' --color never qtop 2>/dev/null)::" | cut -d ' ' -f 1)"
|
||||
|
||||
# Distance to last tag or an alias of VCS_NUM if there is no tag
|
||||
if [ ! -z "${VCS_TAG}" ]; then
|
||||
VCS_TICK="$(hg log -r "${VCS_NUM}" -l 1 --template '{latesttagdistance}\n' 2>/dev/null)"
|
||||
else
|
||||
VCS_TICK="${VCS_NUM}"
|
||||
fi
|
||||
|
||||
# Date of the current commit
|
||||
VCS_DATE="$(hg log -r "${VCS_NUM}" -l 1 --template '{date|isodatesec}\n' 2>/dev/null | sed -e 's: :T:' | sed -e 's: ::')"
|
||||
}
|
||||
|
||||
# For bzr repos
|
||||
bzrRepo() {
|
||||
cd "$(bzr root)"
|
||||
|
||||
VCS_TYPE="bzr"
|
||||
|
||||
VCS_BASENAME="$(basename "${PWD}")"
|
||||
|
||||
# Is the working copy clean?
|
||||
bzr version-info --custom --template='{clean}\n' | grep -q '1'
|
||||
VCS_WC_MODIFIED="${?}"
|
||||
|
||||
# Enumeration of changesets
|
||||
VCS_NUM="$(bzr revno)"
|
||||
|
||||
# The full revision hash
|
||||
VCS_FULL_HASH="$(bzr version-info --custom --template='{revision_id}\n')"
|
||||
|
||||
# The short hash
|
||||
VCS_SHORT_HASH="${VCS_NUM}"
|
||||
|
||||
# Nick of the current branch
|
||||
VCS_BRANCH="$(bzr nick)"
|
||||
|
||||
# Current or last tag ancestor (excluding auto tags, empty if no tags)
|
||||
VCS_TAG="$(bzr tags --sort=time | sed '/?$/d' | tail -n1 | cut -d ' ' -f1)"
|
||||
|
||||
# Distance to last tag or an alias of VCS_NUM if there is no tag
|
||||
if [ ! -z "${VCS_TAG}" ]; then
|
||||
VCS_TICK="$(bzr log --line -r "tag:${VCS_TAG}.." | tail -n +2 | wc -l | sed -e 's:^ *::')"
|
||||
else
|
||||
VCS_TICK="${VCS_NUM}"
|
||||
fi
|
||||
|
||||
# Date of the current commit
|
||||
VCS_DATE="$(bzr version-info --custom --template='{date}\n' | sed -e 's: :T:' | sed -e 's: ::')"
|
||||
}
|
||||
|
||||
# For svn repos
|
||||
svnRepo() {
|
||||
VCS_TYPE="svn"
|
||||
|
||||
case "${PWD}" in
|
||||
/*trunk*|/*branches*|/*tags*)
|
||||
local fn="${PWD}"
|
||||
while [ "$(basename "${fn}")" != 'trunk' ] && [ "$(basename "${fn}")" != 'branches' ] && [ "$(basename "${fn}")" != 'tags' ] && [ "$(basename "${fn}")" != '/' ]; do
|
||||
local fn="$(dirname "${fn}")"
|
||||
done
|
||||
fn="$(dirname "${fn}")"
|
||||
if [ "${fn}" = '/' ]; then
|
||||
VCS_BASENAME="$(basename "${PWD}")"
|
||||
else
|
||||
VCS_BASENAME="$(basename "${fn}")"
|
||||
fi
|
||||
;;
|
||||
*) VCS_BASENAME="$(basename "${PWD}")" ;;
|
||||
esac
|
||||
|
||||
# Cache svnversion output
|
||||
local SVNVERSION="$(svnversion)"
|
||||
|
||||
# Is the working copy clean?
|
||||
echo "${SVNVERSION}" | grep -q "M"
|
||||
case "${?}" in
|
||||
0)
|
||||
VCS_WC_MODIFIED="1"
|
||||
;;
|
||||
1)
|
||||
if [ ! -z "${UNTRACKEDFILES}"]; then
|
||||
# `svnversion` does not detect untracked files and `svn status` is really slow, so only run it if we really have to.
|
||||
if [ -z "$(svn status)" ]; then
|
||||
VCS_WC_MODIFIED="0"
|
||||
else
|
||||
VCS_WC_MODIFIED="1"
|
||||
fi
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
# Enumeration of changesets
|
||||
VCS_NUM="$(echo "${SVNVERSION}" | cut -d : -f 1 | sed -e 's:M::' -e 's:S::' -e 's:P::')"
|
||||
|
||||
# The full revision hash
|
||||
VCS_FULL_HASH="${SVNVERSION}"
|
||||
|
||||
# The short hash
|
||||
VCS_SHORT_HASH="${VCS_NUM}"
|
||||
|
||||
# Current branch
|
||||
case "${PWD}" in
|
||||
/*trunk*|/*branches*|/*tags*)
|
||||
local lastbase=""
|
||||
loacl fn="${PWD}"
|
||||
while :
|
||||
do
|
||||
base="$(basename "${fn}")"
|
||||
if [ "${base}" = 'trunk' ]; then
|
||||
VCS_BRANCH='trunk'
|
||||
break
|
||||
elif [ "${base}" = 'branches' ] || [ "${base}" = 'tags' ]; then
|
||||
VCS_BRANCH="${lastbase}"
|
||||
break
|
||||
elif [ "${base}" = '/' ]; then
|
||||
VCS_BRANCH=""
|
||||
break
|
||||
fi
|
||||
local lastbase="${base}"
|
||||
local fn="$(dirname "${fn}")"
|
||||
done
|
||||
;;
|
||||
*) VCS_BRANCH="" ;;
|
||||
esac
|
||||
|
||||
# Current or last tag ancestor (empty if no tags). But "current tag"
|
||||
# can't be extracted reliably because Subversion doesn't have tags the
|
||||
# way other VCSes do.
|
||||
VCS_TAG=""
|
||||
VCS_TICK=""
|
||||
|
||||
# Date of the current commit
|
||||
VCS_DATE="$(svn info | sed -n -e 's:Last Changed Date\: ::p' | sed 's: (.*)::' | sed -e 's: :T:' | sed -e 's: ::')"
|
||||
VCS_SHORT_HASH="$(echo "${VCS_FULL_HASH}" | cut -b 1-7)"
|
||||
# Current branch (if we are on a branch...)
|
||||
VCS_BRANCH="$(git symbolic-ref --short -q HEAD)"
|
||||
# Check if we are on a tag
|
||||
VCS_TAG="$(git describe --exact-match 2> /dev/null)"
|
||||
# get some extra data in case we are not on a branch or a tag...
|
||||
VCS_EXTRA="$(git describe 2> /dev/null)"
|
||||
}
|
||||
|
||||
|
||||
|
@ -332,11 +122,10 @@ hOutput() {
|
|||
|
||||
#define VCS_TYPE "${VCS_TYPE}"
|
||||
#define VCS_BASENAME "${VCS_BASENAME}"
|
||||
#define VCS_NUM ${VCS_NUM}
|
||||
#define VCS_DATE "${VCS_DATE}"
|
||||
#define VCS_BRANCH "${VCS_BRANCH}"
|
||||
#define VCS_TAG "${VCS_TAG}"
|
||||
#define VCS_TICK ${VCS_TICK}
|
||||
#define VCS_EXTRA "${VCS_EXTRA}"
|
||||
|
||||
|
||||
#define VCS_FULL_HASH "${VCS_FULL_HASH}"
|
||||
#define VCS_SHORT_HASH "${VCS_SHORT_HASH}"
|
||||
|
@ -358,11 +147,9 @@ xcodeOutput() {
|
|||
|
||||
#define VCS_TYPE ${VCS_TYPE}
|
||||
#define VCS_BASENAME ${VCS_BASENAME}
|
||||
#define VCS_NUM ${VCS_NUM}
|
||||
#define VCS_DATE ${VCS_DATE}
|
||||
#define VCS_BRANCH ${VCS_BRANCH}
|
||||
#define VCS_TAG ${VCS_TAG}
|
||||
#define VCS_TICK ${VCS_TICK}
|
||||
#define VCS_EXTRA ${VCS_EXTRA}
|
||||
|
||||
#define VCS_FULL_HASH ${VCS_FULL_HASH}
|
||||
#define VCS_SHORT_HASH ${VCS_SHORT_HASH}
|
||||
|
@ -382,11 +169,9 @@ shOutput() {
|
|||
|
||||
VCS_TYPE="${VCS_TYPE}"
|
||||
VCS_BASENAME="${VCS_BASENAME}"
|
||||
VCS_NUM=${VCS_NUM}
|
||||
VCS_DATE="${VCS_DATE}"
|
||||
VCS_BRANCH="${VCS_BRANCH}"
|
||||
VCS_TAG="${VCS_TAG}"
|
||||
VCS_TICK=${VCS_TICK}
|
||||
VCS_EXTRA="${VCS_EXTRA}"
|
||||
|
||||
VCS_FULL_HASH="${VCS_FULL_HASH}"
|
||||
VCS_SHORT_HASH="${VCS_SHORT_HASH}"
|
||||
|
@ -396,293 +181,12 @@ VCS_WC_MODIFIED=${VCS_WC_MODIFIED}
|
|||
# end
|
||||
EOF
|
||||
}
|
||||
|
||||
# For Python output
|
||||
pyOutput() {
|
||||
case "${VCS_WC_MODIFIED}" in
|
||||
0) VCS_WC_MODIFIED="False" ;;
|
||||
1) VCS_WC_MODIFIED="True" ;;
|
||||
esac
|
||||
cat > "${TARGETFILE}" << EOF
|
||||
# Generated by autorevision - do not hand-hack!
|
||||
|
||||
VCS_TYPE = "${VCS_TYPE}"
|
||||
VCS_BASENAME = "${VCS_BASENAME}"
|
||||
VCS_NUM = ${VCS_NUM}
|
||||
VCS_DATE = "${VCS_DATE}"
|
||||
VCS_BRANCH = "${VCS_BRANCH}"
|
||||
VCS_TAG = "${VCS_TAG}"
|
||||
VCS_TICK = ${VCS_TICK}
|
||||
|
||||
VCS_FULL_HASH = "${VCS_FULL_HASH}"
|
||||
VCS_SHORT_HASH = "${VCS_SHORT_HASH}"
|
||||
|
||||
VCS_WC_MODIFIED = ${VCS_WC_MODIFIED}
|
||||
|
||||
# end
|
||||
EOF
|
||||
}
|
||||
|
||||
# For Perl output
|
||||
plOutput() {
|
||||
cat << EOF
|
||||
# Generated by autorevision - do not hand-hack!
|
||||
|
||||
\$VCS_TYPE = "${VCS_TYPE}";
|
||||
\$VCS_BASENAME = "${VCS_BASENAME}"
|
||||
\$VCS_NUM = ${VCS_NUM};
|
||||
\$VCS_DATE = "${VCS_DATE}";
|
||||
\$VCS_BRANCH = "${VCS_BRANCH}";
|
||||
\$VCS_TAG = "${VCS_TAG}";
|
||||
\$VCS_TICK = ${VCS_TICK};
|
||||
|
||||
\$VCS_FULL_HASH = "${VCS_FULL_HASH}";
|
||||
\$VCS_SHORT_HASH = "${VCS_SHORT_HASH}";
|
||||
|
||||
\$VCS_WC_MODIFIED = ${VCS_WC_MODIFIED};
|
||||
|
||||
# end
|
||||
EOF
|
||||
}
|
||||
|
||||
# For lua output
|
||||
luaOutput() {
|
||||
case "${VCS_WC_MODIFIED}" in
|
||||
0) VCS_WC_MODIFIED="false" ;;
|
||||
1) VCS_WC_MODIFIED="true" ;;
|
||||
esac
|
||||
cat > "${TARGETFILE}" << EOF
|
||||
-- Generated by autorevision - do not hand-hack!
|
||||
|
||||
VCS_TYPE = "${VCS_TYPE}"
|
||||
VCS_BASENAME = "${VCS_BASENAME}"
|
||||
VCS_NUM = ${VCS_NUM}
|
||||
VCS_DATE = "${VCS_DATE}"
|
||||
VCS_BRANCH = "${VCS_BRANCH}"
|
||||
VCS_TAG = "${VCS_TAG}"
|
||||
VCS_TICK = ${VCS_TICK}
|
||||
|
||||
VCS_FULL_HASH = "${VCS_FULL_HASH}"
|
||||
VCS_SHORT_HASH = "${VCS_SHORT_HASH}"
|
||||
|
||||
VCS_WC_MODIFIED = ${VCS_WC_MODIFIED}
|
||||
|
||||
-- end
|
||||
EOF
|
||||
}
|
||||
|
||||
# For php output
|
||||
phpOutput() {
|
||||
case "${VCS_WC_MODIFIED}" in
|
||||
0) VCS_WC_MODIFIED="false" ;;
|
||||
1) VCS_WC_MODIFIED="true" ;;
|
||||
esac
|
||||
cat > "${TARGETFILE}" << EOF
|
||||
<?php
|
||||
# Generated by autorevision - do not hand-hack!
|
||||
|
||||
$GLOBALS["VCS_TYPE"] = "${VCS_TYPE}";
|
||||
$GLOBALS["VCS_BASENAME"] = "${VCS_BASENAME}";
|
||||
$GLOBALS["VCS_NUM"] = ${VCS_NUM};
|
||||
$GLOBALS["VCS_DATE"] = "${VCS_DATE}";
|
||||
$GLOBALS["VCS_BRANCH"] = "${VCS_BRANCH}";
|
||||
$GLOBALS["VCS_TAG"] = "${VCS_TAG}";
|
||||
$GLOBALS["VCS_TICK"] = ${VCS_TICK};
|
||||
|
||||
$GLOBALS["VCS_FULL_HASH"] = "${VCS_FULL_HASH}";
|
||||
$GLOBALS["VCS_SHORT_HASH"] = "${VCS_SHORT_HASH}";
|
||||
|
||||
$GLOBALS["VCS_WC_MODIFIED"] = ${VCS_WC_MODIFIED};
|
||||
|
||||
# end
|
||||
?>
|
||||
EOF
|
||||
}
|
||||
|
||||
# For ini output
|
||||
iniOutput() {
|
||||
case "${VCS_WC_MODIFIED}" in
|
||||
0) VCS_WC_MODIFIED="false" ;;
|
||||
1) VCS_WC_MODIFIED="true" ;;
|
||||
esac
|
||||
cat > "${TARGETFILE}" << EOF
|
||||
; Generated by autorevision - do not hand-hack!
|
||||
[VCS]
|
||||
VCS_TYPE = "${VCS_TYPE}"
|
||||
VCS_BASENAME = "${VCS_BASENAME}"
|
||||
VCS_NUM = ${VCS_NUM}
|
||||
VCS_DATE = "${VCS_DATE}"
|
||||
VCS_BRANCH = "${VCS_BRANCH}"
|
||||
VCS_TAG = "${VCS_TAG}"
|
||||
VCS_TICK = ${VCS_TICK}
|
||||
VCS_FULL_HASH = "${VCS_FULL_HASH}"
|
||||
VCS_SHORT_HASH = "${VCS_SHORT_HASH}"
|
||||
VCS_WC_MODIFIED = ${VCS_WC_MODIFIED}
|
||||
; end
|
||||
EOF
|
||||
}
|
||||
|
||||
# For javascript output
|
||||
jsOutput() {
|
||||
case "${VCS_WC_MODIFIED}" in
|
||||
1) VCS_WC_MODIFIED="true" ;;
|
||||
0) VCS_WC_MODIFIED="false" ;;
|
||||
esac
|
||||
cat > "${TARGETFILE}" << EOF
|
||||
/** Generated by autorevision - do not hand-hack! */
|
||||
|
||||
var autorevision = {
|
||||
VCS_TYPE: "${VCS_TYPE}",
|
||||
VCS_BASENAME: "${VCS_BASENAME}",
|
||||
VCS_NUM: ${VCS_NUM},
|
||||
VCS_DATE: "${VCS_DATE}",
|
||||
VCS_BRANCH: "${VCS_BRANCH}",
|
||||
VCS_TAG: "${VCS_TAG}",
|
||||
VCS_TICK: ${VCS_TICK},
|
||||
|
||||
VCS_FULL_HASH: "${VCS_FULL_HASH}",
|
||||
VCS_SHORT_HASH: "${VCS_SHORT_HASH}",
|
||||
|
||||
VCS_WC_MODIFIED: ${VCS_WC_MODIFIED}
|
||||
};
|
||||
|
||||
/** Node.js compatibility */
|
||||
if (typeof module !== 'undefined') {
|
||||
module.exports = autorevision;
|
||||
}
|
||||
|
||||
/** end */
|
||||
EOF
|
||||
}
|
||||
|
||||
# For JSON output
|
||||
jsonOutput() {
|
||||
case "${VCS_WC_MODIFIED}" in
|
||||
1) VCS_WC_MODIFIED="true" ;;
|
||||
0) VCS_WC_MODIFIED="false" ;;
|
||||
esac
|
||||
cat > "${TARGETFILE}" << EOF
|
||||
{
|
||||
"VCS_TYPE": "${VCS_TYPE}",
|
||||
"VCS_BASENAME": "${VCS_BASENAME}",
|
||||
"VCS_NUM": ${VCS_NUM},
|
||||
"VCS_DATE": "${VCS_DATE}",
|
||||
"VCS_BRANCH":"${VCS_BRANCH}",
|
||||
"VCS_TAG": "${VCS_TAG}",
|
||||
"VCS_TICK": ${VCS_TICK},
|
||||
|
||||
"VCS_FULL_HASH": "${VCS_FULL_HASH}",
|
||||
"VCS_SHORT_HASH": "${VCS_SHORT_HASH}",
|
||||
|
||||
"VCS_WC_MODIFIED": ${VCS_WC_MODIFIED}
|
||||
}
|
||||
EOF
|
||||
}
|
||||
|
||||
# For Java output
|
||||
javaOutput() {
|
||||
case "${VCS_WC_MODIFIED}" in
|
||||
1) VCS_WC_MODIFIED="true" ;;
|
||||
0) VCS_WC_MODIFIED="false" ;;
|
||||
esac
|
||||
cat > "${TARGETFILE}" << EOF
|
||||
/* Generated by autorevision - do not hand-hack! */
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
public class autorevision {
|
||||
public static final String VCS_TYPE = "${VCS_TYPE}";
|
||||
public static final String VCS_BASENAME = "${VCS_BASENAME}";
|
||||
public static final long VCS_NUM = ${VCS_NUM};
|
||||
public static final String VCS_DATE = "${VCS_DATE}";
|
||||
public static final String VCS_BRANCH = "${VCS_BRANCH}";
|
||||
public static final String VCS_TAG = "${VCS_TAG}";
|
||||
public static final long VCS_TICK = ${VCS_TICK};
|
||||
|
||||
public static final String VCS_FULL_HASH = "${VCS_FULL_HASH}";
|
||||
public static final String VCS_SHORT_HASH = "${VCS_SHORT_HASH}";
|
||||
|
||||
public static final boolean VCS_WC_MODIFIED = ${VCS_WC_MODIFIED};
|
||||
}
|
||||
EOF
|
||||
}
|
||||
|
||||
# For Java properties output
|
||||
javapropOutput() {
|
||||
case "${VCS_WC_MODIFIED}" in
|
||||
1) VCS_WC_MODIFIED="true" ;;
|
||||
0) VCS_WC_MODIFIED="false" ;;
|
||||
esac
|
||||
cat > "${TARGETFILE}" << EOF
|
||||
# Generated by autorevision - do not hand-hack!
|
||||
|
||||
VCS_TYPE=${VCS_TYPE}
|
||||
VCS_BASENAME=${VCS_BASENAME}
|
||||
VCS_NUM=${VCS_NUM}
|
||||
VCS_DATE=${VCS_DATE}
|
||||
VCS_BRANCH=${VCS_BRANCH}
|
||||
VCS_TAG=${VCS_TAG}
|
||||
VCS_TICK=${VCS_TICK}
|
||||
|
||||
VCS_FULL_HASH=${VCS_FULL_HASH}
|
||||
VCS_SHORT_HASH=${VCS_SHORT_HASH}
|
||||
|
||||
VCS_WC_MODIFIED=${VCS_WC_MODIFIED}
|
||||
EOF
|
||||
}
|
||||
|
||||
# For m4 output
|
||||
m4Output() {
|
||||
cat > "${TARGETFILE}" << EOF
|
||||
define(\`VCS_TYPE', \`${VCS_TYPE}')dnl
|
||||
define(\`VCS_BASENAME', \`${VCS_BASENAME}')dnl
|
||||
define(\`VCS_NUM', \`${VCS_NUM}')dnl
|
||||
define(\`VCS_DATE', \`${VCS_DATE}')dnl
|
||||
define(\`VCS_BRANCH', \`${VCS_BRANCH}')dnl
|
||||
define(\`VCS_TAG', \`${VCS_TAG}')dnl
|
||||
define(\`VCS_TICK', \`${VCS_TICK}')dnl
|
||||
define(\`VCS_FULLHASH', \`${VCS_FULL_HASH}')dnl
|
||||
define(\`VCS_SHIRTHASH', \`${VCS_SHORT_HASH}')dnl
|
||||
define(\`VCS_WC_MODIFIED', \`${VCS_WC_MODIFIED}')dnl
|
||||
EOF
|
||||
}
|
||||
|
||||
# For (La)TeX output
|
||||
texOutput() {
|
||||
case "${VCS_WC_MODIFIED}" in
|
||||
0) VCS_WC_MODIFIED="false" ;;
|
||||
1) VCS_WC_MODIFIED="true" ;;
|
||||
esac
|
||||
cat > "${TARGETFILE}" << EOF
|
||||
% Generated by autorevision - do not hand-hack!
|
||||
\def \vcsType {${VCS_TYPE}}
|
||||
\def \vcsBasename {${VCS_BASENAME}}
|
||||
\def \vcsNum {${VCS_NUM}}
|
||||
\def \vcsDate {${VCS_DATE}}
|
||||
\def \vcsBranch {${VCS_BRANCH}}
|
||||
\def \vcsTag {${VCS_TAG}}
|
||||
\def \vcsTick {${VCS_TICK}}
|
||||
\def \vcsFullHash {${VCS_FULL_HASH}}
|
||||
\def \vcsShortHash {${VCS_SHORT_HASH}}
|
||||
\def \vcsWCModified {${VCS_WC_MODIFIED}}
|
||||
\endinput
|
||||
EOF
|
||||
}
|
||||
|
||||
|
||||
|
||||
# Detect and collect repo data.
|
||||
if [ -f "${CACHEFILE}" ] && [ "${CACHEFORCE}" = "1" ]; then
|
||||
# When requested only read from the cache to populate our symbols.
|
||||
. "${CACHEFILE}"
|
||||
elif [ ! -z "$(git rev-parse HEAD 2>/dev/null)" ]; then
|
||||
gitRepo
|
||||
elif [ ! -z "$(hg root 2>/dev/null)" ]; then
|
||||
hgRepo
|
||||
elif [ ! -z "$(bzr root 2>/dev/null)" ]; then
|
||||
bzrRepo
|
||||
elif [ ! -z "$(svn info 2>/dev/null)" ]; then
|
||||
svnRepo
|
||||
elif [ -f "${CACHEFILE}" ]; then
|
||||
# We are not in a repo; try to use a previously generated cache to populate our symbols.
|
||||
. "${CACHEFILE}"
|
||||
|
@ -700,16 +204,12 @@ if [ ! -z "${VAROUT}" ]; then
|
|||
echo "${VCS_TYPE}"
|
||||
elif [ "${VAROUT}" = "VCS_BASENAME" ]; then
|
||||
echo "${VCS_BASENAME}"
|
||||
elif [ "${VAROUT}" = "VCS_NUM" ]; then
|
||||
echo "${VCS_NUM}"
|
||||
elif [ "${VAROUT}" = "VCS_DATE" ]; then
|
||||
echo "${VCS_DATE}"
|
||||
elif [ "${VAROUT}" = "VCS_BRANCH" ]; then
|
||||
echo "${VCS_BRANCH}"
|
||||
elif [ "${VAROUT}" = "VCS_TAG" ]; then
|
||||
echo "${VCS_TAG}"
|
||||
elif [ "${VAROUT}" = "VCS_TICK" ]; then
|
||||
echo "${VCS_TICK}"
|
||||
elif [ "${VAROUT}" = "VCS_EXTRA" ]; then
|
||||
echo "${VCS_EXTRA}"
|
||||
elif [ "${VAROUT}" = "VCS_FULL_HASH" ]; then
|
||||
echo "${VCS_FULL_HASH}"
|
||||
elif [ "${VAROUT}" = "VCS_SHORT_HASH" ]; then
|
||||
|
@ -722,7 +222,6 @@ if [ ! -z "${VAROUT}" ]; then
|
|||
fi
|
||||
fi
|
||||
|
||||
|
||||
# Detect requested output type and use it.
|
||||
if [ ! -z "${AFILETYPE}" ]; then
|
||||
if [ "${AFILETYPE}" = "h" ]; then
|
||||
|
@ -731,28 +230,6 @@ if [ ! -z "${AFILETYPE}" ]; then
|
|||
xcodeOutput
|
||||
elif [ "${AFILETYPE}" = "sh" ]; then
|
||||
shOutput
|
||||
elif [ "${AFILETYPE}" = "py" ] || [ "${AFILETYPE}" = "python" ]; then
|
||||
pyOutput
|
||||
elif [ "${AFILETYPE}" = "pl" ] || [ "${AFILETYPE}" = "perl" ]; then
|
||||
plOutput
|
||||
elif [ "${AFILETYPE}" = "lua" ]; then
|
||||
luaOutput
|
||||
elif [ "${AFILETYPE}" = "php" ]; then
|
||||
phpOutput
|
||||
elif [ "${AFILETYPE}" = "ini" ]; then
|
||||
iniOutput
|
||||
elif [ "${AFILETYPE}" = "js" ]; then
|
||||
jsOutput
|
||||
elif [ "${AFILETYPE}" = "json" ]; then
|
||||
jsonOutput
|
||||
elif [ "${AFILETYPE}" = "java" ]; then
|
||||
javaOutput
|
||||
elif [ "${AFILETYPE}" = "javaprop" ]; then
|
||||
javapropOutput
|
||||
elif [ "${AFILETYPE}" = "tex" ]; then
|
||||
texOutput
|
||||
elif [ "${AFILETYPE}" = "m4" ]; then
|
||||
m4Output
|
||||
else
|
||||
echo "error: Not a valid output type." 1>&2
|
||||
exit 1
|
||||
|
|
|
@ -10,7 +10,6 @@ autorevision.h autorevision.cache:
|
|||
|
||||
CLEANFILES = \
|
||||
$(BUILT_SOURCES) \
|
||||
autorevision.cache \
|
||||
autorevision.h.new
|
||||
|
||||
BUILT_SOURCES = \
|
||||
|
|
|
@ -27,90 +27,41 @@
|
|||
|
||||
#include "src/autorevision.h"
|
||||
|
||||
static const char vcs_date_cstr[] = VCS_DATE;
|
||||
static const char vcs_branch_cstr[] = VCS_BRANCH;
|
||||
static const char vcs_tag[] = VCS_TAG;
|
||||
|
||||
unsigned int version_getRevision()
|
||||
{
|
||||
return VCS_NUM;
|
||||
}
|
||||
|
||||
const char* version_getVersionString()
|
||||
/** Composes a nicely formatted version string.
|
||||
* Determine if we are on a tag (which will NOT show the hash)
|
||||
* or a branch (which WILL show the hash)
|
||||
* or in a detached state (which WILL show the hash)
|
||||
*/
|
||||
const char *version_getVersionString()
|
||||
{
|
||||
static const char* version_string = NULL;
|
||||
|
||||
if (version_string == NULL)
|
||||
{
|
||||
if (strncmp(vcs_branch_cstr, "tags/", strlen("tags/")) == 0)
|
||||
if (strlen(vcs_tag))
|
||||
{
|
||||
version_string = vcs_branch_cstr + strlen("tags/");
|
||||
version_string = vcs_tag;
|
||||
}
|
||||
else if (strcmp(vcs_branch_cstr, "trunk") == 0)
|
||||
else if (strlen(vcs_branch_cstr))
|
||||
{
|
||||
version_string = "TRUNK " VCS_SHORT_HASH;
|
||||
}
|
||||
else if (strncmp(vcs_branch_cstr, "branches/", strlen("branches/")) == 0)
|
||||
{
|
||||
version_string = (VCS_BRANCH " branch " VCS_SHORT_HASH) + strlen("branches/");
|
||||
}
|
||||
else if (strncmp(vcs_branch_cstr, "refs/heads/", strlen("refs/heads/")) == 0)
|
||||
{
|
||||
version_string = (VCS_BRANCH " branch " VCS_SHORT_HASH) + strlen("refs/heads/");
|
||||
}
|
||||
else if (VCS_NUM != 0)
|
||||
{
|
||||
version_string = VCS_BRANCH " " VCS_SHORT_HASH;
|
||||
version_string = (VCS_BRANCH " " VCS_SHORT_HASH);
|
||||
}
|
||||
else
|
||||
{
|
||||
version_string = VCS_SHORT_HASH;
|
||||
{ // not a branch or a tag, so we are detached most likely.
|
||||
version_string = VCS_EXTRA;
|
||||
}
|
||||
}
|
||||
|
||||
return version_string;
|
||||
}
|
||||
|
||||
bool version_modified()
|
||||
{
|
||||
return VCS_WC_MODIFIED;
|
||||
}
|
||||
|
||||
const char* version_getBuildDate()
|
||||
{
|
||||
return __DATE__;
|
||||
}
|
||||
|
||||
const char* version_getBuildTime()
|
||||
{
|
||||
return __TIME__;
|
||||
}
|
||||
|
||||
const char* version_getVcsDate()
|
||||
{
|
||||
#if (VCS_NUM == 0)
|
||||
return "";
|
||||
#else
|
||||
static char vcs_date[sizeof(vcs_date_cstr) - 9] = { '\0' };
|
||||
|
||||
if (vcs_date[0] == '\0')
|
||||
{
|
||||
sstrcpy(vcs_date, vcs_date_cstr);
|
||||
}
|
||||
|
||||
return vcs_date;
|
||||
#endif
|
||||
}
|
||||
|
||||
const char* version_getVcsTime()
|
||||
{
|
||||
#if (VCS_NUM == 0)
|
||||
return "";
|
||||
#else
|
||||
return VCS_DATE + sizeof(VCS_DATE) - 8 - 1;
|
||||
#endif
|
||||
}
|
||||
|
||||
const char* version_getFormattedVersionString()
|
||||
/** Composes a nicely formatted version string.
|
||||
*
|
||||
*/
|
||||
const char *version_getFormattedVersionString()
|
||||
{
|
||||
static char versionString[MAX_STR_LENGTH] = {'\0'};
|
||||
|
||||
|
@ -122,7 +73,6 @@ const char* version_getFormattedVersionString()
|
|||
#else
|
||||
const char* wc_state = "";
|
||||
#endif
|
||||
|
||||
// Compose the build type string
|
||||
#ifdef DEBUG
|
||||
const char* build_type = _(" - DEBUG");
|
||||
|
@ -130,21 +80,10 @@ const char* version_getFormattedVersionString()
|
|||
const char* build_type = "";
|
||||
#endif
|
||||
|
||||
const char* build_date = NULL;
|
||||
|
||||
if (strncmp(vcs_branch_cstr, "tags/", strlen("tags/")) != 0)
|
||||
{
|
||||
sasprintf((char**)&build_date, _(" - Built %s"), version_getBuildDate());
|
||||
}
|
||||
else
|
||||
{
|
||||
build_date = "";
|
||||
}
|
||||
|
||||
// Construct the version string
|
||||
// TRANSLATORS: This string looks as follows when expanded.
|
||||
// "Version <version name/number> <working copy state><BUILD DATE><BUILD TYPE>"
|
||||
snprintf(versionString, MAX_STR_LENGTH, _("Version %s%s%s%s"), version_getVersionString(), wc_state, build_date, build_type);
|
||||
snprintf(versionString, MAX_STR_LENGTH, _("Version: %s,%s Built:%s%s"), version_getVersionString(), wc_state, __DATE__, build_type);
|
||||
}
|
||||
|
||||
return versionString;
|
||||
|
|
|
@ -23,75 +23,7 @@
|
|||
|
||||
#include "lib/framework/types.h"
|
||||
|
||||
/** Retrieve the low revision number
|
||||
* \return the lowest revision number of the working copy from which we built
|
||||
*/
|
||||
extern unsigned int version_getLowRevision(void);
|
||||
|
||||
/** Retrieve the revision number
|
||||
* \return the highest revision number of the working copy from which we built
|
||||
*/
|
||||
extern unsigned int version_getRevision(void);
|
||||
|
||||
/** Composes a simple version string.
|
||||
*
|
||||
* If we compiled from a tag, i.e. the checkout URI started with "tags/%s/",
|
||||
* the resulting string will be the "%s" portion of the URI.
|
||||
*
|
||||
* When we compiled from a branch, i.e. the checkout URI started with
|
||||
* "branches/%s/", the resulting string will be "%s branch <revision>".
|
||||
*
|
||||
* If we compiled from trunk, i.e. the checkout URI started with "trunk/",
|
||||
* the resulting string will be "TRUNK <revision>".
|
||||
*
|
||||
* In all cases "<revision>" will be either "r<REVISION_NUMBER>" or
|
||||
* "r<LOW_REVISION_NUMBER>:<HIGH_REVISION_NUMBER" in case of a mixed revision
|
||||
* repository.
|
||||
*/
|
||||
extern const char* version_getVersionString(void);
|
||||
|
||||
/** Determines whether this version is compiled from a modified source tree.
|
||||
* \return true if this version is compiled from modified sources, false when
|
||||
* it is compiled from unmodified sources, or it cannot be determined
|
||||
* whether changes have occurred.
|
||||
*/
|
||||
extern bool version_modified(void);
|
||||
|
||||
/** Retrieves the date at which this build was compiled.
|
||||
* \return the date at which this build was made (uses __DATE__)
|
||||
*/
|
||||
extern const char* version_getBuildDate(void);
|
||||
|
||||
/** Retrieves the time at which this build was compiled.
|
||||
* \return the time at which this build was made (uses __TIME__)
|
||||
*/
|
||||
extern const char* version_getBuildTime(void);
|
||||
|
||||
/** Retrieves the date at which the source of this build was committed.
|
||||
* \return the date when this revision was committed to the subversion
|
||||
* repository
|
||||
*/
|
||||
extern const char* version_getVcsDate(void);
|
||||
|
||||
/** Retrieves the time at which the source of this build was committed.
|
||||
* \return the time when this revision was committed to the subversion
|
||||
* repository
|
||||
*/
|
||||
extern const char* version_getVcsTime(void);
|
||||
|
||||
/** Composes a nicely formatted version string.
|
||||
*
|
||||
* It is formatted as follows:
|
||||
* "Version <version string> <working copy state> - Built <DATE><BUILD TYPE>"
|
||||
*
|
||||
* - "<version string>" is the return value from version_getVersionString()
|
||||
* - "<working copy state>" represents the modification and switch state
|
||||
* of the working copy from which this build was made.
|
||||
* - "<DATE>" the date of building as returned by version_getBuildDate() or
|
||||
* version_getVcsDate(); the latter is only used when the working
|
||||
* copy has no local modifications.
|
||||
* - "<BUILD TYPE>" the type of build produced (i.e. DEBUG or not)
|
||||
*/
|
||||
extern const char* version_getFormattedVersionString(void);
|
||||
extern const char *version_getVersionString(void);
|
||||
extern const char *version_getFormattedVersionString(void);
|
||||
|
||||
#endif // __INCLUDED_VERSION_H__
|
||||
|
|
Loading…
Reference in New Issue