packer-cn/Makefile

125 lines
4.6 KiB
Makefile
Raw Normal View History

TEST?=$(shell go list ./... | grep -v vendor)
VET?=$(shell ls -d */ | grep -v vendor | grep -v website)
# Get the current full sha from git
GITSHA:=$(shell git rev-parse HEAD)
# Get the current local branch name from git (if we can, this may be blank)
GITBRANCH:=$(shell git symbolic-ref --short HEAD 2>/dev/null)
GOOS=$(shell go env GOOS)
GOARCH=$(shell go env GOARCH)
GOPATH=$(shell go env GOPATH)
# gofmt
UNFORMATTED_FILES=$(shell find . -not -path "./vendor/*" -name "*.go" | xargs gofmt -s -l)
EXECUTABLE_FILES=$(shell find . -type f -perm +111 | egrep -v '^\./(website/vendor|vendor/|\.git|bin/|scripts/|pkg/)' | egrep -v '.*(\.sh|\.bats|\.git)' | egrep -v './provisioner/ansible/test-fixtures/exit1')
# Get the git commit
GIT_DIRTY=$(shell test -n "`git status --porcelain`" && echo "+CHANGES" || true)
GIT_COMMIT=$(shell git rev-parse --short HEAD)
GIT_IMPORT=github.com/hashicorp/packer/version
GOLDFLAGS=-X $(GIT_IMPORT).GitCommit=$(GIT_COMMIT)$(GIT_DIRTY)
export GOLDFLAGS
default: deps generate test dev
2013-03-23 03:48:20 -04:00
ci: deps test
2016-08-14 09:28:29 -04:00
release: deps test releasebin package ## Build a release build
2016-08-14 09:28:29 -04:00
bin: deps ## Build debug/test build
@go get github.com/mitchellh/gox
@echo "WARN: 'make bin' is for debug / test builds only. Use 'make release' for release builds."
@sh -c "$(CURDIR)/scripts/build.sh"
releasebin: deps
@go get github.com/mitchellh/gox
@grep 'const VersionPrerelease = "dev"' version/version.go > /dev/null ; if [ $$? -eq 0 ]; then \
echo "ERROR: You must remove prerelease tags from version/version.go prior to release."; \
exit 1; \
fi
@sh -c "$(CURDIR)/scripts/build.sh"
2013-09-17 07:35:07 -04:00
package:
$(if $(VERSION),,@echo 'VERSION= needed to release; Use make package skip compilation'; exit 1)
@sh -c "$(CURDIR)/scripts/dist.sh $(VERSION)"
deps:
@go get golang.org/x/tools/cmd/goimports
@go get golang.org/x/tools/cmd/stringer
@go get -u github.com/mna/pigeon
@go get github.com/kardianos/govendor
2018-07-09 14:49:32 -04:00
@go get golang.org/x/tools/cmd/goimports
2016-08-14 09:28:29 -04:00
dev: deps ## Build and install a development build
@grep 'const VersionPrerelease = ""' version/version.go > /dev/null ; if [ $$? -eq 0 ]; then \
echo "ERROR: You must add prerelease tags to version/version.go prior to making a dev build."; \
exit 1; \
fi
@mkdir -p pkg/$(GOOS)_$(GOARCH)
2017-06-28 21:53:19 -04:00
@mkdir -p bin
2017-05-22 18:03:21 -04:00
@go install -ldflags '$(GOLDFLAGS)'
2017-06-28 21:53:19 -04:00
@cp $(GOPATH)/bin/packer bin/packer
@cp $(GOPATH)/bin/packer pkg/$(GOOS)_$(GOARCH)
2013-08-13 21:42:08 -04:00
2016-08-14 09:28:29 -04:00
fmt: ## Format Go code
@gofmt -w -s main.go $(UNFORMATTED_FILES)
2016-11-01 16:48:10 -04:00
fmt-check: ## Check go code formatting
2018-05-01 23:39:48 -04:00
@echo "==> Checking that code complies with gofmt requirements..."
@if [ ! -z "$(UNFORMATTED_FILES)" ]; then \
2018-05-01 23:39:48 -04:00
echo "gofmt needs to be run on the following files:"; \
echo "$(UNFORMATTED_FILES)" | xargs -n1; \
2018-05-01 23:39:48 -04:00
echo "You can use the command: \`make fmt\` to reformat code."; \
exit 1; \
else \
echo "Check passed."; \
fi
2016-02-12 14:37:49 -05:00
mode-check: ## Check that only certain files are executable
@echo "==> Checking that only certain files are executable..."
@if [ ! -z "$(EXECUTABLE_FILES)" ]; then \
echo "These files should not be executable or they must be white listed in the Makefile:"; \
echo "$(EXECUTABLE_FILES)" | xargs -n1; \
exit 1; \
else \
echo "Check passed."; \
fi
2017-06-14 21:04:16 -04:00
fmt-docs:
@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 {} \;
2016-03-10 20:41:28 -05:00
# Install js-beautify with npm install -g js-beautify
fmt-examples:
find examples -name *.json | xargs js-beautify -r -s 2 -n -eol "\n"
2015-05-26 16:26:22 -04:00
# generate runs `go generate` to build the dynamically generated
# source files.
2016-08-14 09:28:29 -04:00
generate: deps ## Generate dynamically generated code
go generate .
2018-04-18 17:53:59 -04:00
gofmt -w common/bootcommand/boot_command.go
goimports -w common/bootcommand/boot_command.go
2016-09-29 17:20:47 -04:00
gofmt -w command/plugin.go
2015-05-26 16:26:22 -04:00
test: deps fmt-check mode-check ## Run unit tests
@go test $(TEST) $(TESTARGS) -timeout=2m
@go tool vet $(VET) ; if [ $$? -eq 1 ]; then \
echo "ERROR: Vet found problems in the code."; \
exit 1; \
fi
2013-07-18 10:26:36 -04:00
2015-05-26 16:26:22 -04:00
# testacc runs acceptance tests
2016-08-14 09:28:29 -04:00
testacc: deps generate ## Run acceptance tests
@echo "WARN: Acceptance tests will take a long time to run and may cost money. Ctrl-C if you want to cancel."
PACKER_ACC=1 go test -v $(TEST) $(TESTARGS) -timeout=45m
2015-05-26 16:26:22 -04:00
2016-08-14 09:28:29 -04:00
testrace: deps ## Test for race conditions
@go test -race $(TEST) $(TESTARGS) -timeout=2m
2013-03-24 17:47:59 -04:00
updatedeps:
2018-04-02 13:59:59 -04:00
@echo "INFO: Packer deps are managed by govendor. See .github/CONTRIBUTING.md"
2015-01-30 07:03:25 -05:00
2016-08-14 09:28:29 -04:00
help:
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
2017-06-14 21:04:16 -04:00
.PHONY: bin checkversion ci default deps fmt fmt-docs fmt-examples generate releasebin test testacc testrace updatedeps