-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathmakefile
More file actions
109 lines (86 loc) · 3.58 KB
/
makefile
File metadata and controls
109 lines (86 loc) · 3.58 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# README
#
# This file is intended as an example for users of `gow`. It was adapted from a
# larger Go project. At the time of writing, `gow` does not support its own
# configuration files. For complex use cases, users are expected to use Make or
# another similar tool.
#
# Despite being primarily an example, this file contains actual working rules
# convenient for hacking on `gow`.
# This variable `MAKEFLAGS` is special: it modifies Make's own behaviors.
#
# `--silent` causes Make to execute rules without additional verbose logging.
# Without this, we would have to prefix each line in each rule with `@` to
# suppress logging.
#
# `--always-make` makes all rules "abstract". It causes Make to execute each
# rule without checking for an existing file matching the pattern represented
# by the rule name. This is equivalent to marking every rule with `.PHONY`, but
# keeps our makefile cleaner. In projects where some rule names are file names
# or artifact path patterns, this should be removed, and abstract rules should
# be explicitly marked with `.PHONY`.
MAKEFLAGS := --silent --always-make
# Shortcut for executing rules concurrently. See usage examples below.
MAKE_CONC := $(MAKE) -j 128 CONC=true clear=$(or $(clear),false)
VERB ?= $(if $(filter false,$(verb)),,-v)
CLEAR ?= $(if $(filter false,$(clear)),,-c)
GO_SRC ?= .
GO_PKG ?= ./$(or $(pkg),$(GO_SRC)/...)
GO_FLAGS ?= -tags=$(tags) -mod=mod
GO_RUN_ARGS ?= $(GO_FLAGS) $(GO_SRC) $(run)
GO_TEST_FAIL ?= $(if $(filter false,$(fail)),,-failfast)
GO_TEST_SHORT ?= $(if $(filter true,$(short)), -short,)
GO_TEST_FLAGS ?= -count=1 $(GO_FLAGS) $(VERB) $(GO_TEST_FAIL) $(GO_TEST_SHORT)
GO_TEST_PATTERNS ?= -run="$(run)"
GO_TEST_ARGS ?= $(GO_PKG) $(GO_TEST_FLAGS) $(GO_TEST_PATTERNS)
IS_TTY ?= $(shell test -t 0 && printf " ")
# Only one `gow` per terminal is allowed to use raw mode.
# Otherwise they conflict with each other.
GOW_HOTKEYS ?= -r=$(if $(filter true,$(CONC)),,$(if $(IS_TTY),true,false))
GOW_FLAGS ?= $(CLEAR) $(VERB) $(GOW_HOTKEYS)
# Expects an existing stable version of `gow`.
GOW ?= gow $(GOW_FLAGS)
# Replace `cmd.exe` on Windows. Assume a Unix shell is already installed.
SHELL ?= sh
watch:
$(MAKE_CONC) dev_test_w dev_vet_w
# If everything works properly, then we should see a message about the FS event
# (file change), and tests should rerun. And, if everything _really_ works
# properly, modifying local files should trigger FS events in the container,
# causing `gow` to restart the test.
watch_linux:
podman run --rm -it -v=$(PWD):/gow -w=/gow golang:alpine sleep 3 && echo 'package main' > touched.go & go run . -v test -v
all:
$(MAKE_CONC) test vet
dev_test_w:
go run $(GO_RUN_ARGS) $(GOW_FLAGS) test $(GO_TEST_FLAGS)
test_w: test_exe
$(GOW) test $(GO_TEST_ARGS)
test: test_exe
go test $(GO_TEST_ARGS)
dev_vet_w:
go run $(GO_RUN_ARGS) $(GOW_FLAGS) vet $(GO_FLAGS)
vet_w:
$(GOW) vet $(GO_FLAGS)
vet:
go vet $(GO_FLAGS)
check:
gopls check *.go
run_w:
$(GOW) run $(GO_RUN_ARGS)
run:
go run $(GO_RUN_ARGS)
install:
go install $(GO_FLAGS) $(GO_SRC)
# Uses another watcher because when repeatedly reinstalling `gow`,
# it's because we're experimenting and it might be broken.
install_w:
watchexec -n -r -d=1ms -- go install $(GO_FLAGS) $(GO_SRC)
# Uses `[ -f <file> ]` because `--always-make` makes all recipes "phony".
test_exe: testdata/proc0.go testdata/proc1.go
[ -f testdata/proc0.exe ] || go build -o testdata/proc0.exe testdata/proc0.go
[ -f testdata/proc1.exe ] || go build -o testdata/proc1.exe testdata/proc1.go
# `:;` is a syntactic trick to force `sh` on Windows.
# TODO better solution.
clean:
:; $(RM) $(wildcard testdata/*.exe)