mirror of
https://gcc.gnu.org/git/gcc.git
synced 2024-11-23 10:54:07 +08:00
ea1506adbe
This patch adds a new "sarif-replay" command-line tool for viewing .sarif files. It uses libdiagnostics to "replay" any diagnostics found in the .sarif files in text form as if they were GCC diagnostics. contrib/ChangeLog: PR other/96032 * regenerate-sarif-spec-index.py: New file. gcc/ChangeLog: PR other/96032 * Makefile.in (lang_checks): If libdiagnostics is enabled, add check-sarif-replay. (SARIF_REPLAY_OBJS): New. (ALL_HOST_OBJS): If libdiagnostics is enabled, add $(SARIF_REPLAY_OBJS). (sarif-replay): New. (install-libdiagnostics): Add sarif-replay to deps, and install it. * configure: Regenerate. * configure.ac (check_languages): If libdiagnostics is enabled, add check-sarif-replay. (LIBDIAGNOSTICS): If libdiagnostics is enabled, add sarif-replay. * doc/install.texi (--enable-libdiagnostics): Note that it also enables sarif-replay. * libsarifreplay.cc: New file. * libsarifreplay.h: New file. * sarif-replay.cc: New file. * sarif-spec-urls.def: New file. gcc/testsuite/ChangeLog: PR other/96032 * lib/gcc-dg.exp (gcc-dg-test-1): Add "replay-sarif". * lib/sarif-replay-dg.exp: New file. * lib/sarif-replay.exp: New file. * sarif-replay.dg/2.1.0-invalid/3.1-not-an-object.sarif: New test. * sarif-replay.dg/2.1.0-invalid/3.11.11-malformed-placeholder.sarif: New test. * sarif-replay.dg/2.1.0-invalid/3.11.11-missing-arguments-for-placeholders.sarif: New test. * sarif-replay.dg/2.1.0-invalid/3.11.11-not-enough-arguments-for-placeholders.sarif: New test. * sarif-replay.dg/2.1.0-invalid/3.13.2-no-version.sarif: New test. * sarif-replay.dg/2.1.0-invalid/3.13.2-version-not-a-string.sarif: New test. * sarif-replay.dg/2.1.0-invalid/3.13.4-bad-runs.sarif: New test. * sarif-replay.dg/2.1.0-invalid/3.13.4-no-runs.sarif: New test. * sarif-replay.dg/2.1.0-invalid/3.13.4-non-object-in-runs.sarif: New test. * sarif-replay.dg/2.1.0-invalid/3.27.10-bad-level.sarif: New test. * sarif-replay.dg/2.1.0-unhandled/3.27.10-none-level.sarif: New test. * sarif-replay.dg/2.1.0-valid/error-with-note.sarif: New test. * sarif-replay.dg/2.1.0-valid/escaped-braces.sarif: New test. * sarif-replay.dg/2.1.0-valid/null-runs.sarif: New test. * sarif-replay.dg/2.1.0-valid/signal-1.c.sarif: New test. * sarif-replay.dg/2.1.0-valid/spec-example-1.sarif: New test. * sarif-replay.dg/2.1.0-valid/spec-example-2.sarif: New test. * sarif-replay.dg/2.1.0-valid/spec-example-3.sarif: New test. * sarif-replay.dg/2.1.0-valid/spec-example-4.sarif: New test. * sarif-replay.dg/2.1.0-valid/tutorial-example.sarif: New test. * sarif-replay.dg/dg.exp: New script. * sarif-replay.dg/malformed-json/array-missing-comma.sarif: New test. * sarif-replay.dg/malformed-json/array-with-trailing-comma.sarif: New test. * sarif-replay.dg/malformed-json/bad-token.sarif: New test. * sarif-replay.dg/malformed-json/object-missing-comma.sarif: New test. * sarif-replay.dg/malformed-json/object-with-trailing-comma.sarif: New test. Signed-off-by: David Malcolm <dmalcolm@redhat.com>
61 lines
2.1 KiB
Python
61 lines
2.1 KiB
Python
#!/usr/bin/env python3
|
|
|
|
# Copyright (C) 2024 Free Software Foundation, Inc.
|
|
#
|
|
# This file is part of GCC.
|
|
#
|
|
# GCC is free software; you can redistribute it and/or modify it under
|
|
# the terms of the GNU General Public License as published by the Free
|
|
# Software Foundation; either version 3, or (at your option) any later
|
|
# version.
|
|
#
|
|
# GCC is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
# WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
# for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with GCC; see the file COPYING3. If not see
|
|
# <http://www.gnu.org/licenses/>.
|
|
|
|
# Unfortunately the SARIF 2.1.0 spec doesn't have memorable anchors
|
|
# for its subsections
|
|
# (filed as https://github.com/oasis-tcs/sarif-spec/issues/533)
|
|
#
|
|
# In the meantime, use this script to generate a table mapping subsections
|
|
# to anchors.
|
|
|
|
from pprint import pprint
|
|
import re
|
|
|
|
spec_url = 'https://docs.oasis-open.org/sarif/sarif/v2.1.0/errata01/os/sarif-v2.1.0-errata01-os-complete.html'
|
|
filename_in = 'sarif-v2.1.0-errata01-os-complete.html'
|
|
|
|
d = {}
|
|
with open(filename_in, encoding='windows-1252') as infile:
|
|
for line in infile:
|
|
m = re.match(r'<p class=MsoToc[0-9]+><a href="#(.*)">(.*)<span.*\n', line)
|
|
if m:
|
|
#print('MATCH')
|
|
#print(repr(line))
|
|
#print(m.groups())
|
|
m2 = re.match(r'([0-9.]+) .*', m.group(2))
|
|
if m2:
|
|
#print(m2.groups())
|
|
d[m2.group(1)] = m.group(1)
|
|
|
|
filename_out = '../gcc/sarif-spec-urls.def'
|
|
with open(filename_out, 'w') as outfile:
|
|
outfile.write('/* Generated by regenerate-sarif-spec-index.py. */\n\n')
|
|
|
|
outfile.write(f'static const char * const sarif_spec_base_url\n = "{spec_url}";\n\n')
|
|
|
|
outfile.write('static const struct ref_anchor\n'
|
|
'{\n'
|
|
' const char *m_ref;\n'
|
|
' const char *m_anchor;\n'
|
|
'} sarif_spec_anchor_arr[] = {\n');
|
|
for ref, anchor in d.items():
|
|
outfile.write(f' {{ "{ref}", "{anchor}" }},\n')
|
|
outfile.write('};')
|