Adds basic build tag support with different versions. (#2463)
This commit is contained in:
parent
03f623f89b
commit
9003454f88
12
GNUmakefile
12
GNUmakefile
|
@ -7,7 +7,7 @@ GOTOOLS = \
|
|||
PACKAGES=$(shell go list ./... | grep -v '^github.com/hashicorp/consul/vendor/')
|
||||
VETARGS?=-asmdecl -atomic -bool -buildtags -copylocks -methods \
|
||||
-nilfunc -printf -rangeloops -shift -structtags -unsafeptr
|
||||
VERSION?=$(shell awk -F\" '/^const Version/ { print $$2; exit }' version.go)
|
||||
BUILD_TAGS?=consul
|
||||
|
||||
# all builds binaries for all targets
|
||||
all: bin
|
||||
|
@ -20,15 +20,15 @@ ci:
|
|||
|
||||
bin: tools
|
||||
@mkdir -p bin/
|
||||
@sh -c "'$(CURDIR)/scripts/build.sh'"
|
||||
@BUILD_TAGS='$(BUILD_TAGS)' sh -c "'$(CURDIR)/scripts/build.sh'"
|
||||
|
||||
# dev creates binaries for testing locally - these are put into ./bin and $GOPATH
|
||||
dev: format
|
||||
@CONSUL_DEV=1 sh -c "'$(CURDIR)/scripts/build.sh'"
|
||||
@CONSUL_DEV=1 BUILD_TAGS='$(BUILD_TAGS)' sh -c "'$(CURDIR)/scripts/build.sh'"
|
||||
|
||||
# dist builds binaries for all platforms and packages them for distribution
|
||||
dist:
|
||||
@sh -c "'$(CURDIR)/scripts/dist.sh' $(VERSION)"
|
||||
@BUILD_TAGS='$(BUILD_TAGS)' sh -c "'$(CURDIR)/scripts/dist.sh'"
|
||||
|
||||
cov:
|
||||
gocov test ./... | gocov-html > /tmp/coverage.html
|
||||
|
@ -37,7 +37,7 @@ cov:
|
|||
test: format
|
||||
@$(MAKE) vet
|
||||
@./scripts/verify_no_uuid.sh
|
||||
@./scripts/test.sh
|
||||
@BUILD_TAGS='$(BUILD_TAGS)' sh -c "'$(CURDIR)/scripts/test.sh'"
|
||||
|
||||
cover:
|
||||
go list ./... | xargs -n1 go test --cover
|
||||
|
@ -49,7 +49,7 @@ format:
|
|||
vet:
|
||||
@echo "--> Running go tool vet $(VETARGS) ."
|
||||
@go list ./... \
|
||||
| grep -v ^github.com/hashicorp/consul/vendor/ \
|
||||
| grep -v /vendor/ \
|
||||
| cut -d '/' -f 4- \
|
||||
| xargs -n1 \
|
||||
go tool vet $(VETARGS) ;\
|
||||
|
|
11
commands.go
11
commands.go
|
@ -7,6 +7,7 @@ import (
|
|||
|
||||
"github.com/hashicorp/consul/command"
|
||||
"github.com/hashicorp/consul/command/agent"
|
||||
"github.com/hashicorp/consul/version"
|
||||
"github.com/mitchellh/cli"
|
||||
)
|
||||
|
||||
|
@ -19,10 +20,10 @@ func init() {
|
|||
Commands = map[string]cli.CommandFactory{
|
||||
"agent": func() (cli.Command, error) {
|
||||
return &agent.Command{
|
||||
Revision: GitCommit,
|
||||
Version: Version,
|
||||
VersionPrerelease: VersionPrerelease,
|
||||
HumanVersion: GetHumanVersion(),
|
||||
Revision: version.GitCommit,
|
||||
Version: version.Version,
|
||||
VersionPrerelease: version.VersionPrerelease,
|
||||
HumanVersion: version.GetHumanVersion(),
|
||||
Ui: ui,
|
||||
ShutdownCh: make(chan struct{}),
|
||||
}, nil
|
||||
|
@ -177,7 +178,7 @@ func init() {
|
|||
|
||||
"version": func() (cli.Command, error) {
|
||||
return &command.VersionCommand{
|
||||
HumanVersion: GetHumanVersion(),
|
||||
HumanVersion: version.GetHumanVersion(),
|
||||
Ui: ui,
|
||||
}, nil
|
||||
},
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
# This script builds the application from source for multiple platforms.
|
||||
set -e
|
||||
|
||||
export GO15VENDOREXPERIMENT=1
|
||||
export CGO_ENABLED=0
|
||||
|
||||
# Get the parent directory of where this script is.
|
||||
|
@ -43,6 +42,7 @@ echo "==> Building..."
|
|||
-osarch="!darwin/arm" \
|
||||
-ldflags "-X main.GitCommit='${GIT_COMMIT}${GIT_DIRTY}' -X main.GitDescribe='${GIT_DESCRIBE}'" \
|
||||
-output "pkg/{{.OS}}_{{.Arch}}/consul" \
|
||||
-tags="${BUILD_TAGS}" \
|
||||
.
|
||||
|
||||
# Move all the compiled things to the $GOPATH/bin
|
||||
|
|
|
@ -1,14 +1,22 @@
|
|||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
export GO15VENDOREXPERIMENT=1
|
||||
|
||||
# Get the version from the command line.
|
||||
VERSION=$1
|
||||
# Get the version from the environment, or try to figure it out from the build tags.
|
||||
# We process the files in the same order Go does to find the last matching tag.
|
||||
if [ -z $VERSION ]; then
|
||||
echo "Please specify a version."
|
||||
for file in $(ls version/version_*.go | sort); do
|
||||
for tag in "$BUILD_TAGS"; do
|
||||
if grep -q "// +build $tag" $file; then
|
||||
VERSION=$(awk -F\" '/Version =/ { print $2; exit }' <$file)
|
||||
fi
|
||||
done
|
||||
done
|
||||
fi
|
||||
if [ -z $VERSION ]; then
|
||||
echo "Please specify a version (couldn't find one based on build tags)."
|
||||
exit 1
|
||||
fi
|
||||
echo "==> Building version $VERSION..."
|
||||
|
||||
# Get the parent directory of where this script is.
|
||||
SOURCE="${BASH_SOURCE[0]}"
|
||||
|
@ -28,7 +36,7 @@ fi
|
|||
# Do a hermetic build inside a Docker container.
|
||||
if [ -z $NOBUILD ]; then
|
||||
docker build -t hashicorp/consul-builder scripts/consul-builder/
|
||||
docker run --rm -v "$(pwd)":/gopath/src/github.com/hashicorp/consul hashicorp/consul-builder ./scripts/dist_build.sh
|
||||
docker run --rm -e "BUILD_TAGS=$BUILD_TAGS" -v "$(pwd)":/gopath/src/github.com/hashicorp/consul hashicorp/consul-builder ./scripts/dist_build.sh
|
||||
fi
|
||||
|
||||
# Zip all the files.
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
export GO15VENDOREXPERIMENT=1
|
||||
|
||||
# Get the parent directory of where this script is.
|
||||
SOURCE="${BASH_SOURCE[0]}"
|
||||
while [ -h "$SOURCE" ] ; do SOURCE="$(readlink "$SOURCE")"; done
|
||||
|
@ -12,7 +10,7 @@ DIR="$( cd -P "$( dirname "$SOURCE" )/.." && pwd )"
|
|||
cd $DIR
|
||||
|
||||
# Make sure build tools are abailable.
|
||||
make -f GNUMakefile tools
|
||||
make tools
|
||||
|
||||
# Build the standalone version of the web assets for the sanity check.
|
||||
pushd ui
|
||||
|
@ -29,7 +27,7 @@ popd
|
|||
|
||||
# Regenerate the built-in web assets. If there are any diffs after doing this
|
||||
# then we know something is up.
|
||||
make -f GNUMakefile static-assets
|
||||
make static-assets
|
||||
if ! git diff --quiet command/agent/bindata_assetfs.go; then
|
||||
echo "Checked-in web assets are out of date, build aborted"
|
||||
exit 1
|
||||
|
@ -39,7 +37,7 @@ fi
|
|||
# away our pkg folder so we have to regenerate the ui once more. This is probably
|
||||
# for the best since we have meddled with the timestamps.
|
||||
rm -rf pkg
|
||||
make -f GNUMakefile all
|
||||
make all
|
||||
pushd ui
|
||||
make dist
|
||||
popd
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
export GO15VENDOREXPERIMENT=1
|
||||
set -e
|
||||
|
||||
# Create a temp dir and clean it up on exit
|
||||
TEMPDIR=`mktemp -d -t consul-test.XXX`
|
||||
|
@ -8,8 +7,8 @@ trap "rm -rf $TEMPDIR" EXIT HUP INT QUIT TERM
|
|||
|
||||
# Build the Consul binary for the API tests
|
||||
echo "--> Building consul"
|
||||
go build -o $TEMPDIR/consul || exit 1
|
||||
go build -tags="${BUILD_TAGS}" -o $TEMPDIR/consul || exit 1
|
||||
|
||||
# Run the tests
|
||||
echo "--> Running tests"
|
||||
go list ./... | grep -v '^github.com/hashicorp/consul/vendor/' | PATH=$TEMPDIR:$PATH xargs -n1 go test ${GOTEST_FLAGS:--cover -timeout=360s}
|
||||
go list ./... | grep -v '^/vendor/' | PATH=$TEMPDIR:$PATH xargs -n1 go test -tags="${BUILD_TAGS}" ${GOTEST_FLAGS:--cover -timeout=360s}
|
||||
|
|
|
@ -1,24 +1,22 @@
|
|||
package main
|
||||
package version
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// The git commit that was compiled. This will be filled in by the compiler.
|
||||
var (
|
||||
// The git commit that was compiled. These will be filled in by the
|
||||
// compiler.
|
||||
GitCommit string
|
||||
GitDescribe string
|
||||
|
||||
// Release versions of the build. These will be filled in by one of the
|
||||
// build tag-specific files.
|
||||
Version = "unknown"
|
||||
VersionPrerelease = "unknown"
|
||||
)
|
||||
|
||||
// The main version number that is being run at the moment.
|
||||
const Version = "0.7.1"
|
||||
|
||||
// A pre-release marker for the version. If this is "" (empty string)
|
||||
// then it means that it is a final release. Otherwise, this is a pre-release
|
||||
// such as "dev" (in development), "beta", "rc1", etc.
|
||||
const VersionPrerelease = "dev"
|
||||
|
||||
// GetHumanVersion composes the parts of the version in a way that's suitable
|
||||
// for displaying to humans.
|
||||
func GetHumanVersion() string {
|
|
@ -0,0 +1,16 @@
|
|||
// +build consul
|
||||
|
||||
package version
|
||||
|
||||
// NOTE we rely on other "version_*.go" files to be lexically after
|
||||
// "version_base.go" in order for this to get properly overridden. Be careful
|
||||
// adding new versions and pick a name that will follow "version_base.go".
|
||||
func init() {
|
||||
// The main version number that is being run at the moment.
|
||||
Version = "0.7.1"
|
||||
|
||||
// A pre-release marker for the version. If this is "" (empty string)
|
||||
// then it means that it is a final release. Otherwise, this is a pre-release
|
||||
// such as "dev" (in development), "beta", "rc1", etc.
|
||||
VersionPrerelease = "dev"
|
||||
}
|
Loading…
Reference in New Issue