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

name                terragrunt
categories          sysutils
license             MIT
platforms           darwin linux
homepage            https://terragrunt.gruntwork.io

maintainers         {mjrc.nl:macports @mjrc} \
                    openmaintainer

# *NOTE* Remember to update `latestVersion` on a version upgrade.
set latestVersion       terragrunt-0.52
set newBuildType        false

subport terragrunt-0.52 {
    set dependsOn       1.6
    set patchNumber     1
    set newBuildType    true

    checksums           rmd160  fd155f71e3d30158bb028527be23152ef751548b \
                        sha256  ff25fe2b7fd7ca25a563b1686cb1cab5af2c51b850a0015851c6d9c56a7e4eaa \
                        size    2370161
}

subport terragrunt-0.43 {
    set dependsOn       1.2
    set patchNumber     2

    checksums           rmd160  b7b4643a3b78e7145475b7ada30eade4c9c0c80f \
                        sha256  dcfa20ee66ce9001abdde949a2768be88ed45b551b6a4a165b9a62968b7dd61d \
                        size    2316909
}

subport terragrunt-0.42 {
    set dependsOn       1.2
    set patchNumber     8

    checksums           rmd160  d85c229a2cd33551310159106f0ee6c91ed8d0b1 \
                        sha256  fb211253b52e4280195db078917085ffca9cae1aa043fefd02bdfa96d5a7aa72 \
                        size    2316370
}

subport terragrunt-0.41 {
    set dependsOn       1.2
    set patchNumber     0

    checksums           rmd160  9e1104bcea6754c4f6ac2ada3cce99465cb8c4b2 \
                        sha256  679f6cbb943bdbd4aa45fca499e685e68aa8e5bdf4c9ae8aee1831afd9dd631c \
                        size    2307873
}

subport terragrunt-0.40 {
    set dependsOn       1.2
    set patchNumber     2

    checksums           rmd160  355f4c2461e06d21e55fbaf6a959246a5ac86148 \
                        sha256  dcc89a20e348f3d966d0c9977417b5d7e0de697dbd9fef1ac6b5663e9671c659 \
                        size    2310897
}

subport terragrunt-0.39 {
    set dependsOn       1.2
    set patchNumber     2

    checksums           rmd160  6c452e832c090eedb9310bd0e38ab167181093db \
                        sha256  0ab829f74d6942c00d882e6e412799d1e176c769e32833a86f824c2ad21a6d44 \
                        size    2308823
}

subport terragrunt-0.38 {
    set dependsOn       1.2
    set patchNumber     12

    checksums           rmd160  89ffa2c0cf99dbd3aa82294eebe9e2530a56e769 \
                        sha256  bcb7e5396948c65895d87780bfcc257ca1e9cb44c9e37fdb1c1d18e892fafeda \
                        size    2307124
}

subport terragrunt-0.37 {
    set dependsOn       1.1
    set patchNumber     4

    checksums           rmd160  05c2c7f530cf1057c7a1cae0617fffb0ca353c16 \
                        sha256  b2dc6468535e057cf01b7aa5d6b40c74717e0c3b5501a14bb8bb4420136e0a52 \
                        size    2292470
}

subport terragrunt-0.36 {
    set dependsOn       1.1
    set patchNumber     12

    checksums           rmd160  83934e8373eda08aa64391031975195bc059ce6c \
                        sha256  91a6f41056971d231de1b0786ee92019608cda9aa1066fe66119dafd94919024 \
                        size    2288539
}

subport terragrunt-0.35 {
    set dependsOn       1.0
    set patchNumber     20

    checksums           rmd160  5e29cc8cb9adee6612bd76fb7405027231548cd0 \
                        sha256  4b3ea8406e2a42e066148a073cba3413be65f2edb0e4e528d033533774aeefa3 \
                        size    2281426
}

subport terragrunt-0.34 {
    set dependsOn       1.0
    set patchNumber     3

    checksums           rmd160  87f15774fe41a8e2ebe893ce5cfd19dfb813cfc8 \
                        sha256  8885e91d853d9f2284fa6e11d88160d040130cb547595f2f90ad34a1e9fd115f \
                        size    2268245
}

subport terragrunt-0.33 {
    set dependsOn       1.0
    set patchNumber     2

    checksums           rmd160  783302b6ca6845d8743e8cf0ad3da071877e4f76 \
                        sha256  567b61a8f4a739f115e980ee665773584ffe8b01ae306f0dd13b7d0d6c341105 \
                        size    2264318
}

subport terragrunt-0.32 {
    set dependsOn       1.0
    set patchNumber     6

    checksums           rmd160  20a04e3d928d06565327f37e5bed5117ff7d6031 \
                        sha256  a58e87b8a99e3adbfdde5807453236dccd1186e1d100e33aa546d3cecea6b985 \
                        size    2259950
}

subport terragrunt-0.31 {
    set dependsOn       1.0
    set patchNumber     11

    checksums           rmd160  b18d043e757af99213c4668b57f28f2217b4941f \
                        sha256  9ebde9edc147121fada2ecdcb90fd21b67592ee13720401835ed7dae3a1bb091 \
                        size    2246065
}

subport terragrunt-0.29 {
    set dependsOn       0.15
    set patchNumber     4

    checksums           rmd160  26ac8c2618aa7ca869ee45dc8eb55027e2f75159 \
                        sha256  4ee3db5390f93bfe43b49f45a2904d9ebe91179a1d154beb8b43a0a24ba650c3 \
                        size    2232674
}

subport terragrunt_select {}

if {${subport} == ${name}} {
    PortGroup           obsolete 1.0

    replaced_by         ${latestVersion}
    version             0.27.0
    revision            0

} elseif {${subport} eq "terragrunt_select"} {
    version             0.0.0
    revision            0
    supported_archs     noarch
    platforms           any

    description         Common files for selecting the default terragrunt \
                        version
    long_description    This port installs files that allow 'port select' \
                        to create links to the preferred default version \
                        of terragrunt.
    homepage            https://www.macports.org/
    
    conflicts           tenv

    distfiles
    use_configure       no
    build {}

    destroot {
        select::install terragrunt ${filespath}/base
        select::install terragrunt ${filespath}/none
    }

    livecheck.type     none

} else {

    PortGroup           golang 1.0

    supported_archs     x86_64 arm64

    depends_run         port:terragrunt_select port:terraform-${dependsOn}

    set baseVersion     [lindex [split ${subport} "-"] 1]
    set patchVersion    ${baseVersion}.${patchNumber}
    set baseName        terragrunt${baseVersion}

    go.setup            github.com/gruntwork-io/terragrunt ${patchVersion} v
    # Delete this on next update to use golang PortGroup's default ('archive')
    github.tarball_from tarball

    description         Terragrunt is a thin wrapper for Terraform
    long_description    ${description} that provides extra tools for working \
                        with multiple Terraform modules.

    if (${newBuildType}) {
        set go_ldflags      "-X github.com/gruntwork-io/go-commons/version.Version=${patchVersion}"
        patchfiles          patch-options.go.52.diff
    } else {
        set go_ldflags      "-X main.VERSION=${patchVersion}"
        patchfiles          patch-options.go.diff
    }

    # FIXME: This port currently can't be built without allowing go mod to fetch
    # dependencies during the build phase. See
    # https://trac.macports.org/ticket/61192
    go.offline_build no
    build.args          -ldflags \"${go_ldflags}\" -o ${baseName} ${go.package}

    post-patch {
        reinplace "s|@@TERRAFORM_BIN@@|terraform${dependsOn}|g" ${worksrcpath}/options/options.go
    }

    post-build {
        file copy ${filespath}/terragruntX.YY.template ${workpath}/${baseName}
        reinplace "s|@@BASE_VERSION@@|${baseVersion}|g" ${workpath}/${baseName}
    }

    destroot {
        xinstall -m 755 ${worksrcpath}/${baseName} ${destroot}${prefix}/bin/${baseName}
    }

    select.group        terragrunt
    select.file         ${workpath}/${baseName}

    notes "
    To make this the default terragrunt run:
        sudo port select --set terragrunt ${baseName}
    "


}
