Makefile RawHistoryFolder
1.PHONY: build test vet race mocks mocks-check spv-check fakes-check log-check arch adapter-imports check perf-check color-check bin tty logs pkg install
2
3# 0 runs until quit; set e.g. TTY_TIMEOUT=60s for a safety net.
4TTY_TIMEOUT ?= 0
5comma := ,
6# Go runtime profiles for tty runs; set PPROF= to disable.
7PPROF ?= localhost:6060
8RUNS := $(or $(XDG_STATE_HOME),$(HOME)/.local/state)/neferwl/runs/drm
9
10# Build a fresh binary with the git revision embedded.
11bin:
12 CGO_ENABLED=0 go build -o bin/neferwl ./cmd/neferwl
13
14# Run on the current TTY. Quit: Ctrl+Alt+Backspace (or the quit bind).
15# TTY_DEBUG adds narrow categories, e.g. TTY_DEBUG=drm-flip.
16tty: bin
17 ./bin/neferwl --backend=drm --debug=all$(if $(TTY_DEBUG),$(comma)$(TTY_DEBUG)) --timeout=$(TTY_TIMEOUT) $(if $(PPROF),--pprof=$(PPROF)); \
18 echo "exit $$? - log: $(RUNS)/latest.log"
19
20# Summarise the last run: lifecycle, warnings and errors.
21logs:
22 @jq -r 'select(.level != "debug") | "\(.time) \(.level) [\(.component)] \(.message) \(del(.time,.level,.component,.message) | tostring)"' $(RUNS)/latest.log
23build:
24 CGO_ENABLED=0 go build ./...
25test:
26 CGO_ENABLED=0 go test ./...
27vet:
28 CGO_ENABLED=0 go vet ./...
29race:
30 # cgo is enabled only for the race test binary.
31 CGO_ENABLED=1 go test -race ./...
32MOCKS := internal/mocks ':(glob)internal/**/*_mock_test.go'
33# Regenerate from scratch so mocks of removed interfaces disappear too.
34mocks:
35 rm -rf internal/mocks
36 find internal -name '*_mock_test.go' -delete
37 $(HOME)/go/bin/mockery
38# Generated mocks must be committed and up to date.
39mocks-check: mocks
40 git diff --exit-code -- $(MOCKS)
41 @test -z "$$(git ls-files --others --exclude-standard -- $(MOCKS))"
42# Committed SPIR-V must match the GLSL shaders (needs glslc).
43spv-check:
44 go generate ./internal/adapters/vulkan
45 git diff --exit-code -- 'internal/adapters/vulkan/shaders/*.spv'
46# Test doubles come from Mockery only: no handwritten fake/stub/spy types.
47# Matches `type fakeX`, `\ttype RendererStub[T any]` and `spyX struct` in `type (` blocks.
48# grep exit 1 (no match) passes; 0 (match) and 2 (error) fail.
49FAKES := ^\s*type\s+\w*(fake|stub|spy|dummy|mock)\w*|^\s*\w*(fake|stub|spy|dummy|mock)\w*(\[[^]]*\])?\s+(struct|interface)\b
50fakes-check:
51 @rc=0; grep -rniE '$(FAKES)' --include='*_test.go' --exclude='*_mock_test.go' internal cmd || rc=$$?; \
52 [ $$rc -eq 1 ] || { [ $$rc -eq 0 ] && echo 'handwritten test double: add an interface and a Mockery entry (see AGENTS.md)' >&2; exit 1; }
53# The component field comes from logging.For: a second one on a scoped logger
54# duplicates the JSON key. grep exit 1 (no match) passes; 0 and 2 fail.
55LOGCOMPONENT := "component"|FieldComponent
56log-check:
57 @rc=0; grep -rnE '$(LOGCOMPONENT)' --include='*.go' --exclude='*_test.go' --exclude-dir=logging internal cmd || rc=$$?; \
58 [ $$rc -eq 1 ] || { [ $$rc -eq 0 ] && echo 'component log field: derive a logger with logging.For instead (see AGENTS.md)' >&2; exit 1; }
59arch: adapter-imports
60 $(HOME)/go/bin/hexcheck -hexcheck.config .hexcheck.yaml -hexcheck.root . ./...
61# Adapters stay independent: production code may import only the shared
62# adapter libraries below. outputkit holds what both output backends (drm,
63# headless) run; the others are leaf helpers.
64ADAPTER_LIBS := busretry|outputkit/capture|outputkit/presented|outputkit/surfaces|captureallow|clock|logging|sessionsecurity|syncfile|workspaceid|xkb
65adapter-imports:
66 @edges=$$(CGO_ENABLED=0 go list -f '{{$$p := .ImportPath}}{{range .Imports}}{{$$p}} {{.}}{{"\n"}}{{end}}' ./internal/adapters/...) || exit 1; \
67 bad=$$(echo "$$edges" | grep -E ' \S+/internal/adapters/' | grep -vE '/internal/adapters/($(ADAPTER_LIBS))$$' \
68 | while read -r from to; do case $$to in $$from/*) ;; *) echo "$$from -> $$to";; esac; done); \
69 [ -z "$$bad" ] || { echo "$$bad"; echo 'adapter imports another adapter: use ports or a shared library (Makefile ADAPTER_LIBS)' >&2; exit 1; }
70# Fast, mandatory guards for tiled content publications and SHM copies.
71perf-check:
72 CGO_ENABLED=0 go test ./internal/core ./internal/app ./internal/adapters/drm ./internal/adapters/vulkan ./internal/adapters/wayland -run '^(TestAnimateAllocations|TestPublishAllocations|TestPublishStashSlideAllocations|TestPublishOverviewAllocations|TestPublishLeavingAllocations|TestOutputRoutingAllocations|TestReportSeenAllocations|TestFrameLifecycleTransitionsAllocations|TestFullscreenShownAllocations|TestFrameDecisionAllocations|TestCommitFrameAllocations|TestColorPipelineAllocations|TestShownBySnapshotAllocations|TestDueFramesAllocations|TestRenderSteadyStateAllocations|TestSceneOpaqueRegionAllocations|TestSceneDeltaAllocations|TestAccountFlipAllocations|TestFlipDoneAllocations|TestSceneWalkUnchangedTiledSHM|TestTiledCommitPublishAllocations|TestCapturedCommitApplyAllocations|TestCapturedViewportApplyAllocations|TestEffectiveInputEmptyTreeAllocations|TestHeadlessTiledSHMCallbackAndCopyBudget)$$' -count=1
73check: vet test arch fakes-check log-check perf-check
74
75# On-demand SDR/HDR colour check with examples/testpattern on a headless
76# NeferWL. Needs a GPU and /dev/udmabuf; not part of check.
77color-check:
78 CGO_ENABLED=0 go test -tags colorcheck ./internal/app -run '^TestColorCheck' -count=1 -v
79
80# Arch package of the committed HEAD (packaging/arch/PKGBUILD). Go modules
81# come from the module proxy in prepare(); the build itself runs offline.
82# pacman-ordered version: 0.0.0.r<commits>.g<hash>; a tag replaces 0.0.0.
83pkg: SHELL := bash
84pkg: .SHELLFLAGS := -eo pipefail -c
85pkg:
86 @test -z "$$(git status --porcelain)" || echo "warning: uncommitted changes are not packaged" >&2
87 v=$$(t=$$(git describe --tags --abbrev=0 2>/dev/null | sed 's/^v//; s/-/_/g'); \
88 echo "$${t:-0.0.0}.r$$(git rev-list --count HEAD).g$$(git rev-parse --short HEAD)"); \
89 d=$$(mktemp -d /tmp/neferwl-pkg.XXXXXX); trap 'rm -rf "$$d"' EXIT; \
90 git archive --prefix=neferwl-$$v/ -o "$$d/neferwl-$$v.tar.gz" HEAD; \
91 cp packaging/arch/PKGBUILD packaging/neferwl.install "$$d/"; \
92 cd "$$d" && sed -i "s/^pkgver=.*/pkgver=$$v/; s/^sha256sums=.*/sha256sums=('$$(sha256sum *.tar.gz | cut -d' ' -f1)')/" PKGBUILD; \
93 makepkg -f --noconfirm; mkdir -p $(CURDIR)/dist; rm -f $(CURDIR)/dist/neferwl-*.pkg.tar.zst; mv *.pkg.tar.zst $(CURDIR)/dist/
94 @ls dist/*.pkg.tar.zst
95
96# Build the package, then install it with pacman (asks for sudo).
97install: pkg
98 sudo pacman -U dist/neferwl-*.pkg.tar.zst