Print DFLAGS on -v to ease debugging#7865
Conversation
|
Thanks for your pull request, @wilzbach! Bugzilla referencesYour PR doesn't reference any Bugzilla issue. If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog. |
test/compilable/testclidflags.sh
Outdated
| # Force DMD to print the -v menu by passing an invalid object file | ||
| # It will fail with "no object files to link", but print the log | ||
| ( ! "$DMD" -v foo.a 2> /dev/null ) | grep -q "dflags (none)" | ||
| ( ! DFLAGS="-O -D" "$DMD" -v foo.a 2> /dev/null ) | grep -q "dflags -O -D" |
There was a problem hiding this comment.
Imho it sucks that we have to workaround DMD so hard just to get it's config output. Shouldn't we make DMD's raw config settings easier to access? Most of this will be solved by the improved Json output, but there are still many cases where just looking what flags, args and precompiled versions DMD's as helps.
Ideas:
- default for
-v(instead of showing the help page) --version=detailed
src/dmd/mars.d
Outdated
| message("binary %s", global.params.argv0); | ||
| message("version %s", global._version); | ||
| message("config %s", global.inifilename ? global.inifilename : "(none)"); | ||
| OutBuffer buf; |
There was a problem hiding this comment.
I recommend adding a header comment like "Print DFLAGS environment variable" for this block of code.
src/dmd/mars.d
Outdated
| foreach (flag; dflags.asDArray) | ||
| buf.printf("%s ", flag); | ||
| auto res = buf.peekSlice() ? buf.peekSlice()[0 .. $ - 1] : "(none)"; | ||
| message("dflags %.*s", res.length, res.ptr); |
There was a problem hiding this comment.
Please use "DFLAGS" in all caps.
There was a problem hiding this comment.
I used the existing convention of lower-casing everything - the entire output of -v starts with lower-cases tags.
There was a problem hiding this comment.
Environment variables are case-sensitive (at least on Linux). Therefore, I think the case is important here.
There was a problem hiding this comment.
What do other people think? (I don't mind changing it, but for now I focus on getting it to pass on auto-tester, so I won't change it immediately)
There was a problem hiding this comment.
doesn't matter to me, both have small pros/cons. Lower case is consistent with all other verbose output, CAPITAL makes it consistent with the actual variable name.
If it's helpful, rdmd's regex for verbose output is here:
auto pattern = ctRegex!(r"^(import|file|binary|config|library)\s+([^\(]+)\(?([^\)]*)\)?\s*$");9872cc7 to
a158a35
Compare
src/dmd/mars.d
Outdated
| message("version %s", global._version); | ||
| message("config %s", global.inifilename ? global.inifilename : "(none)"); | ||
| // Print DFLAGS environment variable | ||
| OutBuffer buf; |
There was a problem hiding this comment.
Should buf and res go in their own scope?
There was a problem hiding this comment.
Actually I didn't realize this was inside such a small if block...nevermind.
src/dmd/mars.d
Outdated
| // Print DFLAGS environment variable | ||
| OutBuffer buf; | ||
| foreach (flag; dflags.asDArray) | ||
| buf.printf("%s ", flag); |
There was a problem hiding this comment.
I think individual dflags may contain spaces. If so, we may want to surround them with quotes when we see that they contain whitespace.
Maybe something similar to writeFilename in link.d.
There was a problem hiding this comment.
So you want me to detect whether there's a space in the flag and then use quotes for it?
Most flags don't use spaces and it would look pretty ugly if this is done by default.
There was a problem hiding this comment.
it would look pretty ugly if this is done by default
shouldn't be by default, just if there's space:
DFLAGS=-I"path to foo" -Ibar
=>
'-Ipath to foo' -Ibar
so only '' where needed;
also, using
-Ipath\ to\ foo -Ibar
is another option
There was a problem hiding this comment.
Actually, a better solution might just be to print the original unprocessed value of DFLAGS because that one will already be quoted properly
|
Okay let's make a vote:
|
|
why not add it to json output as well? |
|
Yes of course, but we are currently blocked on Walter for the JSON output: #7838 |
Looks like
Okay done.
Not sure that's a good idea. There might potentially be some bugs or other problems with the processing of DFLAGS, so in my experience it's better to dump the actual value the program uses. |
| # On OSX DMD terminates with a successful exit code, so `|| true` is used. | ||
| ( "$DMD" -v foo.d 2> /dev/null || true) | grep -q "DFLAGS (none)" | ||
| ( DFLAGS="-O -D" "$DMD" -v foo.d 2> /dev/null || true) | grep -q "DFLAGS -O -D" | ||
| ( DFLAGS="-O '-Ifoo bar' -c" "$DMD" -v foo.d 2> /dev/null || true) | grep -q "DFLAGS -O '-Ifoo bar' -c" |
There was a problem hiding this comment.
I wonder why this works on the auto tester. For me, this test fails without any helpful output and if I run it explicitly it seems DFLAGS is picked up as a test parameter and d_do_test complains:
object.Exception@d_do_test.d(584): The DFLAGS test argument must be empty: It is ' ="-O -D" "$DMD" -v foo.d 2> /dev/null || true) | grep -q "DFLAGS -O -D" ="-O '-Ifoo bar' -c" "$DMD" -v foo.d 2> /dev/null || true) | grep -q "DFLAGS -O '-Ifoo bar' -c"'
There was a problem hiding this comment.
Yes, but picking up DFLAGS should be OS platfrom-agnostic.
There was a problem hiding this comment.
Maybe something to do with the binutils or bash? What's the actual output of dmd for you?
There was a problem hiding this comment.
It's not dmd complaining, but d_do_test because findTestParameter(envData, file, "DFLAGS", testArgs.dflags); results in the shown string.
There was a problem hiding this comment.
Ouch, totally missed that shell scripts are (no longer?) executed through d_do_test.
There is zero output from the script itself, will have to investigate further...
There was a problem hiding this comment.
We just merged a change which adds sh_do_test.sh that automatically redirects output from all BASH tests to the test output file, i.e. test_results/compilable/mytest.sh.out
There was a problem hiding this comment.
Found the issue: dmd still used an sc.ini which overrides DFLAGS. Better to pass -conf= to dmd in these tests, too?
Motivation: it can be tricky to figure out what dflags DMD has read. This helps debugging at almost no cost (and
-vis only used for debugging anyhow).See also: #7845