summaryrefslogtreecommitdiffstats
path: root/ppapi/generators
diff options
context:
space:
mode:
authornoelallen@google.com <noelallen@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-08-22 23:44:30 +0000
committernoelallen@google.com <noelallen@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-08-22 23:44:30 +0000
commit83bfbb4c3cff5341236817b2e0e0d69254f29a61 (patch)
treed962c05138ac3f013ec601564d317f662a93ac1c /ppapi/generators
parent8eef1e4e309d0edfbc7dc1185c85fee8984df71e (diff)
downloadchromium_src-83bfbb4c3cff5341236817b2e0e0d69254f29a61.zip
chromium_src-83bfbb4c3cff5341236817b2e0e0d69254f29a61.tar.gz
chromium_src-83bfbb4c3cff5341236817b2e0e0d69254f29a61.tar.bz2
IDLOutFile throws execption
Invalid index on diff check causes exception. This CL is a trival check to ensure the line is not empty before checking the first index for a 'comment'. BUG= http://code.google.com/p/chromium/issues/detail?id=93436 TEST= python idl_c_header.py R= dmichael@chromium.org Review URL: http://codereview.chromium.org/7677035 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@97775 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi/generators')
-rw-r--r--ppapi/generators/idl_outfile.py16
1 files changed, 13 insertions, 3 deletions
diff --git a/ppapi/generators/idl_outfile.py b/ppapi/generators/idl_outfile.py
index 100a49e..d643b2f 100644
--- a/ppapi/generators/idl_outfile.py
+++ b/ppapi/generators/idl_outfile.py
@@ -6,6 +6,7 @@
""" Output file objects for generator. """
+import difflib
import os
import time
import sys
@@ -14,6 +15,8 @@ from idl_log import ErrOut, InfoOut, WarnOut
from idl_option import GetOption, Option, ParseOptions
from stat import *
+Option('diff', 'Generate a DIFF when saving the file.')
+
def IsEquivelent(intext, outtext):
if not intext: return False
inlines = intext.split('\n')
@@ -32,6 +35,7 @@ def IsEquivelent(intext, outtext):
inwords = inline.split()
outwords = outline.split()
+ if not inwords or not outwords: return False
if inwords[0] != outwords[0] or inwords[0] != '/*': return False
# Neither the year, nor the modified date need an exact match
@@ -86,6 +90,11 @@ class IDLOutFile(object):
InfoOut.Log('Output %s unchanged.' % self.filename)
return False
+ if GetOption('diff'):
+ for line in difflib.unified_diff(intext.split('\n'), outtext.split('\n'),
+ self.filename, 'NEW', n=1, lineterm=''):
+ ErrOut.Log(line)
+
try:
# If the directory does not exit, try to create it, if we fail, we
# still get the exception when the file is openned.
@@ -94,9 +103,10 @@ class IDLOutFile(object):
InfoOut.Log('Creating directory: %s\n' % basepath)
os.makedirs(basepath)
- outfile = open(filename, 'w')
- outfile.write(''.join(self.outlist))
- InfoOut.Log('Output %s written.' % self.filename)
+ if not GetOption('test'):
+ outfile = open(filename, 'w')
+ outfile.write(outtext)
+ InfoOut.Log('Output %s written.' % self.filename)
return True
except IOError as (errno, strerror):