srpcgen: Use 'const char*' for string parameters
[chromium-blink-merge.git] / ppapi / PRESUBMIT.py
blob227cc41f41cf7e41ac5007a8764aef58810d55e9
1 # 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.
5 import os
6 import sys
7 import subprocess
9 def RunCmdAndCheck(cmd, ppapi_dir, err_string, output_api):
10 results = []
11 p = subprocess.Popen(cmd, cwd=os.path.join(ppapi_dir, 'generators'),
12 stdout=subprocess.PIPE,
13 stderr=subprocess.PIPE)
14 (p_stdout, p_stderr) = p.communicate()
15 if p.returncode:
16 results.append(
17 output_api.PresubmitError(err_string,
18 long_text=p_stderr))
19 return results
22 def RunUnittests(input_api, output_api):
23 # Run some Generator unittests if the generator source was changed.
24 results = []
25 files = input_api.LocalPaths()
26 generator_files = []
27 for filename in files:
28 name_parts = filename.split(os.sep)
29 if name_parts[0:2] == ['ppapi', 'generators']:
30 generator_files.append(filename)
31 if generator_files != []:
32 cmd = [ sys.executable, 'idl_gen_pnacl.py', '--wnone', '--test']
33 ppapi_dir = input_api.PresubmitLocalPath()
34 results.extend(RunCmdAndCheck(cmd,
35 ppapi_dir,
36 'PPAPI IDL Pnacl unittest failed.',
37 output_api))
38 return results
41 def CheckChange(input_api, output_api):
42 results = []
44 results.extend(RunUnittests(input_api, output_api))
46 # Verify all modified *.idl have a matching *.h
47 files = input_api.LocalPaths()
48 h_files = []
49 idl_files = []
51 for filename in files:
52 name, ext = os.path.splitext(filename)
53 name_parts = name.split(os.sep)
54 if name_parts[0:2] == ['ppapi', 'c'] and ext == '.h':
55 h_files.append('/'.join(name_parts[2:]))
56 if name_parts[0:2] == ['ppapi', 'api'] and ext == '.idl':
57 idl_files.append('/'.join(name_parts[2:]))
59 # Generate a list of all appropriate *.h and *.idl changes in this CL.
60 both = h_files + idl_files
62 # If there aren't any, we are done checking.
63 if not both: return results
65 missing = []
66 for filename in idl_files:
67 if filename not in set(h_files):
68 missing.append(' ppapi/c/%s.h' % filename)
69 for filename in h_files:
70 if filename not in set(idl_files):
71 missing.append(' ppapi/api/%s.idl' % filename)
73 if missing:
74 results.append(
75 output_api.PresubmitPromptWarning('Missing matching PPAPI definition:',
76 long_text='\n'.join(missing)))
78 # Verify all *.h files match *.idl definitions, use:
79 # --test to prevent output to disk
80 # --diff to generate a unified diff
81 # --out to pick which files to examine (only the ones in the CL)
82 ppapi_dir = input_api.PresubmitLocalPath()
83 cmd = [ sys.executable, 'generator.py',
84 '--wnone', '--diff', '--test','--cgen', '--range=start,end']
86 # Only generate output for IDL files references (as *.h or *.idl) in this CL
87 cmd.append('--out=' + ','.join([name + '.idl' for name in both]))
88 results.extend(RunCmdAndCheck(cmd,
89 ppapi_dir,
90 'PPAPI IDL Diff detected: Run the generator.',
91 output_api))
92 return results
94 def CheckChangeOnUpload(input_api, output_api):
95 # return []
96 return CheckChange(input_api, output_api)
98 def CheckChangeOnCommit(input_api, output_api):
99 # return []
100 return CheckChange(input_api, output_api)