Skip to content

Commit

Permalink
fix(version): add warning when built with 'go install'
Browse files Browse the repository at this point in the history
and add a check & install for govvv to the makefile, delay call to govvv until
after the check. Drop now-defunct cross-platform compilation
  • Loading branch information
b5 committed Dec 1, 2020
1 parent ad4dcc7 commit 1063a71
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 35 deletions.
45 changes: 10 additions & 35 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ QRI_VERSION?="0.9.14-dev"
BUILD_FLAGS?=CGO_ENABLED=0
PKG=$(shell go list ./version)
GOLANG_VERSION=$(shell go version | awk '{print $$3}')
GOVVV_FLAGS=$(shell govvv -flags -pkg $(PKG) -version $(QRI_VERSION))

require-goversion:
$(eval minver := go1.13)
Expand All @@ -24,11 +23,17 @@ require-goversion:
fi; \
fi;

build: require-goversion
$(BUILD_FLAGS) go build -ldflags="-X ${PKG}.GolangVersion=${GOLANG_VERSION} ${GOVVV_FLAGS}" .
require-govvv:
$(eval govvv_loc := $(shell which govvv))
@if [ "$(govvv_loc)" == "" ]; then go install github.com/ahmetb/govvv; fi;

install: require-goversion
$(BUILD_FLAGS) go install -ldflags="-X ${PKG}.GolangVersion=${GOLANG_VERSION} ${GOVVV_FLAGS}" .
govvv_version_flags:= $(shell govvv -flags -pkg $(PKG) -version $(QRI_VERSION))

build: require-goversion require-govvv
$(BUILD_FLAGS) go build -ldflags="-X ${PKG}.GolangVersion=${GOLANG_VERSION} $(govvv_version_flags)" .

install: require-goversion require-govvv
$(BUILD_FLAGS) go install -ldflags="-X ${PKG}.GolangVersion=${GOLANG_VERSION} $(govvv_version_flags)" .
.PHONY: install

dscache_fbs:
Expand All @@ -51,33 +56,3 @@ cli-docs:

update-changelog:
conventional-changelog -p angular -i CHANGELOG.md -s

build-cross-platform:
@echo "building qri_windows_amd64"
mkdir qri_windows_amd64
env GOOS=windows GOARCH=amd64 go build -o qri_windows_amd64/qri .
zip -r qri_windows_amd64.zip qri_windows_amd64 && rm -r qri_windows_amd64
@echo "building qri_windows_386"
mkdir qri_windows_386
env GOOS=windows GOARCH=386 go build -o qri_windows_386/qri .
zip -r qri_windows_386.zip qri_windows_386 && rm -r qri_windows_386
@echo "building qri_linux_arm"
mkdir qri_linux_arm
env GOOS=linux GOARCH=arm go build -o qri_linux_arm/qri .
zip -r qri_linux_arm.zip qri_linux_arm && rm -r qri_linux_arm
@echo "building qri_linux_amd64"
mkdir qri_linux_amd64
env GOOS=linux GOARCH=amd64 go build -o qri_linux_amd64/qri .
zip -r qri_linux_amd64.zip qri_linux_amd64 && rm -r qri_linux_amd64
@echo "building qri_linux_386"
mkdir qri_linux_386
env GOOS=linux GOARCH=386 go build -o qri_linux_386/qri .
zip -r qri_linux_386.zip qri_linux_386 && rm -r qri_linux_386
@echo "building qri_darwin_386"
mkdir qri_darwin_386
env GOOS=darwin GOARCH=386 go build -o qri_darwin_386/qri .
zip -r qri_darwin_386.zip qri_darwin_386 && rm -r qri_darwin_386
@echo "building qri_darwin_amd64"
mkdir qri_darwin_amd64
env GOOS=darwin GOARCH=amd64 go build -o qri_darwin_amd64/qri .
zip -r qri_darwin_amd64.zip qri_darwin_amd64 && rm -r qri_darwin_amd64
10 changes: 10 additions & 0 deletions version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ var (

// Map returns a summary of build info as a string map
func Map() map[string]string {
if Version == "n/a" {
return map[string]string{
"error": `This qri binary was not built with version information. Please build using 'make install' instead of 'go install'`,
}
}

return map[string]string{
"version": Version,
"gitCommit": GitCommit,
Expand All @@ -34,6 +40,10 @@ func Map() map[string]string {

// Summary prints a summary of all build info.
func Summary() string {
if Version == "n/a" {
return `Warning! This qri binary was not built with version information. Please build using 'make install' instead of 'go install'`
}

return fmt.Sprintf(
"version:\t%s\nbuild date:\t%s\ngit summary:\t%s\ngit branch:\t%s\ngit commit:\t%s\ngit state:\t%s\ngolang version:\t%s",
Version,
Expand Down

0 comments on commit 1063a71

Please sign in to comment.