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.
5 """Presubmit script for ui.
7 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts
8 for more details about the presubmit API built into depot_tools.
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."""
16 # Only check files in ui/gl and ui/gfx for now since that is the
17 # only code converted.
19 source_file_filter = lambda x: input_api.FilterSourceFile(
21 white_list=tuple([r'.*ui[\\/].*\.(cc|h)$']))
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.
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)))
36 def CheckChange(input_api, output_api):
38 results += CheckX11HeaderUsage(input_api, output_api)
42 def CheckChangeOnUpload(input_api, output_api):
43 return CheckChange(input_api, output_api)
46 def CheckChangeOnCommit(input_api, output_api):
47 return CheckChange(input_api, output_api)