Revert "Upgrade NodeJS binary to v16.13.0"
[platform/framework/web/chromium-efl.git] / third_party / PRESUBMIT.py
1 # Copyright 2011 The Chromium Authors
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4
5 import os
6
7 USE_PYTHON3 = True
8
9 PRESUBMIT_VERSION = '2.0.0'
10
11 ANDROID_ALLOWED_LICENSES = [
12   'A(pple )?PSL 2(\.0)?',
13   'Android Software Development Kit License',
14   'Apache( License)?,?( Version)? 2(\.0)?',
15   '(New )?([23]-Clause )?BSD( [23]-Clause)?( with advertising clause)?',
16   'GNU Lesser Public License',
17   'L?GPL ?v?2(\.[01])?( or later)?( with the classpath exception)?',
18   '(The )?MIT(/X11)?(-like)?( License)?',
19   'MPL 1\.1 ?/ ?GPL 2(\.0)? ?/ ?LGPL 2\.1',
20   'MPL 2(\.0)?',
21   'Microsoft Limited Public License',
22   'Microsoft Permissive License',
23   'Public Domain',
24   'Python',
25   'SIL Open Font License, Version 1.1',
26   'SGI Free Software License B',
27   'Unicode, Inc. License',
28   'University of Illinois\/NCSA Open Source',
29   'X11',
30   'Zlib',
31 ]
32
33 def LicenseIsCompatibleWithAndroid(input_api, license):
34   regex = '^(%s)$' % '|'.join(ANDROID_ALLOWED_LICENSES)
35   tokens = \
36     [x.strip() for x in input_api.re.split(' and |,', license) if len(x) > 0]
37   has_compatible_license = False
38   for token in tokens:
39     if input_api.re.match(regex, token, input_api.re.IGNORECASE):
40       has_compatible_license = True
41       break
42   return has_compatible_license
43
44 def CheckThirdPartyReadmesUpdated(input_api, output_api):
45   """
46   Checks to make sure that README.chromium files are properly updated
47   when dependencies in third_party are modified.
48   """
49   readmes = []
50   files = []
51   errors = []
52   for f in input_api.AffectedFiles():
53     local_path = f.LocalPath()
54     if input_api.os_path.dirname(local_path) == 'third_party':
55       continue
56     if (local_path.startswith('third_party' + input_api.os_path.sep) and
57         not local_path.startswith('third_party' + input_api.os_path.sep +
58                                   'blink' + input_api.os_path.sep) and
59         not local_path.startswith('third_party' + input_api.os_path.sep +
60                                   'boringssl' + input_api.os_path.sep) and
61         not local_path.startswith('third_party' + input_api.os_path.sep +
62                                   'closure_compiler' + input_api.os_path.sep +
63                                   'externs' + input_api.os_path.sep) and
64         not local_path.startswith('third_party' + input_api.os_path.sep +
65                                   'closure_compiler' + input_api.os_path.sep +
66                                   'interfaces' + input_api.os_path.sep) and
67         not local_path.startswith('third_party' + input_api.os_path.sep +
68                                   'feed_library' + input_api.os_path.sep) and
69         not local_path.startswith('third_party' + input_api.os_path.sep +
70                                   'ipcz' + input_api.os_path.sep) and
71         # TODO(danakj): We should look for the README.chromium file in
72         # third_party/rust/CRATE_NAME/vVERSION/.
73         not local_path.startswith('third_party' + input_api.os_path.sep +
74                                   'rust' + input_api.os_path.sep) and
75         not local_path.startswith('third_party' + input_api.os_path.sep +
76                                   'webxr_test_pages' + input_api.os_path.sep)):
77       files.append(f)
78       if local_path.endswith("README.chromium"):
79         readmes.append(f)
80   if files and not readmes:
81     errors.append(output_api.PresubmitPromptWarning(
82        'When updating or adding third party code the appropriate\n'
83        '\'README.chromium\' file should also be updated with the correct\n'
84        'version and package information.', files))
85   if not readmes:
86     return errors
87
88   name_pattern = input_api.re.compile(
89     r'^Name: [a-zA-Z0-9_\-\. \(\)]+\r?$',
90     input_api.re.IGNORECASE | input_api.re.MULTILINE)
91   shortname_pattern = input_api.re.compile(
92     r'^Short Name: [a-zA-Z0-9_\-\.]+\r?$',
93     input_api.re.IGNORECASE | input_api.re.MULTILINE)
94   version_pattern = input_api.re.compile(
95     r'^Version: [a-zA-Z0-9_\-\+\.:/]+\r?$',
96     input_api.re.IGNORECASE | input_api.re.MULTILINE)
97   release_pattern = input_api.re.compile(
98     r'^Security Critical: (yes|no)\r?$',
99     input_api.re.IGNORECASE | input_api.re.MULTILINE)
100   license_pattern = input_api.re.compile(
101     r'^License: (.+)\r?$',
102     input_api.re.IGNORECASE | input_api.re.MULTILINE)
103   not_shipped_pattern = input_api.re.compile(
104     r'^License File: NOT_SHIPPED\r?$',
105     input_api.re.IGNORECASE | input_api.re.MULTILINE)
106   license_android_compatible_pattern = input_api.re.compile(
107     r'^License Android Compatible: (yes|no)\r?$',
108     input_api.re.IGNORECASE | input_api.re.MULTILINE)
109
110   for f in readmes:
111     if 'D' in f.Action():
112       _IgnoreIfDeleting(input_api, output_api, f, errors)
113       continue
114
115     contents = input_api.ReadFile(f)
116     if (not shortname_pattern.search(contents)
117         and not name_pattern.search(contents)):
118       errors.append(output_api.PresubmitError(
119         'Third party README files should contain either a \'Short Name\' or\n'
120         'a \'Name\' which is the name under which the package is\n'
121         'distributed. Check README.chromium.template for details.',
122         [f]))
123     if not version_pattern.search(contents):
124       errors.append(output_api.PresubmitError(
125         'Third party README files should contain a \'Version\' field.\n'
126         'If the package is not versioned or the version is not known\n'
127         'list the version as \'unknown\'.\n'
128         'Check README.chromium.template for details.',
129         [f]))
130     if not release_pattern.search(contents):
131       errors.append(output_api.PresubmitError(
132         'Third party README files should contain a \'Security Critical\'\n'
133         'field. This field specifies whether the package is built with\n'
134         'Chromium. Check README.chromium.template for details.',
135         [f]))
136     license_match = license_pattern.search(contents)
137     if not license_match:
138       errors.append(output_api.PresubmitError(
139         'Third party README files should contain a \'License\' field.\n'
140         'This field specifies the license used by the package. Check\n'
141         'README.chromium.template for details.',
142         [f]))
143     not_shipped_match = not_shipped_pattern.search(contents)
144     android_compatible_match = (
145         license_android_compatible_pattern.search(contents))
146     if (not not_shipped_match and not android_compatible_match and
147         not LicenseIsCompatibleWithAndroid(input_api, license_match.group(1))):
148       errors.append(output_api.PresubmitPromptWarning(
149         'Cannot determine whether specified license is compatible with\n' +
150         'the Android licensing requirements. Please check that the license\n' +
151         'name is spelled according to third_party/PRESUBMIT.py. Please see\n' +
152         'README.chromium.template for details.',
153         [f]))
154   return errors
155
156
157 def _IgnoreIfDeleting(input_api, output_api, affected_file, errors):
158   third_party_dir = input_api.os_path.dirname(affected_file.LocalPath()) + \
159     os.path.sep
160   for f in input_api.AffectedFiles():
161     if f.LocalPath().startswith(third_party_dir):
162       if 'D' not in f.Action():
163         errors.append(output_api.PresubmitError(
164           'Third party README should only be removed when the whole\n'
165           'directory is being removed.\n', [f, affected_file]))