-
-
Notifications
You must be signed in to change notification settings - Fork 672
Add more JSON #7894
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
Add more JSON #7894
Conversation
|
Thanks for your pull request and interest in making D better, @marler8997! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please see CONTRIBUTING.md for more information. If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment. 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow that was quick! Thanks!
`compiler` and `frontendVersion` are a bit more effort, so it probably makes sense to do them in a quick followup (I can do this too).
Otherwise LGTM!
src/dmd/json.d
Outdated
| property("binary", global.params.argv0); | ||
| property("vendor", global.compiler.vendor); | ||
| property("version", global._version); | ||
| property("argv0", global.params.argv0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the motivation for renaming this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, I was thinking that argv0 is more true to what it actually is. "binary" sounds more like a filename but argv0 can be an alias/string/filename, you know, whatever argv[0] happens to be. It may be helpful to include both "binary" and "argv0"...
src/dmd/json.d
Outdated
| property("vendor", global.compiler.vendor); | ||
| property("version", global._version); | ||
| property("argv0", global.params.argv0); | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
compiler, frontendVersion are the interesting bits here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you elaborate what frontendVersion and compilerFrontend are for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(these variables are currently used by DUB in its platform probing)
frontendVersion: 2071, 2072, known in D as__VERSION__(and in DMD asVERSIONXtoken). This is important for feature and compatibility detectioncompiler, e.g.dmd,ldcorgdc- as mentioned the vendor might be different to the CLI interface (maybecompilerInterfaceis a better name)compilerFrontend- same asversion(already existent)
src/dmd/json.d
Outdated
| objectStart(); | ||
| property("binary", global.params.argv0); | ||
| property("vendor", global.compiler.vendor); | ||
| property("version", global._version); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably a good idea to add DFLAGS too (see #7865), but I can easily add this in a follow-up PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
inifilename is already in the buildInfo field
If we add DFLAGS...wouldn't we want to add all the command line arguments?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we add DFLAGS...wouldn't we want to add all the command line arguments?
Yes, but again doesn't have to be in this PR.
|
Ah I see:
So I think these would still be useful:
But as mentioned, I don't expect this PR to include them. |
2a52acd to
e24c024
Compare
2447ad3 to
25a356b
Compare
25a356b to
d6b8376
Compare
|
definitely not PR blockers (could be done in future ones) but for reference:
maybe:
|
d6b8376 to
8a40663
Compare
8a40663 to
6cff412
Compare
|
Ok, I think this is a good start. I've included Note for future changes. I opted for the compilerInfo/buildInfo objects to ALWAYS include fields even if their values are null/empty. This way a user can still see the format of the document even if a value is null (see |
6cff412 to
d5faa36
Compare
|
NOTE: If you copy the following script to the test directory, you can run it after building DMD to automatically update the json tests with the new expected JSON output: https://gist.github.com/marler8997/f3973cc6bcde7a88d04f48140ea8fe6b ## Script to update json test files
set -x
make test_results/compilable/json2.d.out
cp test_results/compilable/json2.out.sanitized compilable/extra-files/json2.out
make test_results/compilable/jsonCompilerInfo.d.out
cp test_results/compilable/jsonCompilerInfo.out.sanitized compilable/extra-files/jsonCompilerInfo.out
make test_results/compilable/json_nosource.sh.out
cp test_results/compilable/json_nosource.out.sanitized compilable/extra-files/json_nosource.out |
04db990 to
f81407c
Compare
src/dmd/json.d
Outdated
| propertyOrNull("version", global._version); | ||
| property("__VERSION__", global.versionNumber()); | ||
| propertyOrNull("interface", determineCompilerInterface()); | ||
| property("bitWidth", size_t.sizeof * 8); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if bitWidth is a good name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, any other ideas? It's the same number that's printed in the --version output.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
size_tSizeof, or just size_t
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, size_t seems reasonable. With size_t I also changed it to the "byte-width" instead of "bit-width". Let me know if someone prefers it to be the bit-width instead.
src/dmd/json.d
Outdated
| property("name", m.md.toChars()); | ||
| property("file", m.srcfile.toChars()); | ||
| propertyOrNull("name", m.md ? m.md.toChars() : null); | ||
| propertyOrNull("file", m.srcfile.toChars()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this even be null?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no, but it seemed like consistently using propertyOrNull was better. The new objects should use propertyOrNull and the old modules object uses property....maybe there is a better name....
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The name requiredProperty came to mind and seems like a good idea.
src/dmd/json.d
Outdated
| */ | ||
| private const(char)* determineCompilerInterface() | ||
| { | ||
| if (0 == strcmp(global.compiler.vendor, "Digital Mars D")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pattern is actual == expected (grep through the source code).
Of course !strcmp would work too.
src/dmd/globals.d
Outdated
| alias StorageClass = uinteger_t; | ||
|
|
||
| extern (C++) __gshared Global global; | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unrelated?
src/dmd/json.d
Outdated
| propertyOrNull("cwd", getcwd(null, 0)); | ||
| propertyOrNull("argv0", global.params.argv0); | ||
| propertyOrNull("config", global.inifilename); | ||
| propertyOrNull("libname", global.params.libname); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Everything else uses camelCase, might be a good idea to use libName too?
Precedent is above: we don't use inifilename, but config
003a9e2 to
97b33c4
Compare
src/dmd/globals.d
Outdated
| extern(C++) uint versionNumber() | ||
| { | ||
| import core.stdc.ctype; | ||
| static uint cached = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't use thread local storage for dmd. Use __gshared
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch
src/dmd/json.d
Outdated
| comma(); | ||
| } | ||
|
|
||
| void propertyOrNull(const(char)* name, const(char)* s) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No Ddoc header
src/dmd/json.d
Outdated
| item("posix"); | ||
| if (global.params.isLinux) | ||
| item("linux"); | ||
| if (global.params.isOSX) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
else if, etc.
97b33c4 to
caf1fcf
Compare
| /** | ||
| Returns: the version as the number that would be returned for __VERSION__ | ||
| */ | ||
| extern(C++) uint versionNumber() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code duplicates code in the lexer https://github.com/dlang/dmd/blob/master/src/dmd/lexer.d#L518
In fact, it's a cut&paste of it. It should take an argument instead of relying on a global, and moved to another module (lexer.d?).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As you can see later on in this PR, the code was removed from lexer.d and replaced with a call to this function. I could move this function to lexer.d and have json import lexer (instead of having json and lexer share the implementation from global). Would you prefer that? Although, I'm not sure if json importing lexer would cause a cyclic dependency issue...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes it could take an argument, but then the value won't be cached. This current implementation allows the value to be cached in case __VERSION__ is used multiple times along with outputing the __VERSION__ json value. Plus, there's currently no other caller who would pass something other than global.params._version.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see you are correct. I missed that. I with draw both suggestions.
caf1fcf to
3c6cf52
Compare
|
Is this no longer a WIP? |
|
Correct no longer WIP. Though this does not "finalize" all the JSON fields...this should be ready for merge so others can build upon it. |
Added fields to
compilerInfoobject in JSON object.Note that this is based on #7521
It differs a bit, electing to go for a json representation matching the internals rather than trying to exactly match DUB probe files. Not sure which approach is better for DMD, this one is easier to implement so I went with this one for now.
Example Output:
{ "compilerInfo" : { "vendor" : "Digital Mars D", "version" : "v2.078.2-742-gd6b8376-dirty", "__VERSION__" : 2078, "compilerInterface" : "dmd", "bitWidth" : 64, "platforms" : [ "posix" ], "architectures" : [ "x86_64" ], "predefinedVersions" : [], "supportsIncludeImports" : true }, "buildInfo" : { "cwd" : "/home/marlerj/ddev1/dmd", "argv0" : "./generated/linux/release/64/dmd", "config" : "./generated/linux/release/64/dmd.conf", "importPaths" : [ "./generated/linux/release/64/../../../../../druntime/import", "./generated/linux/release/64/../../../../../phobos" ], "objectFiles" : [], "libraryFiles" : [], "ddocFiles" : [], "mapFile" : null, "resourceFile" : null, "defFile" : null } }