github.com/pingcap/tiup@v1.15.1/Makefile (about)

     1  .PHONY: components server targets
     2  .DEFAULT_GOAL := default
     3  
     4  LANG=C
     5  MAKEOVERRIDES =
     6  targets:
     7  	@printf "%-30s %s\n" "Target" "Description"
     8  	@printf "%-30s %s\n" "------" "-----------"
     9  	@make -pqR : 2>/dev/null \
    10  	| awk -v RS= -F: '/^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' \
    11  	| egrep -v -e '^[^[:alnum:]]' -e '^$@$$' \
    12  	| sort \
    13  	| xargs -I _ sh -c 'printf "%-30s " _; make _ -nB | (grep "^# Target:" || echo "") | tail -1 | sed "s/^# Target: //g"'
    14  
    15  REPO    := github.com/pingcap/tiup
    16  
    17  GOOS    := $(if $(GOOS),$(GOOS),$(shell go env GOOS))
    18  GOARCH  := $(if $(GOARCH),$(GOARCH),$(shell go env GOARCH))
    19  GOENV   := GO111MODULE=on CGO_ENABLED=0 GOOS=$(GOOS) GOARCH=$(GOARCH)
    20  GO      := $(GOENV) go
    21  GOBUILD := $(GO) build $(BUILD_FLAGS)
    22  GOTEST  := GO111MODULE=on CGO_ENABLED=1 go test -p 3
    23  SHELL   := /usr/bin/env bash
    24  
    25  _COMMIT := $(shell git describe --no-match --always --dirty)
    26  _GITREF := $(shell git rev-parse --abbrev-ref HEAD)
    27  COMMIT  := $(if $(COMMIT),$(COMMIT),$(_COMMIT))
    28  GITREF  := $(if $(GITREF),$(GITREF),$(_GITREF))
    29  
    30  LDFLAGS := -w -s
    31  LDFLAGS += -X "$(REPO)/pkg/version.GitHash=$(COMMIT)"
    32  LDFLAGS += -X "$(REPO)/pkg/version.GitRef=$(GITREF)"
    33  LDFLAGS += $(EXTRA_LDFLAGS)
    34  
    35  FILES   := $$(find . -name "*.go")
    36  
    37  FAILPOINT_ENABLE  := $$(tools/bin/failpoint-ctl enable)
    38  FAILPOINT_DISABLE := $$(tools/bin/failpoint-ctl disable)
    39  
    40  default: check build
    41  	@# Target: run the checks and then build.
    42  
    43  include ./tests/Makefile
    44  
    45  # Build TiUP and all components
    46  build: tiup components
    47  	@# Target: build tiup and all it's components
    48  
    49  components: playground client cluster dm server
    50  	@# Target: build the playground, client, cluster, dm and server components
    51  
    52  tiup:
    53  	@# Target: build the tiup driver
    54  	$(GOBUILD) -ldflags '$(LDFLAGS)' -o bin/tiup
    55  
    56  playground:
    57  	@# Target: build tiup-playground component
    58  	$(GOBUILD) -ldflags '$(LDFLAGS)' -o bin/tiup-playground ./components/playground
    59  
    60  client:
    61  	@# Target: build the tiup-client component
    62  	$(MAKE) -C components/client $(MAKECMDGOALS)
    63  
    64  cluster:
    65  	@# Target: build the tiup-cluster component
    66  	$(GOBUILD) -ldflags '$(LDFLAGS)' -o bin/tiup-cluster ./components/cluster
    67  
    68  dm:
    69  	@# Target: build the tiup-dm component
    70  	$(GOBUILD) -ldflags '$(LDFLAGS)' -o bin/tiup-dm ./components/dm
    71  
    72  ctl:
    73  	@# Target: build the tiup-ctl component
    74  	$(GOBUILD) -ldflags '$(LDFLAGS)' -o bin/tiup-ctl ./components/ctl
    75  
    76  server:
    77  	@# Target: build the tiup-server component
    78  	$(GOBUILD) -ldflags '$(LDFLAGS)' -o bin/tiup-server ./server
    79  
    80  check: fmt lint tidy check-static vet
    81  	@# Target: run all checkers. (fmt, lint, tidy, check-static and vet)
    82  	$(MAKE) -C components/client ${MAKECMDGOALS}
    83  
    84  check-static: tools/bin/golangci-lint
    85  	@# Target: run the golangci-lint static check tool
    86  	tools/bin/golangci-lint run --config tools/check/golangci.yaml ./... --deadline=3m --fix
    87  
    88  lint: tools/bin/revive
    89  	@# Target: run the lint checker revive
    90  	@echo "linting"
    91  	@tools/bin/revive -formatter friendly -config tools/check/revive.toml $(FILES)
    92  
    93  vet:
    94  	@# Target: run the go vet tool
    95  	$(GO) vet ./...
    96  
    97  tidy:
    98  	@# Target: run tidy check
    99  	@echo "go mod tidy"
   100  	./tools/check/check-tidy.sh
   101  
   102  clean:
   103  	@# Target: run the build cleanup steps
   104  	@rm -rf bin
   105  	@rm -rf cover
   106  	@rm -rf tests/*/{bin/*.test,logs,cover/*.out}
   107  
   108  test: failpoint-enable run-tests failpoint-disable
   109  	@# Target: run tests with failpoint enabled
   110  	$(MAKE) -C components/client ${MAKECMDGOALS}
   111  
   112  # TODO: refactor integration tests base on v1 manifest
   113  # run-tests: unit-test integration_test
   114  run-tests: unit-test
   115  	@# Target: run the unit tests
   116  
   117  # Run tests
   118  unit-test:
   119  	@# Target: run the code coverage test phase
   120  	mkdir -p cover
   121  	TIUP_HOME=$(shell pwd)/tests/tiup $(GOTEST) ./... -covermode=count -coverprofile cover/cov.unit-test.out
   122  
   123  race: failpoint-enable
   124  	@# Target: run race check with failpoint enabled
   125  	TIUP_HOME=$(shell pwd)/tests/tiup $(GOTEST) -race ./...  || { $(FAILPOINT_DISABLE); exit 1; }
   126  	@$(FAILPOINT_DISABLE)
   127  
   128  failpoint-enable: tools/bin/failpoint-ctl
   129  	@# Target: enable failpoint
   130  	@$(FAILPOINT_ENABLE)
   131  
   132  failpoint-disable: tools/bin/failpoint-ctl
   133  	@# Target: disable failpoint
   134  	@$(FAILPOINT_DISABLE)
   135  
   136  tools/bin/failpoint-ctl: go.mod
   137  	@# Target: build the failpoint-ctl utility
   138  	$(GO) build -o $@ github.com/pingcap/failpoint/failpoint-ctl
   139  
   140  fmt:
   141  	@# Target: run the go formatter utility
   142  	@echo "gofmt (simplify)"
   143  	@gofmt -s -l -w $(FILES) 2>&1
   144  	@echo "goimports (if installed)"
   145  	$(shell goimports -w $(FILES) 2>/dev/null)
   146  
   147  tools/bin/revive: tools/check/go.mod
   148  	@# Target: build revive utility
   149  	cd tools/check; \
   150  	$(GO) build -o ../bin/revive github.com/mgechev/revive
   151  
   152  tools/bin/golangci-lint:
   153  	@# Target: pull in specific version of golangci-lint (v1.54.1)
   154  	curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b ./tools/bin v1.54.1