commit:     93b5c17d2efab24c9535a563986aa757a4cc830b
Author:     Kerin Millar <kfm <AT> plushkava <DOT> net>
AuthorDate: Sat Jul 12 03:58:21 2025 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Tue Jul 22 22:25:39 2025 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=93b5c17d

Define four variables in the PORTAGE_ namespace as lowercase arrays

Presently, the "phase-functions.sh" unit defines the following four
scalar variables.

- PORTAGE_MUTABLE_FILTERED_VARS
- PORTAGE_SAVED_READONLY_VARS
- PORTAGE_READONLY_METADATA
- PORTAGE_READONLY_VARS

Their values are comprised by a whitespace-separated list of variable
names, which are referenced in as many as two ways. Firstly, by the
__filter_readonly_variables() function as the names of variables that
are to be filtered. Secondly, by the "ebuild.sh" utility as the names of
variables for which the readonly attribute should be set.

Given that none of these variables are used in any other capacity, and
that all are acting as mock-arrays, declare them as actual array
variables instead. That way, no word splitting need be performed, be it
with the aid of the read builtin or by way of an unquoted expansion. Two
instances of SC2086 are duly addressed.

Further, rename the variables so as to be in lower case. Given that it
is a widespread convention for environment variables to have names that
are entirely in upper case, this renders the provenance and purpose of
the variables clearer than would otherwise be the case. That is, none of
them are expected to:

- have been defined as an environment variable by the parent process
- be designated for exporting to subprocesses
- be referenced in any other capacity (such as by an ebuild or eclass)

Signed-off-by: Kerin Millar <kfm <AT> plushkava.net>
Signed-off-by: Sam James <sam <AT> gentoo.org>

 bin/ebuild.sh          |  2 +-
 bin/phase-functions.sh | 72 ++++++++++++++++++++++++++------------------------
 2 files changed, 39 insertions(+), 35 deletions(-)

diff --git a/bin/ebuild.sh b/bin/ebuild.sh
index ff2527146d..6a12d65a7c 100755
--- a/bin/ebuild.sh
+++ b/bin/ebuild.sh
@@ -761,7 +761,7 @@ if [[ ${EBUILD_PHASE} = depend ]] ; then
 else
        # Note: readonly variables interfere with __preprocess_ebuild_env(), so
        # declare them only after it has already run.
-       declare -r ${PORTAGE_READONLY_METADATA} ${PORTAGE_READONLY_VARS}
+       declare -r "${portage_readonly_metadata[@]}" 
"${portage_readonly_vars[@]}"
        if ___eapi_has_prefix_variables; then
                declare -r ED EPREFIX EROOT
        fi

diff --git a/bin/phase-functions.sh b/bin/phase-functions.sh
index 58904cd80e..ed64024da5 100644
--- a/bin/phase-functions.sh
+++ b/bin/phase-functions.sh
@@ -8,40 +8,43 @@
 # of ebuild.sh will work for pkg_postinst, pkg_prerm, and pkg_postrm
 # when portage is upgrading itself.
 
-PORTAGE_READONLY_METADATA="BDEPEND DEFINED_PHASES DEPEND DESCRIPTION
-       EAPI HOMEPAGE IDEPEND INHERITED IUSE REQUIRED_USE KEYWORDS LICENSE
-       PDEPEND RDEPEND REPOSITORY RESTRICT SLOT SRC_URI"
-
-PORTAGE_READONLY_VARS="D EBUILD EBUILD_PHASE EBUILD_PHASE_FUNC \
-       EBUILD_SH_ARGS ED EMERGE_FROM EROOT FILESDIR MERGE_TYPE \
-       PM_EBUILD_HOOK_DIR \
-       PORTAGE_ACTUAL_DISTDIR PORTAGE_ARCHLIST PORTAGE_BASHRC  \
-       PORTAGE_BINPKG_FILE PORTAGE_BINPKG_TAR_OPTS PORTAGE_BINPKG_TMPFILE \
-       PORTAGE_BIN_PATH PORTAGE_BUILDDIR PORTAGE_BUILD_GROUP \
-       PORTAGE_BUILD_USER \
-       PORTAGE_COLORMAP PORTAGE_CONFIGROOT \
-       PORTAGE_DEBUG PORTAGE_DEPCACHEDIR PORTAGE_EBUILD_EXIT_FILE \
-       PORTAGE_EBUILD_EXTRA_SOURCE \
-       PORTAGE_ECLASS_LOCATIONS PORTAGE_EXPLICIT_INHERIT \
-       PORTAGE_GID PORTAGE_GRPNAME PORTAGE_INST_GID PORTAGE_INST_UID \
-       PORTAGE_INTERNAL_CALLER PORTAGE_IPC_DAEMON PORTAGE_IUSE 
PORTAGE_LOG_FILE \
-       PORTAGE_MUTABLE_FILTERED_VARS PORTAGE_OVERRIDE_EPREFIX 
PORTAGE_PROPERTIES \
-       PORTAGE_PYM_PATH PORTAGE_PYTHON PORTAGE_PYTHONPATH \
-       PORTAGE_READONLY_METADATA PORTAGE_READONLY_VARS \
-       PORTAGE_REPO_NAME PORTAGE_REPOSITORIES PORTAGE_RESTRICT \
-       PORTAGE_SAVED_READONLY_VARS PORTAGE_SIGPIPE_STATUS \
-       PORTAGE_TMPDIR PORTAGE_UPDATE_ENV PORTAGE_USERNAME \
-       PORTAGE_VERBOSE PORTAGE_WORKDIR_MODE PORTAGE_XATTR_EXCLUDE \
-       REPLACING_VERSIONS REPLACED_BY_VERSION T WORKDIR \
-       __PORTAGE_HELPER __PORTAGE_TEST_HARDLINK_LOCKS"
-
-PORTAGE_SAVED_READONLY_VARS="A CATEGORY P PF PN PR PV PVR"
+portage_readonly_metadata=(
+       BDEPEND DEFINED_PHASES DEPEND DESCRIPTION EAPI HOMEPAGE IDEPEND
+       INHERITED IUSE REQUIRED_USE KEYWORDS LICENSE PDEPEND RDEPEND REPOSITORY
+       RESTRICT SLOT SRC_URI
+)
+
+portage_readonly_vars=(
+       D EBUILD EBUILD_PHASE EBUILD_PHASE_FUNC EBUILD_SH_ARGS ED EMERGE_FROM
+       EROOT FILESDIR MERGE_TYPE PM_EBUILD_HOOK_DIR PORTAGE_ACTUAL_DISTDIR
+       PORTAGE_ARCHLIST PORTAGE_BASHRC PORTAGE_BINPKG_FILE
+       PORTAGE_BINPKG_TAR_OPTS PORTAGE_BINPKG_TMPFILE PORTAGE_BIN_PATH
+       PORTAGE_BUILDDIR PORTAGE_BUILD_GROUP PORTAGE_BUILD_USER
+       PORTAGE_COLORMAP PORTAGE_CONFIGROOT PORTAGE_DEBUG PORTAGE_DEPCACHEDIR
+       PORTAGE_EBUILD_EXIT_FILE PORTAGE_EBUILD_EXTRA_SOURCE
+       PORTAGE_ECLASS_LOCATIONS PORTAGE_EXPLICIT_INHERIT PORTAGE_GID
+       PORTAGE_GRPNAME PORTAGE_INST_GID PORTAGE_INST_UID
+       PORTAGE_INTERNAL_CALLER PORTAGE_IPC_DAEMON PORTAGE_IUSE
+       PORTAGE_LOG_FILE PORTAGE_OVERRIDE_EPREFIX PORTAGE_PROPERTIES
+       PORTAGE_PYM_PATH PORTAGE_PYTHON PORTAGE_PYTHONPATH PORTAGE_REPO_NAME
+       PORTAGE_REPOSITORIES PORTAGE_RESTRICT PORTAGE_SIGPIPE_STATUS
+       PORTAGE_TMPDIR PORTAGE_UPDATE_ENV PORTAGE_USERNAME PORTAGE_VERBOSE
+       PORTAGE_WORKDIR_MODE PORTAGE_XATTR_EXCLUDE REPLACING_VERSIONS
+       REPLACED_BY_VERSION T WORKDIR __PORTAGE_HELPER
+       __PORTAGE_TEST_HARDLINK_LOCKS portage_mutable_filtered_vars
+       portage_saved_readonly_vars portage_readonly_metadata
+       portage_readonly_vars
+)
+
+portage_saved_readonly_vars=(
+       A CATEGORY P PF PN PR PV PVR
+)
 
 # Variables that portage sets but doesn't mark readonly.
 # In order to prevent changed values from causing unexpected
 # interference, they are filtered out of the environment when
 # it is saved or loaded (any mutations do not persist).
-PORTAGE_MUTABLE_FILTERED_VARS="AA HOSTNAME"
+portage_mutable_filtered_vars=( AA HOSTNAME )
 
 # @FUNCTION: __filter_readonly_variables
 # @DESCRIPTION: [--filter-sandbox] [--allow-extra-vars]
@@ -84,7 +87,7 @@ PORTAGE_MUTABLE_FILTERED_VARS="AA HOSTNAME"
 # is to preserve various variables as they were at the time that the binary
 # package was built while protecting against the application of package 
renames.
 __filter_readonly_variables() {
-       local -a {binpkg_untrusted,filtered_sandbox,misc_garbage,bash}_vars 
words
+       local -a {binpkg_untrusted,filtered_sandbox,misc_garbage,bash}_vars
        local IFS
 
        # Collect an initial list of special bash variables by instructing a
@@ -123,11 +126,10 @@ __filter_readonly_variables() {
        misc_garbage_vars=(
                _portage_filter_opts
        )
-       read -rd '' -a words <<<"${PORTAGE_READONLY_VARS}"
        filtered_vars+=(
+               "${portage_readonly_vars[@]}"
                "${misc_garbage_vars[@]}"
                "${bash_vars[@]}"
-               "${words[@]}"
                "___.*"
        )
 
@@ -174,8 +176,10 @@ __filter_readonly_variables() {
                # excluding untrusted variables.
                filtered_vars+=( "${binpkg_untrusted_vars[@]}" )
        else
-               read -rd '' -a words <<<"${PORTAGE_SAVED_READONLY_VARS} 
${PORTAGE_MUTABLE_FILTERED_VARS}"
-               filtered_vars+=( "${words[@]}" )
+               filtered_vars+=(
+                       "${portage_mutable_filtered_vars[@]}"
+                       "${portage_saved_readonly_vars[@]}"
+               )
        fi
 
        "${PORTAGE_PYTHON:-/usr/bin/python}" 
"${PORTAGE_BIN_PATH}"/filter-bash-environment.py "${filtered_vars[*]}" \

Reply via email to