Fix FullScreen crash in Webapp
[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 USE_PYTHON3 = True
15
16 # List of directories to not apply presubmit project checks, relative
17 # to the NaCl top directory
18 EXCLUDE_PROJECT_CHECKS = [
19     # The following contain test data (including automatically generated),
20     # and do not follow our conventions.
21     'src/trusted/validator_ragel/testdata/32/',
22     'src/trusted/validator_ragel/testdata/64/',
23     'src/trusted/validator_x86/testdata/32/',
24     'src/trusted/validator_x86/testdata/64/',
25     'src/trusted/validator/x86/decoder/generator/testdata/32/',
26     'src/trusted/validator/x86/decoder/generator/testdata/64/',
27     # The following directories contains automatically generated source,
28     # which may not follow our conventions.
29     'src/trusted/validator_x86/gen/',
30     'src/trusted/validator/x86/decoder/gen/',
31     'src/trusted/validator/x86/decoder/generator/gen/',
32     'src/trusted/validator/x86/ncval_seg_sfi/gen/',
33     'src/trusted/validator_arm/gen/',
34     'src/trusted/validator_ragel/gen/',
35     # The following files contain code from outside native_client (e.g. newlib)
36     # or are known the contain style violations.
37     'src/trusted/service_runtime/include/sys/',
38     'src/include/win/port_win.h',
39     'src/trusted/service_runtime/include/machine/_types.h'
40     ]
41
42 NACL_TOP_DIR = os.getcwd()
43 while not os.path.isfile(os.path.join(NACL_TOP_DIR, 'PRESUBMIT.py')):
44   NACL_TOP_DIR = os.path.dirname(NACL_TOP_DIR)
45   assert len(NACL_TOP_DIR) >= 3, "Could not find NaClTopDir"
46
47
48 def _CommonChecks(input_api, output_api):
49   """Checks for both upload and commit."""
50   results = []
51
52   results.extend(input_api.canned_checks.PanProjectChecks(
53       input_api, output_api, project_name='Native Client',
54       excluded_paths=tuple(EXCLUDE_PROJECT_CHECKS)))
55
56   # The commit queue assumes PRESUBMIT.py is standalone.
57   # TODO(bradnelson): Migrate code_hygiene to a common location so that
58   # it can be used by the commit queue.
59   old_sys_path = list(sys.path)
60   try:
61     sys.path.append(os.path.join(NACL_TOP_DIR, 'tools'))
62     sys.path.append(os.path.join(NACL_TOP_DIR, 'build'))
63     import code_hygiene
64   finally:
65     sys.path = old_sys_path
66     del old_sys_path
67
68   affected_files = input_api.AffectedFiles(include_deletes=False)
69   exclude_dirs = [ NACL_TOP_DIR + '/' + x for x in EXCLUDE_PROJECT_CHECKS ]
70   for filename in affected_files:
71     filename = filename.AbsoluteLocalPath()
72     if filename in exclude_dirs:
73       continue
74     if not IsFileInDirectories(filename, exclude_dirs):
75       errors, warnings = code_hygiene.CheckFile(filename, False)
76       for e in errors:
77         results.append(output_api.PresubmitError(e, items=errors[e]))
78       for w in warnings:
79         results.append(output_api.PresubmitPromptWarning(w, items=warnings[w]))
80
81   return results
82
83
84 def IsFileInDirectories(f, dirs):
85   """ Returns true if f is in list of directories"""
86   for d in dirs:
87     if d is os.path.commonprefix([f, d]):
88       return True
89   return False
90
91
92 def CheckChangeOnUpload(input_api, output_api):
93   """Verifies all changes in all files.
94   Args:
95     input_api: the limited set of input modules allowed in presubmit.
96     output_api: the limited set of output modules allowed in presubmit.
97   """
98   report = []
99   report.extend(_CommonChecks(input_api, output_api))
100   return report
101
102
103 def CheckChangeOnCommit(input_api, output_api):
104   """Verifies all changes in all files and verifies that the
105   tree is open and can accept a commit.
106   Args:
107     input_api: the limited set of input modules allowed in presubmit.
108     output_api: the limited set of output modules allowed in presubmit.
109   """
110   report = []
111   report.extend(_CommonChecks(input_api, output_api))
112   return report