#!/usr/bin/make -f

include /usr/share/dpkg/default.mk
include /usr/share/dpkg/pkg-info.mk
include /usr/share/rustc/architecture.mk
export DEB_HOST_RUST_TYPE

export DH_VERBOSE = 1

# Individual tests which fail in buildd or autopkgtest
SKIP_TESTS = \
	cli \
	pytest \
	test_adds_note_showing_which_strategy \
	test_can_learn_to_normalize_the_unnormalized \
	test_dateutil_timezones \
	test_gc_hooks_do_not_cause_unraisable_recursionerror \
	test_ghostwriter_suggests_submodules_for_empty_toplevel \
	test_hypothesis_is_not_the_first_to_import_attrs \
	test_hypothesis_is_not_the_first_to_import_numpy \
	test_non_trivial_json \
	test_updating_the_file_include_new_shrinkers \
	test_zoneinfo_timezones

# Test scripts which cannot be imported, e.g. because they
# depend on unpackaged Python modules
IGNORE_TESTS = \
	tests/crosshair \
	tests/dpcontracts \
	tests/patching

space = $(eval) $(eval)
concat_with = $(subst $(space),$1,$2)

export LC_ALL=C.UTF-8
export PYBUILD_DIR=hypothesis
export PYBUILD_TEST_ARGS=$(if $(SKIP_TESTS),-k 'not ($(call concat_with,$(space)or$(space),$(SKIP_TESTS)))') $(addprefix --ignore=,$(IGNORE_TESTS)) tests

export PATH := /usr/share/cargo/bin:$(PATH)
export CARGO_HOME = $(CURDIR)/debian/cargo_home
export DEB_CARGO_CRATE = hypothesis-native_$(DEB_VERSION_UPSTREAM)

%:
	dh $@ --buildsystem=pybuild

execute_before_dh_auto_configure:
	cargo prepare-debian debian/cargo_registry --link-from-system

execute_before_dh_auto_build:
	mv hypothesis/rust/Cargo.lock hypothesis/rust/Cargo.lock.saved
	cd hypothesis/rust && cargo generate-lockfile --offline

execute_after_dh_auto_build:
ifeq ($(filter nodoc,$(DEB_BUILD_PROFILES)),)
	PYTHONPATH=$(shell pybuild --print build_dir --interpreter python3) \
	HYPOTHESIS_FORCE_LOCAL=1 \
	    http_proxy='127.0.0.1:9' \
	    https_proxy='127.0.0.1:9' \
	    python3 -m sphinx -N -b html hypothesis/docs/ $(CURDIR)/.pybuild/docs/html/
endif

execute_before_dh_auto_clean:
	if [ -f hypothesis/rust/Cargo.lock.saved ]; then \
		mv hypothesis/rust/Cargo.lock.saved hypothesis/rust/Cargo.lock; \
	fi

execute_before_dh_installman:
	sed -e 's/@VERSION@/$(DEB_VERSION_UPSTREAM)/g' debian/hypothesis.1.in > debian/hypothesis.1

