summaryrefslogtreecommitdiffstats
path: root/ppapi
diff options
context:
space:
mode:
authornoelallen@google.com <noelallen@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-09-14 16:55:09 +0000
committernoelallen@google.com <noelallen@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-09-14 16:55:09 +0000
commit39375788c550e675967f4571730136374f134a7e (patch)
tree6cf62d6b7069c245aa59b42cb11dd938156afcff /ppapi
parente66b721642dabbf698873468c9e2fa36ba830e87 (diff)
downloadchromium_src-39375788c550e675967f4571730136374f134a7e.zip
chromium_src-39375788c550e675967f4571730136374f134a7e.tar.gz
chromium_src-39375788c550e675967f4571730136374f134a7e.tar.bz2
Add presubmit check to verify PPAPI C headers match IDL files.
Update outfile to print a better filename on diff. Update fix missing 'name' in idl_generator.py BUG= http://code.google.com/p/chromium/issues/detail?id=93534 TEST= gcl upload | presubmit (after modifying a .h or .idl file) R= brettw@chromium.org Review URL: http://codereview.chromium.org/7700001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@101092 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi')
-rw-r--r--ppapi/PRESUBMIT.py72
-rw-r--r--ppapi/generators/idl_generator.py2
-rw-r--r--ppapi/generators/idl_outfile.py4
3 files changed, 76 insertions, 2 deletions
diff --git a/ppapi/PRESUBMIT.py b/ppapi/PRESUBMIT.py
new file mode 100644
index 0000000..0476b63
--- /dev/null
+++ b/ppapi/PRESUBMIT.py
@@ -0,0 +1,72 @@
+# Copyright (c) 2011 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import os
+import sys
+import subprocess
+
+def CheckChange(input_api, output_api):
+ results = []
+
+ # Verify all modified *.idl have a matching *.h
+ files = input_api.LocalPaths()
+ h_files = []
+ idl_files = []
+
+ for filename in files:
+ name, ext = os.path.splitext(filename)
+ name_parts = name.split(os.sep)
+ if name_parts[0:2] == ['ppapi', 'c'] and ext == '.h':
+ h_files.append('/'.join(name_parts[2:]))
+ if name_parts[0:2] == ['ppapi', 'api'] and ext == '.idl':
+ idl_files.append('/'.join(name_parts[2:]))
+
+ # Generate a list of all appropriate *.h and *.idl changes in this CL.
+ both = h_files + idl_files
+
+ # If there aren't any, we are done checking.
+ if not both: return results
+
+ missing = []
+ for filename in idl_files:
+ if filename not in set(h_files):
+ missing.append(' ppapi/c/%s.h' % filename)
+ for filename in h_files:
+ if filename not in set(idl_files):
+ missing.append(' ppapi/api/%s.idl' % filename)
+
+ if missing:
+ results.append(
+ output_api.PresubmitPromptWarning('Missing matching PPAPI definition:',
+ long_text='\n'.join(missing)))
+
+ # Verify all *.h files match *.idl definitions, use:
+ # --test to prevent output to disk
+ # --diff to generate a unified diff
+ # --out to pick which files to examine (only the ones in the CL)
+ ppapi_dir = input_api.PresubmitLocalPath()
+ cmd = [ sys.executable, 'generator.py',
+ '--wnone', '--diff', '--test','--cgen', '--range=M13,M14']
+
+ # Only generate output for IDL files references (as *.h or *.idl) in this CL
+ cmd.append('--out=' + ','.join([name + '.idl' for name in both]))
+
+ p = subprocess.Popen(cmd, cwd=os.path.join(ppapi_dir, 'generators'),
+ stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE)
+ (p_stdout, p_stderr) = p.communicate()
+ if p.returncode:
+ results.append(
+ output_api.PresubmitError('PPAPI IDL Diff detected: Run the generator.',
+ long_text=p_stderr))
+ return results
+
+def CheckChangeOnUpload(input_api, output_api):
+# return []
+ return CheckChange(input_api, output_api)
+
+def CheckChangeOnCommit(input_api, output_api):
+# return []
+ return CheckChange(input_api, output_api)
+
diff --git a/ppapi/generators/idl_generator.py b/ppapi/generators/idl_generator.py
index e66efc1..bd77e07 100644
--- a/ppapi/generators/idl_generator.py
+++ b/ppapi/generators/idl_generator.py
@@ -146,7 +146,7 @@ class GeneratorByFile(Generator):
cnt = 0
for filenode in ast.GetListOf('File'):
# Skip this file if not required
- if outlist and name not in outlist:
+ if outlist and filenode.GetName() not in outlist:
continue
# If this file has errors, skip it
diff --git a/ppapi/generators/idl_outfile.py b/ppapi/generators/idl_outfile.py
index ae8da4e..434cfa0 100644
--- a/ppapi/generators/idl_outfile.py
+++ b/ppapi/generators/idl_outfile.py
@@ -92,7 +92,9 @@ class IDLOutFile(object):
if GetOption('diff'):
for line in difflib.unified_diff(intext.split('\n'), outtext.split('\n'),
- self.filename, 'NEW', n=1, lineterm=''):
+ 'OLD ' + self.filename,
+ 'NEW ' + self.filename,
+ n=1, lineterm=''):
ErrOut.Log(line)
try: