summaryrefslogtreecommitdiffstats
path: root/tools/checkdeps
diff options
context:
space:
mode:
Diffstat (limited to 'tools/checkdeps')
-rwxr-xr-xtools/checkdeps/checkdeps.py8
-rw-r--r--tools/checkdeps/results.py37
2 files changed, 45 insertions, 0 deletions
diff --git a/tools/checkdeps/checkdeps.py b/tools/checkdeps/checkdeps.py
index 0dd0f49..c486a62 100755
--- a/tools/checkdeps/checkdeps.py
+++ b/tools/checkdeps/checkdeps.py
@@ -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()
diff --git a/tools/checkdeps/results.py b/tools/checkdeps/results.py
index 8f9c189..f8b13f8 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