Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(21)

Unified Diff: tools/checkdeps/results.py

Issue 75693002: GTTF: Make checkdeps.py produce JSON output that can be used in a recipe. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/checkdeps/checkdeps.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « tools/checkdeps/checkdeps.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698