github.com/StackPointCloud/packer@v0.10.2-0.20180716202532-b28098e0f79b/Makefile (about) 1 TEST?=$(shell go list ./... | grep -v vendor) 2 VET?=$(shell ls -d */ | grep -v vendor | grep -v website) 3 # Get the current full sha from git 4 GITSHA:=$(shell git rev-parse HEAD) 5 # Get the current local branch name from git (if we can, this may be blank) 6 GITBRANCH:=$(shell git symbolic-ref --short HEAD 2>/dev/null) 7 GOOS=$(shell go env GOOS) 8 GOARCH=$(shell go env GOARCH) 9 GOPATH=$(shell go env GOPATH) 10 11 # gofmt 12 UNFORMATTED_FILES=$(shell find . -not -path "./vendor/*" -name "*.go" | xargs gofmt -s -l) 13 14 # Get the git commit 15 GIT_DIRTY=$(shell test -n "`git status --porcelain`" && echo "+CHANGES" || true) 16 GIT_COMMIT=$(shell git rev-parse --short HEAD) 17 GIT_IMPORT=github.com/hashicorp/packer/version 18 GOLDFLAGS=-X $(GIT_IMPORT).GitCommit=$(GIT_COMMIT)$(GIT_DIRTY) 19 20 export GOLDFLAGS 21 22 default: deps generate test dev 23 24 ci: deps test 25 26 release: deps test releasebin package ## Build a release build 27 28 bin: deps ## Build debug/test build 29 @go get github.com/mitchellh/gox 30 @echo "WARN: 'make bin' is for debug / test builds only. Use 'make release' for release builds." 31 @sh -c "$(CURDIR)/scripts/build.sh" 32 33 releasebin: deps 34 @go get github.com/mitchellh/gox 35 @grep 'const VersionPrerelease = "dev"' version/version.go > /dev/null ; if [ $$? -eq 0 ]; then \ 36 echo "ERROR: You must remove prerelease tags from version/version.go prior to release."; \ 37 exit 1; \ 38 fi 39 @sh -c "$(CURDIR)/scripts/build.sh" 40 41 package: 42 $(if $(VERSION),,@echo 'VERSION= needed to release; Use make package skip compilation'; exit 1) 43 @sh -c "$(CURDIR)/scripts/dist.sh $(VERSION)" 44 45 deps: 46 @go get golang.org/x/tools/cmd/stringer 47 @go get -u github.com/mna/pigeon 48 @go get github.com/kardianos/govendor 49 @go get golang.org/x/tools/cmd/goimports 50 @govendor sync 51 52 dev: deps ## Build and install a development build 53 @grep 'const VersionPrerelease = ""' version/version.go > /dev/null ; if [ $$? -eq 0 ]; then \ 54 echo "ERROR: You must add prerelease tags to version/version.go prior to making a dev build."; \ 55 exit 1; \ 56 fi 57 @mkdir -p pkg/$(GOOS)_$(GOARCH) 58 @mkdir -p bin 59 @go install -ldflags '$(GOLDFLAGS)' 60 @cp $(GOPATH)/bin/packer bin/packer 61 @cp $(GOPATH)/bin/packer pkg/$(GOOS)_$(GOARCH) 62 63 fmt: ## Format Go code 64 @gofmt -w -s $(UNFORMATTED_FILES) 65 66 fmt-check: ## Check go code formatting 67 @echo "==> Checking that code complies with gofmt requirements..." 68 @if [ ! -z "$(UNFORMATTED_FILES)" ]; then \ 69 echo "gofmt needs to be run on the following files:"; \ 70 echo "$(UNFORMATTED_FILES)" | xargs -n1; \ 71 echo "You can use the command: \`make fmt\` to reformat code."; \ 72 exit 1; \ 73 else \ 74 echo "Check passed."; \ 75 fi 76 77 fmt-docs: 78 @find ./website/source/docs -name "*.md" -exec pandoc --wrap auto --columns 79 --atx-headers -s -f "markdown_github+yaml_metadata_block" -t "markdown_github+yaml_metadata_block" {} -o {} \; 79 80 # Install js-beautify with npm install -g js-beautify 81 fmt-examples: 82 find examples -name *.json | xargs js-beautify -r -s 2 -n -eol "\n" 83 84 # generate runs `go generate` to build the dynamically generated 85 # source files. 86 generate: deps ## Generate dynamically generated code 87 go generate . 88 gofmt -w common/bootcommand/boot_command.go 89 goimports -w common/bootcommand/boot_command.go 90 gofmt -w command/plugin.go 91 92 test: deps fmt-check ## Run unit tests 93 @go test $(TEST) $(TESTARGS) -timeout=2m 94 @go tool vet $(VET) ; if [ $$? -eq 1 ]; then \ 95 echo "ERROR: Vet found problems in the code."; \ 96 exit 1; \ 97 fi 98 99 # testacc runs acceptance tests 100 testacc: deps generate ## Run acceptance tests 101 @echo "WARN: Acceptance tests will take a long time to run and may cost money. Ctrl-C if you want to cancel." 102 PACKER_ACC=1 go test -v $(TEST) $(TESTARGS) -timeout=45m 103 104 testrace: deps ## Test for race conditions 105 @go test -race $(TEST) $(TESTARGS) -timeout=2m 106 107 updatedeps: 108 @echo "INFO: Packer deps are managed by govendor. See .github/CONTRIBUTING.md" 109 110 help: 111 @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' 112 113 .PHONY: bin checkversion ci default deps fmt fmt-docs fmt-examples generate releasebin test testacc testrace updatedeps