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.
5 # Documentation on PRESUBMIT.py can be found at:
6 # http://www.chromium.org/developers/how-tos/depottools/presubmit-scripts
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',
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"
37 def _CommonChecks(input_api, output_api):
38 """Checks for both upload and commit."""
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)))
45 def IsFileInDirectories(f, dirs):
46 """ Returns true if f is in list of directories"""
48 if d is os.path.commonprefix([f , d]):
52 def CheckChangeOnUpload(input_api, output_api):
53 """Verifies all changes in all files.
55 input_api: the limited set of input modules allowed in presubmit.
56 output_api: the limited set of output modules allowed in presubmit.
59 report.extend(_CommonChecks(input_api, output_api))
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)
66 sys.path.append(os.path.join(NACL_TOP_DIR, 'tools'))
67 sys.path.append(os.path.join(NACL_TOP_DIR, 'build'))
70 sys.path = old_sys_path
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)
81 report.append(output_api.PresubmitError(e, items=errors[e]))
83 report.append(output_api.PresubmitPromptWarning(w, items=warnings[w]))
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.
92 input_api: the limited set of input modules allowed in presubmit.
93 output_api: the limited set of output modules allowed in presubmit.
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'))
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).
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',
135 'nacl-win7_64_arm_newlib_opt',
136 'nacl-mac10.7_arm_newlib_opt',
137 'nacl-precise64_arm_newlib_opt',
139 'nacl-precise_64-newlib-dbg-clang',
140 'nacl-mac10.6-newlib-dbg-clang',
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',
148 'nacl-arm_perf_panda',
149 'nacl-precise_64-newlib-x86_32-pnacl-spec',
150 'nacl-precise_64-newlib-x86_64-pnacl-spec',
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',
160 TOOLCHAIN_BUILD_TRYBOTS = [
161 'nacl-toolchain-precise64-newlib-arm',
162 'nacl-toolchain-mac-newlib-arm',
166 def GetPreferredTryMasters(_, change):
169 has_toolchain_build = False
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.
179 has_toolchain_build = True
182 elif IsFileInDirectories(file.AbsoluteLocalPath(),
183 [os.path.join(NACL_TOP_DIR, 'pnacl')]):
185 elif IsFileInDirectories(file.AbsoluteLocalPath(),
186 [os.path.join(NACL_TOP_DIR, 'toolchain_build')]):
187 has_toolchain_build = True
193 trybots += PNACL_TOOLCHAIN_TRYBOTS
194 if has_toolchain_build:
195 trybots += TOOLCHAIN_BUILD_TRYBOTS
197 trybots += DEFAULT_TRYBOTS
200 'tryserver.nacl': { t: set(['defaulttests']) for t in trybots },