forked from hack-pad/hackpad
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
126 lines (104 loc) · 2.97 KB
/
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
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
SHELL := /usr/bin/env bash
GO_VERSION = 1.16.6
GOROOT =
PATH := ${PWD}/cache/go/bin:${PWD}/cache/go/misc/wasm:${PATH}
GOOS = js
GOARCH = wasm
export
LINT_VERSION=1.27.0
.PHONY: serve
serve:
go run ./server
.PHONY: lint-deps
lint-deps: go
@if ! which golangci-lint >/dev/null || [[ "$$(golangci-lint version 2>&1)" != *${LINT_VERSION}* ]]; then \
curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $$(go env GOPATH)/bin v${LINT_VERSION}; \
fi
.PHONY: lint
lint: lint-deps
golangci-lint run
.PHONY: lint-fix
lint-fix: lint-deps
golangci-lint run --fix
.PHONY: test-native
test-native:
GOARCH= GOOS= go test \
-race \
-coverprofile=cover.out \
./...
.PHONY: test-js
test-js: go
go test \
-coverprofile=cover_js.out \
./...
.PHONY: test
test: test-native #test-js # TODO restore when this is resolved: https://travis-ci.community/t/goos-js-goarch-wasm-go-run-fails-panic-newosproc-not-implemented/1651
.PHONY: static
static: server/public/wasm/go.tar.gz commands
server/public/wasm:
mkdir -p server/public/wasm
server/public/wasm/go.tar.gz: server/public/wasm go
GOARCH=$$(go env GOHOSTARCH) GOOS=$$(go env GOHOSTOS) \
go run ./internal/cmd/gozip cache/go > server/public/wasm/go.tar.gz
.PHONY: clean
clean:
rm -rf ./out ./server/public/wasm
cache:
mkdir -p cache
.PHONY: commands
commands: server/public/wasm/wasm_exec.js server/public/wasm/main.wasm $(patsubst cmd/%,server/public/wasm/%.wasm,$(wildcard cmd/*))
.PHONY: go
go: cache/go${GO_VERSION}
cache/go${GO_VERSION}: cache
if [[ ! -e cache/go${GO_VERSION} ]]; then \
set -ex; \
TMP=$$(mktemp -d); trap 'rm -rf "$$TMP"' EXIT; \
git clone \
--depth 1 \
--single-branch \
--branch hackpad-go${GO_VERSION} \
https://github.com/hack-pad/go.git \
"$$TMP"; \
pushd "$$TMP/src"; \
./make.bash; \
export PATH="$$TMP/bin:$$PATH"; \
go version; \
mkdir -p ../bin/js_wasm; \
go build -o ../bin/js_wasm/ std cmd/go cmd/gofmt; \
go tool dist test -rebuild -list; \
go build -o ../pkg/tool/js_wasm/ std cmd/buildid cmd/pack cmd/cover cmd/vet; \
go install ./...; \
popd; \
mv "$$TMP" cache/go${GO_VERSION}; \
ln -sfn go${GO_VERSION} cache/go; \
fi
touch cache/go${GO_VERSION}
touch cache/go.mod # Makes it so linters will ignore this dir
server/public/wasm/%.wasm: server/public/wasm go
go build -o $@ ./cmd/$*
server/public/wasm/main.wasm: server/public/wasm go
go build -o server/public/wasm/main.wasm .
server/public/wasm/wasm_exec.js: go
cp cache/go/misc/wasm/wasm_exec.js server/public/wasm/wasm_exec.js
.PHONY: watch
watch:
@if [[ ! -d server/node_modules ]]; then \
npm --prefix=server ci; \
fi
npm --prefix=server run start-go & \
npm --prefix=server start
.PHONY: build
build: static
npm --prefix=server ci
npm --prefix=server run build
mkdir -p out
cp -r server/build/* out/
.PHONY: docker
docker:
docker build -t hackpad .
.PHONY: docker-run
docker-run: docker
docker run -it --rm \
--name hackpad \
-p 8080:80 \
hackpad:latest