Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 69842 - Ebuild policy doesnt mention anything about Global scope
Summary: Ebuild policy doesnt mention anything about Global scope
Status: RESOLVED FIXED
Alias: None
Product: [OLD] Docs-developer
Classification: Unclassified
Component: Contributing ebuilds (show other bugs)
Hardware: All All
: High normal (vote)
Assignee: Gentoo Community Relations Team
URL:
Whiteboard: Review
Keywords:
Depends on:
Blocks:
 
Reported: 2004-11-02 08:03 UTC by REdOG
Modified: 2004-12-04 02:53 UTC (History)
0 users

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 REdOG 2004-11-02 08:03:04 UTC
Only since the latest release of portage warns, "QA Notice: $command in global scope:", have I come to realize that I haven't been submitting proper ebuilds.

Before submitting any, I had read the ebuild policy and thought my ebuilds decent enough to submit. It would have been nice to know that global scope is bad. So I think its worth mentioning in the handbook's ebuild policy section.
Comment 1 Tim Yamin (RETIRED) gentoo-dev 2004-11-13 10:38:47 UTC
Suggested text, please comment:

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.

Such functions are in "local scope", while variables and instructions are in "global scope", meaning that they are executed each time the ebuild is read by the interpreter.

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.

Additionally, any external application that may be called in global scope can not be guaranteed to exist on the system, while in local scope (for example, in the pkg_setup() function) this possibility is less likely since the needed application could be installed via ${DEPEND}, for example.
Comment 2 Jeremy Huddleston (RETIRED) gentoo-dev 2004-11-27 14:24:58 UTC
Just a couple suggestions

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.  Most useful alternatives can be found in the Advanced Bash Scripting Guide (http://www.tldp.org/LDP/abs/html/).

Additionally, any external application that may be called in global scope can not be guaranteed to exist on the system.  If the action is placed in local scope (for example, in the pkg_setup() function), we can gurantee its presence by placing it in the ebuild's ${DEPEND}.
Comment 3 Tim Yamin (RETIRED) gentoo-dev 2004-12-04 02:53:17 UTC
In CVS, update should reach the web nodes within a few hours. Please reopen this bug if you have any problems. Thanks!