aboutsummaryrefslogtreecommitdiff
path: root/gcc/diagnostic-output-spec.h
AgeCommit message (Collapse)AuthorFilesLines
9 daysdiagnostics: move diagnostics_output_spec to diagnostics::output_specDavid Malcolm1-116/+0
No functional change intended. gcc/ChangeLog: * Makefile.in (OBJS-libcommon): Replace diagnostic-output-spec.o with diagnostics/output-spec.o. * diagnostic-output-spec.cc: Move to... * diagnostics/output-spec.cc: ...here. Update #include for move of diagnostic-output-spec.h to diagnostics/output-spec.h. (namespace::diagnostics_output_spec): Replace with... (namespace diagnostics::output_spec): ...this, removing redundant prefixes. (diagnostics_output_spec::gcc_spec_context): Replace with... (diagnostics::output_spec::dc_spec_context): ...this. (diagnostic_output_spec_cc_tests): Rename to... (diagnostics_output_spec_cc_tests): ...this. * diagnostic-output-spec.h: Move to... * diagnostics/output-spec.h: ...here and update inclusion guard. (namespace::diagnostics_output_spec): Replace with... (namespace diagnostics::output_spec): ...this, removing redundant prefixes. (diagnostics_output_spec::gcc_spec_context): Replace with... (diagnostics::output_spec::dc_spec_context): ...this. * libgdiagnostics.cc: Update #include for move of diagnostic-output-spec.h to diagnostics/output-spec.h. * opts-diagnostic.cc: Likewise. Update for namespace and name changes. * selftest-run-tests.cc (selftest::run_tests): Update for renaming of diagnostic_output_spec_cc_tests to diagnostics_output_spec_cc_tests. * selftest.h (diagnostic_output_spec_cc_tests): Rename decl to... (diagnostics_output_spec_cc_tests): ...this. Signed-off-by: David Malcolm <dmalcolm@redhat.com>
9 daysdiagnostics: rename diagnostic_output_file to diagnostics::output_fileDavid Malcolm1-2/+2
No functional change intended. gcc/ChangeLog: * diagnostic-format-html.cc: Update #include for move of diagnostic-output-file.h to diagnostics/output-file.h. Update for move of diagnostic_output_file to diagnostics::output_file. * diagnostic-format-html.h: Likewise. * diagnostic-format-sarif.cc: Likewise. * diagnostic-format-sarif.h: Likewise. * diagnostic-output-spec.cc: Likewise. * diagnostic-output-spec.h (along): Likewise. * diagnostic-output-file.h: Move to... * diagnostics/output-file.h: ...here, updating header guard. (class diagnostic_output_file): Move to... (class diagnostics::output_file): ...here. * libgdiagnostics.cc (sarif_sink::sarif_sink): Update for move of diagnostic_output_file to diagnostics::output_file. Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2025-06-23libgdiagnostics: sarif-replay: add extra sinks via -fdiagnostics-add-output= ↵David Malcolm1-0/+116
[PR116792,PR116163] This patch refactors the support for -fdiagnostics-add-output=SCHEME from GCC's options parsing so that it is also available to sarif-replay and to other clients of libgdiagnostics. With this users of sarif-replay and other such tools can generate HTML or SARIF as well as text output, using the same -fdiagnostics-add-output=SCHEME as GCC. As a test, the patch adds support for this option to the dg-lint script below "contrib". For example dg-lint can now generate text, html, and sarif output via: LD_LIBRARY_PATH=../build/gcc/ \ ./contrib/dg-lint/dg-lint \ contrib/dg-lint/test-*.c \ -fdiagnostics-add-output=experimental-html:file=dg-lint-tests.html \ -fdiagnostics-add-output=sarif:file=dg-lint-tests.sarif where the HTML output from dg-lint can be seen here: https://dmalcolm.fedorapeople.org/gcc/2025-06-20/dg-lint-tests.html the sarif output here: https://dmalcolm.fedorapeople.org/gcc/2025-06-23/dg-lint-tests.sarif and a screenshot of VS Code viewing the sarif output is here: https://dmalcolm.fedorapeople.org/gcc/2025-06-23/vscode-viewing-dg-lint-sarif-output.png As well as allowing sarif-replay to generate HTML, this patch allows sarif-replay to also generate SARIF. Ideally this would faithfully round-trip all the data, but it's not perfect (which I'm tracking as PR sarif-replay/120792). contrib/ChangeLog: PR other/116792 PR testsuite/116163 PR sarif-replay/120792 * dg-lint/dg-lint: Add -fdiagnostics-add-output. * dg-lint/libgdiagnostics.py: Add diagnostic_manager_add_sink_from_spec. (Manager.add_sink_from_spec): New. gcc/ChangeLog: PR other/116792 PR testsuite/116163 PR sarif-replay/120792 * Makefile.in (OBJS-libcommon): Add diagnostic-output-spec.o. * diagnostic-format-html.cc (html_builder::html_builder): Ensure title is non-empty. * diagnostic-output-spec.cc: New file, taken from material in opts-diagnostic.cc. * diagnostic-output-spec.h: New file. * diagnostic.cc (diagnostic_context::set_main_input_filename): New. * diagnostic.h (diagnostic_context::set_main_input_filename): New decl. * doc/libgdiagnostics/topics/compatibility.rst (LIBGDIAGNOSTICS_ABI_2): New. * doc/libgdiagnostics/topics/diagnostic-manager.rst (diagnostic_manager_add_sink_from_spec): New. (diagnostic_manager_set_analysis_target): New. * libgdiagnostics++.h (manager::add_sink_from_spec): New. (manager::set_analysis_target): New. * libgdiagnostics.cc: Include "diagnostic-output-spec.h". (struct spec_context): New. (diagnostic_manager_add_sink_from_spec): New. (diagnostic_manager_set_analysis_target): New. * libgdiagnostics.h (LIBDIAGNOSTICS_HAVE_diagnostic_manager_add_sink_from_spec): New define. (diagnostic_manager_add_sink_from_spec): New decl. (LIBDIAGNOSTICS_HAVE_diagnostic_manager_set_analysis_target): New define. (diagnostic_manager_set_analysis_target): New decl. * libgdiagnostics.map (LIBGDIAGNOSTICS_ABI_2): New. * libsarifreplay.cc (sarif_replayer::handle_artifact_obj): Looks for "analysisTarget" in roles and call set_analysis_target using the artifact if found. * opts-diagnostic.cc: Refactor, moving material to diagnostic-output-spec.cc. (struct opt_spec_context): New. (handle_OPT_fdiagnostics_add_output_): Use opt_spec_context. (handle_OPT_fdiagnostics_set_output_): Likewise. * sarif-replay.cc: Define INCLUDE_STRING. (struct options): Add m_extra_output_specs. (usage_msg): Add -fdiagnostics-add-output=SCHEME. (str_starts_with): New. (parse_options): Add -fdiagnostics-add-output=SCHEME. (main): Likewise. * selftest-run-tests.cc (selftest::run_tests): Call diagnostic_output_spec_cc_tests rather than opts_diagnostic_cc_tests. * selftest.h (selftest::diagnostic_output_spec_cc_tests): Replace... (selftest::opts_diagnostic_cc_tests): ...this. gcc/testsuite/ChangeLog: PR other/116792 PR testsuite/116163 PR sarif-replay/120792 * sarif-replay.dg/2.1.0-valid/signal-1-check-html.py: New test script. * sarif-replay.dg/2.1.0-valid/signal-1.c.sarif: Add html and sarif generation to options. Invoke the new script to verify that HTML and SARIF is generated. Signed-off-by: David Malcolm <dmalcolm@redhat.com>