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

PortSystem          1.0
PortGroup           github 1.0
PortGroup           ruby 1.0

ruby.branches       3.3 3.2 3.1
ruby.setup          heroku 3.99.4 fetch
# Tarball from rubygems is broken.
github.setup        heroku legacy-cli 43f30ff309334c50332876bb5a27511455fa85e7
version             3.99.4
revision            0
checksums           rmd160  52491c72bfe06bfcb588d94dfef95a048ec0bd71 \
                    sha256  8e142cc4559fd29f29a87166c9375ebbd5dc448196afba06da13732fe310fb97 \
                    size    1113502
github.tarball_from archive

maintainers         nomaintainer
categories-append   www devel
license             MIT
description         Legacy client library and CLI to deploy Rails apps \
                    on Heroku
long_description    {*}${description}
homepage            https://heroku.com

if {${name} ne ${subport}} {
    depends_lib-append \
                    port:rb${ruby.suffix}-heroku-api \
                    port:rb${ruby.suffix}-json \
                    port:rb${ruby.suffix}-launchy \
                    port:rb${ruby.suffix}-multi_json \
                    port:rb${ruby.suffix}-net-ssh \
                    port:rb${ruby.suffix}-net-ssh-gateway \
                    port:rb${ruby.suffix}-netrc \
                    port:rb${ruby.suffix}-rest-client \
                    port:rb${ruby.suffix}-rubyzip

    patchfiles      patch-gemspec.diff \
                    patch-fix-archs.diff

    post-patch {
        fs-traverse f ${worksrcpath} {
            # https://github.com/beefproject/beef/pull/2740
            if {[string match *.rb ${f}] || [string match *.rake ${f}]} {
                reinplace -q "s|exists\?|exist\?|g" ${f}
            }
            if {[string match ${ruby.module} ${f}]} {
                reinplace -q "s|/usr/bin/env ruby|${ruby.bin}|" ${f}
            }
        }
    }

    use_configure   no

    build.cmd       ${ruby.gem}
    build.target    build
    build.args      ${ruby.module}.gemspec

    build {
        command_exec build
    }

    destroot.cmd        ${ruby.gem}
    destroot.target     install
    destroot.args       --local --force --install-dir ${destroot}${ruby.gemdir}
    destroot.env-append rake=${ruby.rake}
    destroot.post_args  heroku-${version}.gem

    destroot {
        command_exec destroot

        set binDir ${destroot}${ruby.gemdir}/bin
        if {[file isdirectory $binDir]} {
            foreach file [readdir $binDir] {
                file copy [file join $binDir $file] ${destroot}${ruby.bindir}
            }
        }
        foreach dir {data lib resources spec tasks} {
            copy ${worksrcpath}/${dir} \
                ${destroot}${ruby.gemdir}/gems/${ruby.module}-${version}/
        }
    }
}
