Add -fdiagnostics-format={json-stderr|json-file}
authorDavid Malcolm <dmalcolm@redhat.com>
Thu, 2 Jun 2022 19:38:38 +0000 (15:38 -0400)
committerDavid Malcolm <dmalcolm@redhat.com>
Thu, 2 Jun 2022 19:38:38 +0000 (15:38 -0400)
commit5ab73173cca4610e59df8a3fe9cb5b30ded75aec
tree4a87b670311228c8d5c16ad9af7d0c70fcd10061
parent4f9ad0b4b0a8c780b85a06096b9926ca85d7a9a6
Add -fdiagnostics-format={json-stderr|json-file}

This commit adds -fdiagnostics-format=json-file, writing to
DUMP_BASE_NAME.gcc.json, and adds -fdiagnostics-format=json-stderr,
a synonym for the existing -fdiagnostics-format=json.

gcc/ChangeLog:
* common.opt (fdiagnostics-format=): Add json-stderr and json-file
to description.
(DIAGNOSTICS_OUTPUT_FORMAT_JSON): Rename to...
(DIAGNOSTICS_OUTPUT_FORMAT_JSON_STDERR): ...this.
(diagnostics_output_format): Add json-stderr and json-file.
* diagnostic-format-json.cc (json_flush_to_file): New.
(json_final_cb): Convert to...
(json_flush_to_file): ...this, ...
(json_stderr_final_cb): ...this, and...
(json_file_final_cb): ...this.
(diagnostic_output_format_init): Move to diagnostic.cc.
(json_output_base_file_name): New.
(diagnostic_output_format_init_json): New.
(diagnostic_output_format_init_json_stderr): New.
(diagnostic_output_format_init_json_file): New.
* diagnostic.cc (diagnostic_output_format_init): Move here from
diagnostic-format-json.cc; update for changes to enum.
* diagnostic.h (enum diagnostics_output_format): Rename
DIAGNOSTICS_OUTPUT_FORMAT_JSON to
DIAGNOSTICS_OUTPUT_FORMAT_JSON_STDERR, and add
DIAGNOSTICS_OUTPUT_FORMAT_JSON_FILE.
(diagnostic_output_format_init): Add base_file_name param.
(diagnostic_output_format_init_json_stderr): New decl.
(diagnostic_output_format_init_json_file): New dec.
* doc/invoke.texi (-fdiagnostics-format=): Add "json-stderr" and
"json-file".  Rewrite so that the existing "json" is a synonym of
"json-stderr".
* gcc.cc (driver_handle_option): Pass dump_base_name to
diagnostic_output_format_init.
* opts.cc (common_handle_option): Likewise.

gcc/testsuite/ChangeLog:
* c-c++-common/diagnostic-format-json-file-1.c: New test.
* c-c++-common/diagnostic-format-json-stderr-1.c: New test.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
gcc/common.opt
gcc/diagnostic-format-json.cc
gcc/diagnostic.cc
gcc/diagnostic.h
gcc/doc/invoke.texi
gcc/gcc.cc
gcc/opts.cc
gcc/testsuite/c-c++-common/diagnostic-format-json-file-1.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/diagnostic-format-json-stderr-1.c [new file with mode: 0644]