# Use bash shell with pipefail option enabled so that the return status of a
# piped command is the value of the last (rightmost) commnand to exit with a
# non-zero status. This lets us pipe output into tee but still exit on test
# failures.
SHELL = /bin/bash
.SHELLFLAGS = -o pipefail -c

all: test lint

# wait for the device to be available before beginning the test
# A temporary volume is mounted at /build when 'make test' is executing.
# The following steps copy across useful output to this volume which can
# then be extracted to form the CI summary for the test procedure.
test:
	# option -k 'dir_name' excludes 'dir_name' contents 
	cd /app && python setup.py test | tee setup_py_test.stdout
	mkdir -p /build/reports && \
        if [ -d /build ]; then \
                mv /app/setup_py_test.stdout /build/csp-lmc-subelement-setup-test.stdout; \
                mv /app/htmlcov /build/csp-lmc-subelement_htmlcov; \
                mv /app/build/reports/csp-lmc-subelement-unit-tests.xml /build/reports; \
                mv /app/coverage.xml /build; \
        fi;
lint:
	pip3 install pylint2junit; \
        mkdir -p /build/reports; \
        cd /app && pylint --output-format=parseable cspse/lmc | tee /build/csp-lmc-subelement-code-analysis.stdout; \
        cd /app && pylint --output-format=pylint2junit.JunitReporter cspse/lmc > /build/reports/csp-lmc-subelement-linting.xml;

.PHONY: all test lint

