@@ -18,11 +18,18 @@ ifeq ($(shell basename $(SHELL)),sh)
1818SHELL := $(shell which /bin/bash 2>/dev/null || which /usr/local/bin/bash)
1919endif
2020
21- all :
21+ PYTHON3 ?= python3
22+ ifeq ($(PYTHON3 ) ,)
23+ $(error python3 not found)
24+ endif
25+
26+ all : \
27+ .venv-pre-commit/var/.pre-commit-built.log
2228
2329.PHONY : \
2430 check-mypy \
25- check-supply-chain
31+ check-supply-chain \
32+ check-supply-chain-pre-commit
2633
2734.git_submodule_init.done.log : .gitmodules
2835 # Confirm dfxml_schema has been checked out at least once.
3138 test -r dependencies/dfxml_schema/dfxml.xsd
3239 touch $@
3340
41+ # This virtual environment is meant to be built once and then persist, even through 'make clean'.
42+ # If a recipe is written to remove this flag file, it should first run `pre-commit uninstall`.
43+ .venv-pre-commit/var/.pre-commit-built.log :
44+ rm -rf .venv-pre-commit
45+ test -r .pre-commit-config.yaml \
46+ || (echo " ERROR:Makefile:pre-commit is expected to install for this repository, but .pre-commit-config.yaml does not seem to exist." >&2 ; exit 1)
47+ $(PYTHON3 ) -m venv \
48+ .venv-pre-commit
49+ source .venv-pre-commit/bin/activate \
50+ && pip install \
51+ --upgrade \
52+ pip \
53+ setuptools \
54+ wheel
55+ source .venv-pre-commit/bin/activate \
56+ && pip install \
57+ pre-commit
58+ source .venv-pre-commit/bin/activate \
59+ && pre-commit install
60+ mkdir -p \
61+ .venv-pre-commit/var
62+ touch $@
63+
3464clean :
3565 find . -name ' *~' -exec rm {} \;
3666 $(MAKE ) \
3767 --directory tests \
3868 clean
3969
4070check : \
41- check-mypy
71+ .git_submodule_init.done.log \
72+ .venv-pre-commit/var/.pre-commit-built.log
4273 $(MAKE) \
74+ PYTHON3=$(PYTHON3) \
4375 SHELL=$(SHELL) \
4476 --directory tests \
4577 check
4678
4779check-mypy : \
4880 .git_submodule_init.done.log
4981 $(MAKE) \
82+ PYTHON3=$(PYTHON3) \
5083 SHELL=$(SHELL) \
5184 --directory tests \
5285 check-mypy
5386
5487check-supply-chain : \
88+ check-supply-chain-pre-commit \
5589 check-mypy
5690
91+ # Update pre-commit configuration and use the updated config file to
92+ # review code. Only have Make exit if 'pre-commit run' modifies files.
93+ check-supply-chain-pre-commit : \
94+ .venv-pre-commit/var/.pre-commit-built.log
95+ source .venv-pre-commit/bin/activate \
96+ && pre-commit autoupdate
97+ git diff \
98+ --exit-code \
99+ .pre-commit-config.yaml \
100+ || ( \
101+ source .venv-pre-commit/bin/activate \
102+ && pre-commit run \
103+ --all-files \
104+ --config .pre-commit-config.yaml \
105+ ) \
106+ || git diff \
107+ --stat \
108+ --exit-code \
109+ || ( \
110+ echo \
111+ "WARNING:Makefile:pre-commit configuration can be updated. It appears the updated would change file formatting." \
112+ >&2 \
113+ ; exit 1 \
114+ )
115+ @git diff \
116+ --exit-code \
117+ .pre-commit-config.yaml \
118+ || echo \
119+ "INFO:Makefile:pre-commit configuration can be updated. It appears the update would not change file formatting." \
120+ >&2
121+
57122check-tools :
58123 (cd tests/misc_object_tests; make check)
0 commit comments