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/')
|
PACKAGES=$(shell go list ./... | grep -v '^github.com/hashicorp/consul/vendor/')
|
||||||
VETARGS?=-asmdecl -atomic -bool -buildtags -copylocks -methods \
|
VETARGS?=-asmdecl -atomic -bool -buildtags -copylocks -methods \
|
||||||
-nilfunc -printf -rangeloops -shift -structtags -unsafeptr
|
-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 builds binaries for all targets
|
||||||
all: bin
|
all: bin
|
||||||
|
@ -20,15 +20,15 @@ ci:
|
||||||
|
|
||||||
bin: tools
|
bin: tools
|
||||||
@mkdir -p bin/
|
@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 creates binaries for testing locally - these are put into ./bin and $GOPATH
|
||||||
dev: format
|
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 builds binaries for all platforms and packages them for distribution
|
||||||
dist:
|
dist:
|
||||||
@sh -c "'$(CURDIR)/scripts/dist.sh' $(VERSION)"
|
@BUILD_TAGS='$(BUILD_TAGS)' sh -c "'$(CURDIR)/scripts/dist.sh'"
|
||||||
|
|
||||||
cov:
|
cov:
|
||||||
gocov test ./... | gocov-html > /tmp/coverage.html
|
gocov test ./... | gocov-html > /tmp/coverage.html
|
||||||
|
@ -37,7 +37,7 @@ cov:
|
||||||
test: format
|
test: format
|
||||||
@$(MAKE) vet
|
@$(MAKE) vet
|
||||||
@./scripts/verify_no_uuid.sh
|
@./scripts/verify_no_uuid.sh
|
||||||
@./scripts/test.sh
|
@BUILD_TAGS='$(BUILD_TAGS)' sh -c "'$(CURDIR)/scripts/test.sh'"
|
||||||
|
|
||||||
cover:
|
cover:
|
||||||
go list ./... | xargs -n1 go test --cover
|
go list ./... | xargs -n1 go test --cover
|
||||||
|
@ -49,7 +49,7 @@ format:
|
||||||
vet:
|
vet:
|
||||||
@echo "--> Running go tool vet $(VETARGS) ."
|
@echo "--> Running go tool vet $(VETARGS) ."
|
||||||
@go list ./... \
|
@go list ./... \
|
||||||
| grep -v ^github.com/hashicorp/consul/vendor/ \
|
| grep -v /vendor/ \
|
||||||
| cut -d '/' -f 4- \
|
| cut -d '/' -f 4- \
|
||||||
| xargs -n1 \
|
| xargs -n1 \
|
||||||
go tool vet $(VETARGS) ;\
|
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"
|
||||||
"github.com/hashicorp/consul/command/agent"
|
"github.com/hashicorp/consul/command/agent"
|
||||||
|
"github.com/hashicorp/consul/version"
|
||||||
"github.com/mitchellh/cli"
|
"github.com/mitchellh/cli"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -19,10 +20,10 @@ func init() {
|
||||||
Commands = map[string]cli.CommandFactory{
|
Commands = map[string]cli.CommandFactory{
|
||||||
"agent": func() (cli.Command, error) {
|
"agent": func() (cli.Command, error) {
|
||||||
return &agent.Command{
|
return &agent.Command{
|
||||||
Revision: GitCommit,
|
Revision: version.GitCommit,
|
||||||
Version: Version,
|
Version: version.Version,
|
||||||
VersionPrerelease: VersionPrerelease,
|
VersionPrerelease: version.VersionPrerelease,
|
||||||
HumanVersion: GetHumanVersion(),
|
HumanVersion: version.GetHumanVersion(),
|
||||||
Ui: ui,
|
Ui: ui,
|
||||||
ShutdownCh: make(chan struct{}),
|
ShutdownCh: make(chan struct{}),
|
||||||
}, nil
|
}, nil
|
||||||
|
@ -177,7 +178,7 @@ func init() {
|
||||||
|
|
||||||
"version": func() (cli.Command, error) {
|
"version": func() (cli.Command, error) {
|
||||||
return &command.VersionCommand{
|
return &command.VersionCommand{
|
||||||
HumanVersion: GetHumanVersion(),
|
HumanVersion: version.GetHumanVersion(),
|
||||||
Ui: ui,
|
Ui: ui,
|
||||||
}, nil
|
}, nil
|
||||||
},
|
},
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
# This script builds the application from source for multiple platforms.
|
# This script builds the application from source for multiple platforms.
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
export GO15VENDOREXPERIMENT=1
|
|
||||||
export CGO_ENABLED=0
|
export CGO_ENABLED=0
|
||||||
|
|
||||||
# Get the parent directory of where this script is.
|
# Get the parent directory of where this script is.
|
||||||
|
@ -43,6 +42,7 @@ echo "==> Building..."
|
||||||
-osarch="!darwin/arm" \
|
-osarch="!darwin/arm" \
|
||||||
-ldflags "-X main.GitCommit='${GIT_COMMIT}${GIT_DIRTY}' -X main.GitDescribe='${GIT_DESCRIBE}'" \
|
-ldflags "-X main.GitCommit='${GIT_COMMIT}${GIT_DIRTY}' -X main.GitDescribe='${GIT_DESCRIBE}'" \
|
||||||
-output "pkg/{{.OS}}_{{.Arch}}/consul" \
|
-output "pkg/{{.OS}}_{{.Arch}}/consul" \
|
||||||
|
-tags="${BUILD_TAGS}" \
|
||||||
.
|
.
|
||||||
|
|
||||||
# Move all the compiled things to the $GOPATH/bin
|
# Move all the compiled things to the $GOPATH/bin
|
||||||
|
|
|
@ -1,14 +1,22 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
export GO15VENDOREXPERIMENT=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.
|
||||||
# Get the version from the command line.
|
|
||||||
VERSION=$1
|
|
||||||
if [ -z $VERSION ]; then
|
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
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
echo "==> Building version $VERSION..."
|
||||||
|
|
||||||
# Get the parent directory of where this script is.
|
# Get the parent directory of where this script is.
|
||||||
SOURCE="${BASH_SOURCE[0]}"
|
SOURCE="${BASH_SOURCE[0]}"
|
||||||
|
@ -28,7 +36,7 @@ fi
|
||||||
# Do a hermetic build inside a Docker container.
|
# Do a hermetic build inside a Docker container.
|
||||||
if [ -z $NOBUILD ]; then
|
if [ -z $NOBUILD ]; then
|
||||||
docker build -t hashicorp/consul-builder scripts/consul-builder/
|
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
|
fi
|
||||||
|
|
||||||
# Zip all the files.
|
# Zip all the files.
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
export GO15VENDOREXPERIMENT=1
|
|
||||||
|
|
||||||
# Get the parent directory of where this script is.
|
# Get the parent directory of where this script is.
|
||||||
SOURCE="${BASH_SOURCE[0]}"
|
SOURCE="${BASH_SOURCE[0]}"
|
||||||
while [ -h "$SOURCE" ] ; do SOURCE="$(readlink "$SOURCE")"; done
|
while [ -h "$SOURCE" ] ; do SOURCE="$(readlink "$SOURCE")"; done
|
||||||
|
@ -12,7 +10,7 @@ DIR="$( cd -P "$( dirname "$SOURCE" )/.." && pwd )"
|
||||||
cd $DIR
|
cd $DIR
|
||||||
|
|
||||||
# Make sure build tools are abailable.
|
# Make sure build tools are abailable.
|
||||||
make -f GNUMakefile tools
|
make tools
|
||||||
|
|
||||||
# Build the standalone version of the web assets for the sanity check.
|
# Build the standalone version of the web assets for the sanity check.
|
||||||
pushd ui
|
pushd ui
|
||||||
|
@ -29,7 +27,7 @@ popd
|
||||||
|
|
||||||
# Regenerate the built-in web assets. If there are any diffs after doing this
|
# Regenerate the built-in web assets. If there are any diffs after doing this
|
||||||
# then we know something is up.
|
# then we know something is up.
|
||||||
make -f GNUMakefile static-assets
|
make static-assets
|
||||||
if ! git diff --quiet command/agent/bindata_assetfs.go; then
|
if ! git diff --quiet command/agent/bindata_assetfs.go; then
|
||||||
echo "Checked-in web assets are out of date, build aborted"
|
echo "Checked-in web assets are out of date, build aborted"
|
||||||
exit 1
|
exit 1
|
||||||
|
@ -39,7 +37,7 @@ fi
|
||||||
# away our pkg folder so we have to regenerate the ui once more. This is probably
|
# 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.
|
# for the best since we have meddled with the timestamps.
|
||||||
rm -rf pkg
|
rm -rf pkg
|
||||||
make -f GNUMakefile all
|
make all
|
||||||
pushd ui
|
pushd ui
|
||||||
make dist
|
make dist
|
||||||
popd
|
popd
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
set -e
|
||||||
export GO15VENDOREXPERIMENT=1
|
|
||||||
|
|
||||||
# Create a temp dir and clean it up on exit
|
# Create a temp dir and clean it up on exit
|
||||||
TEMPDIR=`mktemp -d -t consul-test.XXX`
|
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
|
# Build the Consul binary for the API tests
|
||||||
echo "--> Building consul"
|
echo "--> Building consul"
|
||||||
go build -o $TEMPDIR/consul || exit 1
|
go build -tags="${BUILD_TAGS}" -o $TEMPDIR/consul || exit 1
|
||||||
|
|
||||||
# Run the tests
|
# Run the tests
|
||||||
echo "--> Running 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 (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
// The git commit that was compiled. This will be filled in by the compiler.
|
|
||||||
var (
|
var (
|
||||||
|
// The git commit that was compiled. These will be filled in by the
|
||||||
|
// compiler.
|
||||||
GitCommit string
|
GitCommit string
|
||||||
GitDescribe 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
|
// GetHumanVersion composes the parts of the version in a way that's suitable
|
||||||
// for displaying to humans.
|
// for displaying to humans.
|
||||||
func GetHumanVersion() string {
|
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