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