#
# This file and its contents are supplied under the terms of the
# Common Development and Distribution License ("CDDL"), version 1.0.
# You may only use this file in accordance with the terms of version
# 1.0 of the CDDL.
#
# A full copy of the text of the CDDL should have accompanied this
# source.  A copy of the CDDL is also available via the Internet at
# http://www.illumos.org/license/CDDL.
#

#
# Copyright 2017, 2021 Gary Mills
# Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
#

%patch% 01-extdiff.patch
%patch% 02-journal.patch
%patch% 03-Timout.patch
%patch% 04-wait-on-file.patch
%patch% 05-_write_status.patch
%patch% 06-PYTHONPATH-insert.patch
%patch% 07-rmdir-EEXIST.patch
%patch% 08-rmdir-current.patch

%hook-begin%
LICENSE_FILE='COPYING'

%include-2%
COMPONENT_FMRI =		developer/versioning/mercurial
COMPONENT_CLASSIFICATION =	Development/Source Code Management

# This is a standalone application.  Since no other Python project depends on
# it we just provide single unversioned package.
SINGLE_PYTHON_VERSION = yes

TEST_STYLE = custom
%include-3%
# Build and install documentation
COMPONENT_POST_BUILD_ACTION += cd $(@D) ; $(ENV) $(COMPONENT_BUILD_ENV) $(GMAKE) doc ;
COMPONENT_POST_INSTALL_ACTION += cd $(@D) ; $(ENV) $(COMPONENT_INSTALL_ENV) $(GMAKE) DESTDIR=$(PROTO_DIR) PREFIX=$(USRDIR) install-doc ;

# This test fails with PYTHONPATH set
TEST_BLACKLIST += test-hghave.t
# https://bz.mercurial-scm.org/show_bug.cgi?id=6402
TEST_BLACKLIST += test-stdio.py
# https://bz.mercurial-scm.org/show_bug.cgi?id=6915
TEST_BLACKLIST += test-patchbomb.t
# https://bz.mercurial-scm.org/show_bug.cgi?id=6899
TEST_BLACKLIST += test-revlog-mmapindex.t
# https://bz.mercurial-scm.org/show_bug.cgi?id=6957
TEST_BLACKLIST += test-highlight.t

# Use bash in sh mode for the tests; using /bin/sh on Solaris hasn't always
# worked, and using /bin/bash doesn't always work, either.
# Test the bits from the proto area, rather than rebuilding.
COMPONENT_PRE_TEST_ACTION += \
	(cd $(BUILD_DIR); rm -f sh; ln -s /bin/bash sh; \
	printf "%s\n" $(TEST_BLACKLIST) > blacklist);

# see tests/README
COMPONENT_TEST_DIR =	$(@D)/tests
COMPONENT_TEST_ENV +=	TERM=dumb
COMPONENT_TEST_ENV +=	HGTEST_JOBS=$(or $(HGTEST_JOBS),1)
COMPONENT_TEST_ENV +=	PATH=$(PATH.gnu)
COMPONENT_TEST_CMD =	$(PYTHON)
COMPONENT_TEST_ARGS =	./run-tests.py \
			--verbose \
			--shell $(BUILD_DIR)/sh \
			--with-hg $(PROTOUSRBINDIR)/hg \
			--blacklist $(BUILD_DIR)/blacklist
COMPONENT_TEST_TARGETS =

# Random temporary directory
COMPONENT_TEST_TRANSFORMS += "-e 's|/tmp/hgtests\.[^ ]\{8\}|\$$(HGTMP)|g'"
# Sequential number of test working directory
COMPONENT_TEST_TRANSFORMS += "-e 's|\(/child\)[0-9]\{1,\}/|\1X/|g'"
# Daemon process PID
COMPONENT_TEST_TRANSFORMS += "-e 's/\([Dd]aemon process \)[0-9]\{1,\}/\1\$$(PID)/'"