diff options
author | mnaganov@chromium.org <mnaganov@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-02-11 12:10:32 +0000 |
---|---|---|
committer | mnaganov@chromium.org <mnaganov@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-02-11 12:10:32 +0000 |
commit | 46a597cb539267f39c4f4ff47015dbaf275863ed (patch) | |
tree | 86ff4b67620669f2a62ccca467c887ac6668c27a /android_webview | |
parent | 7aa5e0837df7c81a9725aa659e92bd67d83dc823 (diff) | |
download | chromium_src-46a597cb539267f39c4f4ff47015dbaf275863ed.zip chromium_src-46a597cb539267f39c4f4ff47015dbaf275863ed.tar.gz chromium_src-46a597cb539267f39c4f4ff47015dbaf275863ed.tar.bz2 |
[Android WebView] Make 3rd party licenses checker to turn bot red
We have substantially improved the licenses checker to avoid
false positives in finding copyrighted code in non-third_party dirs.
Also, this change makes the presence of stale entries in the
whitelist file to be a warning, not an error.
BUG=161461
NOTRY=true
Review URL: https://chromiumcodereview.appspot.com/12209034
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@181679 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'android_webview')
-rwxr-xr-x | android_webview/tools/webview_licenses.py | 44 |
1 files changed, 27 insertions, 17 deletions
diff --git a/android_webview/tools/webview_licenses.py b/android_webview/tools/webview_licenses.py index 1cbba08..6465e96 100755 --- a/android_webview/tools/webview_licenses.py +++ b/android_webview/tools/webview_licenses.py @@ -74,6 +74,8 @@ def GetIncompatibleDirectories(): break return result +class ScanResult(object): + Ok, Warnings, Errors = range(3) def _CheckLicenseHeaders(excluded_dirs_list, whitelisted_files): """Checks that all files which are not in a listed third-party directory, @@ -82,8 +84,10 @@ def _CheckLicenseHeaders(excluded_dirs_list, whitelisted_files): excluded_dirs_list: The list of directories to exclude from scanning. whitelisted_files: The whitelist of files. Returns: - True if all files with non-standard license headers are whitelisted and the - whitelist contains no stale entries, otherwise false. + ScanResult.Ok if all files with non-standard license headers are whitelisted + and the whitelist contains no stale entries; + ScanResult.Warnings if there are stale entries; + ScanResult.Errors if new non-whitelisted entries found. """ excluded_dirs_list = [d for d in excluded_dirs_list if not 'third_party' in d] @@ -129,23 +133,25 @@ def _CheckLicenseHeaders(excluded_dirs_list, whitelisted_files): offending_files.append(os.path.normpath(entries[0])) break - all_files_valid = True unknown = set(offending_files) - set(whitelisted_files) if unknown: print 'The following files contain a third-party license but are not in ' \ 'a listed third-party directory and are not whitelisted. You must ' \ 'add the following files to the whitelist.\n%s' % \ '\n'.join(sorted(unknown)) - all_files_valid = False stale = set(whitelisted_files) - set(offending_files) if stale: print 'The following files are whitelisted unnecessarily. You must ' \ ' remove the following files from the whitelist.\n%s' % \ '\n'.join(sorted(stale)) - all_files_valid = False - return all_files_valid + if unknown: + return ScanResult.Errors + elif stale: + return ScanResult.Warnings + else: + return ScanResult.Ok def _ReadFile(path): @@ -186,9 +192,13 @@ def _FindThirdPartyDirs(): def _Scan(): - """Checks that license meta-data is present for all third-party code. + """Checks that license meta-data is present for all third-party code and + that all non third-party code doesn't contain external copyrighted code. Returns: - Whether the check succeeded. + ScanResult.Ok if everything is in order; + ScanResult.Warnings if there are non-fatal problems (e.g. stale whitelist + entries) + ScanResult.Errors otherwise. """ third_party_dirs = _FindThirdPartyDirs() @@ -211,8 +221,9 @@ def _Scan(): match = re.match(r'([^#\s]+)', line) if match: whitelisted_files.append(match.group(1)) - return _CheckLicenseHeaders(third_party_dirs, whitelisted_files) \ - and all_licenses_valid + licenses_check = _CheckLicenseHeaders(third_party_dirs, whitelisted_files) + + return licenses_check if all_licenses_valid else ScanResult.Errors def GenerateNoticeFile(): @@ -255,20 +266,19 @@ def main(): (options, args) = parser.parse_args() if len(args) != 1: parser.print_help() - return 1 + return ScanResult.Errors if args[0] == 'scan': - if _Scan(): + scan_result = _Scan() + if scan_result == ScanResult.Ok: print 'OK!' - return 0 - else: - return 1 + return scan_result elif args[0] == 'notice': print GenerateNoticeFile() - return 0 + return ScanResult.Ok parser.print_help() - return 1 + return ScanResult.Errors if __name__ == '__main__': sys.exit(main()) |