GTTF: Make checkdeps.py produce JSON output that can be used in a recipe.

BUG=317931
R=joi@chromium.org

Review URL: https://codereview.chromium.org/75693002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@235848 0039d316-1c4b-4281-b951-d872f2087c98
parent 25740e7a
......@@ -186,6 +186,9 @@ def main():
'-v', '--verbose',
action='store_true', default=False,
help='Print debug logging')
option_parser.add_option(
'', '--json',
help='Path to JSON output file')
options, args = option_parser.parse_args()
deps_checker = DepsChecker(options.base_directory,
......@@ -213,6 +216,11 @@ def main():
deps_checker.results_formatter = results.TemporaryRulesFormatter()
elif options.count_violations:
deps_checker.results_formatter = results.CountViolationsFormatter()
if options.json:
deps_checker.results_formatter = results.JSONResultsFormatter(
options.json, deps_checker.results_formatter)
deps_checker.CheckDirectory(start_dir)
return deps_checker.Report()
......
......@@ -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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment