Skip to content
Closed
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
9 changes: 9 additions & 0 deletions src/dmd/json.d
Original file line number Diff line number Diff line change
Expand Up @@ -806,3 +806,12 @@ extern (C++) void json_generate(OutBuffer* buf, Modules* modules)
json.arrayEnd();
json.removeComma();
}

extern (C++) void json_info(OutBuffer* buf)
{
scope ToJsonVisitor json = new ToJsonVisitor(buf);
json.objectStart();
json.property("compilerVendor", global.compiler.vendor);
json.objectEnd();
json.removeComma();
}
29 changes: 27 additions & 2 deletions src/dmd/mars.d
Original file line number Diff line number Diff line change
Expand Up @@ -360,8 +360,33 @@ private int tryMain(size_t argc, const(char)** argv)
}
if (files.dim == 0)
{
usage();
return EXIT_FAILURE;
// -X without arguments is the JSON analog of --version
if (global.params.doJsonGeneration)
{
OutBuffer buf;
json_info(&buf);
buf.writestring("\n");
// write to stdout for -X and -Xf=-
if (!global.params.jsonfilename || strcmp(global.params.jsonfilename, "-") == 0)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If wanted I can split this if statement and print the manual for -X (previous behavior).

{
fputs(buf.peekString(), stdout);
fflush(stdout);
}
else
{
ensurePathToNameExists(Loc.initial, global.params.jsonfilename);
auto jsonfile = new File(global.params.jsonfilename);
jsonfile.setbuffer(buf.data, buf.offset);
jsonfile._ref = 1;
writeFile(Loc.initial, jsonfile);
}
return EXIT_SUCCESS;
}
else
{
usage();
return EXIT_FAILURE;
}
}
static if (TARGET.OSX)
{
Expand Down
3 changes: 3 additions & 0 deletions test/compilable/extra-files/testjsonstdout.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"compilerVendor" : "Digital Mars D"
}
21 changes: 21 additions & 0 deletions test/compilable/testjsonstdout.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env bash

set -ueo pipefail

name="$(basename "$0" .sh)"
dir="${RESULTS_DIR}/compilable/"
out="$dir/${name}.json.out"

"$DMD" -X > "$out"
diff "$out" compilable/extra-files/$name.json
rm "$out"

"$DMD" -Xf=- > "$out"
diff "$out" compilable/extra-files/$name.json
rm "$out"

"$DMD" -Xf="$out"
diff "$out" compilable/extra-files/$name.json
rm "$out"

echo "OK" > "${dir}/${name}.sh.out"