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

Side by Side Diff: tools/checkdeps/results.py

Issue 10832062: Add ability to format errors as a list of temp-allow rules to paste (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 4 months 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4
5
6 """Results object and results formatters for checkdeps tool."""
7
8
9 class DependencyViolation(object):
10 """A single dependency violation."""
11
12 def __init__(self, include_path, violated_rule, rules):
13 # Path of the included or imported file that is in violation of a rule.
erikwright (departed) 2012/07/31 17:22:46 I would write this as "The include or import path
Jói 2012/08/01 15:22:58 Done.
14 self.include_path = include_path
15
16 # The specific rule
erikwright (departed) 2012/07/31 17:22:46 The violated rule.
Jói 2012/08/01 15:22:58 Done.
17 self.violated_rule = violated_rule
18
19 # The set of rules containing self.violated_rules
erikwright (departed) 2012/07/31 17:22:46 violated_rules -> violated_rule Add a '.'
Jói 2012/08/01 15:22:58 Done.
20 self.rules = rules
21
22
23 class DependeeStatus(object):
24 """Results object for a file that has one or more violations."""
erikwright (departed) 2012/07/31 17:22:46 "one or more" seems wrong, given the presence of "
Jói 2012/08/01 15:22:58 Done.
25
26 def __init__(self, dependee_path):
27 # Path of the file that has the dependencies-in-violation listed
erikwright (departed) 2012/07/31 17:22:46 Maybe "Path of the file whose nonconforming depend
Jói 2012/08/01 15:22:58 Done.
28 # in self.violations.
29 self.dependee_path = dependee_path
30
31 # List of DependencyViolation objects that apply to the dependee
32 # file.
33 self.violations = []
34
35 def AddViolation(self, violation):
36 """Adds a violation."""
37 self.violations.append(violation)
38
39 def HasViolations(self):
40 """Returns True if this dependee is violating one or more rules."""
41 return not not self.violations
42
43
44 class ResultsFormatter(object):
45 """Base class for results formatters."""
46
47 def __init__(self):
48 self.results = []
erikwright (departed) 2012/07/31 17:22:46 I would pull results into NormalResultsFormatter,
Jói 2012/08/01 15:22:58 Done.
49
50 def AddError(self, dependee_status):
51 """Add a formatted result to |self.results| for |dependee_status|,
52 which is guaranteed to return True for
53 |dependee_status.HasViolations|.
54 """
55 raise NotImplementedError()
56
57 def GetResults(self):
58 """Returns the results. May be overridden e.g. to process the
59 results that have been accumulated.
60 """
61 return self.results
62
63 def PrintResults(self):
64 """Prints the results to stdout."""
65 raise NotImplementedError()
66
67
68 class NormalResultsFormatter(ResultsFormatter):
69 """A results formatting object that produces the classical,
70 detailed, human-readable output of the checkdeps tool.
71 """
72
73 def __init__(self, verbose):
74 super(NormalResultsFormatter, self).__init__()
75 self.verbose = verbose
76
77 def AddError(self, dependee_status):
78 lines = []
79 lines.append('\nERROR in %s' % dependee_status.dependee_path)
80 for violation in dependee_status.violations:
81 lines.append(self.FormatViolation(violation))
82 self.results.append('\n'.join(lines))
83
84 def FormatViolation(self, violation):
erikwright (departed) 2012/07/31 17:22:46 I would convert this into a class function taking
85 lines = []
86 if self.verbose:
87 lines.append('For %s' % violation.rules)
88 lines.append(
89 ' Illegal include: "%s"\n Because of %s' %
90 (violation.include_path, str(violation.violated_rule)))
91 return '\n'.join(lines)
92
93 def PrintResults(self):
94 for result in self.results:
95 print result
96 if self.results:
97 print '\nFAILED\n'
98
99
100 class TemporaryRulesFormatter(ResultsFormatter):
101 """A results formatter that produces a single line per file that
erikwright (departed) 2012/07/31 17:22:46 "a single line per file that fails checks" indicat
102 fails checks, that is suitable for directly pasting into a DEPS file
103 as a temporary-allow rule.
104 """
105
106 def __init__(self):
107 self.violations = set()
108
109 def AddError(self, dependee_status):
110 for violation in dependee_status.violations:
111 self.violations.add(violation.include_path)
112
113 def GetResults(self):
114 return [' "!%s",' % path for path in sorted(self.violations)]
115
116 def PrintResults(self):
117 for result in self.GetResults():
118 print result
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698