-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
373 lines (310 loc) · 14.4 KB
/
Makefile
File metadata and controls
373 lines (310 loc) · 14.4 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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
# Makefile for Runner - PineScript Go Port
# Centralized build automation following Go project conventions
.PHONY: help build test test-unit test-integration test-e2e test-parser test-codegen test-runtime test-series test-syminfo regression-syminfo bench bench-series coverage coverage-show check ci clean clean-all cross-compile fmt vet lint build-strategy
# Project configuration
PROJECT_NAME := runner
BINARY_NAME := pine-gen
VERSION := $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
BUILD_TIME := $(shell date -u '+%Y-%m-%d_%H:%M:%S')
COMMIT_HASH := $(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown")
# Directories
CMD_DIR := cmd/pine-gen
BUILD_DIR := build
DIST_DIR := dist
COVERAGE_DIR := coverage
# Go configuration
GO := go
GOFLAGS := -v
LDFLAGS := -ldflags "-s -w -X main.Version=$(VERSION) -X main.BuildTime=$(BUILD_TIME) -X main.CommitHash=$(COMMIT_HASH)"
GOTEST := $(GO) test $(GOFLAGS)
GOBUILD := $(GO) build $(GOFLAGS) $(LDFLAGS)
# Test configuration
TEST_TIMEOUT := 30m
TEST_FLAGS := -race -timeout $(TEST_TIMEOUT)
BENCH_FLAGS := -benchmem -benchtime=3s
# Cross-compilation targets
PLATFORMS := linux/amd64 linux/arm64 darwin/amd64 darwin/arm64 windows/amd64
##@ General
help: ## Display this help
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z0-9_-]+:.*##/ { printf " \033[36m%-20s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
##@ Development
fmt: ## Format Go code
@echo "Formatting code..."
@gofmt -s -w .
@echo "✓ Code formatted"
vet: ## Run go vet
@echo "Running go vet..."
@$(GO) vet ./...
@echo "✓ Vet passed"
lint: ## Run linter
@echo "Running linter..."
@$(GO) vet ./...
@echo "✓ Lint passed"
##@ Build
build: ## Build pine-gen for current platform
@echo "Building $(BINARY_NAME) v$(VERSION)..."
@mkdir -p $(BUILD_DIR)
@$(GOBUILD) -o $(BUILD_DIR)/$(BINARY_NAME) ./cmd/pine-gen
@echo "✓ Binary built: $(BUILD_DIR)/$(BINARY_NAME)"
build-strategy: ## Build standalone strategy binary (usage: make build-strategy STRATEGY=path/to/strategy.pine OUTPUT=runner-name)
@if [ -z "$(STRATEGY)" ]; then echo "Error: STRATEGY not set. Usage: make build-strategy STRATEGY=path/to/strategy.pine OUTPUT=runner-name"; exit 1; fi
@if [ -z "$(OUTPUT)" ]; then echo "Error: OUTPUT not set. Usage: make build-strategy STRATEGY=path/to/strategy.pine OUTPUT=runner-name"; exit 1; fi
@echo "Building strategy: $(STRATEGY) -> $(OUTPUT)"
@$(MAKE) -s _build_strategy_internal STRATEGY=$(STRATEGY) OUTPUT=$(OUTPUT)
_build_strategy_internal:
@mkdir -p $(BUILD_DIR)
@echo "[1/3] Generating Go code from Pine Script..."
@OUTPUT_PATH="$(OUTPUT)"; \
case "$$OUTPUT_PATH" in /*) ;; *) OUTPUT_PATH="$(BUILD_DIR)/$(OUTPUT)";; esac; \
STRATEGY_PATH="$(STRATEGY)"; \
case "$$STRATEGY_PATH" in /*) ;; *) STRATEGY_PATH="$$STRATEGY_PATH";; esac; \
TEMP_FILE=$$($(GO) run ./cmd/pine-gen -input $$STRATEGY_PATH -output $$OUTPUT_PATH 2>&1 | grep "Generated:" | awk '{print $$2}'); \
if [ -z "$$TEMP_FILE" ]; then echo "Failed to generate Go code"; exit 1; fi; \
echo "[2/3] Compiling binary..."; \
$(GO) build -o $$OUTPUT_PATH $$TEMP_FILE
@OUTPUT_PATH="$(OUTPUT)"; \
case "$$OUTPUT_PATH" in /*) ;; *) OUTPUT_PATH="$(BUILD_DIR)/$(OUTPUT)";; esac; \
echo "[3/3] Cleanup..."; \
echo "✓ Strategy compiled: $$OUTPUT_PATH"
cross-compile: ## Build pine-gen for all platforms (strategy code generator)
@echo "Cross-compiling pine-gen for distribution..."
@mkdir -p $(DIST_DIR)
@$(foreach platform,$(PLATFORMS),\
GOOS=$(word 1,$(subst /, ,$(platform))) \
GOARCH=$(word 2,$(subst /, ,$(platform))) \
$(MAKE) -s _cross_compile_platform \
PLATFORM_OS=$(word 1,$(subst /, ,$(platform))) \
PLATFORM_ARCH=$(word 2,$(subst /, ,$(platform))) ; \
)
@echo "✓ Cross-compilation complete: $(DIST_DIR)/"
@ls -lh $(DIST_DIR)/
_cross_compile_platform:
@BINARY=$(DIST_DIR)/pine-gen-$(PLATFORM_OS)-$(PLATFORM_ARCH)$(if $(findstring windows,$(PLATFORM_OS)),.exe,); \
echo " Building $$BINARY..."; \
GOOS=$(PLATFORM_OS) GOARCH=$(PLATFORM_ARCH) \
$(GOBUILD) -o ../$$BINARY ./cmd/pine-gen
##@ Testing
# Main test target: runs all tests (unit + integration + e2e)
test: test-unit test-integration test-e2e ## Run all tests (unit + integration + e2e)
@echo "✓ All tests passed"
test-unit: ## Run unit tests (excludes integration)
@echo "Running unit tests..."
@ $(GOTEST) $(TEST_FLAGS) -short ./...
@echo "✓ Unit tests passed"
test-integration: ## Run integration tests
@echo "Running integration tests..."
@ $(GOTEST) $(TEST_FLAGS) -tags=integration ./tests/test-integration/...
@echo "✓ Integration tests passed"
test-e2e: ## Run E2E tests (compile + execute all Pine fixtures/strategies)
@echo "Running E2E tests..."
@./scripts/e2e-runner.sh
@echo "✓ E2E tests passed"
test-parser: ## Run parser tests only
@echo "Running parser tests..."
@ $(GOTEST) $(TEST_FLAGS) ./parser/...
@echo "✓ Parser tests passed"
test-codegen: ## Run codegen tests only
@echo "Running codegen tests..."
@ $(GOTEST) $(TEST_FLAGS) ./codegen/...
@echo "✓ Codegen tests passed"
test-runtime: ## Run runtime tests only
@echo "Running runtime tests..."
@ $(GOTEST) $(TEST_FLAGS) ./runtime/...
@echo "✓ Runtime tests passed"
test-series: ## Run Series tests only
@echo "Running Series tests..."
@ $(GOTEST) $(TEST_FLAGS) -v ./runtime/series/...
@echo "✓ Series tests passed"
test-syminfo: ## Run syminfo.tickerid integration tests only
@echo "Running syminfo.tickerid tests..."
@ $(GOTEST) $(TEST_FLAGS) -v ./tests/test-integration -run Syminfo
@echo "✓ syminfo.tickerid tests passed"
test-syminfo-regression: ## Run syminfo.tickerid regression test suite
@./scripts/test-syminfo-regression.sh
bench: ## Run benchmarks
@echo "Running benchmarks..."
@ $(GO) test $(BENCH_FLAGS) -bench=. ./...
bench-series: ## Benchmark Series performance
@echo "Benchmarking Series..."
@ $(GO) test $(BENCH_FLAGS) -bench=. ./runtime/series/
@echo ""
@echo "Performance targets:"
@echo " Series.Get(): < 10ns/op"
@echo " Series.Set(): < 5ns/op"
@echo " Series.Next(): < 3ns/op"
coverage: ## Generate test coverage report
@echo "Generating coverage report..."
@mkdir -p $(COVERAGE_DIR)
@ $(GO) test -coverprofile=$(COVERAGE_DIR)/coverage.out ./...
@ $(GO) tool cover -html=$(COVERAGE_DIR)/coverage.out -o $(COVERAGE_DIR)/coverage.html
@ $(GO) tool cover -func=$(COVERAGE_DIR)/coverage.out | tail -1
@echo "✓ Coverage report: $(COVERAGE_DIR)/coverage.html"
coverage-show: coverage ## Generate and open coverage report
@open $(COVERAGE_DIR)/coverage.html
##@ Verification
ci: fmt vet lint build test ## CI pipeline (format, vet, lint, build, all tests)
@echo "✓ CI checks passed"
##@ Cleanup
clean: ## Remove build artifacts
@echo "Cleaning build artifacts..."
@rm -rf $(BUILD_DIR) $(DIST_DIR) $(COVERAGE_DIR)
@ $(GO) clean -cache -testcache
@find . -name "*.test" -type f -delete
@find . -name "*.out" -type f -delete
@echo "✓ Cleaned"
clean-all: clean ## Remove all generated files including dependencies
@echo "Removing all generated files..."
@ $(GO) clean -modcache
@echo "✓ Deep cleaned"
##@ Development Workflow
run-strategy: ## Run strategy with pre-generated data file (usage: make run-strategy STRATEGY=path/to/strategy.pine DATA=path/to/data.json)
@if [ -z "$(STRATEGY)" ]; then echo "Error: STRATEGY not set. Usage: make run-strategy STRATEGY=path/to/strategy.pine DATA=path/to/data.json"; exit 1; fi
@if [ -z "$(DATA)" ]; then echo "Error: DATA not set. Usage: make run-strategy STRATEGY=path/to/strategy.pine DATA=path/to/data.json"; exit 1; fi
@echo "Running strategy: $(STRATEGY)"
@mkdir -p out
@TEMP_FILE=$$( $(GO) run cmd/pine-gen/main.go \
-input ../$(STRATEGY) \
-output /tmp/pinescript-strategy 2>&1 | grep "Generated:" | awk '{print $$2}'); \
$(GO) build -o /tmp/pinescript-strategy $$TEMP_FILE
@SYMBOL=$$(basename $(DATA) | sed 's/_[^_]*\.json//'); \
TIMEFRAME=$$(basename $(DATA) .json | sed 's/.*_//'); \
/tmp/pinescript-strategy -symbol $$SYMBOL -timeframe $$TIMEFRAME -data $(DATA) -datadir testdata/ohlcv -output out/chart-data.json
@echo "✓ Strategy executed: out/chart-data.json"
@ls -lh out/chart-data.json
fetch-strategy: ## Fetch live data and run strategy (usage: make fetch-strategy SYMBOL=GDYN TIMEFRAME=1D BARS=500 STRATEGY=strategies/daily-lines.pine)
@if [ -z "$(SYMBOL)" ] || [ -z "$(STRATEGY)" ]; then \
echo "Usage: make fetch-strategy SYMBOL=<symbol> TIMEFRAME=<tf> BARS=<n> STRATEGY=<file>"; \
echo ""; \
echo "Examples:"; \
echo " make fetch-strategy SYMBOL=BTCUSDT TIMEFRAME=1h BARS=500 STRATEGY=strategies/daily-lines.pine"; \
echo " make fetch-strategy SYMBOL=AAPL TIMEFRAME=1D BARS=200 STRATEGY=strategies/test-simple.pine"; \
echo ""; \
exit 1; \
fi
@./scripts/fetch-strategy.sh $(SYMBOL) $(TIMEFRAME) $(BARS) $(STRATEGY)
serve: ## Serve ./out directory with Python HTTP server on port 8000
@echo "Starting web server on http://localhost:8000"
@echo "Chart data available at: http://localhost:8000/chart-data.json"
@echo "Press Ctrl+C to stop server"
@cd out && python3 -m http.server 8000
serve-strategy: fetch-strategy serve ## Fetch live data, run strategy, and start web server
##@ Visualization Config Management
create-config: ## Create a visualization config for a strategy (usage: make create-config STRATEGY=strategies/my-strategy.pine)
@if [ -z "$(STRATEGY)" ]; then \
echo "Usage: make create-config STRATEGY=<path-to-strategy.pine>"; \
echo ""; \
echo "Example:"; \
echo " make create-config STRATEGY=strategies/rolling-cagr-5-10yr.pine"; \
echo ""; \
echo "This will:"; \
echo " 1. Run the strategy to extract indicator names"; \
echo " 2. Create out/{strategy-name}.config with correct filename"; \
echo " 3. Pre-fill config with actual indicator names"; \
exit 1; \
fi
@./scripts/create-config.sh $(STRATEGY)
validate-configs: ## Validate that all .config files follow naming convention
@./scripts/validate-configs.sh
list-configs: ## List all visualization configs and their matching strategies
@echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
@echo "📋 Visualization Configs"
@echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
@echo ""
@for config in $$(find out -name "*.config" -type f ! -name "template.config" 2>/dev/null); do \
name=$$(basename "$$config" .config); \
pine="strategies/$$name.pine"; \
if [ -f "$$pine" ]; then \
echo "✓ $$name"; \
echo " Config: $$config"; \
echo " Strategy: $$pine"; \
else \
echo "⚠ $$name (orphaned)"; \
echo " Config: $$config"; \
echo " Strategy: NOT FOUND"; \
fi; \
echo ""; \
done || echo "No config files found"
remove-config: ## Remove specific visualization config (usage: make remove-config STRATEGY=strategies/my-strategy.pine)
@if [ -z "$(STRATEGY)" ]; then \
echo "Usage: make remove-config STRATEGY=<path-to-strategy.pine>"; \
echo ""; \
echo "Example:"; \
echo " make remove-config STRATEGY=strategies/rolling-cagr.pine"; \
exit 1; \
fi
@name=$$(basename "$(STRATEGY)" .pine); \
config="out/$$name.config"; \
if [ -f "$$config" ]; then \
echo "Removing config: $$config"; \
rm "$$config"; \
echo "✓ Config removed"; \
else \
echo "Error: Config not found: $$config"; \
exit 1; \
fi
clean-configs: ## Remove ALL visualization configs (except template) - requires confirmation
@echo "⚠️ WARNING: This will delete ALL .config files (except template.config)"
@echo ""
@echo "Config files that will be deleted:"
@for config in $$(find out -name "*.config" -type f ! -name "template.config" 2>/dev/null); do \
echo " - $$config"; \
done || echo " (none found)"
@echo ""
@read -p "Are you sure? Type 'yes' to confirm: " confirm; \
if [ "$$confirm" != "yes" ]; then \
echo "Cancelled."; \
exit 1; \
fi
@echo "Removing visualization configs..."
@find out -name "*.config" -type f ! -name "template.config" -delete 2>/dev/null || true
@echo "✓ All configs cleaned (template.config preserved)"
clean-configs-force: ## Remove ALL configs without confirmation (use with caution)
@echo "Force removing all visualization configs..."
@find out -name "*.config" -type f ! -name "template.config" -delete 2>/dev/null || true
@echo "✓ All configs force-cleaned (template.config preserved)"
##@ Information
check-deps: ## Check if all dependencies are installed
@./scripts/check-deps.sh
version: ## Show version information
@echo "Version: $(VERSION)"
@echo "Build Time: $(BUILD_TIME)"
@echo "Commit: $(COMMIT_HASH)"
@echo "Go Version: $(shell $(GO) version)"
deps: ## Show Go module dependencies
@echo "Go modules:"
@ $(GO) list -m all
mod-tidy: ## Tidy go.mod
@echo "Tidying go.mod..."
@ $(GO) mod tidy
@ $(GO) mod verify
@echo "✓ Dependencies tidied"
mod-update: ## Update all dependencies
@echo "Updating dependencies..."
@ $(GO) get -u ./...
@$(MAKE) mod-tidy
@echo "✓ Dependencies updated"
##@ Quick Commands
all: ci ## Full validation (format, vet, lint, build, all tests)
install-hooks: ## Install git pre-commit hook
@echo "Installing pre-commit hook..."
@echo '#!/bin/sh' > .git/hooks/pre-commit
@echo '# Git pre-commit hook - full validation' >> .git/hooks/pre-commit
@echo 'set -e' >> .git/hooks/pre-commit
@echo 'export PATH="$$HOME/.local/go/bin:/usr/local/go/bin:$$PATH"' >> .git/hooks/pre-commit
@echo 'export GOPATH="$$HOME/go"' >> .git/hooks/pre-commit
@echo 'export PATH="$$PATH:$$GOPATH/bin"' >> .git/hooks/pre-commit
@echo 'if ! command -v go >/dev/null 2>&1; then' >> .git/hooks/pre-commit
@echo ' echo "✗ Go not found. Run: make install"' >> .git/hooks/pre-commit
@echo ' exit 1' >> .git/hooks/pre-commit
@echo 'fi' >> .git/hooks/pre-commit
@echo 'echo "🔍 Running pre-commit validation..."' >> .git/hooks/pre-commit
@echo 'make all' >> .git/hooks/pre-commit
@echo 'exit 0' >> .git/hooks/pre-commit
@chmod +x .git/hooks/pre-commit
@echo "✓ Pre-commit hook installed (runs: make all)"
install: ## Install Go to ~/.local (no sudo required)
@./scripts/install-deps.sh
install-go-only: ## Alias for install (kept for compatibility)
@./scripts/install-deps.sh
setup: ## Initialize project after dependency installation (download modules, build)
@./scripts/post-install.sh