He's not dead, he's resting

EAPI 3: pkg_pretend

This is part of a series on EAPI 3.

EAPI 3 has a new phase function known as pkg_pretend. This can be used to carry out checks at pretend-install time, allowing many things that would otherwise abort in pkg_setup midway through the build process to be caught whilst the user is still at the terminal.

The default is to do nothing. Custom implementations might output warnings (which should be prefixed with the program name, to avoid confusion) or call die.

Care must be taken when writing pkg_pretend, since there is no guarantee that conditions that hold at that stage will also hold later on. Unless developers are absolutely certain they know what they are doing, all checks that aren’t merely checking USE flags of the active package should be repeated in pkg_setup later on — PMS deliberately doesn’t do much to restrict what could have changed between when pkg_pretend was run and when the main build starts, so it’s easiest to assume that pkg_pretend might not have been run at all.

For example, one might do something like this:

pkg_pretend() {
    if use foo && ! use bar ; then
        ewarn "${PF}: Support for foo requires bar enabled, but you have USE=\"foo -bar\"."
        ewarn "${PF}: foo support will not be enabled."


pkg_setup() {

check_foo_not_strict() {
    if grep --quiet '^STRICT' /etc/foo.conf 2>/dev/null ; then
        die "/etc/foo.conf sets foo to STRICT mode, which this build cannot support."

Note the check for foo not being strict being repeated. It’s possible that foo won’t be installed when pkg_pretend is run, but that it will have been installed and incorrectly configured by the time we reach our build.

Also note that there’s no environment saving for pkg_pretend. You can’t set variables in pkg_pretend and have them still around by pkg_setup. Nor are you allowed to modify the root filesystem or perform any action requiring privileges that would not be available in a normal phase.

pkg_pretend was originally an exheres-0 feature.


3 responses to “EAPI 3: pkg_pretend

  1. Pingback: What’s in EAPI 3? « Ciaran McCreesh’s Blag

  2. Nao February 26, 2010 at 7:38 am

    PMS-3 says that this function is only available in EAPI 4

    • Ciaran McCreesh February 26, 2010 at 8:08 am

      Yes, nearly everything that used to be in EAPI 3 got moved to EAPI 4, and EAPI 3 became something else. You can thank Portage for missing its original EAPI 3 implementation goal by six months.

Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s