diff --git a/Makefile b/Makefile index 0a039e5..4ceffd2 100644 --- a/Makefile +++ b/Makefile @@ -14,17 +14,15 @@ VENV=xcffib_venv PYTHON=$(VENV)/bin/python3 FLAKE=$(VENV)/bin/flake8 +GENERATOR_FILES=$(shell find . -path ./test -prune -false -o -name \*.hs) +HANDWRITTEN_MODULE_FILES=$(shell find ./module -name \*.py) + # you should have xcb-proto installed to run this -xcffib: xcffib_py_files xcffib.cabal $(shell find . -path ./test -prune -false -o -name \*.hs) +xcffib: xcffib.cabal $(GENERATOR_FILES) $(HANDWRITTEN_MODULE_FILES) $(GEN) --input $(XCBDIR) --output ./xcffib + cp ./module/*.py ./xcffib/ touch ./xcffib/py.typed - sed -i -e "s/__xcb_proto_version__ = .*/__xcb_proto_version__ = \"${XCBVER}\"/" xcffib/__init__.py - -xcffib_py_files: $(addprefix xcffib/, $(notdir $(wildcard module/*.py))) - -xcffib/%.py: module/%.py - mkdir -p xcffib/ - cp $^ $@ + sed -i "s/__xcb_proto_version__ = .*/__xcb_proto_version__ = \"${XCBVER}\"/" xcffib/__init__.py .PHONY: xcffib-fmt xcffib-fmt: module/*.py @@ -72,32 +70,12 @@ $(VENV): requirements.txt python -m venv $(VENV) $(PYTHON) -m pip install -r requirements.txt -check-abi: xcffib $(VENV) - # check abi precompiled mode - # make a temporary env to test install and ensure we cd somewhere - # we won't pick up the local source xcffib module - $(eval TMPLOC=$(shell mktemp -d)) - python -m venv $(TMPLOC) - CC=/bin/false ${TMPLOC}/bin/python -m pip install --no-cache -v . - ${TMPLOC}/bin/python -m pip install pytest pytest-xdist - ${TMPLOC}/bin/python -c "import os; os.chdir('${TMPLOC}'); import xcffib; print(xcffib.cffi_mode); assert xcffib.cffi_mode == 'abi_precompiled'" - ${TMPLOC}/bin/python -m pytest -v --durations=3 -n auto - -check-api: xcffib $(VENV) - # check abi precompiled mode - # make a temporary env to test install and ensure we cd somewhere - # we won't pick up the local source xcffib module - $(eval TMPLOC=$(shell mktemp -d)) - python -m venv ${TMPLOC} - ${TMPLOC}/bin/python -m pip install -v --no-cache . - ${TMPLOC}/bin/python -m pip install pytest pytest-xdist - ${TMPLOC}/bin/python -c "import os; os.chdir('${TMPLOC}'); import xcffib; print(xcffib.cffi_mode); assert xcffib.cffi_mode == 'api'" - ${TMPLOC}/bin/python -m pytest -v --durations=3 -n auto +check-mode-%: xcffib requirements.txt + ./test/test_mode.sh $* -check: xcffib htests $(VENV) lint check-api check-abi +check: xcffib htests lint check-mode-api check-mode-abi_precompiled $(CABAL) check $(PYTHON) -m compileall xcffib - $(PYTHON) -m pytest -v --durations=3 -n $(NCPUS) # make release ver=0.99.99 release: xcffib diff --git a/test/test_mode.sh b/test/test_mode.sh new file mode 100755 index 0000000..b5eb84c --- /dev/null +++ b/test/test_mode.sh @@ -0,0 +1,27 @@ +#!/bin/bash -eux + +MODE=$1 + +VENV=$(mktemp -d xcffib-test-$MODE.XXXXXXXXXX) + +function cleanup { + rm -rf "${VENV}" +} +trap cleanup EXIT + +# mask CC in abi_precompiled so that we force compilation at runtime +if [ "${MODE}" == "abi" ] || [ "${MODE}" == "abi_precompiled" ]; then + export CC=false +fi + +python -m venv "${VENV}" +source "${VENV}/bin/activate" + +pip install -r requirements.txt +pip install --no-cache -v . + +# make a temporary env to test install and ensure we cd somewhere +# we won't pick up the local source xcffib module. the venv dir is as good a +# place as any +python -I -c "import xcffib; print(\"mode is\", xcffib.cffi_mode, \"path is\", xcffib.__file__); assert xcffib.cffi_mode == \"${MODE}\"" +python -I -m pytest --durations=3 -n auto