Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 803140 - eclass-writing: explain use of @REQUIRED and @PRE_INHERIT
Summary: eclass-writing: explain use of @REQUIRED and @PRE_INHERIT
Status: UNCONFIRMED
Alias: None
Product: Documentation
Classification: Unclassified
Component: Devmanual (show other bugs)
Hardware: All Linux
: Normal enhancement
Assignee: Gentoo Devmanual Team
URL:
Whiteboard:
Keywords: NeedPatch
Depends on:
Blocks:
 
Reported: 2021-07-21 00:44 UTC by Anna Vyalkova
Modified: 2021-08-07 10:15 UTC (History)
1 user (show)

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Anna Vyalkova 2021-07-21 00:44:48 UTC
How should eclasses check whether required variables are set?
* [[ ! ${VAR} ]] && die "error message"
* ${VAR?error message} -- is that valid too?

Where should they do it?
* in functions (like ego_pn_check)
* in global scope before or after "if [[ ! ${_ECLASS} ]]" -- does it also have
  to be @PRE_INHERIT in this case?

Also I had a hard time understanding @PRE_INHERIT:
> This is important if any e.g. dependencies are modified in global scope at
> the point of sourcing

I still don't fully understand what does the location of variable in ebuild
(pre/post inherit) change.

An example featuring different combinations of those variables with
explanation would be helpful.

# FOO is pre-inherit and required because it's used by BAR in global scope:
BAR=${FOO////_}

# FOO_MODE and FOO_OPTIONAL are pre-inherit because they're used in
# _foo_set_globals(), called in global scope. Although none of them
# are required:
: ${FOO_TYPE:=native}
_foo_set_globals() {
	case ${FOO_TYPE} in
		wrapper) RDEPEND="example-misc/foo-wrapper" ;;
		native) ;;
		*) die
	esac
}
[[ ! ${FOO_OPTIONAL} ]] && _foo_set_globals

# FOO_DIRNAME is required but not pre-inherit because it's used
# in foo_src_install only
foo_src_install() {
	insinto /var/foo/${FOO_DIRNAME}
	doins ${BAR}.conf
}