OLD | NEW |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # | 2 # |
3 # Copyright 2008 the V8 project authors. All rights reserved. | 3 # Copyright 2008 the V8 project authors. All rights reserved. |
4 # Redistribution and use in source and binary forms, with or without | 4 # Redistribution and use in source and binary forms, with or without |
5 # modification, are permitted provided that the following conditions are | 5 # modification, are permitted provided that the following conditions are |
6 # met: | 6 # met: |
7 # | 7 # |
8 # * Redistributions of source code must retain the above copyright | 8 # * Redistributions of source code must retain the above copyright |
9 # notice, this list of conditions and the following disclaimer. | 9 # notice, this list of conditions and the following disclaimer. |
10 # * Redistributions in binary form must reproduce the above | 10 # * Redistributions in binary form must reproduce the above |
(...skipping 12 matching lines...) Expand all Loading... | |
23 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
24 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
25 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 | 29 |
30 | 30 |
31 import optparse | 31 import optparse |
32 import os | 32 import os |
33 from os.path import abspath, join, dirname, basename | 33 from os.path import abspath, join, dirname, basename, exists |
34 import re | 34 import re |
35 import sys | 35 import sys |
36 import subprocess | 36 import subprocess |
37 | 37 |
38 # Disabled LINT rules and reason. | 38 # Disabled LINT rules and reason. |
39 # build/include_what_you_use: Started giving false positives for variables | 39 # build/include_what_you_use: Started giving false positives for variables |
40 # named "string" and "map" assuming that you needed to include STL headers. | 40 # named "string" and "map" assuming that you needed to include STL headers. |
41 | 41 |
42 ENABLED_LINT_RULES = """ | 42 ENABLED_LINT_RULES = """ |
43 build/class | 43 build/class |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
96 class SourceFileProcessor(object): | 96 class SourceFileProcessor(object): |
97 """ | 97 """ |
98 Utility class that can run through a directory structure, find all relevant | 98 Utility class that can run through a directory structure, find all relevant |
99 files and invoke a custom check on the files. | 99 files and invoke a custom check on the files. |
100 """ | 100 """ |
101 | 101 |
102 def Run(self, path): | 102 def Run(self, path): |
103 all_files = [] | 103 all_files = [] |
104 for file in self.GetPathsToSearch(): | 104 for file in self.GetPathsToSearch(): |
105 all_files += self.FindFilesIn(join(path, file)) | 105 all_files += self.FindFilesIn(join(path, file)) |
106 if not self.ProcessFiles(all_files): | 106 if not self.ProcessFiles(all_files, path): |
107 return False | 107 return False |
108 return True | 108 return True |
109 | 109 |
110 def IgnoreDir(self, name): | 110 def IgnoreDir(self, name): |
111 return name.startswith('.') or name == 'data' | 111 return name.startswith('.') or name == 'data' |
112 | 112 |
113 def IgnoreFile(self, name): | 113 def IgnoreFile(self, name): |
114 return name.startswith('.') | 114 return name.startswith('.') |
115 | 115 |
116 def FindFilesIn(self, path): | 116 def FindFilesIn(self, path): |
(...skipping 21 matching lines...) Expand all Loading... | |
138 | 138 |
139 IGNORE_LINT = ['flag-definitions.h'] | 139 IGNORE_LINT = ['flag-definitions.h'] |
140 | 140 |
141 def IgnoreFile(self, name): | 141 def IgnoreFile(self, name): |
142 return (super(CppLintProcessor, self).IgnoreFile(name) | 142 return (super(CppLintProcessor, self).IgnoreFile(name) |
143 or (name in CppLintProcessor.IGNORE_LINT)) | 143 or (name in CppLintProcessor.IGNORE_LINT)) |
144 | 144 |
145 def GetPathsToSearch(self): | 145 def GetPathsToSearch(self): |
146 return ['src', 'public', 'samples', join('test', 'cctest')] | 146 return ['src', 'public', 'samples', join('test', 'cctest')] |
147 | 147 |
148 def ProcessFiles(self, files): | 148 def ProcessFiles(self, files, path): |
149 filt = '-,' + ",".join(['+' + n for n in ENABLED_LINT_RULES]) | 149 filt = '-,' + ",".join(['+' + n for n in ENABLED_LINT_RULES]) |
150 command = ['cpplint.py', '--filter', filt] + join(files) | 150 command = ['cpplint.py', '--filter', filt] + join(files) |
151 local_cpplint = join(path, "tools", "cpplint.py") | |
152 if exists(local_cpplint): | |
153 command = ['python', local_cpplint, '--filter', filt] + join(files) | |
Christian Plesner Hansen
2009/09/08 07:48:58
Above we call cpplint.py as the executable, here w
Søren Thygesen Gjesse
2009/09/11 12:30:53
I could not make that work in Windows.
| |
151 process = subprocess.Popen(command) | 154 process = subprocess.Popen(command) |
152 return process.wait() == 0 | 155 return process.wait() == 0 |
153 | 156 |
154 | 157 |
155 COPYRIGHT_HEADER_PATTERN = re.compile( | 158 COPYRIGHT_HEADER_PATTERN = re.compile( |
156 r'Copyright [\d-]*200[8-9] the V8 project authors. All rights reserved.') | 159 r'Copyright [\d-]*200[8-9] the V8 project authors. All rights reserved.') |
157 | 160 |
158 class SourceProcessor(SourceFileProcessor): | 161 class SourceProcessor(SourceFileProcessor): |
159 """ | 162 """ |
160 Check that all files include a copyright notice. | 163 Check that all files include a copyright notice. |
(...skipping 26 matching lines...) Expand all Loading... | |
187 if not base in SourceProcessor.IGNORE_TABS: | 190 if not base in SourceProcessor.IGNORE_TABS: |
188 if '\t' in contents: | 191 if '\t' in contents: |
189 print "%s contains tabs" % name | 192 print "%s contains tabs" % name |
190 result = False | 193 result = False |
191 if not base in SourceProcessor.IGNORE_COPYRIGHTS: | 194 if not base in SourceProcessor.IGNORE_COPYRIGHTS: |
192 if not COPYRIGHT_HEADER_PATTERN.search(contents): | 195 if not COPYRIGHT_HEADER_PATTERN.search(contents): |
193 print "%s is missing a correct copyright header." % name | 196 print "%s is missing a correct copyright header." % name |
194 result = False | 197 result = False |
195 return result | 198 return result |
196 | 199 |
197 def ProcessFiles(self, files): | 200 def ProcessFiles(self, files, path): |
198 success = True | 201 success = True |
199 for file in files: | 202 for file in files: |
200 try: | 203 try: |
201 handle = open(file) | 204 handle = open(file) |
202 contents = handle.read() | 205 contents = handle.read() |
203 success = self.ProcessContents(file, contents) and success | 206 success = self.ProcessContents(file, contents) and success |
204 finally: | 207 finally: |
205 handle.close() | 208 handle.close() |
206 return success | 209 return success |
207 | 210 |
(...skipping 14 matching lines...) Expand all Loading... | |
222 success = CppLintProcessor().Run(workspace) and success | 225 success = CppLintProcessor().Run(workspace) and success |
223 success = SourceProcessor().Run(workspace) and success | 226 success = SourceProcessor().Run(workspace) and success |
224 if success: | 227 if success: |
225 return 0 | 228 return 0 |
226 else: | 229 else: |
227 return 1 | 230 return 1 |
228 | 231 |
229 | 232 |
230 if __name__ == '__main__': | 233 if __name__ == '__main__': |
231 sys.exit(Main()) | 234 sys.exit(Main()) |
OLD | NEW |