forked from livegrep/livegrep
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
91 lines (74 loc) · 3.36 KB
/
Makefile
File metadata and controls
91 lines (74 loc) · 3.36 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
.PHONY: build build-backend build-web run run-backend run-web stop stop-backend stop-web logs-backend logs-web index status help
# Configuration
BACKEND_ADDR ?= localhost:9999
WEB_ADDR ?= 127.0.0.1:8910
INDEX_CONFIG ?= doc/examples/livegrep/index.json
DOCROOT = $(shell pwd)/bazel-bin/cmd/livegrep/livegrep_/livegrep.runfiles/_main/web
CODESEARCH_BIN = bazel-bin/src/tools/codesearch
LIVEGREP_BIN = bazel-bin/cmd/livegrep/livegrep_/livegrep
BACKEND_PID_FILE = /tmp/livegrep-backend.pid
WEB_PID_FILE = /tmp/livegrep-web.pid
BACKEND_LOG = /tmp/livegrep-backend.log
WEB_LOG = /tmp/livegrep-web.log
# Build targets
build: ## Build both backend and web frontend
bazel build //src/tools:codesearch //cmd/livegrep:livegrep
build-backend: ## Build only the codesearch backend
bazel build //src/tools:codesearch
build-web: ## Build only the web frontend
bazel build //cmd/livegrep:livegrep
# Run targets
run: build stop run-backend run-web ## Build and run everything
@echo "Livegrep is running at http://$(WEB_ADDR)"
run-backend: build-backend stop-backend ## Start the codesearch backend
$(CODESEARCH_BIN) -grpc $(BACKEND_ADDR) $(INDEX_CONFIG) > $(BACKEND_LOG) 2>&1 & echo $$! > $(BACKEND_PID_FILE)
@sleep 2
@if kill -0 $$(cat $(BACKEND_PID_FILE)) 2>/dev/null; then \
echo "Backend running (PID $$(cat $(BACKEND_PID_FILE))) on $(BACKEND_ADDR)"; \
else \
echo "Backend failed to start. Logs:"; cat $(BACKEND_LOG); exit 1; \
fi
run-web: build-web stop-web ## Start the web frontend (with template reload)
$(LIVEGREP_BIN) -listen $(WEB_ADDR) -connect $(BACKEND_ADDR) -docroot $(DOCROOT) -reload > $(WEB_LOG) 2>&1 & echo $$! > $(WEB_PID_FILE)
@sleep 2
@if kill -0 $$(cat $(WEB_PID_FILE)) 2>/dev/null; then \
echo "Web frontend running (PID $$(cat $(WEB_PID_FILE))) on http://$(WEB_ADDR)"; \
else \
echo "Web frontend failed to start. Logs:"; cat $(WEB_LOG); exit 1; \
fi
# Stop targets
stop: stop-web stop-backend ## Stop all services
stop-backend: ## Stop the codesearch backend
@if [ -f $(BACKEND_PID_FILE) ] && kill -0 $$(cat $(BACKEND_PID_FILE)) 2>/dev/null; then \
kill $$(cat $(BACKEND_PID_FILE)) && rm -f $(BACKEND_PID_FILE) && echo "Backend stopped"; \
else \
rm -f $(BACKEND_PID_FILE); \
fi
stop-web: ## Stop the web frontend
@if [ -f $(WEB_PID_FILE) ] && kill -0 $$(cat $(WEB_PID_FILE)) 2>/dev/null; then \
kill $$(cat $(WEB_PID_FILE)) && rm -f $(WEB_PID_FILE) && echo "Web frontend stopped"; \
else \
rm -f $(WEB_PID_FILE); \
fi
# Utility targets
logs-backend: ## Tail the backend logs
tail -f $(BACKEND_LOG)
logs-web: ## Tail the web frontend logs
tail -f $(WEB_LOG)
status: ## Check if services are running
@echo "Backend:"; \
if [ -f $(BACKEND_PID_FILE) ] && kill -0 $$(cat $(BACKEND_PID_FILE)) 2>/dev/null; then \
echo " Running (PID $$(cat $(BACKEND_PID_FILE)))"; \
else \
echo " Stopped"; \
fi
@echo "Web frontend:"; \
if [ -f $(WEB_PID_FILE) ] && kill -0 $$(cat $(WEB_PID_FILE)) 2>/dev/null; then \
echo " Running (PID $$(cat $(WEB_PID_FILE)))"; \
else \
echo " Stopped"; \
fi
index: build-backend ## Build an index file (use INDEX_OUTPUT to set path)
$(CODESEARCH_BIN) -index_only -dump_index $(or $(INDEX_OUTPUT),livegrep.idx) $(INDEX_CONFIG)
help: ## Show this help
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-16s\033[0m %s\n", $$1, $$2}'