# -*- 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           github 1.0
PortGroup           python 1.0

github.setup        tensorflow tfx-bsl 0.28.1 v
# Change github.tarball_from to 'releases' or 'archive' next update
github.tarball_from tarball
revision            0
name                py-${github.project}

license             Apache-2
maintainers         nomaintainer

description         TFX Basic Shared Libraries for TFX TensorFlow eXtended libraries \
                    and components.

long_description    {*}${description}

homepage            https://github.com/tensorflow/tfx-bsl

checksums           rmd160  20560d151b200b6ed2f82b1c5bbf1c1853a098e9 \
                    sha256  ef3566bc215e7391a514c0c2f88921ec973ac53bee2cbf6fdb0fd8f08355a513 \
                    size    230850

python.versions     39

proc python_listify {tcl_list} {
    set python_list {}
    foreach item [lreverse ${tcl_list}] {
        set python_list "'${item}', ${python_list}"
    }
    return ${python_list}
}

if {${name} ne ${subport}} {
    PortGroup       bazel 1.0

    bazel.version   3.7
    
    # Disable bazel configure and build phase configuration
    bazel.build_cmd
    bazel.configure_cmd

    # To find selected 'python3'
    bazel.path-append ${python.prefix}/bin

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

    depends_run-append \
                    port:py${python.version}-absl \
                    port:py${python.version}-apache-beam \
                    port:py${python.version}-avro \
                    port:py${python.version}-google-api \
                    port:py${python.version}-numpy \
                    port:py${python.version}-pandas \
                    port:py${python.version}-protobuf3 \
                    port:py${python.version}-pyarrow \
                    port:py${python.version}-six \
                    path:${python.pkgd}/tensorflow:py${python.version}-tensorflow \
                    port:py${python.version}-tensorflow-metadata

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

    # replace with patch files after this repo is a little more stable
    post-patch {
        reinplace -E "s|(self\\\._additional_build_options = \\\[)('--macos_minimum_os=\[\[:digit:].]+'])|\\1[python_listify [option bazel.build_opts]]\\2|" \
                    ${worksrcpath}/setup.py
        reinplace -E "s|\\\[(self\\\._bazel_cmd), 'run', '-c', 'opt'|\[\\1, [python_listify [option bazel.build_cmd_opts]] 'build'|" \
                    ${worksrcpath}/setup.py
    }

    build.asroot    yes

    test.run        yes
    test.cmd        py.test-${python.branch}
    test.target
    test.env-append "PATH=${workpath}/bin:$env(PATH)" \
                    PYTHONPATH=${worksrcpath}/build/lib

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

    livecheck.type  none
}
