Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 922649 - Bash associative arrays from eclasses are not available in ebuilds without declare -g
Summary: Bash associative arrays from eclasses are not available in ebuilds without de...
Status: RESOLVED INVALID
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:
 
Reported: 2024-01-21 21:54 UTC by Anna Vyalkova
Modified: 2024-01-22 01:12 UTC (History)
3 users (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 2024-01-21 21:54:56 UTC
Minimal ebuild example
======================

EAPI=8

inherit kde.org

SLOT=0

src_unpack() {
    echo "${KDE_ORG_CATEGORIES[@]}"
}


Minimal bash example
====================

==> first.sh <==
declare -A TEST=(
    [test]=123
)

==> second.sh <==
inherit() {
    source first.sh
}

==> third.sh <==
source second.sh
echo "${TEST[@]}"
Comment 1 Anna Vyalkova 2024-01-21 21:57:41 UTC
oops (still doesn't work)

==> third.sh <==
source second.sh
inherit
echo "${TEST[@]}"
Comment 2 Anna Vyalkova 2024-01-21 22:00:34 UTC
But if "first.sh" is sourced in the global scope (not in a function), "123" is
printed as expected.
Comment 3 Anna Vyalkova 2024-01-21 22:04:49 UTC
(Disregard the bash example, this "inherit()" function doesn't work for any
types of variables)
Comment 4 Ionen Wolkens gentoo-dev 2024-01-21 22:05:27 UTC
associative arrays from eclasses are only going to be readable with -g because of how eclasses are handled internally by portage

aka with: declare -gA KDE_ORG_CATEGORIES=( ... )
Comment 5 Ionen Wolkens gentoo-dev 2024-01-21 22:07:34 UTC
(not a problem when it's only used within global eclass scope, but when called inside phases the contents can be lost because it's treated like a local variable)
Comment 6 Anna Vyalkova 2024-01-21 22:09:59 UTC
(In reply to Ionen Wolkens from comment #5)
> (not a problem when it's only used within global eclass scope, but when
> called inside phases the contents can be lost because it's treated like a
> local variable)

BDEPEND="${KDE_ORG_CATEGORIES[@]}"

Also doesn't work.
Comment 7 Ionen Wolkens gentoo-dev 2024-01-21 22:11:37 UTC
(In reply to Anna Vyalkova from comment #6)
> (In reply to Ionen Wolkens from comment #5)
> > (not a problem when it's only used within global eclass scope, but when
> > called inside phases the contents can be lost because it's treated like a
> > local variable)
> 
> BDEPEND="${KDE_ORG_CATEGORIES[@]}"
> 
> Also doesn't work.
I said global eclass scope, not ebuild (the variables are local to inherit() or so)
Comment 8 Ionen Wolkens gentoo-dev 2024-01-21 22:13:44 UTC
In all, I don't think it's worth trying to change how portage handles inherits over just adding a -g when they're needed.
Comment 9 Anna Vyalkova 2024-01-21 22:16:34 UTC
(In reply to Ionen Wolkens from comment #8)
> In all, I don't think it's worth trying to change how portage handles
> inherits over just adding a -g when they're needed.

Thanks, completely missed this flag >_>
Comment 10 Ionen Wolkens gentoo-dev 2024-01-21 22:18:09 UTC
(In reply to Ionen Wolkens from comment #8)
> In all, I don't think it's worth trying to change how portage handles
> inherits over just adding a -g when they're needed.
and fwiw KDE_ORG_CATEGORIES does not need it, only used in eclass scope and is marked @INTERNAL

we *could* decide that all associative arrays in global eclass should be -g for consistency though, personally I used it in linux-mod-r1 given these internal variables needed to be accessed in phases
Comment 11 Ionen Wolkens gentoo-dev 2024-01-21 22:18:29 UTC
Oops, didn't mean to change state.