Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / native_client / PRESUBMIT.py
1 # Copyright (c) 2012 The Native Client 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
5 # Documentation on PRESUBMIT.py can be found at:
6 # http://www.chromium.org/developers/how-tos/depottools/presubmit-scripts
7
8 import os.path
9 import sys
10
11 # List of directories to not apply presubmit project checks, relative
12 # to the NaCl top directory
13 EXCLUDE_PROJECT_CHECKS_DIRS = [
14     # The following contain test data (including automatically generated),
15     # and do not follow our conventions.
16     'src/trusted/validator_ragel/testdata/32',
17     'src/trusted/validator_ragel/testdata/64',
18     'src/trusted/validator_x86/testdata/32',
19     'src/trusted/validator_x86/testdata/64',
20     'src/trusted/validator/x86/decoder/generator/testdata/32',
21     'src/trusted/validator/x86/decoder/generator/testdata/64',
22     # The following directories contains automatically generated source,
23     # which may not follow our conventions.
24     'src/trusted/validator_x86/gen',
25     'src/trusted/validator/x86/decoder/gen',
26     'src/trusted/validator/x86/decoder/generator/gen',
27     'src/trusted/validator/x86/ncval_seg_sfi/gen',
28     'src/trusted/validator_arm/gen',
29     'src/trusted/validator_ragel/gen',
30     ]
31
32 def NaClTopDir():
33   # git-cl and gcl run PRESUBMIT.py with the current directory set to
34   # the native_client directory (which may have a different basename
35   # in a standalone checkout).
36   return os.getcwd()
37
38 def _CommonChecks(input_api, output_api):
39   """Checks for both upload and commit."""
40   results = []
41   results.extend(input_api.canned_checks.PanProjectChecks(
42       input_api, output_api, project_name='Native Client',
43       excluded_paths=tuple(EXCLUDE_PROJECT_CHECKS_DIRS)))
44   return results
45
46 def IsFileInDirectories(f, dirs):
47   """ Returns true if f is in list of directories"""
48   for d in dirs:
49     if d is os.path.commonprefix([f , d]):
50       return True
51   return False
52
53 def CheckChangeOnUpload(input_api, output_api):
54   """Verifies all changes in all files.
55   Args:
56     input_api: the limited set of input modules allowed in presubmit.
57     output_api: the limited set of output modules allowed in presubmit.
58   """
59   report = []
60   report.extend(_CommonChecks(input_api, output_api))
61
62   # The commit queue assumes PRESUBMIT.py is standalone.
63   # TODO(bradnelson): Migrate code_hygiene to a common location so that
64   # it can be used by the commit queue.
65   old_sys_path = list(sys.path)
66   try:
67     sys.path.append(os.path.join(NaClTopDir(), 'tools'))
68     sys.path.append(os.path.join(NaClTopDir(), 'build'))
69     import code_hygiene
70   finally:
71     sys.path = old_sys_path
72     del old_sys_path
73
74   affected_files = input_api.AffectedFiles(include_deletes=False)
75   exclude_dirs = [ NaClTopDir() + '/' + x + '/'
76                    for x in EXCLUDE_PROJECT_CHECKS_DIRS ]
77   for filename in affected_files:
78     filename = filename.AbsoluteLocalPath()
79     if not IsFileInDirectories(filename, exclude_dirs):
80       errors, warnings = code_hygiene.CheckFile(filename, False)
81       for e in errors:
82         report.append(output_api.PresubmitError(e, items=errors[e]))
83       for w in warnings:
84         report.append(output_api.PresubmitPromptWarning(w, items=warnings[w]))
85
86   return report
87
88
89 def CheckChangeOnCommit(input_api, output_api):
90   """Verifies all changes in all files and verifies that the
91   tree is open and can accept a commit.
92   Args:
93     input_api: the limited set of input modules allowed in presubmit.
94     output_api: the limited set of output modules allowed in presubmit.
95   """
96   report = []
97   report.extend(CheckChangeOnUpload(input_api, output_api))
98   report.extend(input_api.canned_checks.CheckTreeIsOpen(
99       input_api, output_api,
100       json_url='http://nativeclient-status.appspot.com/current?format=json'))
101   return report
102
103
104 DEFAULT_TRYBOTS = [
105     'nacl-precise32_newlib_dbg',
106     'nacl-precise32_newlib_opt',
107     'nacl-precise32_glibc_opt',
108     'nacl-precise64_newlib_dbg',
109     'nacl-precise64_newlib_opt',
110     'nacl-precise64_glibc_opt',
111     'nacl-mac10.6_newlib_opt',
112     'nacl-mac10.6_glibc_opt',
113     'nacl-mac10.6_64_newlib_dbg',
114     'nacl-mac10.6_64_glibc_opt',
115     'nacl-mac10.7_newlib_opt',
116     'nacl-mac10.7_glibc_opt',
117     'nacl-mac10.7_64_newlib_dbg',
118     'nacl-mac10.7_64_glibc_opt',
119     'nacl-mac10.8_32_newlib_dbg',
120     'nacl-mac10.8_32_glibc_opt',
121     'nacl-mac10.8_64_newlib_dbg',
122     'nacl-mac10.8_64_glibc_opt',
123     'nacl-win32_newlib_opt',
124     'nacl-win32_glibc_opt',
125     'nacl-win64_newlib_dbg',
126     'nacl-win64_newlib_opt',
127     'nacl-win64_glibc_opt',
128     'nacl-win8-64_newlib_dbg',
129     'nacl-win8-64_newlib_opt',
130     'nacl-arm_opt_panda',
131     # arm-nacl-gcc bots
132     'nacl-win7_64_arm_newlib_opt',
133     'nacl-mac10.7_arm_newlib_opt',
134     'nacl-precise64_arm_newlib_opt',
135     # Clang bots
136     'nacl-precise_64-newlib-dbg-clang',
137     'nacl-mac10.6-newlib-dbg-clang',
138     # pnacl scons bots
139     'nacl-precise_64-newlib-arm_qemu-pnacl',
140     'nacl-precise_64-newlib-x86_32-pnacl',
141     'nacl-precise_64-newlib-x86_64-pnacl',
142     'nacl-mac10.8_newlib_opt_pnacl',
143     'nacl-win7_64_newlib_opt_pnacl',
144     # pnacl spec2k bots
145     'nacl-arm_perf_panda',
146     'nacl-precise_64-newlib-x86_32-pnacl-spec',
147     'nacl-precise_64-newlib-x86_64-pnacl-spec',
148     ]
149
150 PNACL_TOOLCHAIN_TRYBOTS = [
151     'nacl-toolchain-linux-pnacl-x86_64',
152     'nacl-toolchain-linux-pnacl-x86_32',
153     'nacl-toolchain-mac-pnacl-x86_32',
154     'nacl-toolchain-win7-pnacl-x86_64',
155     ]
156
157 TOOLCHAIN_BUILD_TRYBOTS = [
158     'nacl-toolchain-precise64-newlib-arm',
159     'nacl-toolchain-mac-newlib-arm',
160     ]
161
162
163 def GetPreferredTryMasters(_, change):
164
165   has_pnacl = False
166   has_toolchain_build = False
167   has_others = False
168
169   for file in change.AffectedFiles(include_dirs=True):
170     if IsFileInDirectories(file.AbsoluteLocalPath(),
171                            [os.path.join(NaClTopDir(), 'build'),
172                             os.path.join(NaClTopDir(), 'buildbot'),
173                             os.path.join(NaClTopDir(), 'pynacl')]):
174       # Buildbot and infrastructure changes should trigger all the try bots.
175       has_pnacl = True
176       has_toolchain_build = True
177       has_others = True
178       break
179     elif IsFileInDirectories(file.AbsoluteLocalPath(),
180                            [os.path.join(NaClTopDir(), 'pnacl')]):
181       has_pnacl = True
182     elif IsFileInDirectories(file.AbsoluteLocalPath(),
183                              [os.path.join(NaClTopDir(), 'toolchain_build')]):
184       has_toolchain_build = True
185     else:
186       has_others = True
187
188   trybots = []
189   if has_pnacl:
190     trybots += PNACL_TOOLCHAIN_TRYBOTS
191   if has_toolchain_build:
192     trybots += TOOLCHAIN_BUILD_TRYBOTS
193   if has_others:
194     trybots += DEFAULT_TRYBOTS
195
196   return {
197     'tryserver.nacl': { t: set(['defaulttests']) for t in trybots },
198   }