Makefile RawHistoryFolder
1.PHONY: build test vet race e2e-xwayland 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 ./...
29 CGO_ENABLED=0 go vet -tags xwayland ./internal/app
30race:
31 # cgo is enabled only for the race test binary.
32 CGO_ENABLED=1 go test -race ./...
33MOCKS := internal/mocks ':(glob)internal/**/*_mock_test.go'
34# Regenerate from scratch so mocks of removed interfaces disappear too.
35mocks:
36 rm -rf internal/mocks
37 find internal -name '*_mock_test.go' -delete
38 $(HOME)/go/bin/mockery
39# Generated mocks must be committed and up to date.
40mocks-check: mocks
41 git diff --exit-code -- $(MOCKS)
42 @test -z "$$(git ls-files --others --exclude-standard -- $(MOCKS))"
43# Committed SPIR-V must match the GLSL shaders (needs glslc).
44spv-check:
45 go generate ./internal/adapters/vulkan
46 git diff --exit-code -- 'internal/adapters/vulkan/shaders/*.spv'
47# Test doubles come from Mockery only: no handwritten fake/stub/spy types.
48# Matches `type fakeX`, `\ttype RendererStub[T any]` and `spyX struct` in `type (` blocks.
49# grep exit 1 (no match) passes; 0 (match) and 2 (error) fail.
50FAKES := ^\s*type\s+\w*(fake|stub|spy|dummy|mock)\w*|^\s*\w*(fake|stub|spy|dummy|mock)\w*(\[[^]]*\])?\s+(struct|interface)\b
51fakes-check:
52 @rc=0; grep -rniE '$(FAKES)' --include='*_test.go' --exclude='*_mock_test.go' internal cmd || rc=$$?; \
53 [ $$rc -eq 1 ] || { [ $$rc -eq 0 ] && echo 'handwritten test double: add an interface and a Mockery entry (see AGENTS.md)' >&2; exit 1; }
54# The component field comes from logging.For: a second one on a scoped logger
55# duplicates the JSON key. grep exit 1 (no match) passes; 0 and 2 fail.
56LOGCOMPONENT := "component"|FieldComponent
57log-check:
58 @rc=0; grep -rnE '$(LOGCOMPONENT)' --include='*.go' --exclude='*_test.go' --exclude-dir=logging internal cmd || rc=$$?; \
59 [ $$rc -eq 1 ] || { [ $$rc -eq 0 ] && echo 'component log field: derive a logger with logging.For instead (see AGENTS.md)' >&2; exit 1; }
60arch: adapter-imports
61 $(HOME)/go/bin/hexcheck -config .hexcheck.yaml -root . ./...
62# Adapters stay independent: production code may import only the shared
63# adapter libraries below. outputkit holds what both output backends (drm,
64# headless) run; the others are leaf helpers.
65ADAPTER_LIBS := fdwait|busretry|hintlabel|outputkit/capture|outputkit/corewake|outputkit/presented|outputkit/surfaces|captureallow|clock|hdrcursor|logging|peerexe|sessionsecurity|syncfile|workspaceid|xkb
66adapter-imports:
67 @edges=$$(CGO_ENABLED=0 go list -f '{{$$p := .ImportPath}}{{range .Imports}}{{$$p}} {{.}}{{"\n"}}{{end}}' ./internal/adapters/...) || exit 1; \
68 bad=$$(echo "$$edges" | grep -E ' \S+/internal/adapters/' | grep -vE '/internal/adapters/($(ADAPTER_LIBS))$$' \
69 | while read -r from to; do case $$to in $$from/*) ;; *) echo "$$from -> $$to";; esac; done); \
70 [ -z "$$bad" ] || { echo "$$bad"; echo 'adapter imports another adapter: use ports or a shared library (Makefile ADAPTER_LIBS)' >&2; exit 1; }
71# Fast, mandatory guards for tiled content publications and SHM copies.
72perf-check:
73 CGO_ENABLED=0 go test ./internal/core ./internal/app ./internal/adapters/drm ./internal/adapters/headless ./internal/adapters/vulkan ./internal/adapters/wayland ./internal/adapters/outputkit/capture ./internal/adapters/screencast ./internal/adapters/wayland/xwm -run '^(TestAnimateAllocations|TestPublishAllocations|TestPublishSubscribersAllocations|TestPublishStashSlideAllocations|TestPublishOverviewAllocations|TestPublishLeavingAllocations|TestOutputRoutingAllocations|TestReportSeenAllocations|TestFrameLifecycleTransitionsAllocations|TestFullscreenShownAllocations|TestFrameDecisionAllocations|TestCommitFrameAllocations|TestColorPipelineAllocations|TestShownBySnapshotAllocations|TestFlipShowsAllocations|TestMRUNoteFocusDoesNotAllocateWhenSettled|TestDueFramesAllocations|TestRenderSteadyStateAllocations|TestRenderSteadyStateDMABufAllocations|TestSceneOpaqueRegionAllocations|TestSceneDeltaAllocations|TestAccountFlipAllocations|TestFlipDoneAllocations|TestSceneWalkUnchangedTiledSHM|TestTiledCommitPublishAllocations|TestCapturedCommitApplyAllocations|TestCapturedViewportApplyAllocations|TestEffectiveInputEmptyTreeAllocations|TestHeadlessTiledSHMCallbackAndCopyBudget|TestReleaseHeldAllocations|TestCommitDamageAllocations|TestEmitContentAllocations|TestPresentationPushAllocations|TestAnimatingFrameSendAllocations|TestContentBatchCycleAllocations|TestWriteMappedAllocations|TestCapturedForwardAllocations|TestCommandForwardAllocations|TestOutboxQueuedDeliveryAllocations|TestCastFrameAllocations|TestCastProducerAllocations|TestCaptureCycleAllocations|TestLogScenesAllocations|TestOverviewNamedRowsAllocations|TestBufferContentAllocations|TestDueFramesFireScratch|TestRetireSemaphoreAllocatesNothing|TestTableLookupAllocations|TestTableInsertRemoveAllocations|TestPropertyUnchangedAllocations|TestDispatchAllocations|TestConfigureFlushAllocations|TestFocusAllocations|TestSpaceAllocations|TestUnmanagedGeometryAllocations|TestFocusInUnmanagedAllocations|TestUnmanagedPublishAllocations|TestUnmanagedHitAllocations|TestOverrideMovedUnchangedAllocations|TestFullscreenConfigureAllocations|TestKeyboardGrabSyncAllocations|TestSelectionCopyAllocations|TestSelectionCopyAllocationsWaylandToX|TestSelectionINCRChunkAllocations|TestXSettingsNoChangeAllocations|TestSettleLeftAllocs)$$' -count=1
74 CGO_ENABLED=0 go test -tags xturbo_poison ./internal/adapters/wayland/xwm -count=1
75check: vet test arch fakes-check log-check perf-check
76
77# On-demand SDR/HDR colour check with examples/testpattern on a headless
78# NeferWL. Needs a GPU and /dev/udmabuf; not part of check.
79color-check:
80 CGO_ENABLED=0 go test -tags colorcheck ./internal/app -run '^TestColorCheck' -count=1 -v
81
82# End-to-end test of the built-in XWM: a real Xwayland and an X11 probe on a
83# headless NeferWL. Needs Xwayland and a GPU; not part of check.
84e2e-xwayland:
85 CGO_ENABLED=1 go test -tags xwayland -race ./internal/app -run TestXwayland -count=1 -v
86
87# Arch package of the committed HEAD (packaging/arch/PKGBUILD). Go modules
88# come from the module proxy in prepare(); the build itself runs offline.
89# pacman-ordered version: 0.0.0.r<commits>.g<hash>; a tag replaces 0.0.0.
90pkg: SHELL := bash
91pkg: .SHELLFLAGS := -eo pipefail -c
92pkg:
93 @test -z "$$(git status --porcelain)" || echo "warning: uncommitted changes are not packaged" >&2
94 v=$$(t=$$(git describe --tags --abbrev=0 2>/dev/null | sed 's/^v//; s/-/_/g'); \
95 echo "$${t:-0.0.0}.r$$(git rev-list --count HEAD).g$$(git rev-parse --short HEAD)"); \
96 d=$$(mktemp -d /tmp/neferwl-pkg.XXXXXX); trap 'rm -rf "$$d"' EXIT; \
97 git archive --prefix=neferwl-$$v/ -o "$$d/neferwl-$$v.tar.gz" HEAD; \
98 cp packaging/arch/PKGBUILD packaging/neferwl.install "$$d/"; \
99 cd "$$d" && sed -i "s/^pkgver=.*/pkgver=$$v/; s/^sha256sums=.*/sha256sums=('$$(sha256sum *.tar.gz | cut -d' ' -f1)')/" PKGBUILD; \
100 makepkg -f --noconfirm; mkdir -p $(CURDIR)/dist; rm -f $(CURDIR)/dist/neferwl-*.pkg.tar.zst; mv *.pkg.tar.zst $(CURDIR)/dist/
101 @ls dist/*.pkg.tar.zst
102
103# Build the package, then install it with pacman (asks for sudo).
104install: pkg
105 sudo pacman -U dist/neferwl-*.pkg.tar.zst