Enable dev build with the latest repo
[platform/framework/web/chromium-efl.git] / 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 from __future__ import print_function
9
10 import os
11 import subprocess
12 import sys
13
14 # List of directories to not apply presubmit project checks, relative
15 # to the NaCl top directory
16 EXCLUDE_PROJECT_CHECKS = [
17     # The following contain test data (including automatically generated),
18     # and do not follow our conventions.
19     'src/trusted/validator_ragel/testdata/32/',
20     'src/trusted/validator_ragel/testdata/64/',
21     'src/trusted/validator_x86/testdata/32/',
22     'src/trusted/validator_x86/testdata/64/',
23     'src/trusted/validator/x86/decoder/generator/testdata/32/',
24     'src/trusted/validator/x86/decoder/generator/testdata/64/',
25     # The following directories contains automatically generated source,
26     # which may not follow our conventions.
27     'src/trusted/validator_x86/gen/',
28     'src/trusted/validator/x86/decoder/gen/',
29     'src/trusted/validator/x86/decoder/generator/gen/',
30     'src/trusted/validator/x86/ncval_seg_sfi/gen/',
31     'src/trusted/validator_arm/gen/',
32     'src/trusted/validator_ragel/gen/',
33     # The following files contain code from outside native_client (e.g. newlib)
34     # or are known the contain style violations.
35     'src/trusted/service_runtime/include/sys/',
36     'src/include/win/port_win.h',
37     'src/trusted/service_runtime/include/machine/_types.h'
38     ]
39
40 NACL_TOP_DIR = os.getcwd()
41 while not os.path.isfile(os.path.join(NACL_TOP_DIR, 'PRESUBMIT.py')):
42   NACL_TOP_DIR = os.path.dirname(NACL_TOP_DIR)
43   assert len(NACL_TOP_DIR) >= 3, "Could not find NaClTopDir"
44
45
46 def CheckGitBranch():
47   p = subprocess.Popen("git branch -vv", shell=True,
48                        stdout=subprocess.PIPE)
49   output, _ = p.communicate()
50   lines = output.split('\n')
51   for line in lines:
52     # output format for checked-out branch should be
53     # * branchname hash [TrackedBranchName ...
54     toks = line.split()
55     if '*' not in toks[0]:
56       continue
57     if not ('origin/master' in toks[3] or
58             'origin/refs/heads/master' in toks[3]):
59       warning = 'Warning: your current branch:\n' + line
60       warning += '\nis not tracking origin/master. git cl push may silently '
61       warning += 'fail to push your change. To fix this, do\n'
62       warning += 'git branch -u origin/master'
63       return warning
64     return None
65   print('Warning: presubmit check could not determine local git branch')
66   return None
67
68
69 def _CommonChecks(input_api, output_api):
70   """Checks for both upload and commit."""
71   results = []
72
73   results.extend(input_api.canned_checks.PanProjectChecks(
74       input_api, output_api, project_name='Native Client',
75       excluded_paths=tuple(EXCLUDE_PROJECT_CHECKS)))
76
77   # The commit queue assumes PRESUBMIT.py is standalone.
78   # TODO(bradnelson): Migrate code_hygiene to a common location so that
79   # it can be used by the commit queue.
80   old_sys_path = list(sys.path)
81   try:
82     sys.path.append(os.path.join(NACL_TOP_DIR, 'tools'))
83     sys.path.append(os.path.join(NACL_TOP_DIR, 'build'))
84     import code_hygiene
85   finally:
86     sys.path = old_sys_path
87     del old_sys_path
88
89   affected_files = input_api.AffectedFiles(include_deletes=False)
90   exclude_dirs = [ NACL_TOP_DIR + '/' + x for x in EXCLUDE_PROJECT_CHECKS ]
91   for filename in affected_files:
92     filename = filename.AbsoluteLocalPath()
93     if filename in exclude_dirs:
94       continue
95     if not IsFileInDirectories(filename, exclude_dirs):
96       errors, warnings = code_hygiene.CheckFile(filename, False)
97       for e in errors:
98         results.append(output_api.PresubmitError(e, items=errors[e]))
99       for w in warnings:
100         results.append(output_api.PresubmitPromptWarning(w, items=warnings[w]))
101
102   return results
103
104
105 def IsFileInDirectories(f, dirs):
106   """ Returns true if f is in list of directories"""
107   for d in dirs:
108     if d is os.path.commonprefix([f, d]):
109       return True
110   return False
111
112
113 def CheckChangeOnUpload(input_api, output_api):
114   """Verifies all changes in all files.
115   Args:
116     input_api: the limited set of input modules allowed in presubmit.
117     output_api: the limited set of output modules allowed in presubmit.
118   """
119   report = []
120   report.extend(_CommonChecks(input_api, output_api))
121
122   branch_warning = CheckGitBranch()
123   if branch_warning:
124     report.append(output_api.PresubmitPromptWarning(branch_warning))
125
126   return report
127
128
129 def CheckChangeOnCommit(input_api, output_api):
130   """Verifies all changes in all files and verifies that the
131   tree is open and can accept a commit.
132   Args:
133     input_api: the limited set of input modules allowed in presubmit.
134     output_api: the limited set of output modules allowed in presubmit.
135   """
136   report = []
137   report.extend(_CommonChecks(input_api, output_api))
138   report.extend(input_api.canned_checks.CheckTreeIsOpen(
139       input_api, output_api,
140       json_url='http://nativeclient-status.appspot.com/current?format=json'))
141   return report
142
143
144 # Note that this list is duplicated in the Commit Queue.  If you change
145 # this list, you should also update the CQ's list in infra/config/cq.cfg
146 # (see https://crbug.com/399059).
147 DEFAULT_TRYBOTS = [
148     'nacl-precise32_newlib_dbg',
149     'nacl-precise32_newlib_opt',
150     'nacl-precise32_glibc_opt',
151     'nacl-precise64_newlib_dbg',
152     'nacl-precise64_newlib_opt',
153     'nacl-precise64_glibc_opt',
154     'nacl-mac_newlib_dbg',
155     'nacl-mac_newlib_opt',
156     'nacl-mac_glibc_dbg',
157     'nacl-mac_glibc_opt',
158     'nacl-win32_newlib_opt',
159     'nacl-win32_glibc_opt',
160     'nacl-win64_newlib_dbg',
161     'nacl-win64_newlib_opt',
162     'nacl-win64_glibc_opt',
163     'nacl-win8-64_newlib_dbg',
164     'nacl-win8-64_newlib_opt',
165     'nacl-arm_opt_panda',
166     # arm-nacl-gcc bots
167     'nacl-win7_64_arm_newlib_opt',
168     'nacl-mac_arm_newlib_opt',
169     'nacl-precise64_arm_newlib_opt',
170     'nacl-precise64_arm_glibc_opt',
171     # pnacl scons bots
172     'nacl-precise_64-newlib-arm_qemu-pnacl',
173     'nacl-precise_64-newlib-x86_32-pnacl',
174     'nacl-precise_64-newlib-x86_64-pnacl',
175     'nacl-mac_newlib_opt_pnacl',
176     'nacl-win7_64_newlib_opt_pnacl',
177     # pnacl spec2k bots
178     'nacl-arm_perf_panda',
179     'nacl-precise_64-newlib-x86_32-pnacl-spec',
180     'nacl-precise_64-newlib-x86_64-pnacl-spec',
181     ]
182
183 PNACL_TOOLCHAIN_TRYBOTS = [
184     'nacl-toolchain-linux-pnacl-x86_64',
185     'nacl-toolchain-linux-pnacl-x86_32',
186     'nacl-toolchain-mac-pnacl-x86_32',
187     'nacl-toolchain-win7-pnacl-x86_64',
188     ]
189
190 TOOLCHAIN_BUILD_TRYBOTS = [
191     'nacl-toolchain-precise64-newlib-arm',
192     'nacl-toolchain-mac-newlib-arm',
193     ] + PNACL_TOOLCHAIN_TRYBOTS