Scope
Whenever an ebuild is sourced, the functions and variables within it are loaded into memory by the script interpreter. However, only variables and instructions that are not part of a function are interpreted - functions such as src_compile() are only executed by Portage when the ebuild has reached the compile stage.
The code within these functions are considered in "local scope" while everything outside of the functions is in the "global scope" meaning they are executed every time the ebuild is sourced.
An external application (such as grep, sed or awk) should never be called in global scope for performance reasons, and alternatives such as using built-in bash replacement should be used instead. Useful alternatives can be found in the Advanced Bash Scripting Guide.
Additionally, any external application that may be called in global scope can not be guaranteed to exist on the system. If the command is placed in local scope (for example, in the pkg_setup()
function), we can guarantee its presence by placing it in the ebuild's ${DEPEND}
.
What it means to ebuild to be sourced? Can it be the source command (btw I don't understand it, it was from and book and it doesn't have "man source".
Okay, variables - how they can be interpreted? I somehow understand how functions can. Functions probably are of some type of programming. It is compiled one or interpreted one. And if ebuild language is scripting (may be it is bash) - like pearl or python that is widely used in Gentoo Portage, how ebuild can contain compilation functions (I remember some from pascal from school).
And thus what is
src_compile()
function - it was not mentioned in revdel."compile stage" - what is this terminology is telling? Which are those ebuild stages, or stages of ebuild?
The same is about local/global scope. I completely don't understand, together with some internal applications - couldn't catch the thought also the opposite (awk..) are mentioned.
pkg_setup()
function,$DEPEND
- are those only example or imply implicit meanings?