Skip to content

Always cache colored diagnostics; strip color codes from ccache's stderr output as appropriate#596

Merged
jrosdahl merged 17 commits intoccache:masterfrom
whitslack:cache-colored-diagnostics
Jun 7, 2020
Merged

Always cache colored diagnostics; strip color codes from ccache's stderr output as appropriate#596
jrosdahl merged 17 commits intoccache:masterfrom
whitslack:cache-colored-diagnostics

Conversation

@whitslack
Copy link
Copy Markdown
Contributor

@whitslack whitslack commented May 22, 2020

This pull request resolves #223 and resolves #224.

  • Implement function to strip ANSI escape sequences from a string.
    • Implement a test case of the preceding.
  • Interpret any colored diagnostics options given to ccache as ccache options, not as compiler options.
  • Always pass {GCC: -fdiagnostics-color} {Clang: -fcolor-diagnostics} to the real compiler, except…
    • Don't pass any color option to the preprocessor if run_second_cpp is true.
    • {GCC: If the initial GCC invocation fails and its emitted error message contains unrecognized command-line option and -fdiagnostics-color, then remove the color option and retry the command. Also, remember the failure and omit the color option from any subsequent GCC invocation.}
  • When copying cached stderr output to ccache's stderr, if the invoking command specified {GCC: -fno-diagnostics-color or -fdiagnostics-color=never} {Clang: -fno-color-diagnostics} or ccache's stderr is not a TTY and the invoking command did not specify {GCC: -fdiagnostics-color or -fdiagnostics-color=always} {Clang: -fcolor-diagnostics}, then use the aforementioned new function to strip ANSI CSI actions K and m.
  • Implement a test case to demonstrate that color codes are always stored in the cache, regardless of any color options given to ccache, and that color codes are stripped from ccache's stderr output when suppression of colored diagnostics is requested by explicit option given to ccache or when stderr is not a TTY and no explicit color option is given to ccache.
  • Remove the caveat that was documented in 67fdd3b.

@liljenzin
Copy link
Copy Markdown
Contributor

@whitslack: See my comment here: #224 (comment)

whitslack added a commit to whitslack/ccache that referenced this pull request May 25, 2020
@whitslack whitslack force-pushed the cache-colored-diagnostics branch from 54e0c70 to 2fa45a3 Compare May 25, 2020 19:48
whitslack added a commit to whitslack/ccache that referenced this pull request May 28, 2020
whitslack added a commit to whitslack/ccache that referenced this pull request May 28, 2020
whitslack added a commit to whitslack/ccache that referenced this pull request May 28, 2020
@whitslack whitslack marked this pull request as ready for review May 28, 2020 22:57
whitslack added 7 commits May 28, 2020 18:58
This function works like copy_fd but strips out selected ANSI CSI
escape sequences. The intention is for this function to be called
instead of copy_fd when copying cached compiler stderr output to
ccache's stderr when the invoking command specifies
-fno-diagnostics-color or -fdiagnostics-color=never or ccache's stderr
is not a terminal and the invoking command does not specify
-fdiagnostics-color or -fdiagnostics-color=always.
Testing -f fails when the file is not a regular file, such as when
using Bash's process substitution.
@whitslack whitslack force-pushed the cache-colored-diagnostics branch from 9cb24d4 to d19cd72 Compare May 28, 2020 23:02
Merge remote-tracking branch 'origin/master' into cache-colored-diagnostics
whitslack and others added 7 commits June 4, 2020 15:00
Quoting Joel Rosdahl:

> I intend to relatively soon refactor the code related to stderr
> handling so that the stderr data read from the aggregated result file
> won't hit the file system as a temporary file. Therefore, stripping
> color codes from data read explicitly from a file descriptor does not
> quite fit my plans.

See: ccache#596 (comment)
Per request by Joel Rosdahl.

See: ccache#596 (comment)

Co-authored-by: Joel Rosdahl <joel@rosdahl.net>
The --log-out option was added to script(1) in util-linux 2.35. Since
some distributions are still running older versions, remove the use of
the option from the color_diagnostics test suite. Equivalent
functionality is obtained simply by passing the name of the output file
without using the --log-out option.

See: ccache#596 (comment)
According to Joel Rosdahl, the intention in
3eb2483 was not to support regular
expressions. This commit makes expect_file_{,not_}contains perform
literal substring matching only.

See: ccache#596 (comment)
“stderr” is a macro in MinGW and cannot be used as a variable name.
If the user running the test suite sets GCC_COLORS in their shell rc
file the color_diagnostics tests fail. Fix this by explicitly unsetting
GCC_COLORS where needed.
@jrosdahl
Copy link
Copy Markdown
Member

jrosdahl commented Jun 6, 2020

Good work.

There are still some CI test failures and I've fixed one of them in e13badd. I also fixed an issue I had locally in b1bd4b7. Feel free to rework them if you like.

There's however one CI test issue left, a unit test segfault in the "Build on Linux with native Clang" job. Disabling the unit test makes the ccache binary segfault in the bash test suite later. There seems to be some bad interaction between Clang 7.0.0, nonstd::string_view and std::regex in the Travis-CI environment. I can't reproduce the problem locally with Clang 7.0.1 on Ubuntu 20.04.

I modified the build to run the unit test with Valgrind to get a backtrace. It looks like this: https://travis-ci.org/github/jrosdahl/ccache/builds/695447083#L470 (followed by a crash further down). Rewriting {edit,strip}_ansi_csi_seqs to work on const std::string& instead of nonstd::string_view fixes the issue. Building without -O2 also makes the issue go away.

The CI setup currently uses the Ubuntu 16.04. I spent some time to upgrade it (not yet on master) to Ubuntu 18.04 (I guess it's time for that anyway) and that fixes the Clang build, but doing so leaves the Ubuntu 16.04 Clang issue unsolved, which feels slightly uncomfortable.

Here are some ways forward:

  1. Dig deeper and try to find the root cause. I don't feel like I have time to do that.
  2. Rewrite to use const std::string& (easy). That would be fine by me.
  3. Rewrite to not use std::regex (more work). That would be fine by me.
  4. Disable the Clang build. I would rather not do that.
  5. Ignore the problem and upgrade to Ubuntu 18.04. I guess that would be OK.

@whitslack: Any ideas or opinions on this?

@jrosdahl
Copy link
Copy Markdown
Member

jrosdahl commented Jun 7, 2020

I've updated the CI environment to Ubuntu 18.04 on master now so I'll merge this.

This fixes the Clang-Format CI job.
@jrosdahl jrosdahl merged commit 1c6ccf1 into ccache:master Jun 7, 2020
@jrosdahl
Copy link
Copy Markdown
Member

jrosdahl commented Jun 7, 2020

Thanks!

@whitslack
Copy link
Copy Markdown
Contributor Author

Any ideas or opinions on this?

@jrosdahl: Moot at this point, but my opinion is that neither runtime efficiency nor code legibility/maintainability should be sacrificed to cater to deficient compilers that are obsolete by several major releases. I'm glad you went with upgrading your CI environment. I doubt Ubuntu 16.04 will ever package ccache 4.0 anyway.

@jrosdahl
Copy link
Copy Markdown
Member

jrosdahl commented Jun 8, 2020

To clarify, this is not about dropping support for Ubuntu 16.04 (which comes with Clang 3.8) or Clang 7 (which is not even 2 years old). It's about if the Clang 7 installation on Travis-CI's Ubuntu 16.04 is buggy or if there's a lurking bug in ccache (or nonstd::string_view). I'm hoping for the former. Edit: And it's also not about if Ubuntu 16.04 will package ccache 4.0 (which they of course won't) but about supporting users who want to compile and use ccache themselves on legacy systems.

On the subject of portability, I want to continue supporting CentOS 7 which has GCC 4.8.5 which I now realize doesn't implement std::regex. I'll think some more about this, but it might end up in not using std::regex. No shadow falls in you, of course. 🙂

jrosdahl added a commit to jrosdahl/ccache that referenced this pull request Jul 25, 2020
The implementation from ccache#596 uses the spelling “command-line” instead of
“command line” (which is what is actually emitted by GCC and specified
in ccache#224).
@jrosdahl jrosdahl added the issue: feature New feature label Aug 6, 2020
@jrosdahl jrosdahl added this to the 4.0 milestone Aug 6, 2020
jrosdahl added a commit to jrosdahl/ccache that referenced this pull request Aug 6, 2020
The CCACHE_PREFIX test logs execution of prefixes. After
1c6ccf1 (ccache#596) the compiler and
prefixes can be run twice if GCC doesn’t support -fdiagnostics-color and
the test case is not prepared for that. Fix this by letting prefix-a
truncate the log file.
jrosdahl added a commit that referenced this pull request Aug 6, 2020
The CCACHE_PREFIX test logs execution of prefixes. After
1c6ccf1 (#596) the compiler and
prefixes can be run twice if GCC doesn’t support -fdiagnostics-color and
the test case is not prepared for that. Fix this by letting prefix-a
truncate the log file.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

issue: feature New feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make colored warnings work for GCC out of the box Share cache entries for the TTY and redirected stderr cases for clang

3 participants