blob: 3e0f963ce9f90c36ce21fdec928fd61af04b0cff [file] [log] [blame]
[email protected]e4f373e2012-01-10 23:18:241# Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]39375782011-09-14 16:55:092# 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
[email protected]e4f373e2012-01-10 23:18:249def RunCmdAndCheck(cmd, err_string, output_api, cwd=None):
[email protected]2978339a72011-11-30 17:59:1410 results = []
[email protected]e4f373e2012-01-10 23:18:2411 p = subprocess.Popen(cmd, cwd=cwd,
[email protected]2978339a72011-11-30 17:59:1412 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
20
21
22def 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,
[email protected]2978339a72011-11-30 17:59:1435 'PPAPI IDL Pnacl unittest failed.',
[email protected]e4f373e2012-01-10 23:18:2436 output_api,
37 os.path.join(ppapi_dir, 'generators')))
[email protected]2978339a72011-11-30 17:59:1438 return results
39
40
[email protected]e4f373e2012-01-10 23:18:2441# If any .srpc files were changed, run run_srpcgen.py --diff_mode.
42def CheckSrpcChange(input_api, output_api):
43 if [True for filename in input_api.LocalPaths() if
44 os.path.splitext(filename)[1] == '.srpc']:
45 return RunCmdAndCheck([sys.executable,
46 os.path.join(input_api.PresubmitLocalPath(),
47 'native_client', 'src',
48 'shared', 'ppapi_proxy',
49 'run_srpcgen.py'),
50 '--diff_mode'],
51 'PPAPI SRPC Diff detected: Run run_srpcgen.py.',
52 output_api)
53 return []
54
[email protected]39375782011-09-14 16:55:0955def CheckChange(input_api, output_api):
56 results = []
57
[email protected]e4f373e2012-01-10 23:18:2458 results.extend(CheckSrpcChange(input_api, output_api))
59
[email protected]2978339a72011-11-30 17:59:1460 results.extend(RunUnittests(input_api, output_api))
61
[email protected]39375782011-09-14 16:55:0962 # Verify all modified *.idl have a matching *.h
63 files = input_api.LocalPaths()
64 h_files = []
65 idl_files = []
66
67 for filename in files:
68 name, ext = os.path.splitext(filename)
69 name_parts = name.split(os.sep)
70 if name_parts[0:2] == ['ppapi', 'c'] and ext == '.h':
71 h_files.append('/'.join(name_parts[2:]))
72 if name_parts[0:2] == ['ppapi', 'api'] and ext == '.idl':
73 idl_files.append('/'.join(name_parts[2:]))
74
75 # Generate a list of all appropriate *.h and *.idl changes in this CL.
76 both = h_files + idl_files
77
78 # If there aren't any, we are done checking.
79 if not both: return results
80
81 missing = []
82 for filename in idl_files:
83 if filename not in set(h_files):
84 missing.append(' ppapi/c/%s.h' % filename)
85 for filename in h_files:
86 if filename not in set(idl_files):
87 missing.append(' ppapi/api/%s.idl' % filename)
88
89 if missing:
90 results.append(
91 output_api.PresubmitPromptWarning('Missing matching PPAPI definition:',
92 long_text='\n'.join(missing)))
93
94 # Verify all *.h files match *.idl definitions, use:
95 # --test to prevent output to disk
96 # --diff to generate a unified diff
97 # --out to pick which files to examine (only the ones in the CL)
98 ppapi_dir = input_api.PresubmitLocalPath()
99 cmd = [ sys.executable, 'generator.py',
[email protected]a3aec322011-11-04 19:48:48100 '--wnone', '--diff', '--test','--cgen', '--range=start,end']
[email protected]39375782011-09-14 16:55:09101
102 # Only generate output for IDL files references (as *.h or *.idl) in this CL
103 cmd.append('--out=' + ','.join([name + '.idl' for name in both]))
[email protected]2978339a72011-11-30 17:59:14104 results.extend(RunCmdAndCheck(cmd,
[email protected]2978339a72011-11-30 17:59:14105 'PPAPI IDL Diff detected: Run the generator.',
[email protected]e4f373e2012-01-10 23:18:24106 output_api,
107 os.path.join(ppapi_dir, 'generators')))
[email protected]39375782011-09-14 16:55:09108 return results
109
110def CheckChangeOnUpload(input_api, output_api):
111# return []
112 return CheckChange(input_api, output_api)
113
114def CheckChangeOnCommit(input_api, output_api):
115# return []
116 return CheckChange(input_api, output_api)