Upstream version 10.39.225.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
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 NACL_TOP_DIR = os.getcwd()
33 while not os.path.isfile(os.path.join(NACL_TOP_DIR, 'PRESUBMIT.py')):
34   NACL_TOP_DIR = os.path.dirname(NACL_TOP_DIR)
35   assert len(NACL_TOP_DIR) >= 3, "Could not find NaClTopDir"
36
37 def _CommonChecks(input_api, output_api):
38   """Checks for both upload and commit."""
39   results = []
40   results.extend(input_api.canned_checks.PanProjectChecks(
41       input_api, output_api, project_name='Native Client',
42       excluded_paths=tuple(EXCLUDE_PROJECT_CHECKS_DIRS)))
43   return results
44
45 def IsFileInDirectories(f, dirs):
46   """ Returns true if f is in list of directories"""
47   for d in dirs:
48     if d is os.path.commonprefix([f , d]):
49       return True
50   return False
51
52 def CheckChangeOnUpload(input_api, output_api):
53   """Verifies all changes in all files.
54   Args:
55     input_api: the limited set of input modules allowed in presubmit.
56     output_api: the limited set of output modules allowed in presubmit.
57   """
58   report = []
59   report.extend(_CommonChecks(input_api, output_api))
60
61   # The commit queue assumes PRESUBMIT.py is standalone.
62   # TODO(bradnelson): Migrate code_hygiene to a common location so that
63   # it can be used by the commit queue.
64   old_sys_path = list(sys.path)
65   try:
66     sys.path.append(os.path.join(NACL_TOP_DIR, 'tools'))
67     sys.path.append(os.path.join(NACL_TOP_DIR, 'build'))
68     import code_hygiene
69   finally:
70     sys.path = old_sys_path
71     del old_sys_path
72
73   affected_files = input_api.AffectedFiles(include_deletes=False)
74   exclude_dirs = [ NACL_TOP_DIR + '/' + x + '/'
75                    for x in EXCLUDE_PROJECT_CHECKS_DIRS ]
76   for filename in affected_files:
77     filename = filename.AbsoluteLocalPath()
78     if not IsFileInDirectories(filename, exclude_dirs):
79       errors, warnings = code_hygiene.CheckFile(filename, False)
80       for e in errors:
81         report.append(output_api.PresubmitError(e, items=errors[e]))
82       for w in warnings:
83         report.append(output_api.PresubmitPromptWarning(w, items=warnings[w]))
84
85   return report
86
87
88 def CheckChangeOnCommit(input_api, output_api):
89   """Verifies all changes in all files and verifies that the
90   tree is open and can accept a commit.
91   Args:
92     input_api: the limited set of input modules allowed in presubmit.
93     output_api: the limited set of output modules allowed in presubmit.
94   """
95   report = []
96   report.extend(CheckChangeOnUpload(input_api, output_api))
97   report.extend(input_api.canned_checks.CheckTreeIsOpen(
98       input_api, output_api,
99       json_url='http://nativeclient-status.appspot.com/current?format=json'))
100   return report
101
102
103 # Note that this list is duplicated in the Commit Queue.  If you
104 # change this list, you should also update the CQ's list here:
105 # https://chrome-internal.googlesource.com/infra/infra_internal/+/master/commit_queue/projects.py
106 # (see https://crbug.com/399059).
107 DEFAULT_TRYBOTS = [
108     'nacl-precise32_newlib_dbg',
109     'nacl-precise32_newlib_opt',
110     'nacl-precise32_glibc_opt',
111     'nacl-precise64_newlib_dbg',
112     'nacl-precise64_newlib_opt',
113     'nacl-precise64_glibc_opt',
114     'nacl-mac10.6_newlib_opt',
115     'nacl-mac10.6_glibc_opt',
116     'nacl-mac10.6_64_newlib_dbg',
117     'nacl-mac10.6_64_glibc_opt',
118     'nacl-mac10.7_newlib_opt',
119     'nacl-mac10.7_glibc_opt',
120     'nacl-mac10.7_64_newlib_dbg',
121     'nacl-mac10.7_64_glibc_opt',
122     'nacl-mac10.8_32_newlib_dbg',
123     'nacl-mac10.8_32_glibc_opt',
124     'nacl-mac10.8_64_newlib_dbg',
125     'nacl-mac10.8_64_glibc_opt',
126     'nacl-win32_newlib_opt',
127     'nacl-win32_glibc_opt',
128     'nacl-win64_newlib_dbg',
129     'nacl-win64_newlib_opt',
130     'nacl-win64_glibc_opt',
131     'nacl-win8-64_newlib_dbg',
132     'nacl-win8-64_newlib_opt',
133     'nacl-arm_opt_panda',
134     # arm-nacl-gcc bots
135     'nacl-win7_64_arm_newlib_opt',
136     'nacl-mac10.7_arm_newlib_opt',
137     'nacl-precise64_arm_newlib_opt',
138     # Clang bots
139     'nacl-precise_64-newlib-dbg-clang',
140     'nacl-mac10.6-newlib-dbg-clang',
141     # pnacl scons bots
142     'nacl-precise_64-newlib-arm_qemu-pnacl',
143     'nacl-precise_64-newlib-x86_32-pnacl',
144     'nacl-precise_64-newlib-x86_64-pnacl',
145     'nacl-mac10.8_newlib_opt_pnacl',
146     'nacl-win7_64_newlib_opt_pnacl',
147     # pnacl spec2k bots
148     'nacl-arm_perf_panda',
149     'nacl-precise_64-newlib-x86_32-pnacl-spec',
150     'nacl-precise_64-newlib-x86_64-pnacl-spec',
151     ]
152
153 PNACL_TOOLCHAIN_TRYBOTS = [
154     'nacl-toolchain-linux-pnacl-x86_64',
155     'nacl-toolchain-linux-pnacl-x86_32',
156     'nacl-toolchain-mac-pnacl-x86_32',
157     'nacl-toolchain-win7-pnacl-x86_64',
158     ]
159
160 TOOLCHAIN_BUILD_TRYBOTS = [
161     'nacl-toolchain-precise64-newlib-arm',
162     'nacl-toolchain-mac-newlib-arm',
163     ]
164
165
166 def GetPreferredTryMasters(_, change):
167
168   has_pnacl = False
169   has_toolchain_build = False
170   has_others = False
171
172   for file in change.AffectedFiles(include_dirs=True):
173     if IsFileInDirectories(file.AbsoluteLocalPath(),
174                            [os.path.join(NACL_TOP_DIR, 'build'),
175                             os.path.join(NACL_TOP_DIR, 'buildbot'),
176                             os.path.join(NACL_TOP_DIR, 'pynacl')]):
177       # Buildbot and infrastructure changes should trigger all the try bots.
178       has_pnacl = True
179       has_toolchain_build = True
180       has_others = True
181       break
182     elif IsFileInDirectories(file.AbsoluteLocalPath(),
183                            [os.path.join(NACL_TOP_DIR, 'pnacl')]):
184       has_pnacl = True
185     elif IsFileInDirectories(file.AbsoluteLocalPath(),
186                              [os.path.join(NACL_TOP_DIR, 'toolchain_build')]):
187       has_toolchain_build = True
188     else:
189       has_others = True
190
191   trybots = []
192   if has_pnacl:
193     trybots += PNACL_TOOLCHAIN_TRYBOTS
194   if has_toolchain_build:
195     trybots += TOOLCHAIN_BUILD_TRYBOTS
196   if has_others:
197     trybots += DEFAULT_TRYBOTS
198
199   return {
200     'tryserver.nacl': { t: set(['defaulttests']) for t in trybots },
201   }