Skip to content

Commit

Permalink
Stop implicitly manipulating NO_COLOR/NOCOLOR
Browse files Browse the repository at this point in the history
Stop implicitly forcing `NO_COLOR` and `NOCOLOR` in ebuild environment.
This is undesired for several reasons:

1. It makes it impossible to control color for emerge output
   independently of command output, e.g. when one goes to a pty while
   the other goes to logs.

2. It makes it impossible to get color output in logs when running
   `emerge --jobs ...`.

3. Forcing `NO_COLOR=1` turns out to cause random test failures,
   and while fixing them is commendable, it is a pain for arch testing
   and it is currently blocking stabilization requests.

With the new approach, the color output in programs is consistent
between using ``--jobs`` or ``--quiet-build``, and not.  Therefore,
both cases generate uniform logs.  In order to obtain logs free of color
codes, one can either filter them via `ansifilter(1)` (as the manpages
already recommend) or explicitly set `NO_COLOR`.

Furthermore, one can combine color-free build output (for clean logs)
with colorful emerge output by using:

    NO_COLOR=true emerge --color y ...

Bug: https://bugs.gentoo.org/918515
Signed-off-by: Michał Górny <mgorny@gentoo.org>
  • Loading branch information
mgorny committed Nov 29, 2023
1 parent 9823f70 commit 9c02566
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 18 deletions.
5 changes: 5 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ Release notes take the form of the following optional categories:
portage-3.0.56 (UNRELEASED)
--------------

Breaking changes:
* ebuild: no longer implicitly set NOCOLOR and NO_COLOR when color output
is disabled for emerge itself. In order to obtain color-free logs, please
either explicitly set NO_COLOR environment variable or use e.g. ansifilter.

Features:
* sync: git: Add sync-git-verify-max-age-days option.

Expand Down
4 changes: 0 additions & 4 deletions bin/ebuild
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,6 @@ def main():
or not sys.stdout.isatty()
):
portage.output.nocolor()
portage.settings.unlock()
portage.settings["NO_COLOR"] = "true"
portage.settings.backup_changes("NO_COLOR")
portage.settings.lock()

apply_priorities(portage.settings)

Expand Down
6 changes: 0 additions & 6 deletions lib/_emerge/AbstractEbuildProcess.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,6 @@ def _start(self):
self._async_wait()
return

if self.background:
# Automatically prevent color codes from showing up in logs,
# since we're not displaying to a terminal anyway.
self.settings["NOCOLOR"] = "true"
self.settings["NO_COLOR"] = "true"

start_ipc_daemon = False
if self._enable_ipc_daemon:
self.settings.pop("PORTAGE_EBUILD_EXIT_FILE", None)
Expand Down
5 changes: 0 additions & 5 deletions lib/_emerge/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2749,15 +2749,10 @@ def adjust_config(myopts, settings):
if "--color" in myopts:
if "y" == myopts["--color"]:
portage.output.havecolor = 1
settings["NO_COLOR"] = ""
else:
portage.output.havecolor = 0
settings["NO_COLOR"] = "true"
settings.backup_changes("NO_COLOR")
elif settings.get("TERM") == "dumb" or not sys.stdout.isatty():
portage.output.havecolor = 0
settings["NO_COLOR"] = "true"
settings.backup_changes("NO_COLOR")

if "--pkg-format" in myopts:
settings["PORTAGE_BINPKG_FORMAT"] = myopts["--pkg-format"]
Expand Down
3 changes: 0 additions & 3 deletions lib/portage/tests/resolver/ResolverPlayground.py
Original file line number Diff line number Diff line change
Expand Up @@ -591,9 +591,6 @@ def _create_profile(
"PORTAGE_TMPDIR": os.path.join(self.eroot, "var/tmp"),
}

if portage.util.no_color(os.environ):
make_conf["NO_COLOR"] = os.environ["NO_COLOR"]

# Pass along PORTAGE_USERNAME and PORTAGE_GRPNAME since they
# need to be inherited by ebuild subprocesses.
if "PORTAGE_USERNAME" in os.environ:
Expand Down

0 comments on commit 9c02566

Please sign in to comment.