-
-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathMakefile
More file actions
212 lines (189 loc) · 6.24 KB
/
Copy pathMakefile
File metadata and controls
212 lines (189 loc) · 6.24 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
# binary name
BINARY_NAME=mkbrr
# go related variables
GO=go
GOBIN=$(shell $(GO) env GOPATH)/bin
# build variables
BUILD_DIR=build
VERSION=$(shell git describe --tags 2>/dev/null || echo "dev")
BUILD_TIME=$(shell date +%FT%T%z)
LDFLAGS=-ldflags "-X main.version=${VERSION} -X main.buildTime=${BUILD_TIME}"
# race detector settings
GORACE=log_path=./race_report.log \
history_size=2 \
halt_on_error=1 \
atexit_sleep_ms=2000
# make all builds and installs
.PHONY: all
all: clean build install
# build binary
.PHONY: build
build:
@echo "Building ${BINARY_NAME}..."
@mkdir -p ${BUILD_DIR}
CGO_ENABLED=0 $(GO) build ${LDFLAGS} -o ${BUILD_DIR}/${BINARY_NAME}
# build with PGO
.PHONY: build-pgo
build-pgo:
@echo "Building ${BINARY_NAME} with PGO..."
@if [ ! -f "cpu.pprof" ]; then \
echo "No PGO profile found. Run 'make profile' first."; \
exit 1; \
fi
@mkdir -p ${BUILD_DIR}
CGO_ENABLED=0 $(GO) build -pgo=cpu.pprof ${LDFLAGS} -o ${BUILD_DIR}/${BINARY_NAME}
# generate PGO profile with various workloads
.PHONY: profile
profile:
@echo "Generating PGO profile..."
@mkdir -p test_data
@dd if=/dev/urandom of=test_data/test1.bin bs=1M count=100
@dd if=/dev/urandom of=test_data/test2.bin bs=1M count=100
@go build -o ${BUILD_DIR}/${BINARY_NAME}
@echo "Running profile workload 1: Large file..."
@${BUILD_DIR}/${BINARY_NAME} create test_data/test1.bin --cpuprofile=./cpu1.pprof
@echo "Running profile workload 2: Multiple files..."
@${BUILD_DIR}/${BINARY_NAME} create test_data --cpuprofile=./cpu2.pprof
@echo "Merging profiles..."
@if [ -f "cpu1.pprof" ] && [ -f "cpu2.pprof" ]; then \
go tool pprof -proto cpu1.pprof cpu2.pprof > cpu.pprof; \
rm cpu1.pprof cpu2.pprof; \
echo "Profile generated at cpu.pprof"; \
else \
echo "Error: Profile files not generated correctly"; \
exit 1; \
fi
@rm -rf test_data
# install binary in system path
.PHONY: install
install: build
@echo "Installing ${BINARY_NAME}..."
@if [ "$$(id -u)" = "0" ]; then \
install -m 755 ${BUILD_DIR}/${BINARY_NAME} /usr/local/bin/; \
else \
install -m 755 ${BUILD_DIR}/${BINARY_NAME} ${GOBIN}/; \
fi
# install binary with PGO optimization
.PHONY: install-pgo
install-pgo:
@echo "Installing ${BINARY_NAME} with PGO..."
@if [ ! -f "cpu.pprof" ]; then \
echo "No PGO profile found. Run 'make profile' first."; \
exit 1; \
fi
@mkdir -p ${BUILD_DIR}
CGO_ENABLED=0 $(GO) build -pgo=cpu.pprof ${LDFLAGS} -o ${BUILD_DIR}/${BINARY_NAME}
@if [ "$$(id -u)" = "0" ]; then \
install -m 755 ${BUILD_DIR}/${BINARY_NAME} /usr/local/bin/; \
else \
install -m 755 ${BUILD_DIR}/${BINARY_NAME} ${GOBIN}/; \
fi
# run all tests (excluding large tests)
.PHONY: test
test:
@echo "Running tests..."
$(GO) test -v ./...
# run quick tests with race detector (for CI and quick feedback)
.PHONY: test-race-short
test-race-short:
@echo "Running quick tests with race detector..."
GORACE="$(GORACE)" $(GO) test -race -short ./torrent -v
@if [ -f "./race_report.log" ]; then \
echo "Race conditions detected! Check race_report.log"; \
cat "./race_report.log"; \
fi
# run all tests with race detector (excluding large tests)
.PHONY: test-race
test-race:
@echo "Running tests with race detector..."
GORACE="$(GORACE)" $(GO) test -race ./torrent -v
@if [ -f "./race_report.log" ]; then \
echo "Race conditions detected! Check race_report.log"; \
cat "./race_report.log"; \
fi
# run large tests (resource intensive)
.PHONY: test-large
test-large:
@echo "Running large tests..."
GORACE="$(GORACE)" $(GO) test -v -tags=large_tests ./torrent
@if [ -f "./race_report.log" ]; then \
echo "Race conditions detected! Check race_report.log"; \
cat "./race_report.log"; \
fi
# run tests with coverage
.PHONY: test-coverage
test-coverage:
@echo "Running tests with coverage..."
GORACE="$(GORACE)" $(GO) test -v -race -coverprofile=coverage.txt -covermode=atomic ./...
$(GO) tool cover -html=coverage.txt -o coverage.html
@if [ -f "./race_report.log" ]; then \
echo "Race conditions detected! Check race_report.log"; \
cat "./race_report.log"; \
fi
# run golangci-lint
.PHONY: lint
lint:
@echo "Running linter..."
@if ! command -v golangci-lint &> /dev/null; then \
echo "Installing golangci-lint..."; \
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest; \
fi
golangci-lint run
# clean build artifacts
.PHONY: clean
clean:
@echo "Cleaning..."
@rm -rf ${BUILD_DIR}
@rm -f coverage.txt coverage.html
# GUI targets
WAILS=$(GOBIN)/wails
WAILS_VERSION=v2.13.0
# install wails cli
.PHONY: install-wails
install-wails:
@echo "Installing Wails CLI..."
$(GO) install github.com/wailsapp/wails/v2/cmd/wails@$(WAILS_VERSION)
# run gui in development mode
.PHONY: gui-dev
gui-dev:
@echo "Starting GUI in development mode..."
cd gui && $(WAILS) dev
# build gui for current platform
.PHONY: gui-build
gui-build:
@echo "Building GUI..."
cd gui && $(WAILS) build
# build gui for all platforms
.PHONY: gui-build-all
gui-build-all:
@echo "Building GUI for all platforms..."
cd gui && $(WAILS) build -platform darwin/universal,linux/amd64,windows/amd64
# clean gui build artifacts
.PHONY: gui-clean
gui-clean:
@echo "Cleaning GUI build artifacts..."
@rm -rf gui/build/bin
# show help
.PHONY: help
help:
@echo "Available targets:"
@echo " all - Clean, build, and install the binary"
@echo " build - Build the binary"
@echo " build-pgo - Build the binary with PGO optimization"
@echo " install - Install the binary in GOPATH"
@echo " install-pgo - Install the binary with PGO optimization"
@echo " test - Run tests (excluding large tests)"
@echo " test-race-short- Run quick tests with race detector"
@echo " test-race - Run all tests with race detector (excluding large tests)"
@echo " test-large - Run large tests (resource intensive)"
@echo " test-coverage - Run tests with coverage report"
@echo " lint - Run golangci-lint"
@echo " clean - Remove build artifacts"
@echo " help - Show this help"
@echo ""
@echo "GUI targets:"
@echo " install-wails - Install Wails CLI"
@echo " gui-dev - Run GUI in development mode"
@echo " gui-build - Build GUI for current platform"
@echo " gui-build-all - Build GUI for all platforms"
@echo " gui-clean - Clean GUI build artifacts"