diff options
author | mnaganov@chromium.org <mnaganov@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-02-10 12:44:09 +0000 |
---|---|---|
committer | mnaganov@chromium.org <mnaganov@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-02-10 12:44:09 +0000 |
commit | fd00e49adcf05f05a5cff215abed207e738c606c (patch) | |
tree | a53a61b29acbbe88db2179e3e919817872ed98cc | |
parent | 0819558cee773646a70d92adb6ed2ca944677e0d (diff) | |
download | chromium_src-fd00e49adcf05f05a5cff215abed207e738c606c.zip chromium_src-fd00e49adcf05f05a5cff215abed207e738c606c.tar.gz chromium_src-fd00e49adcf05f05a5cff215abed207e738c606c.tar.bz2 |
Add checking for license formats to third_party/PRESUBMIT
Since we expect a certain format for the "License:" field, it's better to
check it earlier -- during the presubmit stage, so people won't get
surprises later.
Also, updated the license checking code to accept multiple licenses if
one of them is compatible with Android.
BUG=168324
R=dannyb@google.com, mkosiba@chromium.org
TBR=darin@chromium.org
Review URL: https://codereview.chromium.org/146803006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@250068 0039d316-1c4b-4281-b951-d872f2087c98
-rwxr-xr-x | android_webview/tools/webview_licenses.py | 36 | ||||
-rw-r--r-- | third_party/PRESUBMIT.py | 46 | ||||
-rw-r--r-- | third_party/README.chromium.template | 2 |
3 files changed, 58 insertions, 26 deletions
diff --git a/android_webview/tools/webview_licenses.py b/android_webview/tools/webview_licenses.py index 40755da..d87c47b 100755 --- a/android_webview/tools/webview_licenses.py +++ b/android_webview/tools/webview_licenses.py @@ -17,6 +17,7 @@ aren't in a third-party directory with a README.chromium file. """ import glob +import imp import optparse import os import re @@ -28,11 +29,22 @@ import textwrap REPOSITORY_ROOT = os.path.abspath(os.path.join( os.path.dirname(__file__), '..', '..')) +# Import third_party/PRESUBMIT.py via imp to avoid importing a random +# PRESUBMIT.py from $PATH, also make sure we don't generate a .pyc file. +sys.dont_write_bytecode = True +third_party = \ + imp.load_source('PRESUBMIT', \ + os.path.join(REPOSITORY_ROOT, 'third_party', 'PRESUBMIT.py')) + sys.path.append(os.path.join(REPOSITORY_ROOT, 'tools')) import licenses import known_issues +class InputApi(object): + def __init__(self): + self.re = re + def GetIncompatibleDirectories(): """Gets a list of third-party directories which use licenses incompatible with Android. This is used by the snapshot tool. @@ -40,23 +52,6 @@ def GetIncompatibleDirectories(): A list of directories. """ - whitelist = [ - 'A(pple )?PSL 2(\.0)?', - 'Apache( Version)? 2(\.0)?', - '(New )?([23]-Clause )?BSD( [23]-Clause)?( with advertising clause)?', - 'L?GPL ?v?2(\.[01])?( or later)?', - 'MIT(/X11)?(-like)?', - 'MPL 1\.1 ?/ ?GPL 2(\.0)? ?/ ?LGPL 2\.1', - 'MPL 2(\.0)?', - 'Microsoft Limited Public License', - 'Microsoft Permissive License', - 'Public Domain', - 'Python', - 'SGI Free Software License B', - 'University of Illinois\/NCSA Open Source', - 'X11', - ] - regex = '^(%s)$' % '|'.join(whitelist) result = [] for directory in _FindThirdPartyDirs(): if directory in known_issues.KNOWN_ISSUES: @@ -71,11 +66,8 @@ def GetIncompatibleDirectories(): if metadata.get('License Android Compatible', 'no').upper() == '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 + if not third_party.LicenseIsCompatibleWithAndroid(InputApi(), license): + result.append(directory) return result def GetUnknownIncompatibleDirectories(): diff --git a/third_party/PRESUBMIT.py b/third_party/PRESUBMIT.py index 4a6cba8..623b14b 100644 --- a/third_party/PRESUBMIT.py +++ b/third_party/PRESUBMIT.py @@ -2,6 +2,34 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. +ANDROID_WHITELISTED_LICENSES = [ + 'A(pple )?PSL 2(\.0)?', + 'Apache( Version)? 2(\.0)?', + '(New )?([23]-Clause )?BSD( [23]-Clause)?( with advertising clause)?', + 'L?GPL ?v?2(\.[01])?( or later)?', + 'MIT(/X11)?(-like)?', + 'MPL 1\.1 ?/ ?GPL 2(\.0)? ?/ ?LGPL 2\.1', + 'MPL 2(\.0)?', + 'Microsoft Limited Public License', + 'Microsoft Permissive License', + 'Public Domain', + 'Python', + 'SGI Free Software License B', + 'University of Illinois\/NCSA Open Source', + 'X11', +] + +def LicenseIsCompatibleWithAndroid(input_api, license): + regex = '^(%s)$' % '|'.join(ANDROID_WHITELISTED_LICENSES) + tokens = \ + [x.strip() for x in input_api.re.split(' and |,', license) if len(x) > 0] + has_compatible_license = False + for token in tokens: + if input_api.re.match(regex, token, input_api.re.IGNORECASE): + has_compatible_license = True + break + return has_compatible_license + def _CheckThirdPartyReadmesUpdated(input_api, output_api): """ Checks to make sure that README.chromium files are properly updated @@ -36,10 +64,13 @@ def _CheckThirdPartyReadmesUpdated(input_api, output_api): r'^Version: [a-zA-Z0-9_\-\.:]+\r?$', input_api.re.IGNORECASE | input_api.re.MULTILINE) release_pattern = input_api.re.compile( - r'^Security Critical: (yes)|(no)\r?$', + r'^Security Critical: (yes|no)\r?$', input_api.re.IGNORECASE | input_api.re.MULTILINE) license_pattern = input_api.re.compile( - r'^License: .+\r?$', + r'^License: (.+)\r?$', + input_api.re.IGNORECASE | input_api.re.MULTILINE) + license_android_compatible_pattern = input_api.re.compile( + r'^License Android Compatible: (yes|no)\r?$', input_api.re.IGNORECASE | input_api.re.MULTILINE) for f in readmes: @@ -68,12 +99,21 @@ def _CheckThirdPartyReadmesUpdated(input_api, output_api): 'field. This field specifies whether the package is built with\n' 'Chromium. Check README.chromium.template for details.', [f])) - if not license_pattern.search(contents): + license_match = license_pattern.search(contents) + if not license_match: errors.append(output_api.PresubmitError( 'Third party README files should contain a \'License\' field.\n' 'This field specifies the license used by the package. Check\n' 'README.chromium.template for details.', [f])) + elif not LicenseIsCompatibleWithAndroid(input_api, license_match.group(1)) \ + and not license_android_compatible_pattern.search(contents): + errors.append(output_api.PresubmitPromptWarning( + 'Cannot determine whether specified license is compatible with\n' + + 'the Android licensing requirements. Please check that the license\n' + + 'name is spelled according to third_party/PRESUBMIT.py. Please see\n' + + 'README.chromium.template for details.', + [f])) return errors diff --git a/third_party/README.chromium.template b/third_party/README.chromium.template index 7294612..fb27166 100644 --- a/third_party/README.chromium.template +++ b/third_party/README.chromium.template @@ -4,7 +4,7 @@ URL: The URL where the package lives Version: A searchable version number for the package (if the package does not version or is versioned by date or revision this field should be "0" and the revision, or date should be enumerated in the appropriate field)
Date: (OPTIONAL if version is supplied) The date that the package was updated
Revision: (OPTIONAL if version is supplied) The current revision of the package
-License: The license under which the package is distributed. Arbitrary text is allowed, but prefer standard forms, eg MIT/X11/BSD/Apache 2.0/GPL/LGPL.
+License: The license under which the package is distributed. Standard forms are only accepted, eg MIT/X11/BSD/Apache 2.0/GPL/LGPL. See ANDROID_WHITELISTED_LICENSES in PRESUBMIT.py for allowed patterns.
License File: (OPTIONAL) File that contains a copy of the package's license. Use the special value NOT_SHIPPED to indicate that the package is not included in the shipped product, so its license does not need to be included in about:credits and no license file is required.
Security Critical: Either yes or no depending on whether this package is shipped in releases. For example openssl is critical where cygwin is not.
License Android Compatible: (OPTIONAL) Whether the package uses a license compatible with Android. Required only if the package is compatible and the 'License' field uses a non-standard value.
|