mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-09-07 09:05:55 +00:00
Clean up Makefile
Turn off the automatic installation of build-time dependencies, which was confusing and inconsistent. Update PHONY list. Simplify git status check. Remove PKGS as Go 1.9+ automatically ignores `vendor` when running tests. Consolidate release/prerelease build code. Add comments.
This commit is contained in:
parent
99eb00bbdc
commit
96e2ef534f
1 changed files with 90 additions and 70 deletions
160
Makefile
160
Makefile
|
|
@ -1,113 +1,133 @@
|
|||
.PHONY: dep docker pilosa release-build prerelease-build release prerelease prerelease-upload install generate generate-statik generate-protoc statik test cover cover-pkg cover-viz clean docker-build docker-test
|
||||
.PHONY: build check-clean clean cover cover-viz default docker docker-build docker-test generate generate-protoc generate-statik install install-build-deps install-dep install-protoc install-protoc-gen-gofast install-statik prerelease prerelease-build prerelease-upload release release-build require-dep require-protoc require-protoc-gen-gofast require-statik test
|
||||
|
||||
DEP := $(shell command -v dep 2>/dev/null)
|
||||
STATIK := $(shell command -v statik 2>/dev/null)
|
||||
PROTOC := $(shell command -v protoc 2>/dev/null)
|
||||
VERSION := $(shell git describe --tags 2> /dev/null || echo unknown)
|
||||
STATUS := $(shell git status --porcelain)
|
||||
IDENTIFIER := $(VERSION)-$(GOOS)-$(GOARCH)
|
||||
CLONE_URL=github.com/pilosa/pilosa
|
||||
PKGS := $(shell cd $(GOPATH)/src/$(CLONE_URL); go list ./... | grep -v vendor)
|
||||
BUILD_TIME=`date -u +%FT%T%z`
|
||||
VERSION := $(shell git describe --tags 2> /dev/null || echo unknown)
|
||||
VERSION_ID := $(VERSION)-$(GOOS)-$(GOARCH)
|
||||
BRANCH := $(if $(TRAVIS_BRANCH),$(TRAVIS_BRANCH),$(shell git rev-parse --abbrev-ref HEAD))
|
||||
BRANCH_ID := $(BRANCH)-$(GOOS)-$(GOARCH)
|
||||
BUILD_TIME := $(shell date -u +%FT%T%z)
|
||||
LDFLAGS="-X github.com/pilosa/pilosa.Version=$(VERSION) -X github.com/pilosa/pilosa.BuildTime=$(BUILD_TIME)"
|
||||
DOCKER_GOLANG_IMAGE=golang:latest
|
||||
GIT_BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
|
||||
BRANCH := $(if $(TRAVIS_BRANCH),$(TRAVIS_BRANCH),$(GIT_BRANCH))
|
||||
BRANCH_IDENTIFIER := $(BRANCH)-$(GOOS)-$(GOARCH)
|
||||
GO_VERSION=latest
|
||||
|
||||
default: test pilosa
|
||||
# Run tests and compile Pilosa
|
||||
default: test build
|
||||
|
||||
# Remove vendor and build directories
|
||||
clean:
|
||||
rm -rf vendor build
|
||||
|
||||
$(GOPATH)/bin:
|
||||
mkdir $(GOPATH)/bin
|
||||
|
||||
dep: $(GOPATH)/bin
|
||||
go get -u github.com/golang/dep/cmd/dep
|
||||
|
||||
# Set up vendor directory using `dep`
|
||||
vendor: Gopkg.toml
|
||||
ifndef DEP
|
||||
make dep
|
||||
endif
|
||||
$(MAKE) require-dep
|
||||
dep ensure
|
||||
touch vendor
|
||||
|
||||
Gopkg.lock: dep Gopkg.toml
|
||||
dep ensure
|
||||
|
||||
# Run test suite
|
||||
test: vendor
|
||||
go test $(PKGS) $(TESTFLAGS)
|
||||
go test ./... $(TESTFLAGS)
|
||||
|
||||
# Run test suite with coverage enabled
|
||||
cover: vendor
|
||||
make test TESTFLAGS="-coverprofile=build/coverage.out"
|
||||
$(MAKE) test TESTFLAGS="-coverprofile=build/coverage.out"
|
||||
|
||||
# Run test suite with coverage enabled and view coverage results in browser
|
||||
cover-viz: cover
|
||||
go tool cover -html=build/coverage.out
|
||||
|
||||
pilosa: vendor
|
||||
go build -tags release -ldflags $(LDFLAGS) $(FLAGS) $(CLONE_URL)/cmd/pilosa
|
||||
# Compile Pilosa
|
||||
build: vendor
|
||||
go build -tags release -ldflags $(LDFLAGS) $(FLAGS) ./cmd/pilosa
|
||||
|
||||
# Create a single release build under the build directory
|
||||
release-build: vendor
|
||||
ifdef DOCKER_BUILD
|
||||
make docker-build FLAGS="-o build/pilosa-$(IDENTIFIER)/pilosa"
|
||||
else
|
||||
make pilosa FLAGS="-o build/pilosa-$(IDENTIFIER)/pilosa"
|
||||
endif
|
||||
cp LICENSE README.md build/pilosa-$(IDENTIFIER)
|
||||
tar -cvz -C build -f build/pilosa-$(IDENTIFIER).tar.gz pilosa-$(IDENTIFIER)/
|
||||
@echo "Created release build: build/pilosa-$(IDENTIFIER).tar.gz"
|
||||
$(MAKE) $(if DOCKER_BUILD,docker-)build FLAGS="-o build/pilosa-$(VERSION_ID)/pilosa"
|
||||
cp LICENSE README.md build/pilosa-$(VERSION_ID)
|
||||
tar -cvz -C build -f build/pilosa-$(VERSION_ID).tar.gz pilosa-$(VERSION_ID)/
|
||||
@echo Created release build: build/pilosa-$(VERSION_ID).tar.gz
|
||||
|
||||
release:
|
||||
ifeq ($(STATUS),"")
|
||||
make release-build GOOS=darwin GOARCH=amd64
|
||||
make release-build GOOS=linux GOARCH=amd64 DOCKER_BUILD=1
|
||||
make release-build GOOS=linux GOARCH=386 DOCKER_BUILD=1
|
||||
else
|
||||
@echo "Will not create release with unclean git status."
|
||||
endif
|
||||
# Error out if there are untracked changes in Git
|
||||
check-clean:
|
||||
$(if $(shell git status --porcelain),$(error Git status is not clean! Please commit or checkout/reset changes.))
|
||||
|
||||
# Create release build tarballs for all supported platforms. Linux compilation happens under Docker.
|
||||
release: check-clean
|
||||
$(MAKE) release-build GOOS=darwin GOARCH=amd64
|
||||
$(MAKE) release-build GOOS=linux GOARCH=amd64 DOCKER_BUILD=1
|
||||
$(MAKE) release-build GOOS=linux GOARCH=386 DOCKER_BUILD=1
|
||||
|
||||
# Create branch-tagged pre-release for client library CI jobs
|
||||
prerelease-build: vendor
|
||||
make pilosa FLAGS="-o build/pilosa-$(BRANCH_IDENTIFIER)/pilosa"
|
||||
cp LICENSE README.md build/pilosa-$(BRANCH_IDENTIFIER)
|
||||
tar -cvz -C build -f build/pilosa-$(BRANCH_IDENTIFIER).tar.gz pilosa-$(BRANCH_IDENTIFIER)/
|
||||
@echo "Created pre-release build: build/pilosa-$(BRANCH_IDENTIFIER).tar.gz"
|
||||
$(MAKE) release-build VERSION_ID=$(BRANCH_ID)
|
||||
|
||||
# Create prerelease build for Linux/amd64
|
||||
prerelease:
|
||||
make prerelease-build GOOS=linux GOARCH=amd64
|
||||
$(MAKE) prerelease-build GOOS=linux GOARCH=amd64
|
||||
|
||||
# Upload prerelease to S3
|
||||
prerelease-upload: prerelease
|
||||
aws s3 cp build/pilosa-$(BRANCH_IDENTIFIER).tar.gz s3://build.pilosa.com/pilosa-$(BRANCH_IDENTIFIER).tar.gz --acl public-read
|
||||
aws s3 cp build/pilosa-$(BRANCH_ID).tar.gz s3://build.pilosa.com/pilosa-$(BRANCH_ID).tar.gz --acl public-read
|
||||
|
||||
# Install Pilosa
|
||||
install: vendor
|
||||
go install -ldflags $(LDFLAGS) $(FLAGS) $(CLONE_URL)/cmd/pilosa
|
||||
go install -ldflags $(LDFLAGS) $(FLAGS) ./cmd/pilosa
|
||||
|
||||
.protoc-gen-gofast: vendor
|
||||
ifndef PROTOC
|
||||
$(error "protoc is not available. please install protoc from https://github.com/google/protobuf/releases")
|
||||
endif
|
||||
go build -o .protoc-gen-gofast ./vendor/github.com/gogo/protobuf/protoc-gen-gofast
|
||||
cp ./.protoc-gen-gofast $(GOPATH)/bin/protoc-gen-gofast
|
||||
|
||||
generate-protoc: .protoc-gen-gofast
|
||||
# `go generate` protocol buffers
|
||||
generate-protoc: require-protoc require-protoc-gen-gofast
|
||||
go generate github.com/pilosa/pilosa/internal
|
||||
|
||||
generate-statik: statik
|
||||
# `go generate` statik assets (WebUI)
|
||||
generate-statik: require-statik
|
||||
go generate github.com/pilosa/pilosa/statik
|
||||
|
||||
# `go generate` all needed packages
|
||||
generate: generate-protoc generate-statik
|
||||
|
||||
statik:
|
||||
ifndef STATIK
|
||||
go get github.com/rakyll/statik
|
||||
endif
|
||||
|
||||
# Create Docker image from Dockerfile
|
||||
docker:
|
||||
docker build -t "pilosa:$(VERSION)" --build-arg ldflags=$(LDFLAGS) .
|
||||
@echo "Created image: pilosa:$(VERSION)"
|
||||
@echo Created docker image: pilosa:$(VERSION)
|
||||
|
||||
# Compile Pilosa inside Docker container
|
||||
docker-build:
|
||||
docker run --rm -v $(PWD):/go/src/$(CLONE_URL) -w /go/src/$(CLONE_URL) -e GOOS=$(GOOS) -e GOARCH=$(GOARCH) $(DOCKER_GOLANG_IMAGE) go build -tags release -ldflags $(LDFLAGS) $(FLAGS) $(CLONE_URL)/cmd/pilosa
|
||||
docker run --rm -v $(PWD):/go/src/$(CLONE_URL) -w /go/src/$(CLONE_URL) -e GOOS=$(GOOS) -e GOARCH=$(GOARCH) golang:$(GO_VERSION) go build -tags release -ldflags $(LDFLAGS) $(FLAGS) $(CLONE_URL)/cmd/pilosa
|
||||
|
||||
# Run Pilosa tests inside Docker container
|
||||
docker-test:
|
||||
docker run --rm -v $(PWD):/go/src/$(CLONE_URL) -w /go/src/$(CLONE_URL) $(DOCKER_GOLANG_IMAGE) go test $(TESTFLAGS) $(PKGS)
|
||||
docker run --rm -v $(PWD):/go/src/$(CLONE_URL) -w /go/src/$(CLONE_URL) golang:$(GO_VERSION) go test $(TESTFLAGS) ./...
|
||||
|
||||
######################
|
||||
# Build dependencies #
|
||||
######################
|
||||
|
||||
# Verifies that needed build dependency is installed. Errors out if not installed.
|
||||
define require
|
||||
$(if $(shell command -v $1 2>/dev/null),
|
||||
$(info Verified build dependency "$1" is installed.),
|
||||
$(error Build dependency "$1" not installed. To install, run `make install-$1` or `make install-build-deps`))
|
||||
endef
|
||||
|
||||
require-dep:
|
||||
$(call require,dep)
|
||||
|
||||
require-statik:
|
||||
$(call require,statik)
|
||||
|
||||
require-protoc-gen-gofast:
|
||||
$(call require,protoc-gen-gofast)
|
||||
|
||||
require-protoc:
|
||||
$(call require,protoc)
|
||||
|
||||
install-build-deps: install-dep install-statik install-protoc-gen-gofast install-protoc
|
||||
|
||||
install-dep:
|
||||
go get -u github.com/golang/dep/cmd/dep
|
||||
|
||||
install-statik:
|
||||
go get -u github.com/rakyll/statik
|
||||
|
||||
install-protoc-gen-gofast:
|
||||
go get -u github.com/gogo/protobuf/protoc-gen-gofast
|
||||
|
||||
install-protoc:
|
||||
@echo This tool cannot automatically install protoc. Please download and install protoc from https://github.com/google/protobuf/releases
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue