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
):
7 Checks to make sure that README.chromium files are properly updated
8 when dependancies in third_party are modified.
13 for f
in input_api
.AffectedFiles():
14 if f
.LocalPath().startswith('third_party' + input_api
.os_path
.sep
):
16 if f
.LocalPath().endswith("README.chromium"):
18 if files
and not readmes
:
19 errors
.append(output_api
.PresubmitPromptWarning(
20 'When updating or adding third party code the appropriate\n'
21 '\'README.chromium\' file should also be updated with the correct\n'
22 'version and package information.', files
))
26 name_pattern
= input_api
.re
.compile(
27 r
'^Name: [a-zA-Z0-9_\-\. \(\)]+\r?$',
28 input_api
.re
.IGNORECASE | input_api
.re
.MULTILINE
)
29 shortname_pattern
= input_api
.re
.compile(
30 r
'^Short Name: [a-zA-Z0-9_\-\.]+\r?$',
31 input_api
.re
.IGNORECASE | input_api
.re
.MULTILINE
)
32 version_pattern
= input_api
.re
.compile(
33 r
'^Version: [a-zA-Z0-9_\-\.:]+\r?$',
34 input_api
.re
.IGNORECASE | input_api
.re
.MULTILINE
)
35 release_pattern
= input_api
.re
.compile(
36 r
'^Security Critical: (yes)|(no)\r?$',
37 input_api
.re
.IGNORECASE | input_api
.re
.MULTILINE
)
38 license_pattern
= input_api
.re
.compile(
40 input_api
.re
.IGNORECASE | input_api
.re
.MULTILINE
)
43 contents
= input_api
.ReadFile(f
)
44 if (not shortname_pattern
.search(contents
)
45 and not name_pattern
.search(contents
)):
46 errors
.append(output_api
.PresubmitError(
47 'Third party README files should contain either a \'Short Name\' or\n'
48 'a \'Name\' which is the name under which the package is\n'
49 'distributed. Check README.chromium.template for details.',
51 if not version_pattern
.search(contents
):
52 errors
.append(output_api
.PresubmitError(
53 'Third party README files should contain a \'Version\' field.\n'
54 'If the package is not versioned or the version is not known\n'
55 'list the version as \'unknown\'.\n'
56 'Check README.chromium.template for details.',
58 if not release_pattern
.search(contents
):
59 errors
.append(output_api
.PresubmitError(
60 'Third party README files should contain a \'Security Critical\'\n'
61 'field. This field specifies whether the package is built with\n'
62 'Chromium. Check README.chromium.template for details.',
64 if not license_pattern
.search(contents
):
65 errors
.append(output_api
.PresubmitError(
66 'Third party README files should contain a \'License\' field.\n'
67 'This field specifies the license used by the package. Check\n'
68 'README.chromium.template for details.',
73 def CheckChangeOnUpload(input_api
, output_api
):
75 results
.extend(_CheckThirdPartyReadmesUpdated(input_api
, output_api
))