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