#!/usr/bin/make -f

include /usr/share/openstack-pkg-tools/pkgos.make

TEST_SPEC := not test_add_point_and_get_zipped_graph_2
ifeq ($(shell nproc),1)
  TEST_SPEC += and not test_run_scenario_constantly_for_duration
  TEST_SPEC += and not test_run_scenario_constantly_for_duration_exception
  TEST_SPEC += and not test_run_scenario_constantly_for_duration_timeout
endif

export TOX_ENV_NAME=debianpackage

%:
	dh $@ --buildsystem=pybuild --with python3

override_dh_clean:
	dh_clean
	rm -rf build debian/rally.config debian/rally.postinst
	rm -rf .pytest_cache
	find . -type d -name __pycache__ -exec rm -r {} \+

override_dh_auto_clean:
	python3 setup.py clean

override_dh_install:
	echo "Do nothing..."

override_dh_auto_test:
	echo "Do nothing..."

override_dh_auto_install:
	pkgos-dh_auto_install --no-py2

ifeq (,$(findstring nocheck, $(DEB_BUILD_OPTIONS)))
	set -e ; set -x ; for PYVER in $(PYTHON3S); do \
		PYTHONPATH=$(CURDIR)/debian/tmp/usr/lib/python3/dist-packages \
			PYTHON=python$$PYVER \
			python$$PYVER -m pytest -v -n `nproc` tests/unit -Wignore -k '$(TEST_SPEC)' ; \
	done
endif

	dh_install
	
	rm -rf $(CURDIR)/debian/python3-rally/usr/etc
	mv $(CURDIR)/debian/python3-rally/usr/bin $(CURDIR)/debian/rally/usr

	install -D -m 0755 $(CURDIR)/etc/rally.bash_completion $(CURDIR)/debian/rally/usr/share/bash-completion/completions/rally
	install -D -m 0644 $(CURDIR)/etc/rally/rally.conf.sample $(CURDIR)/debian/rally/usr/share/rally/rally.conf
	sed -i 's|^[ \t#]connection[ \t]*=|connection=sqlite:///var/lib/rally/rally.db|' $(CURDIR)/debian/rally/usr/share/rally/rally.conf

override_dh_auto_build:
	/usr/share/openstack-pkg-tools/pkgos_insert_include pkgos_func rally.config
	/usr/share/openstack-pkg-tools/pkgos_insert_include pkgos_func rally.postinst

override_dh_python3:
	dh_python3 --shebang=/usr/bin/python3
