def GetIncompatibleDirectories(): """Gets a list of third-party directories which use licenses incompatible with Android. This is used by the snapshot tool. Returns: A list of directories. """ result = [] for directory in _FindThirdPartyDirs(): if directory in known_issues.KNOWN_ISSUES: result.append(directory) continue try: metadata = licenses.ParseDir( directory, REPOSITORY_ROOT, require_license_file=False, optional_keys=['License Android Compatible']) except licenses.LicenseError as e: print 'Got LicenseError while scanning ' + directory raise if metadata.get('License Android Compatible', 'no').upper() == 'YES': continue license = re.split(' [Ll]icenses?$', metadata['License'])[0] if not third_party.LicenseIsCompatibleWithAndroid(InputApi(), license): result.append(directory) return result
def GetIncompatibleDirectories(): """Gets a list of third-party directories which use licenses incompatible with Android. This is used by the snapshot tool. Returns: A list of directories. """ whitelist = [ 'Apache( Version)? 2(\.0)?', '(New )?BSD( 3-Clause)?( with advertising clause)?', 'L?GPL ?v?2(\.[01])?( or later)?', 'MIT(/X11)?(-like)?', 'MPL 1\.1 ?/ ?GPL 2(\.0)? ?/ ?LGPL 2\.1', 'Microsoft Limited Public License', 'Microsoft Permissive License', 'Public Domain', 'SGI Free Software License B', 'X11', ] regex = '^(%s)$' % '|'.join(whitelist) result = [] for directory in _FindThirdPartyDirs(): metadata = licenses.ParseDir(directory, require_license_file=False) if metadata.get('License Android Compatible', 'no') == 'yes': continue license = re.split(' [Ll]icenses?$', metadata['License'])[0] tokens = [ x.strip() for x in re.split(' and |,', license) if len(x) > 0 ] for token in tokens: if not re.match(regex, token, re.IGNORECASE): result.append(directory) break return result
def GenerateLicense(): """Generates the contents of an Cronet LICENSE file for the third-party code. Returns: The contents of the LICENSE file. """ # TODO(mef): Generate list of third_party libraries using checkdeps. third_party_dirs = [ 'base/third_party/libevent', 'third_party/ashmem', 'third_party/boringssl', 'third_party/modp_b64', 'third_party/zlib', ] # Start with Chromium's LICENSE file content = [_ReadFile('LICENSE')] # Add necessary third_party. for directory in sorted(third_party_dirs): metadata = licenses.ParseDir(directory, REPOSITORY_ROOT, require_license_file=True) content.append('-' * 20) content.append(directory) content.append('-' * 20) license_file = metadata['License File'] if license_file and license_file != licenses.NOT_SHIPPED: content.append(_ReadFile(license_file)) return '\n'.join(content)
def find_chromium_licenses(chromium_root): """Look for license files in a Chromium checkout and return a set with all files that are actually shipped and used in the final Chromium binary.""" try: import licenses except ImportError: raise ImportError('Failed to import licenses.py. Make sure %s ' 'contains tools/licenses.py.' % chromium_root) # Make sure the main Chromium LICENSE file is always present. license_files = set([os.path.join(chromium_root, 'LICENSE')]) for d in licenses.FindThirdPartyDirs(licenses.PRUNE_PATHS, chromium_root): if d in SKIPPED_DIRECTORIES: continue try: metadata = licenses.ParseDir(d, chromium_root) except licenses.LicenseError as e: print('Exception in directory %s: %s' % (d, e)) if input('Ignore (y)? ') == 'y': continue raise # We are not interested in licenses for projects that are not marked as # used in the final product (ie. they might be optional development # aids, or only used in a build). if metadata['License File'] != licenses.NOT_SHIPPED: license_files.add(metadata['License File']) return license_files
def GenerateLicense(output_filename=None): """Generate list of licenses in html form. Dumps the result to output file. Args: output_filename: Filename to write the license.html to. Writes to stdout if None. Returns: 0 on success. """ chromium_root = os.path.join(toplevel_dir, 'external', 'chromium') third_party_dirs = set( licenses.FindThirdPartyDirs(licenses.PRUNE_PATHS, chromium_root)) prune_paths = CreateSteelPruneList(third_party_dirs) third_party_dirs -= prune_paths entries = [] for path in sorted(third_party_dirs): try: metadata = licenses.ParseDir(path, chromium_root) except licenses.LicenseError: print >> sys.stderr, ('WARNING: licensing info for ' + path + ' is incomplete, skipping.') continue if metadata['License File'] != 'NOT_SHIPPED': env = { 'name': metadata['Name'], 'url': metadata['URL'], 'license': open(metadata['License File'], 'rb').read(), } entries.append(env) if output_filename: output_file = open(output_filename, 'wb') else: output_file = sys.stdout for e in entries: output_file.write('<h4>\n') output_file.write(e['name'] + '\n') output_file.write('</h4>\n') output_file.write('<pre>\n') output_file.write(e['license'] + '\n') output_file.write('</pre>\n') return 0
def GenerateNoticeFile(): """Generates the contents of an Android NOTICE file for the third-party code. This is used by the snapshot tool. Returns: A tuple of (input paths, contents of the NOTICE file). """ generator = TemplateEntryGenerator() # Start from Chromium's LICENSE file entries = [ generator.MetadataToTemplateEntry({ 'Name': 'The Chromium Project', 'URL': 'http://www.chromium.org', 'License File': os.path.join(REPOSITORY_ROOT, 'LICENSE') }) ] third_party_dirs = licenses.FindThirdPartyDirsWithFiles(REPOSITORY_ROOT) # We provide attribution for all third-party directories. # TODO(mnaganov): Limit this to only code used by the WebView binary. for directory in sorted(third_party_dirs): try: metadata = licenses.ParseDir(directory, REPOSITORY_ROOT, require_license_file=False) except licenses.LicenseError: # Since this code is called during project files generation, # we don't want to break the it. But we assume that release # WebView apks are built using checkouts that pass # 'webview_licenses.py scan' check, thus they don't contain # projects with non-compatible licenses. continue license_file = metadata['License File'] if license_file and license_file != licenses.NOT_SHIPPED: entries.append(generator.MetadataToTemplateEntry(metadata)) entries.sort(key=lambda entry: entry['name']) license_file_list = sorted( set([entry['license_file'] for entry in entries])) license_file_list = [os.path.relpath(p) for p in license_file_list] env = jinja2.Environment(loader=jinja2.FileSystemLoader( os.path.dirname(__file__)), extensions=['jinja2.ext.autoescape']) template = env.get_template('licenses_notice.tmpl') notice_file_contents = template.render({'entries': entries}).encode('utf8') return (license_file_list, notice_file_contents)
def _Scan(): """Checks that license meta-data is present for all third-party code. Returns: Whether the check succeeded. """ third_party_dirs = _FindThirdPartyDirs() # First, check designated third-party directories using src/tools/licenses.py. all_licenses_valid = True for path in sorted(third_party_dirs): try: licenses.ParseDir(path) except licenses.LicenseError, e: print 'Got LicenseError "%s" while scanning %s' % (e, path) all_licenses_valid = False
def GenerateLicense(): """Generates the contents of an Cronet LICENSE file for the third-party code. Returns: The contents of the LICENSE file. """ # Start with Chromium's LICENSE file content = [_ReadFile('LICENSE')] # Add necessary third_party. for directory in sorted(third_party_dirs): metadata = licenses.ParseDir(directory, REPOSITORY_ROOT, require_license_file=True) content.append('-' * 20) content.append(directory.split("/")[-1]) content.append('-' * 20) license_file = metadata['License File'] if license_file and license_file != licenses.NOT_SHIPPED: content.append(_ReadFile(license_file)) return '\n'.join(content)
def _Scan(): """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: 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() # First, check designated third-party directories using src/tools/licenses.py. all_licenses_valid = True for path in sorted(third_party_dirs): try: licenses.ParseDir(path, REPOSITORY_ROOT) except licenses.LicenseError, e: if not (path in known_issues.KNOWN_ISSUES): print 'Got LicenseError "%s" while scanning %s' % (e, path) all_licenses_valid = False
def GenerateNoticeFile(): """Generates the contents of an Android NOTICE file for the third-party code. This is used by the snapshot tool. Returns: The contents of the NOTICE file. """ third_party_dirs = _FindThirdPartyDirs() # Don't forget Chromium's LICENSE file content = [_ReadFile('LICENSE')] # We provide attribution for all third-party directories. # TODO(steveblock): Limit this to only code used by the WebView binary. for directory in third_party_dirs: metadata = licenses.ParseDir(directory, require_license_file=False) license_file = metadata['License File'] if license_file and license_file != licenses.NOT_SHIPPED: content.append(_ReadFile(license_file)) return '\n'.join(content)