github.com/vmware/govmomi@v0.43.0/Makefile (about) 1 # Copyright (c) 2021 VMware, Inc. All Rights Reserved. 2 # SPDX-License-Identifier: Apache-2.0 3 4 # If you update this file, please follow 5 # https://www.thapaliya.com/en/writings/well-documented-makefiles/ 6 7 # Ensure Make is run with bash shell as some syntax below is bash-specific 8 SHELL := /usr/bin/env bash 9 10 # Print the help/usage when make is executed without any other arguments 11 .DEFAULT_GOAL := help 12 13 14 ## -------------------------------------- 15 ## Help 16 ## -------------------------------------- 17 18 .PHONY: help 19 help: ## Display usage 20 @awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make [target] \033[36m\033[0m\n\nTargets:\n"} /^[a-zA-Z_-]+:.*?##/ { printf " \033[36m%-20s\033[0m %s\n", $$1, $$2 }' $(MAKEFILE_LIST) 21 22 23 ## -------------------------------------- 24 ## Locations and programs 25 ## -------------------------------------- 26 27 # Directories 28 BIN_DIR := bin 29 TOOLS_DIR := hack/tools 30 TOOLS_BIN_DIR := $(TOOLS_DIR)/bin 31 32 # Tooling binaries 33 GO ?= $(shell command -v go 2>/dev/null) 34 GOLANGCI_LINT := $(TOOLS_BIN_DIR)/golangci-lint 35 36 37 ## -------------------------------------- 38 ## Prerequisites 39 ## -------------------------------------- 40 41 # Do not proceed unless the go binary is present. 42 ifeq (,$(strip $(GO))) 43 $(error The "go" program cannot be found) 44 endif 45 46 47 ## -------------------------------------- 48 ## Linting and fixing linter errors 49 ## -------------------------------------- 50 51 .PHONY: lint 52 lint: ## Run all the lint targets 53 $(MAKE) lint-go-full 54 55 GOLANGCI_LINT_FLAGS ?= --fast=true 56 .PHONY: lint-go 57 lint-go: $(GOLANGCI_LINT) ## Lint codebase 58 $(GOLANGCI_LINT) run -v $(GOLANGCI_LINT_FLAGS) 59 60 .PHONY: lint-go-full 61 lint-go-full: GOLANGCI_LINT_FLAGS = --fast=false --max-same-issues=200 62 lint-go-full: lint-go ## Run slower linters to detect possible issues 63 64 .PHONY: fix 65 fix: GOLANGCI_LINT_FLAGS = --fast=false --fix 66 fix: lint-go ## Tries to fix errors reported by lint-go-full target 67 68 .PHONY: check 69 check: lint-go-full 70 check: ## Run linters 71 72 73 ## -------------------------------------- 74 ## Tooling Binaries 75 ## -------------------------------------- 76 77 TOOLING_BINARIES := $(GOLANGCI_LINT) 78 tools: $(TOOLING_BINARIES) ## Build tooling binaries 79 .PHONY: $(TOOLING_BINARIES) 80 $(TOOLING_BINARIES): 81 cd $(TOOLS_DIR); make $(@F) 82 83 84 ## -------------------------------------- 85 ## Build / Install 86 ## -------------------------------------- 87 .PHONY: install 88 install: ## Install govc and vcsim 89 $(MAKE) -C govc install 90 $(MAKE) -C vcsim install 91 92 93 ## -------------------------------------- 94 ## Generate 95 ## -------------------------------------- 96 97 .PHONY: mod 98 mod: ## Runs go mod tidy to validate modules 99 go mod tidy -v 100 101 .PHONY: mod-get 102 mod-get: ## Downloads and caches the modules 103 go mod download 104 105 .PHONY: doc 106 doc: install 107 doc: ## Generates govc USAGE.md 108 ./govc/usage.sh > ./govc/USAGE.md 109 110 .PHONY: generate-types 111 generate-types: ## Generate the types 112 $(MAKE) -C ./gen/ $@ 113 114 115 ## -------------------------------------- 116 ## Tests 117 ## -------------------------------------- 118 119 # Test options 120 TEST_COUNT ?= 1 121 TEST_TIMEOUT ?= 5m 122 TEST_RACE_HISTORY_SIZE ?= 5 123 GORACE ?= history_size=$(TEST_RACE_HISTORY_SIZE) 124 125 ifeq (-count,$(findstring -count,$(TEST_OPTS))) 126 $(error Use TEST_COUNT to override this option) 127 endif 128 129 ifeq (-race,$(findstring -race,$(TEST_OPTS))) 130 $(error The -race flag is enabled by default & cannot be specified in TEST_OPTS) 131 endif 132 133 ifeq (-timeout,$(findstring -timeout,$(TEST_OPTS))) 134 $(error Use TEST_TIMEOUT to override this option) 135 endif 136 137 .PHONY: go-test 138 go-test: ## Runs go unit tests with race detector enabled 139 GORACE=$(GORACE) CGO_ENABLED=1 $(GO) test \ 140 -count $(TEST_COUNT) \ 141 -race \ 142 -timeout $(TEST_TIMEOUT) \ 143 -v $(TEST_OPTS) \ 144 ./... 145 146 .PHONY: govc-test 147 govc-test: install 148 govc-test: ## Runs govc bats tests 149 ./govc/test/images/update.sh 150 (cd govc/test && ./vendor/github.com/bats-core/bats-core/bin/bats -t .) 151 152 .PHONY: test 153 test: go-test govc-test ## Runs go-test and govc-test