public inbox for gentoo-portage-dev@lists.gentoo.org
 help / color / mirror / Atom feed
Search results ordered by [date|relevance]  view[summary|nested|Atom feed]
thread overview below | download: 
* [gentoo-portage-dev] [PATCH 1/4] Prefix color vars with "PORTAGE_COLOR_"
  @ 2021-09-28 14:20 99% ` Michał Górny
  0 siblings, 0 replies; 1+ results
From: Michał Górny @ 2021-09-28 14:20 UTC (permalink / raw
  To: gentoo-portage-dev; +Cc: Michał Górny

Rename color variables used by einfo etc. to use "PORTAGE_COLOR_"
prefix.  Currently these variables are prone to being accidentally
ovewritten e.g. if an ebuild uses GOOD or BAD variables for some
purpose.  Using PORTAGE prefix should keep us safe.

As an extra benefit, this makes it trivial to grep for all uses of color
variables.

Signed-off-by: Michał Górny <mgorny@gentoo.org>
---
 bin/install-qa-check.d/10ignored-flags |  4 +--
 bin/isolated-functions.sh              | 42 +++++++++++++-------------
 bin/save-ebuild-env.sh                 | 16 +++++-----
 lib/portage/output.py                  |  4 +--
 4 files changed, 34 insertions(+), 32 deletions(-)

diff --git a/bin/install-qa-check.d/10ignored-flags b/bin/install-qa-check.d/10ignored-flags
index 89706cd4c..7cd073578 100644
--- a/bin/install-qa-check.d/10ignored-flags
+++ b/bin/install-qa-check.d/10ignored-flags
@@ -52,7 +52,7 @@ ignored_flag_check() {
 			f=$(<"${T}"/scanelf-ignored-CFLAGS.log)
 			if [[ -n ${f} ]] ; then
 				__vecho -ne '\n'
-				eqawarn "${BAD}QA Notice: Files built without respecting CFLAGS have been detected${NORMAL}"
+				eqawarn "${PORTAGE_COLOR_BAD}QA Notice: Files built without respecting CFLAGS have been detected${PORTAGE_COLOR_NORMAL}"
 				eqawarn " Please include the following list of files in your report:"
 				eqawarn "${f}"
 				__vecho -ne '\n'
@@ -82,7 +82,7 @@ ignored_flag_check() {
 			f=$(<"${T}"/scanelf-ignored-LDFLAGS.log)
 			if [[ -n ${f} ]] ; then
 				__vecho -ne '\n'
-				eqawarn "${BAD}QA Notice: Files built without respecting LDFLAGS have been detected${NORMAL}"
+				eqawarn "${PORTAGE_COLOR_BAD}QA Notice: Files built without respecting LDFLAGS have been detected${PORTAGE_COLOR_NORMAL}"
 				eqawarn " Please include the following list of files in your report:"
 				eqawarn "${f}"
 				__vecho -ne '\n'
diff --git a/bin/isolated-functions.sh b/bin/isolated-functions.sh
index 5630dcf4c..3e79ea6e3 100644
--- a/bin/isolated-functions.sh
+++ b/bin/isolated-functions.sh
@@ -255,7 +255,7 @@ __elog_base() {
 			shift
 			;;
 		*)
-			__vecho -e " ${BAD}*${NORMAL} Invalid use of internal function __elog_base(), next message will not be logged"
+			__vecho -e " ${PORTAGE_COLOR_BAD}*${PORTAGE_COLOR_NORMAL} Invalid use of internal function __elog_base(), next message will not be logged"
 			return 1
 			;;
 	esac
@@ -270,7 +270,7 @@ eqawarn() {
 	__elog_base QA "$*"
 	[[ ${RC_ENDCOL} != "yes" && ${LAST_E_CMD} == "ebegin" ]] && echo >&2
 	echo -e "$@" | while read -r ; do
-		echo " $WARN*$NORMAL $REPLY" >&2
+		echo " ${PORTAGE_COLOR_WARN}*${PORTAGE_COLOR_NORMAL} ${REPLY}" >&2
 	done
 	LAST_E_CMD="eqawarn"
 	return 0
@@ -280,7 +280,7 @@ elog() {
 	__elog_base LOG "$*"
 	[[ ${RC_ENDCOL} != "yes" && ${LAST_E_CMD} == "ebegin" ]] && echo >&2
 	echo -e "$@" | while read -r ; do
-		echo " $GOOD*$NORMAL $REPLY" >&2
+		echo " ${PORTAGE_COLOR_GOOD}*${PORTAGE_COLOR_NORMAL} ${REPLY}" >&2
 	done
 	LAST_E_CMD="elog"
 	return 0
@@ -290,7 +290,7 @@ einfo() {
 	__elog_base INFO "$*"
 	[[ ${RC_ENDCOL} != "yes" && ${LAST_E_CMD} == "ebegin" ]] && echo >&2
 	echo -e "$@" | while read -r ; do
-		echo " $GOOD*$NORMAL $REPLY" >&2
+		echo " ${PORTAGE_COLOR_GOOD}*${PORTAGE_COLOR_NORMAL} ${REPLY}" >&2
 	done
 	LAST_E_CMD="einfo"
 	return 0
@@ -299,7 +299,7 @@ einfo() {
 einfon() {
 	__elog_base INFO "$*"
 	[[ ${RC_ENDCOL} != "yes" && ${LAST_E_CMD} == "ebegin" ]] && echo >&2
-	echo -ne " ${GOOD}*${NORMAL} $*" >&2
+	echo -ne " ${PORTAGE_COLOR_GOOD}*${PORTAGE_COLOR_NORMAL} $*" >&2
 	LAST_E_CMD="einfon"
 	return 0
 }
@@ -308,7 +308,7 @@ ewarn() {
 	__elog_base WARN "$*"
 	[[ ${RC_ENDCOL} != "yes" && ${LAST_E_CMD} == "ebegin" ]] && echo >&2
 	echo -e "$@" | while read -r ; do
-		echo " $WARN*$NORMAL $RC_INDENTATION$REPLY" >&2
+		echo " ${PORTAGE_COLOR_WARN}*${PORTAGE_COLOR_NORMAL} ${RC_INDENTATION}${REPLY}" >&2
 	done
 	LAST_E_CMD="ewarn"
 	return 0
@@ -318,7 +318,7 @@ eerror() {
 	__elog_base ERROR "$*"
 	[[ ${RC_ENDCOL} != "yes" && ${LAST_E_CMD} == "ebegin" ]] && echo >&2
 	echo -e "$@" | while read -r ; do
-		echo " $BAD*$NORMAL $RC_INDENTATION$REPLY" >&2
+		echo " ${PORTAGE_COLOR_BAD}*${PORTAGE_COLOR_NORMAL} ${RC_INDENTATION}${REPLY}" >&2
 	done
 	LAST_E_CMD="eerror"
 	return 0
@@ -345,12 +345,12 @@ __eend() {
 	shift 2
 
 	if [[ ${retval} == "0" ]] ; then
-		msg="${BRACKET}[ ${GOOD}ok${BRACKET} ]${NORMAL}"
+		msg="${PORTAGE_COLOR_BRACKET}[ ${PORTAGE_COLOR_GOOD}ok${PORTAGE_COLOR_BRACKET} ]${PORTAGE_COLOR_NORMAL}"
 	else
 		if [[ -n $* ]] ; then
 			${efunc} "$*"
 		fi
-		msg="${BRACKET}[ ${BAD}!!${BRACKET} ]${NORMAL}"
+		msg="${PORTAGE_COLOR_BRACKET}[ ${PORTAGE_COLOR_BAD}!!${PORTAGE_COLOR_BRACKET} ]${PORTAGE_COLOR_NORMAL}"
 	fi
 
 	if [[ ${RC_ENDCOL} == "yes" ]] ; then
@@ -378,12 +378,12 @@ __unset_colors() {
 	COLS=80
 	ENDCOL=
 
-	GOOD=
-	WARN=
-	BAD=
-	NORMAL=
-	HILITE=
-	BRACKET=
+	PORTAGE_COLOR_GOOD=
+	PORTAGE_COLOR_WARN=
+	PORTAGE_COLOR_BAD=
+	PORTAGE_COLOR_HILITE=
+	PORTAGE_COLOR_NORMAL=
+	PORTAGE_COLOR_BRACKET=
 }
 
 __set_colors() {
@@ -403,12 +403,12 @@ __set_colors() {
 	if [ -n "${PORTAGE_COLORMAP}" ] ; then
 		eval ${PORTAGE_COLORMAP}
 	else
-		GOOD=$'\e[32;01m'
-		WARN=$'\e[33;01m'
-		BAD=$'\e[31;01m'
-		HILITE=$'\e[36;01m'
-		BRACKET=$'\e[34;01m'
-		NORMAL=$'\e[0m'
+		PORTAGE_COLOR_GOOD=$'\e[32;01m'
+		PORTAGE_COLOR_WARN=$'\e[33;01m'
+		PORTAGE_COLOR_BAD=$'\e[31;01m'
+		PORTAGE_COLOR_HILITE=$'\e[36;01m'
+		PORTAGE_COLOR_BRACKET=$'\e[34;01m'
+		PORTAGE_COLOR_NORMAL=$'\e[0m'
 	fi
 }
 
diff --git a/bin/save-ebuild-env.sh b/bin/save-ebuild-env.sh
index 947ac79d5..8d2ec67ed 100644
--- a/bin/save-ebuild-env.sh
+++ b/bin/save-ebuild-env.sh
@@ -1,5 +1,5 @@
 #!/bin/bash
-# Copyright 1999-2018 Gentoo Foundation
+# Copyright 1999-2021 Gentoo Authors
 # Distributed under the terms of the GNU General Public License v2
 
 # @FUNCTION: __save_ebuild_env
@@ -94,15 +94,17 @@ __save_ebuild_env() {
 	unset ${!___*}
 
 	# portage config variables and variables set directly by portage
-	unset ACCEPT_LICENSE BAD BRACKET BUILD_PREFIX COLS \
+	unset ACCEPT_LICENSE BUILD_PREFIX COLS \
 		DISTDIR DOC_SYMLINKS_DIR \
 		EBUILD_FORCE_TEST EBUILD_MASTER_PID \
 		ECLASS_DEPTH ENDCOL FAKEROOTKEY \
-		GOOD HILITE HOME \
+		HOME \
 		LAST_E_CMD LAST_E_LEN LD_PRELOAD MISC_FUNCTIONS_ARGS MOPREFIX \
-		NOCOLOR NORMAL PKGDIR PKGUSE PKG_LOGDIR PKG_TMPDIR \
-		PORTAGE_BASHRC_FILES PORTAGE_BASHRCS_SOURCED PORTAGE_COMPRESS \
-		PORTAGE_COMPRESS_EXCLUDE_SUFFIXES \
+		NOCOLOR PKGDIR PKGUSE PKG_LOGDIR PKG_TMPDIR \
+		PORTAGE_BASHRC_FILES PORTAGE_BASHRCS_SOURCED \
+		PORTAGE_COLOR_BAD PORTAGE_COLOR_BRACKET PORTAGE_COLOR_GOOD \
+		PORTAGE_COLOR_HILITE PORTAGE_COLOR_NORMAL PORTAGE_COLOR_WARN \
+		PORTAGE_COMPRESS PORTAGE_COMPRESS_EXCLUDE_SUFFIXES \
 		PORTAGE_DOHTML_UNWARNED_SKIPPED_EXTENSIONS \
 		PORTAGE_DOHTML_UNWARNED_SKIPPED_FILES \
 		PORTAGE_DOHTML_WARN_ON_SKIPPED_FILES \
@@ -113,7 +115,7 @@ __save_ebuild_env() {
 		QA_INTERCEPTORS \
 		RC_DEFAULT_INDENT RC_DOT_PATTERN RC_ENDCOL RC_INDENTATION  \
 		ROOT ROOTPATH RPMDIR TEMP TMP TMPDIR USE_EXPAND \
-		WARN XARGS _RC_GET_KV_CACHE
+		XARGS _RC_GET_KV_CACHE
 
 	# user config variables
 	unset DOC_SYMLINKS_DIR INSTALL_MASK PKG_INSTALL_MASK
diff --git a/lib/portage/output.py b/lib/portage/output.py
index c1949717d..9d8601b24 100644
--- a/lib/portage/output.py
+++ b/lib/portage/output.py
@@ -1,4 +1,4 @@
-# Copyright 1998-2020 Gentoo Authors
+# Copyright 1998-2021 Gentoo Authors
 # Distributed under the terms of the GNU General Public License v2
 
 __docformat__ = "epytext"
@@ -378,7 +378,7 @@ def style_to_ansi_code(style):
 def colormap():
     mycolors = []
     for c in ("GOOD", "WARN", "BAD", "HILITE", "BRACKET", "NORMAL"):
-        mycolors.append("%s=$'%s'" % (c, style_to_ansi_code(c)))
+        mycolors.append("PORTAGE_COLOR_{}=$'{}'".format(c, style_to_ansi_code(c)))
     return "\n".join(mycolors)
 
 
-- 
2.33.0



^ permalink raw reply related	[relevance 99%]

Results 1-1 of 1 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2021-09-28 14:20     [gentoo-portage-dev] [PATCH 0/4] Output rewrite for better clarify and greppability Michał Górny
2021-09-28 14:20 99% ` [gentoo-portage-dev] [PATCH 1/4] Prefix color vars with "PORTAGE_COLOR_" Michał Górny

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox