2010-02-08 10:46:53 -07:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
# Copyright 2010 The Go Authors. All rights reserved.
|
|
|
|
# Use of this source code is governed by a BSD-style
|
|
|
|
# license that can be found in the LICENSE file.
|
|
|
|
|
2011-08-15 11:25:54 -06:00
|
|
|
GOROOT=$(dirname $0)/..
|
2011-08-15 11:19:30 -06:00
|
|
|
|
|
|
|
# If a version file created by -save is available, use it
|
2011-08-24 19:10:25 -06:00
|
|
|
if [ -f "$GOROOT/VERSION" -a "$1" != "-save" ]; then
|
2011-08-15 11:19:30 -06:00
|
|
|
cat $GOROOT/VERSION
|
2011-08-15 05:19:07 -06:00
|
|
|
exit 0
|
2010-02-08 10:46:53 -07:00
|
|
|
fi
|
|
|
|
|
2011-08-15 11:19:30 -06:00
|
|
|
# Otherwise, if hg doesn't work for whatever reason, fail
|
|
|
|
if [ ! -d "$GOROOT/.hg" ] || ! hg version > /dev/null 2>&1; then
|
|
|
|
echo 'Unable to report version: hg and VERSION file missing' 1>&2
|
|
|
|
echo 'Generate VERSION with `src/version.bash -save` while hg is usable' 1>&2
|
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
|
2010-02-08 10:46:53 -07:00
|
|
|
# Get numerical revision
|
2010-03-16 19:45:06 -06:00
|
|
|
VERSION=$(hg identify -n 2>/dev/null)
|
2011-02-03 11:51:43 -07:00
|
|
|
if [ $? != 0 ]; then
|
2010-03-16 19:45:06 -06:00
|
|
|
OLD=$(hg identify | sed 1q)
|
|
|
|
VERSION=$(echo $OLD | awk '{print $1}')
|
|
|
|
fi
|
2010-02-08 10:46:53 -07:00
|
|
|
|
2011-06-29 23:39:00 -06:00
|
|
|
# Get branch type
|
|
|
|
BRANCH=release
|
|
|
|
if [ "$(hg identify -b 2>/dev/null)" == "default" ]; then
|
|
|
|
BRANCH=weekly
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Find most recent known release or weekly tag.
|
2011-03-11 00:04:18 -07:00
|
|
|
TAG=$(hg tags |
|
2011-06-29 23:39:00 -06:00
|
|
|
grep $BRANCH |
|
2011-04-03 18:06:09 -06:00
|
|
|
sed 's/:.*//' |
|
2011-03-11 00:04:18 -07:00
|
|
|
sort -rn -k2 |
|
2011-03-25 16:00:19 -06:00
|
|
|
awk -v ver=$VERSION '$2 <= ver && $1~/^(release|weekly)\./ {print $1}' |
|
2011-03-11 00:04:18 -07:00
|
|
|
sed -n 1p)
|
2011-02-03 11:51:43 -07:00
|
|
|
|
|
|
|
if [ "$TAG" != "" ]; then
|
|
|
|
VERSION="$TAG $VERSION"
|
2010-02-08 10:46:53 -07:00
|
|
|
fi
|
|
|
|
|
2011-08-15 11:19:30 -06:00
|
|
|
if [ "$1" = "-save" ]; then
|
|
|
|
echo $VERSION > $GOROOT/VERSION
|
|
|
|
else
|
|
|
|
echo $VERSION
|
|
|
|
fi
|