OLD | NEW |
---|---|
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """Checks third-party licenses for the purposes of the Android WebView build. | 6 """Checks third-party licenses for the purposes of the Android WebView build. |
7 | 7 |
8 The Android tree includes a snapshot of Chromium in order to power the system | 8 The Android tree includes a snapshot of Chromium in order to power the system |
9 WebView. This tool checks that all code uses open-source licenses compatible | 9 WebView. This tool checks that all code uses open-source licenses compatible |
10 with Android, and that we meet the requirements of those licenses. It can also | 10 with Android, and that we meet the requirements of those licenses. It can also |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
79 """Checks that all files which are not in a listed third-party directory, | 79 """Checks that all files which are not in a listed third-party directory, |
80 and which do not use the standard Chromium license, are whitelisted. | 80 and which do not use the standard Chromium license, are whitelisted. |
81 Args: | 81 Args: |
82 directory_list: The list of directories. | 82 directory_list: The list of directories. |
83 whitelisted_files: The whitelist of files. | 83 whitelisted_files: The whitelist of files. |
84 Returns: | 84 Returns: |
85 True if all files with non-standard license headers are whitelisted and the | 85 True if all files with non-standard license headers are whitelisted and the |
86 whitelist contains no stale entries, otherwise false. | 86 whitelist contains no stale entries, otherwise false. |
87 """ | 87 """ |
88 | 88 |
89 # Matches one of ... | 89 directory_list = [d for d in directory_list if not 'third_party' in d] |
90 # - '[Cc]opyright', but not when followed by | 90 # This makes the ignore regexp shorter |
91 # ' 20[0-9][0-9] The Chromium Authors.', with optional (c) and date range | 91 directory_list.append('third_party') |
92 # - '([Cc]) (19|20)[0-9][0-9]', but not when preceeded by the word copyright, | 92 # 'Copyright' appears in license agreements |
93 # as this is handled above | 93 directory_list.append('chrome/app/resources') |
94 regex = '[Cc]opyright(?!( \(c\))? 20[0-9][0-9](-20[0-9][0-9])? ' \ | 94 # Arm sysroot tools, doesn't exist in the snapshot |
95 'The Chromium Authors\. All rights reserved\.)' \ | 95 directory_list.append('arm-sysroot') |
96 '|' \ | |
97 '(?<!(pyright |opyright))\([Cc]\) (19|20)[0-9][0-9]' | |
98 | 96 |
99 args = ['grep', | 97 ignore_patterns = [] |
100 '-rPlI', | 98 for d in directory_list: |
101 '--exclude', '*.orig', | 99 ignore_patterns.append('(?:/' + d.replace('+', '\+') + '/)') |
102 '--exclude', '*.rej', | 100 |
103 '--exclude-dir', 'third_party', | 101 args = ['third_party/devscripts/licensecheck.pl', |
104 '--exclude-dir', 'out', | 102 '--lines', '99', |
105 '--exclude-dir', '.git', | 103 '--copyright', |
106 '--exclude-dir', '.svn', | 104 '--machine', |
107 regex, | 105 '--recursive', |
106 '--check', '\.(c(c|pp|xx)?|h(h|pp|xx)?|p(l|m)|xs|sh|php|py(|x)|rb' \ | |
Paweł Hajdan Jr.
2013/01/25 17:54:33
Do you need to use --check? Why?
mnaganov (inactive)
2013/01/28 14:51:54
Because the pattern in licensecheck.pl apparently
Paweł Hajdan Jr.
2013/01/28 16:28:29
Why not update the pattern in licensecheck.pl then
mnaganov (inactive)
2013/01/28 17:12:38
I was considering these additions to be Chromium-s
| |
107 '|java|vala|el|sc(i|e)|cs|pas|inc|dtd|xsl|mod|m|tex|mli?|js|html' \ | |
108 '|pac|mm|asm|idl)$', | |
109 '--ignore', '|'.join(ignore_patterns), | |
108 '.'] | 110 '.'] |
109 p = subprocess.Popen(args=args, cwd=REPOSITORY_ROOT, stdout=subprocess.PIPE) | 111 p = subprocess.Popen(args=args, cwd=REPOSITORY_ROOT, stdout=subprocess.PIPE) |
110 files = p.communicate()[0].splitlines() | 112 lines = p.communicate()[0].splitlines() |
111 | 113 |
112 directory_list = directory_list[:] | |
113 # Ignore these tools. | |
114 directory_list.append('android_webview/tools/') | |
115 # This is a build intermediate directory. | |
116 directory_list.append('chrome/app/theme/google_chrome/') | |
117 # This is tests directory, doesn't exist in the snapshot | |
118 directory_list.append('content/test/data/') | |
119 # This is a test output directory. | |
120 directory_list.append('data/dom_perf/') | |
121 # This is a test output directory. | |
122 directory_list.append('data/page_cycler/') | |
123 # 'Copyright' appears in strings. | |
124 directory_list.append('chrome/app/resources/') | |
125 # This is a Chrome on Linux reference build, doesn't exist in the snapshot | |
126 directory_list.append('chrome/tools/test/reference_build/chrome_linux/') | |
127 # Remoting internal tools, doesn't exist in the snapshot | |
128 directory_list.append('remoting/appengine/') | |
129 # Histogram tools, doesn't exist in the snapshot | |
130 directory_list.append('tools/histograms/') | |
131 # Arm sysroot tools, doesn't exist in the snapshot | |
132 directory_list.append('arm-sysroot/') | |
133 # Windows-only | |
134 directory_list.append('tools/win/toolchain/7z/') | |
135 | |
136 # Exclude files under listed directories and some known offenders. | |
137 offending_files = [] | 114 offending_files = [] |
138 for x in files: | 115 allowed_copyrights = '^(?:\*No copyright\*' \ |
139 x = os.path.normpath(x) | 116 '|20[0-9][0-9](?:-20[0-9][0-9])? The Chromium Authors\. ' \ |
140 is_in_listed_directory = False | 117 'All rights reserved.*)$' |
141 for y in directory_list: | 118 allowed_copyrights_re = re.compile(allowed_copyrights) |
142 if x.startswith(y): | 119 for l in lines: |
143 is_in_listed_directory = True | 120 entries = l.split('\t') |
121 if entries[1] == "GENERATED FILE": | |
122 continue | |
123 copyrights = entries[2].split(' / ') | |
124 for c in copyrights: | |
125 if c and not allowed_copyrights_re.match(c): | |
126 offending_files.append(os.path.normpath(entries[0])) | |
144 break | 127 break |
145 if not is_in_listed_directory: | |
146 offending_files.append(x) | |
147 | 128 |
148 all_files_valid = True | 129 all_files_valid = True |
149 unknown = set(offending_files) - set(whitelisted_files) | 130 unknown = set(offending_files) - set(whitelisted_files) |
150 if unknown: | 131 if unknown: |
151 print 'The following files contain a third-party license but are not in ' \ | 132 print 'The following files contain a third-party license but are not in ' \ |
152 'a listed third-party directory and are not whitelisted. You must ' \ | 133 'a listed third-party directory and are not whitelisted. You must ' \ |
153 'add the following files to the whitelist.\n%s' % \ | 134 'add the following files to the whitelist.\n%s' % \ |
154 '\n'.join(sorted(unknown)) | 135 '\n'.join(sorted(unknown)) |
155 all_files_valid = False | 136 all_files_valid = False |
156 | 137 |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
281 return 1 | 262 return 1 |
282 elif args[0] == 'notice': | 263 elif args[0] == 'notice': |
283 print GenerateNoticeFile() | 264 print GenerateNoticeFile() |
284 return 0 | 265 return 0 |
285 | 266 |
286 parser.print_help() | 267 parser.print_help() |
287 return 1 | 268 return 1 |
288 | 269 |
289 if __name__ == '__main__': | 270 if __name__ == '__main__': |
290 sys.exit(main()) | 271 sys.exit(main()) |
OLD | NEW |