2022-06-20 16:33:04 +03:00
|
|
|
include Makefile.tests
|
|
|
|
|
2021-09-24 00:22:27 +03:00
|
|
|
# skip contrib with its generated .hs file because it doesn't
|
|
|
|
# come with a cabal file, which can trigger a bug in ormolu
|
2022-06-14 18:20:12 +03:00
|
|
|
HS_FILES = $(shell git ls-files '*.hs' '*.hs-boot' | grep -v '^contrib/')
|
2022-06-15 13:26:00 +03:00
|
|
|
CHANGED_HS_FILES = $(shell git diff --diff-filter=d --name-only `git merge-base HEAD origin/main` | grep '.*\(\.hs\|hs-boot\)$$' | grep -v '^contrib/')
|
|
|
|
|
2022-06-20 16:01:37 +03:00
|
|
|
NIX_FILES = $(shell git ls-files '*.nix' 'nix/*.nix')
|
|
|
|
|
2022-06-15 13:26:00 +03:00
|
|
|
SHELL_FILES = $(shell git ls-files '*.sh')
|
|
|
|
CHANGED_SHELL_FILES = $(shell git diff --diff-filter=d --name-only `git merge-base HEAD origin/main` | grep '.*\.sh$$')
|
2022-06-14 18:20:12 +03:00
|
|
|
|
|
|
|
HLINT = hlint
|
2021-09-24 00:22:27 +03:00
|
|
|
|
2022-06-20 16:01:37 +03:00
|
|
|
NIX_FMT = nixpkgs-fmt
|
|
|
|
|
2021-09-24 00:22:27 +03:00
|
|
|
ORMOLU_CHECK_VERSION = 0.3.0.0
|
|
|
|
ORMOLU_ARGS = --cabal-default-extensions
|
|
|
|
ORMOLU = ormolu
|
|
|
|
ORMOLU_VERSION = $(shell $(ORMOLU) --version | awk 'NR==1 { print $$2 }')
|
|
|
|
|
2022-06-15 13:26:00 +03:00
|
|
|
SHELLCHECK = shellcheck
|
|
|
|
|
2021-09-24 00:22:27 +03:00
|
|
|
# default target
|
|
|
|
.PHONY: help
|
|
|
|
## help: prints help message
|
|
|
|
help:
|
|
|
|
@echo "Usage:"
|
|
|
|
@sed -n 's/^##//p' ${MAKEFILE_LIST} | column -t -s ':' | sed -e 's/^/ /'
|
|
|
|
|
|
|
|
.PHONY: check-ormolu-version
|
|
|
|
check-ormolu-version:
|
|
|
|
@if ! [ "$(ORMOLU_VERSION)" = "$(ORMOLU_CHECK_VERSION)" ]; then \
|
|
|
|
echo "WARNING: ormolu version mismatch, expected $(ORMOLU_CHECK_VERSION)"; \
|
|
|
|
fi
|
|
|
|
|
|
|
|
.PHONY: format-hs
|
|
|
|
## format-hs: auto-format Haskell source code using ormolu
|
|
|
|
format-hs: check-ormolu-version
|
|
|
|
@echo running ormolu --mode inplace
|
2022-06-14 18:20:12 +03:00
|
|
|
@$(ORMOLU) $(ORMOLU_ARGS) --mode inplace $(HS_FILES)
|
2021-09-24 00:22:27 +03:00
|
|
|
|
|
|
|
.PHONY: format-hs-changed
|
|
|
|
## format-hs-changed: auto-format Haskell source code using ormolu (changed files only)
|
|
|
|
format-hs-changed: check-ormolu-version
|
|
|
|
@echo running ormolu --mode inplace
|
2022-06-14 18:20:12 +03:00
|
|
|
@if [ -n "$(CHANGED_HS_FILES)" ]; then \
|
|
|
|
$(ORMOLU) $(ORMOLU_ARGS) --mode inplace $(CHANGED_HS_FILES); \
|
2021-09-24 00:22:27 +03:00
|
|
|
fi
|
|
|
|
|
|
|
|
.PHONY: check-format-hs
|
|
|
|
## check-format-hs: check Haskell source code formatting using ormolu
|
|
|
|
check-format-hs: check-ormolu-version
|
|
|
|
@echo running ormolu --mode check
|
2022-06-14 18:20:12 +03:00
|
|
|
@$(ORMOLU) $(ORMOLU_ARGS) --mode check $(HS_FILES)
|
2021-09-24 00:22:27 +03:00
|
|
|
|
2022-06-15 13:26:00 +03:00
|
|
|
.PHONY: check-format-hs-changed
|
|
|
|
## check-format-hs-changed: check Haskell source code formatting using ormolu (changed-files-only)
|
|
|
|
check-format-hs-changed: check-ormolu-version
|
|
|
|
@echo running ormolu --mode check
|
|
|
|
@if [ -n "$(CHANGED_HS_FILES)" ]; then \
|
|
|
|
$(ORMOLU) $(ORMOLU_ARGS) --mode check $(CHANGED_HS_FILES); \
|
|
|
|
fi
|
|
|
|
|
2022-06-20 16:01:37 +03:00
|
|
|
# We don't bother checking only changed *.nix files, as there's so few.
|
|
|
|
|
|
|
|
.PHONY: format-nix
|
|
|
|
## format-nix: auto-format Nix source code using `nixpkgs-fmt`
|
|
|
|
format-nix:
|
|
|
|
@if command -v $(NIX_FMT) > /dev/null; then \
|
|
|
|
echo "running $(NIX_FMT)"; \
|
|
|
|
$(NIX_FMT) $(NIX_FILES); \
|
|
|
|
else \
|
|
|
|
echo "$(NIX_FMT) is not installed; skipping"; \
|
|
|
|
fi
|
|
|
|
|
|
|
|
.PHONY: check-format-nix
|
|
|
|
## check-format-nix: check Nix source code using `nixpkgs-fmt`
|
|
|
|
check-format-nix:
|
|
|
|
@if command -v $(NIX_FMT) > /dev/null; then \
|
|
|
|
echo "running $(NIX_FMT) --check"; \
|
|
|
|
$(NIX_FMT) --check $(NIX_FILES); \
|
|
|
|
else \
|
|
|
|
echo "$(NIX_FMT) is not installed; skipping"; \
|
|
|
|
fi
|
|
|
|
|
2021-09-24 00:22:27 +03:00
|
|
|
.PHONY: format
|
2022-06-20 16:01:37 +03:00
|
|
|
format: format-hs format-nix
|
2021-09-24 00:22:27 +03:00
|
|
|
|
|
|
|
.PHONY: format-changed
|
2022-06-20 16:01:37 +03:00
|
|
|
format-changed: format-hs-changed format-nix
|
2021-09-24 00:22:27 +03:00
|
|
|
|
|
|
|
.PHONY: check-format
|
2022-06-20 16:01:37 +03:00
|
|
|
check-format: check-format-hs check-format-nix
|
2022-06-14 18:20:12 +03:00
|
|
|
|
2022-06-15 13:26:00 +03:00
|
|
|
.PHONY: check-format-changed
|
2022-06-20 16:01:37 +03:00
|
|
|
check-format-changed: check-format-hs-changed check-format-nix
|
2022-06-15 13:26:00 +03:00
|
|
|
|
2022-06-14 18:20:12 +03:00
|
|
|
.PHONY: lint-hs
|
|
|
|
## lint-hs: lint Haskell code using `hlint`
|
|
|
|
lint-hs:
|
|
|
|
@echo running hlint
|
|
|
|
@$(HLINT) $(HS_FILES)
|
|
|
|
|
|
|
|
.PHONY: lint-hs-changed
|
|
|
|
## lint-hs-changed: lint Haskell code using `hlint` (changed files only)
|
|
|
|
lint-hs-changed:
|
|
|
|
@echo running hlint
|
|
|
|
@if [ -n "$(CHANGED_HS_FILES)" ]; then \
|
|
|
|
$(HLINT) $(CHANGED_HS_FILES); \
|
|
|
|
fi
|
|
|
|
|
2022-06-15 13:26:00 +03:00
|
|
|
.PHONY: lint-shell
|
2022-06-20 16:01:37 +03:00
|
|
|
## lint-shell: lint shell scripts using `shellcheck`
|
2022-06-15 13:26:00 +03:00
|
|
|
lint-shell:
|
|
|
|
@echo running shellcheck
|
|
|
|
@$(SHELLCHECK) $(SHELL_FILES)
|
|
|
|
|
|
|
|
.PHONY: lint-shell-changed
|
2022-06-20 16:01:37 +03:00
|
|
|
## lint-shell-changed: lint shell scripts using `shellcheck` (changed files only)
|
2022-06-15 13:26:00 +03:00
|
|
|
lint-shell-changed:
|
|
|
|
@echo running shellcheck
|
|
|
|
@if [ -n "$(CHANGED_SHELL_FILES)" ]; then \
|
|
|
|
$(SHELLCHECK) $(CHANGED_SHELL_FILES); \
|
|
|
|
fi
|
|
|
|
|
2022-06-14 18:20:12 +03:00
|
|
|
.PHONY: lint
|
2022-06-15 13:26:00 +03:00
|
|
|
lint: lint-hs lint-shell check-format
|
2022-06-14 18:20:12 +03:00
|
|
|
|
|
|
|
.PHONY: lint-changed
|
2022-06-15 13:26:00 +03:00
|
|
|
lint-changed: lint-hs-changed lint-shell-changed check-format-changed
|
2022-06-20 16:33:04 +03:00
|
|
|
|
|
|
|
|