diff options
author | Ondřej Surý <ondrej@sury.org> | 2011-09-13 13:13:40 +0200 |
---|---|---|
committer | Ondřej Surý <ondrej@sury.org> | 2011-09-13 13:13:40 +0200 |
commit | 5ff4c17907d5b19510a62e08fd8d3b11e62b431d (patch) | |
tree | c0650497e988f47be9c6f2324fa692a52dea82e1 /src/version.bash | |
parent | 80f18fc933cf3f3e829c5455a1023d69f7b86e52 (diff) | |
download | golang-upstream/60.tar.gz |
Imported Upstream version 60upstream/60
Diffstat (limited to 'src/version.bash')
-rwxr-xr-x | src/version.bash | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/src/version.bash b/src/version.bash new file mode 100755 index 000000000..fc899e2e3 --- /dev/null +++ b/src/version.bash @@ -0,0 +1,50 @@ +#!/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. + +GOROOT=$(dirname $0)/.. + +# If a version file created by -save is available, use it +if [ -f "$GOROOT/VERSION" ]; then + cat $GOROOT/VERSION + exit 0 +fi + +# 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 + +# Get numerical revision +VERSION=$(hg identify -n 2>/dev/null) +if [ $? != 0 ]; then + OLD=$(hg identify | sed 1q) + VERSION=$(echo $OLD | awk '{print $1}') +fi + +# 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. +TAG=$(hg tags | + grep $BRANCH | + sed 's/:.*//' | + sort -rn -k2 | + awk -v ver=$VERSION '$2 <= ver && $1~/^(release|weekly)\./ {print $1}' | + sed -n 1p) + +if [ "$TAG" != "" ]; then + VERSION="$TAG $VERSION" +fi + +if [ "$1" = "-save" ]; then + echo $VERSION > $GOROOT/VERSION +else + echo $VERSION +fi |