Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(98)

Side by Side Diff: android_webview/tools/webview_licenses.py

Issue 12047113: Make webview_licenses.py script to use licensecheck.pl (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Comments addressed Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 '--ignore', '|'.join(ignore_patterns),
108 '.'] 107 '.']
109 p = subprocess.Popen(args=args, cwd=REPOSITORY_ROOT, stdout=subprocess.PIPE) 108 p = subprocess.Popen(args=args, cwd=REPOSITORY_ROOT, stdout=subprocess.PIPE)
110 files = p.communicate()[0].splitlines() 109 lines = p.communicate()[0].splitlines()
111 110
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 = [] 111 offending_files = []
138 for x in files: 112 allowed_copyrights = '^(?:\*No copyright\*' \
139 x = os.path.normpath(x) 113 '|20[0-9][0-9](?:-20[0-9][0-9])? The Chromium Authors\. ' \
140 is_in_listed_directory = False 114 'All rights reserved.*)$'
141 for y in directory_list: 115 allowed_copyrights_re = re.compile(allowed_copyrights)
142 if x.startswith(y): 116 for l in lines:
143 is_in_listed_directory = True 117 entries = l.split('\t')
118 if entries[1] == "GENERATED FILE":
119 continue
120 copyrights = entries[2].split(' / ')
121 for c in copyrights:
122 if c and not allowed_copyrights_re.match(c):
123 offending_files.append(os.path.normpath(entries[0]))
144 break 124 break
145 if not is_in_listed_directory:
146 offending_files.append(x)
147 125
148 all_files_valid = True 126 all_files_valid = True
149 unknown = set(offending_files) - set(whitelisted_files) 127 unknown = set(offending_files) - set(whitelisted_files)
150 if unknown: 128 if unknown:
151 print 'The following files contain a third-party license but are not in ' \ 129 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 ' \ 130 'a listed third-party directory and are not whitelisted. You must ' \
153 'add the following files to the whitelist.\n%s' % \ 131 'add the following files to the whitelist.\n%s' % \
154 '\n'.join(sorted(unknown)) 132 '\n'.join(sorted(unknown))
155 all_files_valid = False 133 all_files_valid = False
156 134
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 return 1 259 return 1
282 elif args[0] == 'notice': 260 elif args[0] == 'notice':
283 print GenerateNoticeFile() 261 print GenerateNoticeFile()
284 return 0 262 return 0
285 263
286 parser.print_help() 264 parser.print_help()
287 return 1 265 return 1
288 266
289 if __name__ == '__main__': 267 if __name__ == '__main__':
290 sys.exit(main()) 268 sys.exit(main())
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698