summaryrefslogtreecommitdiffstats
path: root/tools/checkdeps
diff options
context:
space:
mode:
authorphajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-11-18 23:37:43 +0000
committerphajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-11-18 23:37:43 +0000
commit63f932e423b03ca9f32fa1ef1ae70bc516a9d429 (patch)
treecbaa728c24ef0e7c26b5466950f78c68a31feee7 /tools/checkdeps
parent25740e7ad3e6ec9728688219a3fbf7e7163cb187 (diff)
downloadchromium_src-63f932e423b03ca9f32fa1ef1ae70bc516a9d429.zip
chromium_src-63f932e423b03ca9f32fa1ef1ae70bc516a9d429.tar.gz
chromium_src-63f932e423b03ca9f32fa1ef1ae70bc516a9d429.tar.bz2
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
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