2019-02-27 04:37:10 -05:00
|
|
|
TEST?=$(shell go list ./...)
|
|
|
|
VET?=$(shell go list ./...)
|
2020-04-03 12:17:09 -04:00
|
|
|
ACC_TEST_BUILDERS?=all
|
|
|
|
ACC_TEST_PROVISIONERS?=all
|
2015-08-07 02:45:39 -04:00
|
|
|
# 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)
|
2017-05-04 23:30:09 -04:00
|
|
|
GOOS=$(shell go env GOOS)
|
|
|
|
GOARCH=$(shell go env GOARCH)
|
2017-07-22 11:45:34 -04:00
|
|
|
GOPATH=$(shell go env GOPATH)
|
2017-05-04 23:30:09 -04:00
|
|
|
|
2019-01-20 10:43:47 -05:00
|
|
|
EXECUTABLE_FILES=$(shell find . -type f -executable | egrep -v '^\./(website/[vendor|tmp]|vendor/|\.git|bin/|scripts/|pkg/)' | egrep -v '.*(\.sh|\.bats|\.git)' | egrep -v './provisioner/(ansible|inspec)/test-fixtures/exit1')
|
2018-08-15 10:08:20 -04:00
|
|
|
|
2017-05-04 23:30:09 -04:00
|
|
|
# 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
|
2020-04-14 14:48:50 -04:00
|
|
|
UNAME_S := $(shell uname -s)
|
|
|
|
LDFLAGS=-s -w
|
|
|
|
GOLDFLAGS=-X $(GIT_IMPORT).GitCommit=$(GIT_COMMIT)$(GIT_DIRTY) $(LDFLAGS)
|
2017-05-04 23:30:09 -04:00
|
|
|
|
|
|
|
export GOLDFLAGS
|
2016-11-01 16:49:13 -04:00
|
|
|
|
2020-02-14 11:42:29 -05:00
|
|
|
.PHONY: bin checkversion ci ci-lint default install-build-deps install-gen-deps fmt fmt-docs fmt-examples generate install-lint-deps lint \
|
|
|
|
releasebin test testacc testrace
|
2018-10-16 08:59:16 -04:00
|
|
|
|
2019-05-27 09:06:49 -04:00
|
|
|
default: install-build-deps install-gen-deps generate testrace dev releasebin package dev fmt fmt-check mode-check fmt-docs fmt-examples
|
2013-03-23 03:48:20 -04:00
|
|
|
|
2019-05-27 09:06:49 -04:00
|
|
|
ci: testrace ## Test in continuous integration
|
2015-08-07 02:45:39 -04:00
|
|
|
|
2019-05-27 09:06:49 -04:00
|
|
|
release: install-build-deps test releasebin package ## Build a release build
|
2015-08-07 02:45:39 -04:00
|
|
|
|
2019-05-27 09:06:49 -04:00
|
|
|
bin: install-build-deps ## Build debug/test build
|
2015-10-14 00:54:01 -04:00
|
|
|
@echo "WARN: 'make bin' is for debug / test builds only. Use 'make release' for release builds."
|
2019-06-14 14:12:58 -04:00
|
|
|
@GO111MODULE=auto sh -c "$(CURDIR)/scripts/build.sh"
|
2015-10-07 18:33:01 -04:00
|
|
|
|
2019-05-27 09:06:49 -04:00
|
|
|
releasebin: install-build-deps
|
2016-04-21 16:19:43 -04:00
|
|
|
@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."; \
|
2015-08-07 02:45:39 -04:00
|
|
|
exit 1; \
|
|
|
|
fi
|
2019-06-14 14:12:58 -04:00
|
|
|
@GO111MODULE=auto sh -c "$(CURDIR)/scripts/build.sh"
|
2013-09-17 07:35:07 -04:00
|
|
|
|
2016-02-17 23:11:25 -05:00
|
|
|
package:
|
|
|
|
$(if $(VERSION),,@echo 'VERSION= needed to release; Use make package skip compilation'; exit 1)
|
|
|
|
@sh -c "$(CURDIR)/scripts/dist.sh $(VERSION)"
|
|
|
|
|
2019-05-27 09:06:49 -04:00
|
|
|
install-build-deps: ## Install dependencies for bin build
|
|
|
|
@go get github.com/mitchellh/gox
|
|
|
|
|
|
|
|
install-gen-deps: ## Install dependencies for code generation
|
2019-09-05 11:19:50 -04:00
|
|
|
# to avoid having to tidy our go deps, we `go get` our binaries from a temp
|
|
|
|
# dir. `go get` will change our deps and the following deps are not part of
|
|
|
|
# out code dependencies; so a go mod tidy will remove them again. `go
|
|
|
|
# install` seems to install the last tagged version and we want to install
|
2020-02-14 11:42:29 -05:00
|
|
|
# master.
|
2019-09-05 11:06:30 -04:00
|
|
|
@(cd $(TEMPDIR) && GO111MODULE=on go get github.com/mna/pigeon@master)
|
2019-09-06 06:15:48 -04:00
|
|
|
@(cd $(TEMPDIR) && GO111MODULE=on go get github.com/alvaroloes/enumer@master)
|
2019-06-06 10:47:03 -04:00
|
|
|
@go install ./cmd/struct-markdown
|
2019-10-15 05:12:39 -04:00
|
|
|
@go install ./cmd/mapstructure-to-hcl2
|
2015-08-07 02:45:39 -04:00
|
|
|
|
2020-02-14 11:42:29 -05:00
|
|
|
install-lint-deps: ## Install linter dependencies
|
2020-04-15 06:53:51 -04:00
|
|
|
# Pinning golangci-lint at v1.23.8 as --new-from-rev seems to work properly; the latest 1.24.0 has caused issues with memory consumption
|
2020-02-14 11:42:29 -05:00
|
|
|
@echo "==> Updating linter dependencies..."
|
2020-03-12 05:36:10 -04:00
|
|
|
@curl -sSfL -q https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOPATH)/bin v1.23.8
|
2020-02-14 11:42:29 -05:00
|
|
|
|
2019-05-27 09:06:49 -04:00
|
|
|
dev: ## Build and install a development build
|
2016-04-21 16:19:43 -04:00
|
|
|
@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."; \
|
2015-08-07 02:45:39 -04:00
|
|
|
exit 1; \
|
|
|
|
fi
|
2017-05-04 23:30:09 -04:00
|
|
|
@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
|
2017-05-04 23:30:09 -04:00
|
|
|
@cp $(GOPATH)/bin/packer pkg/$(GOOS)_$(GOARCH)
|
2013-08-13 21:42:08 -04:00
|
|
|
|
2020-02-14 11:42:29 -05:00
|
|
|
lint: install-lint-deps ## Lint Go code
|
|
|
|
@if [ ! -z $(PKG_NAME) ]; then \
|
|
|
|
echo "golangci-lint run ./$(PKG_NAME)/..."; \
|
|
|
|
golangci-lint run ./$(PKG_NAME)/...; \
|
|
|
|
else \
|
2020-02-17 05:24:08 -05:00
|
|
|
echo "golangci-lint run ./..."; \
|
|
|
|
golangci-lint run ./...; \
|
2020-02-14 11:42:29 -05:00
|
|
|
fi
|
|
|
|
|
|
|
|
ci-lint: install-lint-deps ## On ci only lint newly added Go source files
|
|
|
|
@echo "==> Running linter on newly added Go source files..."
|
2020-04-15 06:53:51 -04:00
|
|
|
GO111MODULE=on golangci-lint run --new-from-rev=$(shell git merge-base origin/master HEAD) ./...
|
2020-02-14 11:42:29 -05:00
|
|
|
|
2016-08-14 09:28:29 -04:00
|
|
|
fmt: ## Format Go code
|
2019-05-27 09:37:03 -04:00
|
|
|
@go fmt ./...
|
2016-11-01 16:48:10 -04:00
|
|
|
|
2019-05-27 09:37:03 -04:00
|
|
|
fmt-check: fmt ## Check go code formatting
|
|
|
|
@echo "==> Checking that code complies with go fmt requirements..."
|
|
|
|
@git diff --exit-code; if [ $$? -eq 1 ]; then \
|
|
|
|
echo "Found files that are not fmt'ed."; \
|
2018-05-01 23:39:48 -04:00
|
|
|
echo "You can use the command: \`make fmt\` to reformat code."; \
|
|
|
|
exit 1; \
|
|
|
|
fi
|
2016-02-12 14:37:49 -05:00
|
|
|
|
2018-08-15 10:08:20 -04: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:
|
2020-04-01 23:30:51 -04:00
|
|
|
@find ./website/pages/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 {} \;
|
2017-06-14 21:04:16 -04:00
|
|
|
|
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.
|
2019-05-27 09:06:49 -04:00
|
|
|
generate: install-gen-deps ## Generate dynamically generated code
|
2019-06-14 08:58:58 -04:00
|
|
|
@echo "==> removing autogenerated markdown..."
|
2020-04-01 18:54:21 -04:00
|
|
|
@find website/pages/ -type f | xargs grep -l '^<!-- Code generated' | xargs rm
|
2019-10-15 05:12:39 -04:00
|
|
|
@echo "==> removing autogenerated code..."
|
2019-10-16 04:24:34 -04:00
|
|
|
@find post-processor common helper template builder provisioner -type f | xargs grep -l '^// Code generated' | xargs rm
|
2019-05-27 08:52:04 -04:00
|
|
|
go generate ./...
|
2019-05-27 10:00:20 -04:00
|
|
|
go fmt common/bootcommand/boot_command.go
|
|
|
|
|
|
|
|
generate-check: generate ## Check go code generation is on par
|
|
|
|
@echo "==> Checking that auto-generated code is not changed..."
|
|
|
|
@git diff --exit-code; if [ $$? -eq 1 ]; then \
|
|
|
|
echo "Found diffs in go generated code."; \
|
|
|
|
echo "You can use the command: \`make generate\` to reformat code."; \
|
|
|
|
exit 1; \
|
|
|
|
fi
|
2015-05-26 16:26:22 -04:00
|
|
|
|
2019-05-27 09:42:58 -04:00
|
|
|
test: mode-check vet ## Run unit tests
|
2019-04-05 13:57:47 -04:00
|
|
|
@go test $(TEST) $(TESTARGS) -timeout=3m
|
2013-07-18 10:26:36 -04:00
|
|
|
|
2020-04-03 12:17:09 -04:00
|
|
|
# acctest runs provisioners acceptance tests
|
|
|
|
provisioners-acctest: install-build-deps generate
|
|
|
|
ACC_TEST_BUILDERS=$(ACC_TEST_BUILDERS) ACC_TEST_PROVISIONERS=$(ACC_TEST_PROVISIONERS) go test ./provisioner/... -timeout=1h
|
|
|
|
|
2015-05-26 16:26:22 -04:00
|
|
|
# testacc runs acceptance tests
|
2019-05-27 09:06:49 -04:00
|
|
|
testacc: install-build-deps generate ## Run acceptance tests
|
2015-08-07 02:45:39 -04:00
|
|
|
@echo "WARN: Acceptance tests will take a long time to run and may cost money. Ctrl-C if you want to cancel."
|
2016-02-08 23:02:56 -05:00
|
|
|
PACKER_ACC=1 go test -v $(TEST) $(TESTARGS) -timeout=45m
|
2015-05-26 16:26:22 -04:00
|
|
|
|
2019-05-27 09:42:58 -04:00
|
|
|
testrace: mode-check vet ## Test with race detection enabled
|
2019-04-10 09:42:22 -04:00
|
|
|
@GO111MODULE=off go test -race $(TEST) $(TESTARGS) -timeout=3m -p=8
|
2013-03-24 17:47:59 -04:00
|
|
|
|
2020-03-12 05:36:10 -04:00
|
|
|
# Runs code coverage and open a html page with report
|
|
|
|
cover:
|
|
|
|
go test $(TEST) $(TESTARGS) -timeout=3m -coverprofile=coverage.out
|
|
|
|
go tool cover -html=coverage.out
|
|
|
|
rm coverage.out
|
|
|
|
|
2019-05-27 09:06:49 -04:00
|
|
|
check-vendor-vs-mod: ## Check that go modules and vendored code are on par
|
2019-06-14 14:12:58 -04:00
|
|
|
@GO111MODULE=on go mod vendor
|
2019-04-10 09:56:04 -04:00
|
|
|
@git diff --exit-code --ignore-space-change --ignore-space-at-eol -- vendor ; if [ $$? -eq 1 ]; then \
|
|
|
|
echo "ERROR: vendor dir is not on par with go modules definition." && \
|
|
|
|
exit 1; \
|
|
|
|
fi
|
|
|
|
|
2018-10-16 06:04:41 -04:00
|
|
|
vet: ## Vet Go code
|
2019-02-27 04:21:10 -05:00
|
|
|
@go vet $(VET) ; if [ $$? -eq 1 ]; then \
|
2018-10-16 06:04:41 -04:00
|
|
|
echo "ERROR: Vet found problems in the code."; \
|
|
|
|
exit 1; \
|
|
|
|
fi
|
|
|
|
|
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}'
|