Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 908552 - EBUILD_PHASE and EBUILD_PHASE_FUNC have bad values in global scope
Summary: EBUILD_PHASE and EBUILD_PHASE_FUNC have bad values in global scope
Status: CONFIRMED
Alias: None
Product: Portage Development
Classification: Unclassified
Component: Core - Ebuild Support (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Portage team
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 563798
  Show dependency tree
 
Reported: 2023-06-15 18:34 UTC by Ulrich Müller
Modified: 2024-03-03 17:30 UTC (History)
2 users (show)

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


Attachments
Test ebuild (foo-1.ebuild,377 bytes, text/plain)
2023-06-15 18:34 UTC, Ulrich Müller
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Ulrich Müller gentoo-dev 2023-06-15 18:34:01 UTC
Created attachment 863880 [details]
Test ebuild

According to PMS, when the ebuild is being sourced, variables EBUILD_PHASE and EBUILD_PHASE_FUNC must be either unset or set to a single word that is not the name of any phase (function).
https://projects.gentoo.org/pms/8/pms.html#x1-109001r1

With attached test ebuild, I get this output:

$ ebuild foo-1.ebuild unpack
*** begin global scope
EBUILD_PHASE      = pretend
EBUILD_PHASE_FUNC = pkg_pretend
*** end global scope
*** begin global scope
EBUILD_PHASE      = setup
EBUILD_PHASE_FUNC = pkg_setup
*** end global scope
>>> Unpacking source...
>>> Source unpacked in /tmp/portage/app-misc/foo-1/work
Comment 1 Ionen Wolkens gentoo-dev 2023-06-15 18:54:29 UTC
fwiw iwdevtools' portage-only bashrc files relies on EBUILD_PHASE being empty or unset to avoid qa-sed from being used when it shouldn't (potentially by portage internals), not that it's an issue once phases start being called so left-over value hasn't been a real "problem".

But being always unset/empty in non-phase scope would be more consistent, and potentially kill bit more misuse.

If set to non-empty if preferred (for some reason) like "global" then I'll need to do an update (which is fine).
Comment 2 Ulrich Müller gentoo-dev 2023-11-28 09:19:12 UTC
ping
Comment 3 Ionen Wolkens gentoo-dev 2024-02-20 11:42:26 UTC
Just to note that this may break existing /etc/portage/bashrc expectations. Came across [1] which noted that [2] has:

    It is important to note that this file will be sourced multiple
    times during the build, at least once per phase plus several
    other times. Therefore when code gets executed should be
    controlled using e.g. EBUILD_PHASE, EBUILD_PHASE_FUNC (EAPI 5),
    or otherwise avoid using the global scope by only putting code
    into hook functions (e.g. pre_pkg_setup()). See bug #250240.

I'd assume that fixing this will not allow the former to work anymore (which I'd agree shouldn't be used over pre/post_<phase> either way).

[1] https://forums.gentoo.org/viewtopic-p-8816876.html
[2] https://wiki.gentoo.org/wiki//etc/portage/bashrc#Multiple_calls
Comment 4 Ionen Wolkens gentoo-dev 2024-03-03 14:46:05 UTC
Had forgotten about these, but EBUILD_PHASE is also used in several profile.bashrc, e.g.

profiles/prefix/linux/profile.bashrc:if [[ ${EBUILD_PHASE} == setup ]]; then

And I do assume fixing this would break these too.

profile.bashrc is *not* a PMS thing and support and how to use them is  bit up in the air. Unsure if anything but portage tries to read these and if pre_pkg_setup and such could actually be used instead.
Comment 5 Ionen Wolkens gentoo-dev 2024-03-03 14:51:04 UTC
(In reply to Ionen Wolkens from comment #4)
> ... if pre_pkg_setup and such could actually be used instead.
(either way that would complicate things with redefinitions when there's multiple profile.bashrc loaded or even combined with user's which expect these to belong to them)
Comment 6 Larry the Git Cow gentoo-dev 2024-03-03 17:30:45 UTC
The bug has been referenced in the following commit(s):

https://gitweb.gentoo.org/proj/pms.git/commit/?id=ef9be7c2a696a476514de29e2f88df82f37f2ceb

commit ef9be7c2a696a476514de29e2f88df82f37f2ceb
Author:     Ulrich Müller <ulm@gentoo.org>
AuthorDate: 2024-02-22 17:19:40 +0000
Commit:     Ulrich Müller <ulm@gentoo.org>
CommitDate: 2024-02-22 17:19:40 +0000

    ebuild-env-vars.tex: EBUILD_PHASE{,_FUNC} are valid only in phases
    
    Portage didn't ever set (or unset) these variables to a special value
    when sourcing the ebuild, so obviously ebuilds cannot rely on this.
    Restrict their validity to actual phases and make global scope
    behaviour unspecified.
    
    The previous wording was introduced with commit 58d3bc0.
    
    Bug: https://bugs.gentoo.org/908552
    Signed-off-by: Ulrich Müller <ulm@gentoo.org>

 ebuild-env-vars.tex | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)