| Index: tools/checkdeps/results.py
|
| diff --git a/tools/checkdeps/results.py b/tools/checkdeps/results.py
|
| index 8f9c1898549e68a0fa94db3784c902e55075d3ad..f8b13f89f02370891d5db1d98ebfec1ba34f0b4d 100644
|
| --- a/tools/checkdeps/results.py
|
| +++ b/tools/checkdeps/results.py
|
| @@ -6,6 +6,9 @@
|
| """Results object and results formatters for checkdeps tool."""
|
|
|
|
|
| +import json
|
| +
|
| +
|
| class DependencyViolation(object):
|
| """A single dependency violation."""
|
|
|
| @@ -98,6 +101,40 @@ class NormalResultsFormatter(ResultsFormatter):
|
| print '\nFAILED\n'
|
|
|
|
|
| +class JSONResultsFormatter(ResultsFormatter):
|
| + """A results formatter that outputs results to a file as JSON."""
|
| +
|
| + def __init__(self, output_path, wrapped_formatter=None):
|
| + self.output_path = output_path
|
| + self.wrapped_formatter = wrapped_formatter
|
| +
|
| + self.results = []
|
| +
|
| + def AddError(self, dependee_status):
|
| + self.results.append({
|
| + 'dependee_path': dependee_status.dependee_path,
|
| + 'violations': [{
|
| + 'include_path': violation.include_path,
|
| + 'violated_rule': violation.violated_rule.AsDependencyTuple(),
|
| + } for violation in dependee_status.violations]
|
| + })
|
| +
|
| + if self.wrapped_formatter:
|
| + self.wrapped_formatter.AddError(dependee_status)
|
| +
|
| + def GetResults(self):
|
| + with open(self.output_path, 'w') as f:
|
| + f.write(json.dumps(self.results))
|
| +
|
| +
|
| + def PrintResults(self):
|
| + if self.wrapped_formatter:
|
| + self.wrapped_formatter.PrintResults()
|
| + return
|
| +
|
| + print self.results
|
| +
|
| +
|
| class TemporaryRulesFormatter(ResultsFormatter):
|
| """A results formatter that produces a single line per nonconforming
|
| include. The combined output is suitable for directly pasting into a
|
|
|