Fix PowerSaveBlocker crash in Android WebView
[chromium-blink-merge.git] / third_party / PRESUBMIT.py
blob4a6cba81e640304285cd986d166f5d97f82b22bc
1 # Copyright (c) 2011 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 def _CheckThirdPartyReadmesUpdated(input_api, output_api):
6 """
7 Checks to make sure that README.chromium files are properly updated
8 when dependancies in third_party are modified.
9 """
10 readmes = []
11 files = []
12 errors = []
13 for f in input_api.AffectedFiles():
14 local_path = f.LocalPath()
15 if input_api.os_path.dirname(local_path) == 'third_party':
16 continue
17 if local_path.startswith('third_party' + input_api.os_path.sep):
18 files.append(f)
19 if local_path.endswith("README.chromium"):
20 readmes.append(f)
21 if files and not readmes:
22 errors.append(output_api.PresubmitPromptWarning(
23 'When updating or adding third party code the appropriate\n'
24 '\'README.chromium\' file should also be updated with the correct\n'
25 'version and package information.', files))
26 if not readmes:
27 return errors
29 name_pattern = input_api.re.compile(
30 r'^Name: [a-zA-Z0-9_\-\. \(\)]+\r?$',
31 input_api.re.IGNORECASE | input_api.re.MULTILINE)
32 shortname_pattern = input_api.re.compile(
33 r'^Short Name: [a-zA-Z0-9_\-\.]+\r?$',
34 input_api.re.IGNORECASE | input_api.re.MULTILINE)
35 version_pattern = input_api.re.compile(
36 r'^Version: [a-zA-Z0-9_\-\.:]+\r?$',
37 input_api.re.IGNORECASE | input_api.re.MULTILINE)
38 release_pattern = input_api.re.compile(
39 r'^Security Critical: (yes)|(no)\r?$',
40 input_api.re.IGNORECASE | input_api.re.MULTILINE)
41 license_pattern = input_api.re.compile(
42 r'^License: .+\r?$',
43 input_api.re.IGNORECASE | input_api.re.MULTILINE)
45 for f in readmes:
46 if 'D' in f.Action():
47 _IgnoreIfDeleting(input_api, output_api, f, errors)
48 continue
50 contents = input_api.ReadFile(f)
51 if (not shortname_pattern.search(contents)
52 and not name_pattern.search(contents)):
53 errors.append(output_api.PresubmitError(
54 'Third party README files should contain either a \'Short Name\' or\n'
55 'a \'Name\' which is the name under which the package is\n'
56 'distributed. Check README.chromium.template for details.',
57 [f]))
58 if not version_pattern.search(contents):
59 errors.append(output_api.PresubmitError(
60 'Third party README files should contain a \'Version\' field.\n'
61 'If the package is not versioned or the version is not known\n'
62 'list the version as \'unknown\'.\n'
63 'Check README.chromium.template for details.',
64 [f]))
65 if not release_pattern.search(contents):
66 errors.append(output_api.PresubmitError(
67 'Third party README files should contain a \'Security Critical\'\n'
68 'field. This field specifies whether the package is built with\n'
69 'Chromium. Check README.chromium.template for details.',
70 [f]))
71 if not license_pattern.search(contents):
72 errors.append(output_api.PresubmitError(
73 'Third party README files should contain a \'License\' field.\n'
74 'This field specifies the license used by the package. Check\n'
75 'README.chromium.template for details.',
76 [f]))
77 return errors
80 def _IgnoreIfDeleting(input_api, output_api, affected_file, errors):
81 third_party_dir = input_api.os_path.dirname(affected_file.LocalPath())
82 for f in input_api.AffectedFiles():
83 if f.LocalPath().startswith(third_party_dir):
84 if 'D' not in f.Action():
85 errors.append(output_api.PresubmitError(
86 'Third party README should only be removed when the whole\n'
87 'directory is being removed.\n', [f, affected_file]))
90 def CheckChangeOnUpload(input_api, output_api):
91 results = []
92 results.extend(_CheckThirdPartyReadmesUpdated(input_api, output_api))
93 return results