diff options
author | noelallen@chromium.org <noelallen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-05-02 23:09:08 +0000 |
---|---|---|
committer | noelallen@chromium.org <noelallen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-05-02 23:09:08 +0000 |
commit | 53efaa468e85c632b757fc7000e8b5fc2d6321da (patch) | |
tree | 1ee9cf4822398a61ae977ea41d3241d247a26a31 /ppapi/generators/idl_outfile.py | |
parent | 34d58a296e3b0d3f81f4692a48bc54ec3128c850 (diff) | |
download | chromium_src-53efaa468e85c632b757fc7000e8b5fc2d6321da.zip chromium_src-53efaa468e85c632b757fc7000e8b5fc2d6321da.tar.gz chromium_src-53efaa468e85c632b757fc7000e8b5fc2d6321da.tar.bz2 |
There is a range failure when an old file differs from the file about to be generated on a line containing just a '*'.
This CL fixes that issue by having a length check on the appropriate lists. It also cleans up the naming of the various variables to make it more obvious which ones refer to the old text file and which ones refer to lines to be written.
NOTRY=true
R=binji@chromium.org, sehr@chromium.org
+sehr for Owners
Review URL: https://codereview.chromium.org/14686003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@198002 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi/generators/idl_outfile.py')
-rwxr-xr-x | ppapi/generators/idl_outfile.py | 97 |
1 files changed, 55 insertions, 42 deletions
diff --git a/ppapi/generators/idl_outfile.py b/ppapi/generators/idl_outfile.py index bb9b849..538267f 100755 --- a/ppapi/generators/idl_outfile.py +++ b/ppapi/generators/idl_outfile.py @@ -16,38 +16,6 @@ from stat import * Option('diff', 'Generate a DIFF when saving the file.') -def IsEquivalent(intext, outtext): - if not intext: return False - inlines = intext.split('\n') - outlines = outtext.split('\n') - - # If number of lines don't match, it's a mismatch - if len(inlines) != len(outlines): return False - - for index in range(len(inlines)): - inline = inlines[index] - outline = outlines[index] - - if inline == outline: continue - - # If the line is not an exact match, check for comment deltas - inwords = inline.split() - outwords = outline.split() - - if not inwords or not outwords: return False - if inwords[0] != outwords[0] or inwords[0] not in ('/*', '*', '//'): - return False - - # Neither the year, nor the modified date need an exact match - if inwords[1] == 'Copyright': - if inwords[4:] == outwords[4:]: continue - elif inwords[1] == 'From': # Un-wrapped modified date. - if inwords[0:4] == outwords[0:4]: continue - elif inwords[1] == 'modified': # Wrapped modified date. - if inwords[0:2] == outwords[0:2]: continue - return False - return True - # # IDLOutFile @@ -65,6 +33,53 @@ class IDLOutFile(object): self.outlist = [] self.open = True + # Compare the old text to the current list of output lines. + def IsEquivalent_(self, oldtext): + if not oldtext: return False + + oldlines = oldtext.split('\n') + curlines = (''.join(self.outlist)).split('\n') + + # If number of lines don't match, it's a mismatch + if len(oldlines) != len(curlines): + return False + + for index in range(len(oldlines)): + oldline = oldlines[index] + curline = curlines[index] + + if oldline == curline: continue + + curwords = curline.split() + oldwords = oldline.split() + + # Unmatched lines must be the same length + if len(curwords) != len(oldwords): + return False + + # If it's not a comment then it's a mismatch + if curwords[0] not in ['*', '/*', '//']: + return False + + # Ignore changes to the Copyright year which is autogenerated + # /* Copyright (c) 2011 The Chromium Authors. All rights reserved. + if len(curwords) > 4 and curwords[1] == 'Copyright': + if curwords[4:] == oldwords[4:]: continue + + # Ignore changes to auto generation timestamp when line unwrapped + # // From FILENAME.idl modified DAY MON DATE TIME YEAR. + # /* From FILENAME.idl modified DAY MON DATE TIME YEAR. */ + if len(curwords) > 8 and curwords[1] == 'From': + if curwords[0:4] == oldwords[0:4]: continue + + # Ignore changes to auto generation timestamp when line is wrapped + # * modified DAY MON DATE TIME YEAR. + if len(curwords) > 6 and curwords[1] == 'modified': + continue + + return False + return True + # Return the file name def Filename(self): return self.filename @@ -75,24 +90,22 @@ class IDLOutFile(object): raise RuntimeError('Could not write to closed file %s.' % self.filename) self.outlist.append(string) - # Close the file + # Close the file, flushing it to disk def Close(self): filename = os.path.realpath(self.filename) self.open = False outtext = ''.join(self.outlist) + if not self.always_write: if os.path.isfile(filename): - intext = open(filename, 'rb').read() - else: - intext = '' - - if IsEquivalent(intext, outtext): - if GetOption('verbose'): - InfoOut.Log('Output %s unchanged.' % self.filename) - return False + oldtext = open(filename, 'rb').read() + if self.IsEquivalent_(oldtext): + if GetOption('verbose'): + InfoOut.Log('Output %s unchanged.' % self.filename) + return False if GetOption('diff'): - for line in difflib.unified_diff(intext.split('\n'), outtext.split('\n'), + for line in difflib.unified_diff(oldtext.split('\n'), outtext.split('\n'), 'OLD ' + self.filename, 'NEW ' + self.filename, n=1, lineterm=''): |