
# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4

PortSystem          1.0
PortGroup           python 1.0
PortGroup           app 1.0
PortGroup           gitlab 1.0

# NB: only update non-patch releases when updating Mercurial as well, as
# TortoiseHg generally does not retain compatibility
gitlab.instance     https://foss.heptapod.net
gitlab.setup        mercurial/tortoisehg thg 7.0.1
revision            1
checksums           rmd160  6548bf2e9634be2cb3c4dec3469e8d565f0429b3 \
                    sha256  4e738bcaa37d5713a876669dceb89e38670da6b37a290e52e0e5a5098f965790 \
                    size    7667925

name                tortoisehg
categories          devel python
license             GPL-2+
maintainers         nomaintainer
supported_archs     noarch

description         A set of graphical tools for Mercurial

long_description    A set of graphical tools for the Mercurial distributed \
                    source control management system.

# must be same as Mercurial
python.default_version 313

# we use qt5 only if macOS is 10.12 or later
# as defined on qt5 port
if {${os.platform} eq "darwin" && ${os.major} < 16} {
    set qt_version 4
} else {
    set qt_version 5
}

depends_lib-append  port:mercurial \
                    port:py${python.version}-iniparse \
                    port:py${python.version}-pyqt${qt_version}

if {${qt_version} == 4} {
    depends_lib-append \
                    port:py${python.version}-qscintilla-qt4
} else {
    depends_lib-append \
                    port:py${python.version}-pyqt5-scintilla
}

depends_build-append port:py${python.version}-sphinx

depends_test-append port:py${python.version}-mock \
                    port:py${python.version}-pynose \
                    port:py${python.version}-pytest

build.env-append    THG_QT_API=PyQt${qt_version}

test.run            yes
test.cmd            ${python.bin} ./tests/run-tests.py \
                    --tmpdir=${workpath}/testtmp \
                    --verbose
test.target

pre-test {
    delete ${workpath}/testtmp
}

post-extract {
    copy ${filespath}/config.py ${worksrcpath}/tortoisehg/util/
    reinplace -W ${worksrcpath} "s,pyrcc${qt_version},pyrcc${qt_version}-${python.branch},g" setup.py
    delete file ${worksrcpath}/hgext3rd/__init__.py
}

post-patch {
    reinplace "s|{prefix}|${prefix}|" ${worksrcpath}/tortoisehg/util/config.py
    reinplace "s|{python.prefix}|${python.prefix}|" ${worksrcpath}/tortoisehg/util/config.py

    foreach f [glob -types {f x} \
                   ${worksrcpath}/thg \
                   ${worksrcpath}/contrib/hg \
                   ${worksrcpath}/contrib/*.py \
                   ${worksrcpath}/i18n/*.py] {
        reinplace "s,#! */usr/bin/env python,#!${python.bin}," $f
    }

    # fix version detection
    set versionpath ${worksrcpath}/tortoisehg/util/__version__.py
    copy ${filespath}/__version__.py ${versionpath}
    reinplace "s/__VERSION__/${version}/" ${versionpath}
}

post-destroot {
    system -W ${worksrcpath}/doc "make SPHINXBUILD=sphinx-build-${python.branch} html"
    copy ${worksrcpath}/doc/build/html ${destroot}${prefix}/share/doc/${name}/html

    xinstall -m 644 -W ${worksrcpath} COPYING.txt ${destroot}${prefix}/share/doc/${name}
}

app.name            TortoiseHg
app.executable      ${python.prefix}/bin/thg
app.icon            icons/svg/thg_logo.svg

# suppress release candidates
gitlab.livecheck.branch \
    "default"
gitlab.livecheck.regex \
    (\[0-9.]+)
