OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """ Output file objects for generator. """ | 6 """ Output file objects for generator. """ |
7 | 7 |
8 import difflib | 8 import difflib |
9 import os | 9 import os |
10 import time | 10 import time |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 | 47 |
48 for index in range(len(oldlines)): | 48 for index in range(len(oldlines)): |
49 oldline = oldlines[index] | 49 oldline = oldlines[index] |
50 curline = curlines[index] | 50 curline = curlines[index] |
51 | 51 |
52 if oldline == curline: continue | 52 if oldline == curline: continue |
53 | 53 |
54 curwords = curline.split() | 54 curwords = curline.split() |
55 oldwords = oldline.split() | 55 oldwords = oldline.split() |
56 | 56 |
| 57 # It wasn't a perfect match. Check for changes we should ignore. |
57 # Unmatched lines must be the same length | 58 # Unmatched lines must be the same length |
58 if len(curwords) != len(oldwords): | 59 if len(curwords) != len(oldwords): |
59 return False | 60 return False |
60 | 61 |
61 # If it's not a comment then it's a mismatch | 62 # If it's not a comment then it's a mismatch |
62 if curwords[0] not in ['*', '/*', '//']: | 63 if curwords[0] not in ['*', '/*', '//']: |
63 return False | 64 return False |
64 | 65 |
65 # Ignore changes to the Copyright year which is autogenerated | 66 # Ignore changes to the Copyright year which is autogenerated |
66 # /* Copyright (c) 2011 The Chromium Authors. All rights reserved. | 67 # /* Copyright (c) 2011 The Chromium Authors. All rights reserved. |
67 if len(curwords) > 4 and curwords[1] == 'Copyright': | 68 if len(curwords) > 4 and curwords[1] == 'Copyright': |
68 if curwords[4:] == oldwords[4:]: continue | 69 if curwords[4:] == oldwords[4:]: continue |
69 | 70 |
70 # Ignore changes to auto generation timestamp when line unwrapped | 71 # Ignore changes to auto generation timestamp. |
71 # // From FILENAME.idl modified DAY MON DATE TIME YEAR. | 72 # // From FILENAME.idl modified DAY MON DATE TIME YEAR. |
72 # /* From FILENAME.idl modified DAY MON DATE TIME YEAR. */ | 73 # /* From FILENAME.idl modified DAY MON DATE TIME YEAR. */ |
73 if len(curwords) > 8 and curwords[1] == 'From': | 74 # The line may be wrapped, so first deal with the first "From" line. |
| 75 if curwords[1] == 'From': |
74 if curwords[0:4] == oldwords[0:4]: continue | 76 if curwords[0:4] == oldwords[0:4]: continue |
75 | 77 |
76 # Ignore changes to auto generation timestamp when line is wrapped | 78 # Ignore changes to auto generation timestamp when line is wrapped |
77 # * modified DAY MON DATE TIME YEAR. | 79 if index > 0: |
78 if len(curwords) > 6 and curwords[1] == 'modified': | 80 two_line_oldwords = oldlines[index - 1].split() + oldwords[1:] |
79 continue | 81 two_line_curwords = curlines[index - 1].split() + curwords[1:] |
| 82 if len(two_line_curwords) > 8 and two_line_curwords[1] == 'From': |
| 83 if two_line_curwords[0:4] == two_line_oldwords[0:4]: continue |
80 | 84 |
81 return False | 85 return False |
82 return True | 86 return True |
83 | 87 |
84 # Return the file name | 88 # Return the file name |
85 def Filename(self): | 89 def Filename(self): |
86 return self.filename | 90 return self.filename |
87 | 91 |
88 # Append to the output if the file is still open | 92 # Append to the output if the file is still open |
89 def Write(self, string): | 93 def Write(self, string): |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 errors += TestFile(filename, stringlist + ['X'], force=False, update=True) | 200 errors += TestFile(filename, stringlist + ['X'], force=False, update=True) |
197 | 201 |
198 # Clean up file | 202 # Clean up file |
199 os.remove(filename) | 203 os.remove(filename) |
200 if not errors: InfoOut.Log('All tests pass.') | 204 if not errors: InfoOut.Log('All tests pass.') |
201 return errors | 205 return errors |
202 | 206 |
203 | 207 |
204 if __name__ == '__main__': | 208 if __name__ == '__main__': |
205 sys.exit(main()) | 209 sys.exit(main()) |
OLD | NEW |