# -*- 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 metadata 0.29.0 v
revision            0
name                py-${github.author}-${github.project}

platforms           darwin
license             Apache-2
maintainers         nomaintainer

description         Library and standards for schema and statistics.
long_description    TensorFlow Metadata provides standard representations \
                    for metadata that are useful when training machine \
                    learning models with TensorFlow.

homepage            https://github.com/tensorflow/metadata

checksums           rmd160  0a2f521f254c62a0d56547c997b606300210f2f8 \
                    sha256  414085638e580b5c5e2fab68d9f4c2e6dfaf1a51d03b027a30af41cf91e939f1 \
                    size    36167

python.versions     37 38 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

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

    depends_run-append \
                    port:py${python.version}-google-api \
                    port:py${python.version}-protobuf3

    # see ${worksrcpath}/bazel-bin/tensorflow_metadata/move_generated_files
    set bazel_build_workspace_path \
                    ${workpath}/build
    set bazel_build_proto_path \
                    ${bazel_build_workspace_path}/tensorflow_metadata/proto/v0
    
    post-extract {
        xinstall -d ${workpath}/bin ${bazel_build_proto_path}
        ln -s ${python.bin} ${workpath}/bin/python
    }

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

    build.env-append \
                    "PATH=${workpath}/bin:$env(PATH)"
    build.asroot    yes

    destroot.env-append \
                    "PATH=${workpath}/bin:$env(PATH)"
    destroot.asroot yes

    test.run        yes
    test.cmd        python${python.branch}
    test.target     ${github.author}_${github.project}/python/proto_test.py
    test.env-append 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
}
