Repository: incubator-htrace Updated Branches: refs/heads/master 0db15ee34 -> 4ef0d4834
HTRACE-42. Automatically generate version.go (cmccabe) Project: http://git-wip-us.apache.org/repos/asf/incubator-htrace/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-htrace/commit/4ef0d483 Tree: http://git-wip-us.apache.org/repos/asf/incubator-htrace/tree/4ef0d483 Diff: http://git-wip-us.apache.org/repos/asf/incubator-htrace/diff/4ef0d483 Branch: refs/heads/master Commit: 4ef0d48349ea209a7c646c8654015771a92cd986 Parents: 0db15ee Author: Colin P. Mccabe <[email protected]> Authored: Wed Dec 31 14:06:56 2014 -0800 Committer: Colin P. Mccabe <[email protected]> Committed: Wed Dec 31 15:29:25 2014 -0800 ---------------------------------------------------------------------- .gitignore | 1 + htrace-core/pom.xml | 1 + htrace-core/src/go/generate_version.sh | 66 ++++++++++++++++++++ htrace-core/src/go/gobuild.sh | 2 + .../src/go/src/org/apache/htrace/common/rest.go | 5 +- .../go/src/org/apache/htrace/common/version.go | 22 ------- .../src/go/src/org/apache/htrace/htrace/cmd.go | 2 +- .../go/src/org/apache/htrace/htraced/rest.go | 3 +- 8 files changed, 77 insertions(+), 25 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/4ef0d483/.gitignore ---------------------------------------------------------------------- diff --git a/.gitignore b/.gitignore index 7238b01..f6c1807 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,4 @@ htrace-core/src/go/pkg htrace-core/src/go/src/org/apache/htrace/resource htrace-core/src/go/src/github.com/ htrace-core/src/go/src/gopkg.in/ +htrace-core/src/go/src/org/apache/htrace/common/version.go http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/4ef0d483/htrace-core/pom.xml ---------------------------------------------------------------------- diff --git a/htrace-core/pom.xml b/htrace-core/pom.xml index bd0b65e..91d906c 100644 --- a/htrace-core/pom.xml +++ b/htrace-core/pom.xml @@ -85,6 +85,7 @@ language governing permissions and limitations under the License. --> <exec executable="./gobuild.sh" dir="${basedir}/src/go/" failonerror="true"> + <env key="RELEASE_VERSION" value="${version}"/> </exec> </tasks> </configuration> http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/4ef0d483/htrace-core/src/go/generate_version.sh ---------------------------------------------------------------------- diff --git a/htrace-core/src/go/generate_version.sh b/htrace-core/src/go/generate_version.sh new file mode 100755 index 0000000..cece713 --- /dev/null +++ b/htrace-core/src/go/generate_version.sh @@ -0,0 +1,66 @@ +#!/usr/bin/env bash + +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +# +# Generates the version.go file. +# +# ./generate_version.sh [release-version] Generates the version.go file +# + +die() { + echo $@ + exit 1 +} + +[ $# -lt 1 ] && die "You must specify the release version." +RELEASE_VERSION=$1 + +SCRIPT_DIR="$(cd "$( dirname $0 )" && pwd)" +cd "${SCRIPT_DIR}" +GIT_VERSION=$(git rev-parse HEAD) +[ $? -eq 0 ] || die "Failed to run 'git rev-parse HEAD'" +cat <<EOF > "./src/org/apache/htrace/common/version.go" +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +// THIS IS GENERATED CODE. DO NOT EDIT. + +package common + +const RELEASE_VERSION = "$RELEASE_VERSION" +const GIT_VERSION = "$GIT_VERSION" +EOF http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/4ef0d483/htrace-core/src/go/gobuild.sh ---------------------------------------------------------------------- diff --git a/htrace-core/src/go/gobuild.sh b/htrace-core/src/go/gobuild.sh index d8a6b47..9e1efa8 100755 --- a/htrace-core/src/go/gobuild.sh +++ b/htrace-core/src/go/gobuild.sh @@ -44,6 +44,7 @@ if [ $# -gt 0 ]; then fi shift fi +RELEASE_VERSION=${RELEASE_VERSION:-unknown} SCRIPT_DIR="$(cd "$( dirname $0 )" && pwd)" export GOPATH="$GOPATH:${SCRIPT_DIR}" @@ -84,5 +85,6 @@ if [ "$ACTION" == "get" ]; then go run "$SCRIPT_DIR/src/org/apache/htrace/bundler/bundler.go" \ --src="$SCRIPT_DIR/../web/" --dst="$SCRIPT_DIR/src/org/apache/htrace/resource/" \ || die "bundler failed" + ${SCRIPT_DIR}/generate_version.sh "${RELEASE_VERSION}" fi go "${ACTION}" -v org/apache/htrace/... "$@" http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/4ef0d483/htrace-core/src/go/src/org/apache/htrace/common/rest.go ---------------------------------------------------------------------- diff --git a/htrace-core/src/go/src/org/apache/htrace/common/rest.go b/htrace-core/src/go/src/org/apache/htrace/common/rest.go index 1b1db03..eeb9568 100644 --- a/htrace-core/src/go/src/org/apache/htrace/common/rest.go +++ b/htrace-core/src/go/src/org/apache/htrace/common/rest.go @@ -22,5 +22,8 @@ package common // Info returned by /serverInfo type ServerInfo struct { // The server release version. - Version string + ReleaseVersion string + + // The git hash that this software was built with. + GitVersion string } http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/4ef0d483/htrace-core/src/go/src/org/apache/htrace/common/version.go ---------------------------------------------------------------------- diff --git a/htrace-core/src/go/src/org/apache/htrace/common/version.go b/htrace-core/src/go/src/org/apache/htrace/common/version.go deleted file mode 100644 index c560c09..0000000 --- a/htrace-core/src/go/src/org/apache/htrace/common/version.go +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package common - -const RELEASE_VERSION = "3.1.0-SNAPSHOT" http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/4ef0d483/htrace-core/src/go/src/org/apache/htrace/htrace/cmd.go ---------------------------------------------------------------------- diff --git a/htrace-core/src/go/src/org/apache/htrace/htrace/cmd.go b/htrace-core/src/go/src/org/apache/htrace/htrace/cmd.go index 0437628..3b89c72 100644 --- a/htrace-core/src/go/src/org/apache/htrace/htrace/cmd.go +++ b/htrace-core/src/go/src/org/apache/htrace/htrace/cmd.go @@ -84,7 +84,7 @@ func printServerInfo(restAddr string) int { string(buf), err.Error()) return 1 } - fmt.Printf("HTraced server version %s\n", info.Version) + fmt.Printf("HTraced server version %s (%s)\n", info.ReleaseVersion, info.GitVersion) return 0 } http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/4ef0d483/htrace-core/src/go/src/org/apache/htrace/htraced/rest.go ---------------------------------------------------------------------- diff --git a/htrace-core/src/go/src/org/apache/htrace/htraced/rest.go b/htrace-core/src/go/src/org/apache/htrace/htraced/rest.go index b704bd2..74018c0 100644 --- a/htrace-core/src/go/src/org/apache/htrace/htraced/rest.go +++ b/htrace-core/src/go/src/org/apache/htrace/htraced/rest.go @@ -34,7 +34,8 @@ type serverInfoHandler struct { } func (handler *serverInfoHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) { - version := common.ServerInfo{Version: common.RELEASE_VERSION} + version := common.ServerInfo{ReleaseVersion: common.RELEASE_VERSION, + GitVersion: common.GIT_VERSION} buf, err := json.Marshal(&version) if err != nil { log.Printf("error marshalling ServerInfo: %s\n", err.Error())
