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

# This port deliberately does not use github.tarball_from archive because that
# does not provide us with the commit hash which we want to know.
# This block must be declared before the one declared by the github portgroup
# (which is included by the golang portgroup).
post-extract {
    global git_commit
    set dir [glob ${workpath}/*]
    regexp "/${github.author}-${github.project}-(\[0-9a-f\]+)$" ${dir} -> git_commit
    set fp [open ${workpath}/git_commit w]
    puts -nonewline ${fp} ${git_commit}
    close ${fp}
}

PortGroup           golang 1.0

go.setup            github.com/mongodb/mongo-tools 100.10.0
revision            0
checksums           rmd160  9318385ebd290a4525785f7ad0709d21238ae8a9 \
                    sha256  ffd0fc867a850a44e6e749e12c8fd0c52f7886a9dc17002f0ba99516d9a9a4ea \
                    size    5186983

categories          devel
maintainers         {ryandesign @ryandesign} openmaintainer
license             Apache-2

# On older OS versions, the go port uses an older version of go with which this
# port is not compatible.
platforms           {darwin >= 17}

description         utilities for working with mongodb databases: bsondump, \
                    mongoimport, mongoexport, mongodump, mongorestore, \
                    mongostat, mongofiles, mongooplog, mongotop

long_description    mongo-tools is a collection of utilities for working with \
                    mongodb databases: \
                    \
                    \n\n* bsondump: display BSON files in a human-readable format \
                    \n* mongoimport: Convert data from JSON, TSV or CSV and insert them into a collection \
                    \n* mongoexport: Write an existing collection to CSV or JSON format \
                    \n* mongodump: Dump MongoDB backups to disk in .BSON format \
                    \n* mongorestore: Restore MongoDB backups in .BSON format to a live database \
                    \n* mongostat: Monitor live MongoDB servers, replica sets, or sharded clusters \
                    \n* mongofiles: Read, write, delete, or update files in GridFS \
                    \n* mongotop: Monitor read/write activity on a mongo server \
                    \n* mongoreplay: Inspect and record commands sent to a MongoDB instance, and then replay the commands back onto another host at a later time

extract.rename      no
dist_subdir         ${name}

patchfiles          deployment_target.patch \
                    version.patch

post-patch {
    global git_commit
    if {![exists git_commit]} {
        set fp [open ${workpath}/git_commit r]
        set git_commit [read ${fp}]
        close ${fp}
    }
    reinplace -W ${worksrcpath} "s|@GIT_COMMIT@|${git_commit}|g" \
        buildscript/build.go \
        release/version/version.go
    reinplace -W ${worksrcpath} "s|@VERSION@|${version}|g" \
        release/version/version.go
}

build.cmd           ./make
build.target        build

destroot {
    copy {*}[glob ${worksrcpath}/bin/*] ${destroot}${prefix}/bin/

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