# -*- 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           golang 1.0

go.setup            github.com/herbygillot/dockhand 0.3.0 v
revision            0

description         A port maintenance utility for MacPorts

long_description    dockhand automates the mechanical part of maintaining a \
                    port: it bumps a port to a new upstream release, \
                    build-tests the change in a clean virtual machine or on \
                    GitHub Actions, and opens the pull request. Each step can \
                    be run on its own. When it cannot be sure of something it \
                    declines and says why, rather than guessing.

categories          sysutils macports
license             MIT
maintainers         {gmail.com:herby.gillot @herbygillot} openmaintainer

checksums           rmd160  4b31f241cd59042f137e1efaba7aeee4bc511579 \
                    sha256  3ff1fd0ffbabb42de54e66609cec047b30f731613ffac56ec804c1d0ee392c8f \
                    size    32139053

go.toolchain_min    1.27.1

# dockhand drives git itself, and needs Git 2.40 or newer, which the
# command-line tools' git on older macOS isn't; the rest of what it uses --
# MacPorts, a GitHub credential -- is found at runtime and reported when
# missing.
depends_run         port:git

# Verifying in a local VM needs tart, which runs only on Apple silicon,
# macOS 15 or later; elsewhere dockhand builds on GitHub Actions.
if {${os.platform} eq "darwin" && ${os.arch} eq "arm" && ${os.major} >= 24} {
    depends_run-append  port:tart
}

notes "
dockhand regenerates the dependency block of a port that has one, which needs
the matching generator installed:

    sudo port install cargo2port    # for Rust ports (cargo.crates)
    sudo port install go2port       # for Go ports (go.vendors)

Dockhand finds them in your PATH. Ports without a generated block need
neither.
"

# No go.vendors: the release tarball carries its own vendor directory.
build.args \
    -ldflags=-X=${go.package}/internal/buildinfo.Version=v${version} \
    ./cmd/dockhand

destroot {
    xinstall -m 0755 ${worksrcpath}/${name} ${destroot}${prefix}/bin/

    set docdir ${prefix}/share/doc/${name}
    xinstall -d ${destroot}${docdir}
    xinstall -m 0644 -W ${worksrcpath} LICENSE README.md ${destroot}${docdir}

    set completions [list \
        bash    share/bash-completion/completions/${name} \
        zsh     share/zsh/site-functions/_${name} \
        fish    share/fish/vendor_completions.d/${name}.fish]

    foreach {shell path} ${completions} {
        xinstall -d ${destroot}${prefix}/[file dirname ${path}]
        system -W ${worksrcpath} \
            "./${name} completion ${shell} > ${destroot}${prefix}/${path}"
    }
}
