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

github.setup        returntocorp semgrep 0.14.0 v
# Change github.tarball_from to 'releases' or 'archive' next update
github.tarball_from tarball

description         Fast and syntax-aware semantic code pattern search for \
                    many languages: like grep but for code.

long_description    semgrep is like grep but for code: it is a tool for \
                    easily detecting and preventing bugs and anti-patterns \
                    in your codebase. It combines the convenience of grep \
                    with the correctness of syntactical and semantic search.

maintainers         {gmail.com:herby.gillot @herbygillot} \
                    openmaintainer

categories          devel
license             LGPL-2.1

# Git repository needed as additional dependencies are provided as submodules.
fetch.type          git

depends_build       port:ocaml \
                    port:opam  \
                    port:pkgconfig

installs_libs       no
use_configure       no

post-fetch {
    system -W ${worksrcpath} "git submodule update --init --recursive"
}

build {
    set opam_env_file ${workpath}/opam.env
    set opam_install ". ${opam_env_file} && opam install -j ${build.jobs} -y"

    system -W ${workpath} "opam init -n --disable-sandboxing"
    system "opam env > ${opam_env_file}"

    system "${opam_install} yaml parmap dune-glob"
    system -W ${worksrcpath} "${opam_install} ./pfff"
    system -W ${worksrcpath}/semgrep-core ". ${opam_env_file} && ${build.cmd} all"
}

set sg_doc_dir      ${prefix}/share/doc/${name}

destroot {
    xinstall -m 755 ${worksrcpath}/semgrep-core/_build/default/bin/Main.exe \
                    ${destroot}${prefix}/bin/${name}

    file mkdir ${destroot}${sg_doc_dir}
    copy {*}[glob ${worksrcpath}/docs/*] ${destroot}${sg_doc_dir}/
}

github.livecheck.regex {([0-9.]+)}
