-
-
Notifications
You must be signed in to change notification settings - Fork 672
Add more stuff to JSON file #7757
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| Added more information to the json output | ||
|
|
||
| The following objects were to the json output: | ||
| --- | ||
| [ | ||
| { | ||
| "kind" : "compilerInfo", | ||
| "binary" : "<filename-of-compiler-binary>", | ||
| "version" : "<compiler-version>", | ||
| "supportsIncludeImports" : true | ||
| }, | ||
| { | ||
| "kind" : "buildInfo", | ||
| "config": "<filename-of-config-file>", | ||
| "cwd": "<cwd-during-compiler-invocation>", | ||
| "importPaths": [ | ||
| "<import-path1>", | ||
| "<import-path2>", | ||
| //... | ||
| ] | ||
| }, | ||
| // ... | ||
| { | ||
| "kind": "semantics", | ||
| "modules": [ | ||
| { | ||
| "name": "<module-name>" | ||
| "file": "<module-filename>", | ||
| // isRoot is true if the module is going to be taken | ||
| // to object code. | ||
| "isRoot": true|false, | ||
| }, | ||
| // ... | ||
| ] | ||
| } | ||
| ] | ||
| --- |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,6 +34,12 @@ import dmd.mtype; | |
| import dmd.root.outbuffer; | ||
| import dmd.visitor; | ||
|
|
||
| version(Windows) { | ||
| extern (C) char* getcwd(char* buffer, size_t maxlen); | ||
| } else { | ||
| import core.sys.posix.unistd : getcwd; | ||
| } | ||
|
|
||
| private extern (C++) final class ToJsonVisitor : Visitor | ||
| { | ||
| alias visit = Visitor.visit; | ||
|
|
@@ -789,19 +795,78 @@ public: | |
| jsonProperties(d); | ||
| objectEnd(); | ||
| } | ||
|
|
||
| private void generateCompilerInfo() | ||
| { | ||
| objectStart(); | ||
| property("kind", "compilerInfo"); | ||
| property("binary", global.params.argv0); | ||
| property("version", global._version); | ||
| propertyBool("supportsIncludeImports", true); | ||
| objectEnd(); | ||
| } | ||
| private void generateBuildInfo() | ||
| { | ||
| objectStart(); | ||
| property("kind", "buildInfo"); | ||
| property("cwd", getcwd(null, 0)); | ||
| property("config", global.inifilename ? global.inifilename : null); | ||
| if (global.params.lib) { | ||
| property("library", global.params.libname); | ||
| } | ||
| propertyStart("importPaths"); | ||
| arrayStart(); | ||
| foreach (importPath; *global.params.imppath) | ||
| { | ||
| item(importPath); | ||
| } | ||
| arrayEnd(); | ||
| objectEnd(); | ||
| } | ||
| private void generateSemantics() | ||
| { | ||
| objectStart(); | ||
| property("kind", "semantics"); | ||
| propertyStart("modules"); | ||
| arrayStart(); | ||
| foreach (m; Module.amodules) | ||
| { | ||
| objectStart(); | ||
| if(m.md) | ||
| property("name", m.md.toChars()); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how about:
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was following the convention established here (https://github.com/dlang/dmd/pull/7757/files/a90c983d6e436e46dde3b1ee07fdd280ea1396e7#diff-1d73c979f233c43e47fb88fac32c21b3L475) I don't really see much difference whether or not there is an empty name or no name at all, but following the existing convention seems the better choice. |
||
| property("file", m.srcfile.toChars()); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how about
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hmmmm, interesting thought. I'd have to think about that one. This is mimicking the current functionality from the verbose output, but maybe it can be improved. I'll come back to this.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NOTE: "contentImports" appears to use absolutePath (i tried with -J. and
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe that would be changing behavior though...we could end up with a regression if we change the behavior.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. well, that info wasn't in json output before... so it's one of those gray area things.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now that I think about it, there might be a bug in the current design. If you build with rdmd, and then you change directories and build again, then all the relative module filenames will be incorrect. It might just force you to do a rebuild, but that's no good. We could fix this using absolute paths, or we could save off the original CWD that rdmd was using when it first performed the build.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There should be a test for that in the rdmd test suite, FWIW.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. there may even be corner cases where it picks up wrong file eg: ls rdmd main.d Here's a good compromise: add a CWD field, and when rdmd reads a path (any path) call buildPath(json.CWD, json.path) (does the right thing w absolute paths) and allow for:
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. but we should definitely make behavior consistent between contentImports and modules.file:
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm thinking that the JSON file saves the CWD in the new |
||
| propertyBool("isRoot", m.isRoot()); | ||
| if(m.contentImportedFiles.dim > 0) | ||
| { | ||
| propertyStart("contentImports"); | ||
| arrayStart(); | ||
| foreach (file; m.contentImportedFiles) | ||
| { | ||
| item(file); | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This isn't covered. |
||
| arrayEnd(); | ||
| } | ||
| objectEnd(); | ||
| } | ||
| arrayEnd(); | ||
| objectEnd(); | ||
| } | ||
| } | ||
|
|
||
| extern (C++) void json_generate(OutBuffer* buf, Modules* modules) | ||
| { | ||
| scope ToJsonVisitor json = new ToJsonVisitor(buf); | ||
| json.arrayStart(); | ||
| json.generateCompilerInfo(); | ||
| json.generateBuildInfo(); | ||
| for (size_t i = 0; i < modules.dim; i++) | ||
| { | ||
| Module m = (*modules)[i]; | ||
| if (global.params.verbose) | ||
| fprintf(global.stdmsg, "json gen %s\n", m.toChars()); | ||
| m.accept(json); | ||
| } | ||
| json.generateSemantics(); | ||
| json.arrayEnd(); | ||
| json.removeComma(); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,14 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| grep -v "\"file\" : " ${RESULTS_DIR}/compilable/json.out | grep -v "\"offset\" : " | grep -v "\"deco\" : " > ${RESULTS_DIR}/compilable/json.out.2 | ||
| grep -v "\"file\" : " compilable/extra-files/json.out | grep -v "\"offset\" : " | grep -v "\"deco\" : " > ${RESULTS_DIR}/compilable/json.out.3 | ||
| echo SANITIZING JSON... | ||
| ${RESULTS_DIR}/sanitize_json ${RESULTS_DIR}/compilable/json.out > ${RESULTS_DIR}/compilable/json.out.sanitized | ||
| if [ $? -ne 0 ]; then | ||
| exit 1; | ||
| fi | ||
|
|
||
| diff --strip-trailing-cr ${RESULTS_DIR}/compilable/json.out.2 ${RESULTS_DIR}/compilable/json.out.3 | ||
| diff --strip-trailing-cr compilable/extra-files/json.out ${RESULTS_DIR}/compilable/json.out.sanitized | ||
| if [ $? -ne 0 ]; then | ||
| exit 1; | ||
| fi | ||
|
|
||
| rm ${RESULTS_DIR}/compilable/json.out{.2,.3} | ||
| rm ${RESULTS_DIR}/compilable/json.out.sanitized |
Uh oh!
There was an error while loading. Please reload this page.
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.
is that a concern? what does other version(Windows) code do in other D files?
https://msdn.microsoft.com/en-us/library/ms235450.aspx
This POSIX function is deprecated. Use the ISO C++ conformant _getcwd instead.
Uh oh!
There was an error while loading. Please reload this page.
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 declaration was copied from
dmodule.d. If it's a problem then the fix should be a separate PR.Uh oh!
There was an error while loading. Please reload this page.
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.
Always open an issue about such stuff, otherwise it will be forgotten.
I just did so for this: https://issues.dlang.org/show_bug.cgi?id=18291