dub icon indicating copy to clipboard operation
dub copied to clipboard

WIP: Forward flag -color to compiler calls

Open nordlow opened this issue 3 years ago • 4 comments

Need help determining how to forward options.colors_mode to setting the instance of BuildOption.color which should, afaict, be forwarded automatically to DMDCompiler.s_options and LDCCompiler.s_options.

Update: I think I nailed it.

Can you have a look, @Geod24?

FYI, @kinke.

nordlow avatar Aug 14 '22 21:08 nordlow

should we only pass explicit color argument to dmd or also implicit as set by NO_COLOR env (or other external ways)?

WebFreak001 avatar Aug 15 '22 00:08 WebFreak001

What's important to me is that the color switch (-fdiagnostics-color=always for GDC btw) isn't used for the build hash - enforcing colors should not lead to cached packages being rebuilt. Otherwise colors could already be enforced via DFLAGS env var.

kinke avatar Aug 15 '22 09:08 kinke

-fdiagnostics-color=always for GDC btw

Thanks, added via 50fe225b.

nordlow avatar Aug 15 '22 10:08 nordlow

Should BuildOption.color be part of inheritedBuildOptions in buildsettings.d?

nordlow avatar Aug 15 '22 11:08 nordlow

What's important to me is that the color switch (-fdiagnostics-color=always for GDC btw) isn't used for the build hash - enforcing colors should not lead to cached packages being rebuilt.

Can anybody point me to the source location where this hash is calculated? Searching now...

Update: Is it computeBuildID(). If so, the parameter buildSettings.options is not included in the hash and buildsettings.dflags doesn't contain the compiler flag when --colors=on is passed to dub.

Update: Wrong, I need to adjust the expression

(cast(uint)buildsettings.options).to!string

in computeBuildID. On to it...

Update: Resolved via f53d7c05, @kinke.

nordlow avatar Aug 15 '22 11:08 nordlow

Btw, https://github.com/dlang/dub/issues/2385.

nordlow avatar Aug 15 '22 12:08 nordlow

should we only pass explicit color argument to dmd or also implicit as set by NO_COLOR env (or other external ways)?

I don't know.

nordlow avatar Aug 15 '22 12:08 nordlow

Otherwise colors could already be enforced via DFLAGS env var.

Are you saying we shall exclude color flags from DFLAGS env var aswell, @kinke?

nordlow avatar Aug 15 '22 12:08 nordlow

[Nope, just saying those rebuilds prevented me from working around this via DFLAGS for now.]

kinke avatar Aug 15 '22 12:08 kinke

[Nope, just saying those rebuilds prevented me from working around this via DFLAGS for now.]

So is this good to go, @thewilsonator @Geod24?

nordlow avatar Aug 15 '22 12:08 nordlow

I'm on vacation this week so on mobile most of the time but I'll try to take a look one evening.

Geod24 avatar Aug 15 '22 12:08 Geod24

Changes look good but please add a test.

Geod24 avatar Aug 17 '22 23:08 Geod24

Changes look good but please add a test.

Is it ok if I extend the existing tests for the --color(s) flag?

nordlow avatar Aug 18 '22 08:08 nordlow

Changes look good but please add a test.

Do you have a suggestion for how to add a test for this? I vote for grepping for the forwarded compiler flag in the output of a call to dub -v ... for both dmd, ldc and gdc? This prevents use from having to build with all 3 compilers.

Ping, @veelo.

nordlow avatar Aug 18 '22 08:08 nordlow

Changes look good but please add a test.

Do you have a suggestion for how to add a test for this? I vote for grepping for the forwarded compiler flag in the output of a call to dub -v ... for both dmd, ldc and gdc? This prevents use from having to build with all 3 compilers.

I think that will be good enough. If you really would want to check the existence of color in the compiler output you could probably check for the presence of ANSI escape codes, but that requires you to know how each compiler formats its output, which can change between releases.

veelo avatar Aug 18 '22 09:08 veelo

I'm trying to run the test colored-output.sh as

DC=/usr/bin/dmd DUB=../bin/dub CURR_DIR=. ./colored-output.sh 

under test sub-dir but that fails

as

DC=/usr/bin/dmd DUB=../bin/dub CURR_DIR=. ./colored-output.sh 
0
[ERROR] ./colored-output.sh:8 command failed

. What am I doing wrong?

Need help. Ping, @Geod24 @thewilsonator @veelo.

IMO, dub desperately needs a obvious and trivial way to run individual and all tests along with a documentation for it.

nordlow avatar Aug 19 '22 16:08 nordlow

Just to rule out the obvious: did you try to run the command at line 8 by hand (after cd 1-exec-simple)?

veelo avatar Aug 19 '22 17:08 veelo

Just to rule out the obvious: did you try to run the command at line 8 by hand (after cd 1-exec-simple)?

That's not the command that fails.

I found it out now the problem was that the piping hid the real error message. On to it now again.

nordlow avatar Aug 19 '22 17:08 nordlow

Figured it out. The project build and test command I currently use is

dub build && cd test && DC=dmd DUB=~/Work/dub/bin/dub CURR_DIR=. ./colored-output.sh 

. What are yours? Is this documented somewhere in dub? If not we need to add it. Along with a convenience wrapper script that is present in the root directory and that is obvious how one uses.

Questions. Why isn't variable

  1. CURR_DIR defaulted to ${BASH_SOURCE[0]}?
  2. DC defaulted to dmd?
  3. DUB defaulted to ../bin/dub?

nordlow avatar Aug 19 '22 17:08 nordlow

Going green now for the dmd forwarding case. I'm gonna see if can make the ldc and gdc cases work aswell.

nordlow avatar Aug 19 '22 17:08 nordlow

IMNSHO all shell scripts should be eliminated from all repositories. D is great for scripting, and cross platform.

veelo avatar Aug 19 '22 18:08 veelo

Questions. Why isn't variable

  1. CURR_DIR defaulted to ${BASH_SOURCE[0]}?
  2. DC defaulted to dmd?
  3. DUB defaulted to ../bin/dub?

2 and 3, because that would make it way too easy to accidentally make things work when we fail to pass the right compiler. 1 I don't remember but I think there's a reason. In any case, this test suite infrastructure was started almost 10 years ago by a college student that had no idea what he was doing at the time, so yeah we should rewrite it in D. I'm on a (side) quest of moving environment reads / IO out of some deeply nested functions so that we can actually unittest things (much faster than integration tests).

Geod24 avatar Aug 21 '22 18:08 Geod24

@nordlow : Whenever you want to update a PR, please do git fetch upstream && git rebase upstream/master, it makes life much easier.

Geod24 avatar Aug 21 '22 18:08 Geod24

Rebased, G2G

Geod24 avatar Aug 21 '22 18:08 Geod24

How long does buildkite/dub normally take? It's been running for 2 hours now.

nordlow avatar Aug 21 '22 20:08 nordlow

Hmm, I might have forgotten to forward coloring to compilers in the case where --color=automatic...

nordlow avatar Aug 22 '22 00:08 nordlow

Hum, probably :)

Geod24 avatar Aug 22 '22 03:08 Geod24

Hum, probably :)

Shall we do anything about this?

To be strict about this we need to add to change the type of the flag BuildOption.color from bool to enum color { automatic, on, off } which will require significant refactor of the type of build options as it currently assumes all build options boolean. Soon or later we need to deal with this. Shall we bother with this now?

nordlow avatar Aug 22 '22 08:08 nordlow

Don't the compilers already display colors automatically (i.e., if output is a TTY)? In that case not forcing anything will already do the right thing in the default case.

change the type of the flag BuildOption.color from bool to enum color { automatic, on, off } which will require significant refactor of the type of build options as it currently assumes all build options boolean.

Which leads me to question how this is currently implemented.

color = 1<<26, /// Colorize output (-color)

This adds a flag to force color on, no? And we don't have a flag to force color off. Thus from the tristate we only forward one state to the compiler currently.

I don't know if this is needed in any practical situation, but you could add another flag nocolor to force color off. Then if both flags are false it would imply automatic. Both flags true would be illegal.

veelo avatar Aug 22 '22 09:08 veelo

I don't know if this is needed in any practical situation, but you could add another flag nocolor to force color off. Then if both flags are false it would imply automatic. Both flags true would be illegal.

We could add that but that is bad design because it introduces error states. I vote for refactoring build options to be able to store flags other boolean such as, in this case, enum color.

nordlow avatar Aug 22 '22 10:08 nordlow