blob: 0476b630a389d2e4adc045ff7a4cf2663dedb917 [file] [log] [blame]
[email protected]39375782011-09-14 16:55:091# Copyright (c) 2011 The Chromium Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5import os
6import sys
7import subprocess
8
9def CheckChange(input_api, output_api):
10 results = []
11
12 # Verify all modified *.idl have a matching *.h
13 files = input_api.LocalPaths()
14 h_files = []
15 idl_files = []
16
17 for filename in files:
18 name, ext = os.path.splitext(filename)
19 name_parts = name.split(os.sep)
20 if name_parts[0:2] == ['ppapi', 'c'] and ext == '.h':
21 h_files.append('/'.join(name_parts[2:]))
22 if name_parts[0:2] == ['ppapi', 'api'] and ext == '.idl':
23 idl_files.append('/'.join(name_parts[2:]))
24
25 # Generate a list of all appropriate *.h and *.idl changes in this CL.
26 both = h_files + idl_files
27
28 # If there aren't any, we are done checking.
29 if not both: return results
30
31 missing = []
32 for filename in idl_files:
33 if filename not in set(h_files):
34 missing.append(' ppapi/c/%s.h' % filename)
35 for filename in h_files:
36 if filename not in set(idl_files):
37 missing.append(' ppapi/api/%s.idl' % filename)
38
39 if missing:
40 results.append(
41 output_api.PresubmitPromptWarning('Missing matching PPAPI definition:',
42 long_text='\n'.join(missing)))
43
44 # Verify all *.h files match *.idl definitions, use:
45 # --test to prevent output to disk
46 # --diff to generate a unified diff
47 # --out to pick which files to examine (only the ones in the CL)
48 ppapi_dir = input_api.PresubmitLocalPath()
49 cmd = [ sys.executable, 'generator.py',
50 '--wnone', '--diff', '--test','--cgen', '--range=M13,M14']
51
52 # Only generate output for IDL files references (as *.h or *.idl) in this CL
53 cmd.append('--out=' + ','.join([name + '.idl' for name in both]))
54
55 p = subprocess.Popen(cmd, cwd=os.path.join(ppapi_dir, 'generators'),
56 stdout=subprocess.PIPE,
57 stderr=subprocess.PIPE)
58 (p_stdout, p_stderr) = p.communicate()
59 if p.returncode:
60 results.append(
61 output_api.PresubmitError('PPAPI IDL Diff detected: Run the generator.',
62 long_text=p_stderr))
63 return results
64
65def CheckChangeOnUpload(input_api, output_api):
66# return []
67 return CheckChange(input_api, output_api)
68
69def CheckChangeOnCommit(input_api, output_api):
70# return []
71 return CheckChange(input_api, output_api)
72