Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always pass -fdiagnostics-color=always to cc-style compilers to avoid useless recompilations when Dune's stderr is redirected #10883

Merged
merged 6 commits into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions doc/changes/10883.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Fix an issue where C stubs would be rebuilt whenever the stderr of Dune was
redirected. (#10883, @nojb)
3 changes: 1 addition & 2 deletions src/dune_rules/cxx_flags.ml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ let base_cxx_flags ~for_ cc =
;;

let fdiagnostics_color = function
| (Gcc | Clang) when Lazy.force Ansi_color.stderr_supports_color ->
[ "-fdiagnostics-color=always" ]
| Gcc | Clang -> [ "-fdiagnostics-color=always" ]
| _ -> []
;;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,27 @@
This test won't work with MSVC as it's using GCC and clang CLI
parameters.

We have to force Dune outputting colors, for that we use
`CLICOLOR_FORCE=1`.

The flag should be present in the command, as we want it in the
:standard set.

We don't actually test that the compiler outputs colors, just that
Dune correctly passes the flag when required, and doesn't when it's
not.

test, color enabled, color flag default (enabled)
=================================================
test that we pass the flag
==========================

$ cat >dune <<EOF
> (library
> (name test)
> (foreign_stubs (language c) (names stub)))
> EOF

$ CLICOLOR_FORCE=1 dune rules -m stub.o | grep -ce "-fdiagnostics-color=always"
$ dune rules -m stub.o | grep -ce "-fdiagnostics-color=always"
1

test, color enabled, color flag disabled
========================================
test color flag disabled
========================

$ cat >dune <<EOF
> (library
Expand All @@ -34,12 +31,12 @@ test, color enabled, color flag disabled
> (language c) (names stub)))
> EOF

$ CLICOLOR_FORCE=1 dune rules -m stub.o | grep -ce "-fdiagnostics-color=always"
$ dune rules -m stub.o | grep -ce "-fdiagnostics-color=always"
0
[1]

test, color disabled, color flag default (enabled)
==================================================
test that we correctly filter out the color codes
=================================================

$ cat >dune <<EOF
> (library
Expand All @@ -48,6 +45,7 @@ test, color disabled, color flag default (enabled)
> (language c) (names stub)))
> EOF

$ CLICOLOR=0 dune rules -m stub.o | grep -ce "-fdiagnostics-color=always"
0
We check there is no ESC [ sequence.

$ dune build 2>&1 | grep `printf '\033\\['`
[1]
4 changes: 2 additions & 2 deletions test/blackbox-tests/test-cases/variables/var-cc.t/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ No env
> (action (echo %{cc})))
> EOF

$ dune build @cc28 | sed "s,${O_CC} ${O_CCF} ${O_CCPPF},OK,"
$ dune build @cc28 | sed "s,${O_CC} ${O_CCF} ${O_CCPPF} -fdiagnostics-color=always,OK,"
OK

With added env flags
$ cat >> dune <<'EOF'
> (env (_ (c_flags :standard -fPIC)))
> EOF

$ dune build @cc28 | sed "s,${O_CC} ${O_CCF} ${O_CCPPF} -fPIC,OK,"
$ dune build @cc28 | sed "s,${O_CC} ${O_CCF} ${O_CCPPF} -fdiagnostics-color=always -fPIC,OK,"
OK

With redefining env flags
Expand Down
Loading