用于Golang项目的Makefile文件

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
.PHONY: todo analyse test coverage run build clean

COVERAGE_DIR := ./coverage
BUILD_DIR    := ./build

todo:
    @grep -r --include "*" --exclude="Makefile" --exclude-dir=".git" "TODO:" . || true

analyse:
    @go vet ./...

test:
    @go test -cover ./...

coverage:
    @mkdir -p $(COVERAGE_DIR)
    @go test -covermode=count -coverprofile=$(COVERAGE_DIR)/cover.out ./...
    @go tool cover -html=$(COVERAGE_DIR)/cover.out -o $(COVERAGE_DIR)/cover.html
    @open $(COVERAGE_DIR)/cover.html

run:
    @go run .

build:
    @go build -o $(BUILD_DIR)

clean:
    @rm -rf $(COVERAGE_DIR) $(BUILD_DIR)