Recover Skipped Phases in a Portfile

Introduction

The ruby-1.0 PortGroup has a special fetch mode that allows us to customize the build while handling subports and the ${ruby.suffix} variable itself. For example:

PortGroup           ruby 1.0

ruby.branches       2.6 2.5 2.4
ruby.setup          ronn-ng 0.8.2 fetch

However, the fetch mode (called type in the PortGroup) clears the build phase. So how could we make MacPorts run build.cmd while using this PortGroup?

fetch {
    # do nothing but fetch and extract - for strange installers
    build {}
}

Solution

There is a mysterious piece of code in gem mode (same PortGroup). It’s a command_exec call in destroot {...}.

destroot {
    command_exec destroot
    ...
}

Looking up a bit we can see that destroot.cmd is set in gem mode, but the destroot phase is overridden by destroot {...}.

destroot.cmd    ${ruby.gem}
destroot.target install
destroot.args   --local --force --install-dir ${destroot}${ruby.gemdir}
destroot.env-append rake=${ruby.rake}
destroot.post_args ${worksrcpath}/${ruby.filename}.gem

Bingo! All we need is the following piece of code to re-enable the build phase.

build {
    command_exec build
}