The Portage cache
Portage uses a cache for most top-level variables (DEPEND
, DESCRIPTION
,
SRC_URI
and so on). This cache may be generated on a different machine, so
these variables must be either static or generated using only unchanging
'version / name' variables (P
, PN
, PV
, PR
, PVR
and PF
).
The cache, when generated, must be identical independent of the used machine or environment. This concept is referred to as metadata invariance.
So, the following will not work:
# DO NOT DO THIS!
if ! has_version "x11-libs/gtk+" ; then
DEPEND="${DEPEND}
gtk? ( >=x11-libs/gtk+-2 )
!gtk? ( =x11-libs/gtk+-1.2* )"
fi
However, the following is legal, since the ver_test
function works upon
PV
, and the PV
and PN
variables are both static:
if ver_test -ge 7.0 ; then
IUSE="${IUSE} tcltk mzscheme"
DEPEND="${DEPEND}
tcltk? ( dev-lang/tcl )
mzscheme? ( dev-lisp/mzscheme )"
RDEPEND="${RDEPEND}
tcltk? ( dev-lang/tcl )
mzscheme? ( dev-lisp/mzscheme )"
if [[ "${MY_PN}" != "vim-core" ]] ; then
RDEPEND="${RDEPEND} !<app-vim/align-30-r1"
fi
fi
Conditional inherits
Because eclasses modify various cached variables, conditional inheritance is not
allowed except where the same results will always be obtained on every system.
For example, inherits based upon USE
flags are illegal, but inherits based
solely upon the unchanging variables (e.g. PV
) mentioned above are
allowed.
As an example of a legal and possibly useful conditional inherit, some eclasses or ebuilds do:
if [[ ${PV} == 9999 ]]; then
inherit git-r3
EGIT_REPO_URI="https://anongit.gentoo.org/git/proj/devmanual.git"
else
SRC_URI="https://dev.gentoo.org/~ulm/distfiles/${P}.tar.xz"
KEYWORDS="~amd64 ~arm ~hppa ~ppc ~ppc64 ~sparc ~x86"
fi
This allows the same eclass (or the same ebuild "template") to be used for both regular and live packages.