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 local_path
= f
.LocalPath()
15 if input_api
.os_path
.dirname(local_path
) == 'third_party':
17 if local_path
.startswith('third_party' + input_api
.os_path
.sep
):
19 if local_path
.endswith("README.chromium"):
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
))
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(
43 input_api
.re
.IGNORECASE | input_api
.re
.MULTILINE
)
47 _IgnoreIfDeleting(input_api
, output_api
, f
, errors
)
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.',
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.',
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.',
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.',
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
):
92 results
.extend(_CheckThirdPartyReadmesUpdated(input_api
, output_api
))