The Go Programming Language

Text file src/version.bash

     1	#!/usr/bin/env bash
     2	# Copyright 2010 The Go Authors. All rights reserved.
     3	# Use of this source code is governed by a BSD-style
     4	# license that can be found in the LICENSE file.
     5	
     6	GOROOT=$(dirname $0)/..
     7	
     8	# If a version file created by -save is available, use it
     9	if [ -f "$GOROOT/VERSION" ]; then
    10		cat $GOROOT/VERSION
    11		exit 0
    12	fi
    13	
    14	# Otherwise, if hg doesn't work for whatever reason, fail
    15	if [ ! -d "$GOROOT/.hg" ] || ! hg version > /dev/null 2>&1; then
    16		echo 'Unable to report version: hg and VERSION file missing' 1>&2
    17		echo 'Generate VERSION with `src/version.bash -save` while hg is usable' 1>&2
    18		exit 2
    19	fi
    20	
    21	# Get numerical revision
    22	VERSION=$(hg identify -n 2>/dev/null)
    23	if [ $? != 0 ]; then
    24		OLD=$(hg identify | sed 1q)
    25		VERSION=$(echo $OLD | awk '{print $1}')
    26	fi
    27	
    28	# Get branch type
    29	BRANCH=release
    30	if [ "$(hg identify -b 2>/dev/null)" == "default" ]; then
    31		BRANCH=weekly
    32	fi
    33	
    34	# Find most recent known release or weekly tag.
    35	TAG=$(hg tags |
    36		grep $BRANCH |
    37		sed 's/:.*//' |
    38		sort -rn -k2 |
    39		awk -v ver=$VERSION '$2 <= ver && $1~/^(release|weekly)\./ {print $1}' |
    40		sed -n 1p)
    41	
    42	if [ "$TAG" != "" ]; then
    43		VERSION="$TAG $VERSION"
    44	fi
    45	
    46	if [ "$1" = "-save" ]; then
    47		echo $VERSION > $GOROOT/VERSION
    48	else
    49		echo $VERSION
    50	fi

release.r60.3. Except as noted, this content is licensed under a Creative Commons Attribution 3.0 License.