Skip to content

Commit 3af5f7c

Browse files
committed
Add dependency check to Makefile
Introduce a new `check-dependencies` target that verifies the presence of required system packages and Go tools on Debian systems. This target is added as a prerequisite to the `default` build target. This change improves the developer experience by providing clear, actionable feedback if necessary dependencies are missing. Instead of failing with cryptic errors during the build or test phases, the user is informed upfront and given instructions on how to install the missing components. Additionally, fix goimports execution in fmt target. The `$(shell ...)` make function is evaluated when the Makefile is first parsed, not when a target is executed. This caused `goimports` to run every time `make` was invoked, regardless of the specified target, including for unrelated targets like `make clean`.
1 parent 678c52d commit 3af5f7c

File tree

1 file changed

+31
-4
lines changed

1 file changed

+31
-4
lines changed

Makefile

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.PHONY: components server targets
1+
.PHONY: components server targets check-dependencies
22
.DEFAULT_GOAL := default
33

44
LANG=C
@@ -37,13 +37,13 @@ FILES := $$(find . -name "*.go")
3737
FAILPOINT_ENABLE := $$(tools/bin/failpoint-ctl enable)
3838
FAILPOINT_DISABLE := $$(tools/bin/failpoint-ctl disable)
3939

40-
default: check build
40+
default: check-dependencies check build
4141
@# Target: run the checks and then build.
4242

4343
include ./tests/Makefile
4444

4545
# Build TiUP and all components
46-
build: tiup components
46+
build: check-dependencies tiup components
4747
@# Target: build tiup and all it's components
4848

4949
components: playground client cluster dm server
@@ -105,6 +105,33 @@ clean:
105105
@rm -rf cover
106106
@rm -rf tests/*/{bin/*.test,logs,cover/*.out}
107107

108+
check-dependencies:
109+
@# Target: check for required dependencies on Debian systems
110+
@# Use shell commands for OS detection to avoid relying on go env
111+
@if [ "$$(uname -s)" != "Linux" ]; then \
112+
echo "Skipping dependency check on non-Linux OS: $$(uname -s)"; \
113+
exit 0; \
114+
fi
115+
@if [ ! -f /etc/debian_version ]; then \
116+
echo "Skipping dependency check on non-Debian system"; \
117+
exit 0; \
118+
fi
119+
@echo "Checking dependencies on Debian..."; \
120+
missing_packages=""; \
121+
for pkg in ca-certificates golang git curl; do \
122+
dpkg -s $$pkg > /dev/null 2>&1 || missing_packages="$$missing_packages $$pkg"; \
123+
done; \
124+
if [ -n "$$missing_packages" ]; then \
125+
echo "Error: Missing required system packages:$$missing_packages"; \
126+
echo "Please install them using: apt install -y$$missing_packages"; \
127+
exit 1; \
128+
fi
129+
@if [[ "$$(go version | cut -c 14-20)" < "1.19" ]]; then \
130+
echo "Error: Go version is too old. Please use Go 1.21 or later."; \
131+
exit 1; \
132+
fi
133+
@echo "Dependencies check passed."
134+
108135
test: failpoint-enable run-tests failpoint-disable
109136
@# Target: run tests with failpoint enabled
110137
$(MAKE) -C components/client ${MAKECMDGOALS}
@@ -142,7 +169,7 @@ fmt:
142169
@echo "gofmt (simplify)"
143170
@gofmt -s -l -w $(FILES) 2>&1
144171
@echo "goimports (if installed)"
145-
$(shell goimports -w $(FILES) 2>/dev/null)
172+
@goimports -w $(FILES) 2>/dev/null || true
146173

147174
tools/bin/revive: tools/check/go.mod
148175
@# Target: build revive utility

0 commit comments

Comments
 (0)