# -*- 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           legacysupport 1.1
PortGroup           R 1.0

# strnlen, lutimes
# TARGET_OS_* macros
legacysupport.newest_darwin_requires_legacy 14

# Revert to GitHub once updated there.
R.setup             cran r-lib fs 1.6.5
revision            0
# libuv version used:
set uv_ver          1.44.2
categories-append   sysutils
maintainers         {@barracuda156 gmail.com:vital.had} openmaintainer
license             MIT
description         Cross-platform uniform interface to file system operations
long_description    fs provides a cross-platform, uniform interface to file system operations. \
                    It shares the same back-end component as nodejs, the libuv C library, \
                    which brings the benefit of extensive real-world use and rigorous cross-platform testing. \
                    The name, and some of the interface, is partially inspired by Rust’s fs module.
homepage            https://fs.r-lib.org
checksums           rmd160  3939e37843360e980cbccefe7b81f50ba1a4ae06 \
                    sha256  0e3b4d40215bee77b52d158a2e4967f4408721576aaf39bc6a77024522c70b34 \
                    size    1200455

patch.pre_args-replace  -p0 -p1
patchfiles          0001-fs-fix-libuv-for-10.7.patch \
                    0002-core.c-patch-close_nocancel.patch

if {${os.platform} eq "darwin" && ${os.major} < 15} {
    patchfiles-append \
                    0003-libuv-link-to-legacysupport.patch
    post-patch {
        # https://trac.macports.org/ticket/69853
        if {[string match *clang* ${configure.compiler}]} {
            reinplace "s|@MP_FLAGS@|-I${prefix}/include/LegacySupport -Wno-error=incompatible-function-pointer-types|" ${worksrcpath}/src/Makevars
        } else {
            reinplace "s|@MP_FLAGS@|-I${prefix}/include/LegacySupport|" ${worksrcpath}/src/Makevars
        }
    }
}

depends_test-append port:R-covr \
                    port:R-crayon \
                    port:R-knitr \
                    port:R-pillar \
                    port:R-rmarkdown \
                    port:R-spelling \
                    port:R-testthat \
                    port:R-tibble \
                    port:R-vctrs \
                    port:R-withr

test.run            yes
