[M67 Dev][Tizen] Integrate GN and set up build environment
[platform/framework/web/chromium-efl.git] / ui / PRESUBMIT.py
1 # Copyright 2015 The Chromium 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 """Presubmit script for ui.
6
7 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts
8 for more details about the presubmit API built into depot_tools.
9 """
10
11 def CheckX11HeaderUsage(input_api, output_api):
12   """X11 headers pollute the global namespace with macros for common
13 names so instead code should include "ui/gfx/x/x11.h" which hide the
14 dangerous macros inside the x11 namespace."""
15
16   # Only check files in ui/gl and ui/gfx for now since that is the
17   # only code converted.
18
19   source_file_filter = lambda x: input_api.FilterSourceFile(
20     x,
21     white_list=tuple([r'.*ui[\\/].*\.(cc|h)$']))
22   errors = []
23   x11_include_pattern = input_api.re.compile(r'#include\s+<X11/.*\.h>')
24   for f in input_api.AffectedSourceFiles(source_file_filter):
25     if f.LocalPath().endswith(input_api.os_path.normpath("ui/gfx/x/x11.h")):
26       # This is the only file that is allowed to include X11 headers.
27       continue
28     for line_number, line in f.ChangedContents():
29       if input_api.re.search(x11_include_pattern, line):
30         errors.append(output_api.PresubmitError(
31           '%s:%d includes an X11 header. Include "ui/gfx/x/x11.h" instead.' %
32           (f.LocalPath(), line_number)))
33   return errors
34
35
36 def CheckChange(input_api, output_api):
37   results = []
38   results += CheckX11HeaderUsage(input_api, output_api)
39   return results
40
41
42 def CheckChangeOnUpload(input_api, output_api):
43   return CheckChange(input_api, output_api)
44
45
46 def CheckChangeOnCommit(input_api, output_api):
47   return CheckChange(input_api, output_api)