Part 9 Use Flags, Tests & Basic Dependencies

WARNING:
THESE ARE MY PERSONAL NOTES ON MY FIRST EBUILD.
THIS IS BY NO MEANS A USEFUL GUIDE OR ANYTHING SIMILAR TO ANYONE.
RTFM

I’ll try to write an ebuild from scratch and document the progress here.

Ebuild from scratch: Part 9 Use Flags, Tests & Basic Dependencies

MultiMarkdowns Installation guide mentioned “sub-modules”, xslt-support and tests.
Let’s include these features!

Documentation:
If something is not understood ==>: Gentoo Development Guide
And man ebuild!

Usefull Commands
ebuild pkg clean
ebuild pkg manifest
ebuild pkg test
emerge --config pkg

(Git-)Sub-Modules

Now this is really easy!
Just setting the varibale EGIT_HAS_SUBMODULES to a non-empty value triggers loading of git-sub-modules by the git-2.eclass.

EGIT_HAS_SUBMODULES="Y"

USE Flags

We define 3 USE flags in the ebuild file and document them in metadata.xml (see below).

IUSE="test latex xslt"

Dependencies

We could just force a dependency on perl, but since perl seems only required for latex/xslt-upport and the tests, this seems better:

# basic depenedencies
DEPEND=""
RDEPEND="${DEPEND}"

# conditional dependencies
DEPEND="${DEPEND}
    test? ( dev-lang/perl app-text/htmltidy )"
RDEPEND="${RDEPEND}
    latex? ( dev-lang/perl )
    xslt? ( dev-lang/perl )"
if use test || use latex || use xslt ; then
    # we also need the sub-modules, this triggers it in git-2.eclass
    EGIT_HAS_SUBMODULES="Y"
fi

So now for normal compilation, no dependency is triggered.
But if the test flag is set – or ebuild pkg.ebuild test is used – then dev-lang/perl and app-text/htmltidy are pulled in with MultiMarkdown.

And since running MultiMarkdown with latex or xslt support (USE flags latex/xslt) requires perl, dev-lang/perl is pulled in if one of these flags is set.

The last part (if use test || …) evaluates if flags are set and then sets the variable to trigger loading the sub-modules.
Otherwise the sub-modules are not pulled in.

Tests

Multimarkdowns Linux Installation guide mentions some tests.
The following code is a modified version of this example in the gentoo dev-guide.
It simply loops over the available tests in the Makefile.

src_test()
{
    einfo "Now running tests for package ${PN}"
    einfo "It is considered \"normal\" for some tests to fails, but at least one should pass ..."
    # the Makefile does not have a check-target, but let's leave it in here
    for test_phase in check test mmd-test compat-test latex-test ; do
        # only run the latex test with latex use flag
        if [ "$test_phase" != "latex-test" ] || use latex ; then
            if emake -j1 $test_phase -n &> /dev/null; then
                einfo ">>> Test phase 2 [${test_phase}]: ${CATEGORY}/${PF}"
                if ! emake -j1 $test_phase; then
                    hasq test $FEATURES && die "Make ${test_phase} failed. See above for details."
                    hasq test $FEATURES || eerror "Make ${test_phase} failed. See above for details."
                fi
            fi
        fi
    done
    einfo "Done running tests for package ${PN}"
}

Home: Ebuild From Scratch
Previous chapter: Part 8 Informative ebuild
Next chapter: … work in progress …

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: