mirror of
https://github.com/flutter/packages.git
synced 2025-06-17 20:19:14 +08:00
Update third_party license checking (#3844)
In preparation for enabling license checks in flutter/packages, update the allowed licenses: - Allow our license, for cases where we've locally added files - Allow the license used by the bsdiff package
This commit is contained in:
@ -1,3 +1,7 @@
|
||||
## 0.1.1
|
||||
|
||||
- Update the allowed third-party licenses for flutter/packages.
|
||||
|
||||
## 0.1.0+1
|
||||
|
||||
- Re-add the bin/ directory.
|
||||
|
@ -52,10 +52,14 @@ const Set<String> _ignoredFullBasenameList = <String>{
|
||||
final List<RegExp> _thirdPartyLicenseBlockRegexes = <RegExp>[
|
||||
// Third-party code used in url_launcher_web.
|
||||
RegExp(
|
||||
r'^// Copyright 2017 Workiva Inc..*'
|
||||
'^// Licensed under the Apache License, Version 2.0',
|
||||
r'^// Copyright 2017 Workiva Inc\..*'
|
||||
r'^// Licensed under the Apache License, Version 2\.0',
|
||||
multiLine: true,
|
||||
dotAll: true),
|
||||
// bsdiff in flutter/packages.
|
||||
RegExp(r'// Copyright 2003-2005 Colin Percival\. All rights reserved\.\n'
|
||||
r'// Use of this source code is governed by a BSD-style license that can be\n'
|
||||
r'// found in the LICENSE file\.\n'),
|
||||
];
|
||||
|
||||
// The exact format of the BSD license that our license files should contain.
|
||||
@ -158,16 +162,19 @@ class LicenseCheckCommand extends PluginCommand {
|
||||
_print('Checking ${file.path}');
|
||||
final String content = await file.readAsString();
|
||||
|
||||
final String firstParyLicense =
|
||||
firstPartyLicenseBlockByExtension[p.extension(file.path)] ??
|
||||
defaultFirstParyLicenseBlock;
|
||||
if (_isThirdParty(file)) {
|
||||
// Third-party directories allow either known third-party licenses, our
|
||||
// the first-party license, as there may be local additions.
|
||||
if (!_thirdPartyLicenseBlockRegexes
|
||||
.any((RegExp regex) => regex.hasMatch(content))) {
|
||||
.any((RegExp regex) => regex.hasMatch(content)) &&
|
||||
!content.contains(firstParyLicense)) {
|
||||
unrecognizedThirdPartyFiles.add(file);
|
||||
}
|
||||
} else {
|
||||
final String license =
|
||||
firstPartyLicenseBlockByExtension[p.extension(file.path)] ??
|
||||
defaultFirstParyLicenseBlock;
|
||||
if (!content.contains(license)) {
|
||||
if (!content.contains(firstParyLicense)) {
|
||||
incorrectFirstPartyFiles.add(file);
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
name: flutter_plugin_tools
|
||||
description: Productivity utils for flutter/plugins and flutter/packages
|
||||
repository: https://github.com/flutter/plugins/tree/master/script/tool
|
||||
version: 0.1.0+1
|
||||
version: 0.1.1
|
||||
|
||||
dependencies:
|
||||
args: "^1.4.3"
|
||||
|
@ -269,6 +269,24 @@ void main() {
|
||||
expect(printedMessages, contains('All source files passed validation!'));
|
||||
});
|
||||
|
||||
test('allows first-party code in a third_party directory', () async {
|
||||
final File firstPartyFileInThirdParty = root
|
||||
.childDirectory('a_plugin')
|
||||
.childDirectory('lib')
|
||||
.childDirectory('src')
|
||||
.childDirectory('third_party')
|
||||
.childFile('first_party.cc');
|
||||
firstPartyFileInThirdParty.createSync(recursive: true);
|
||||
_writeLicense(firstPartyFileInThirdParty);
|
||||
|
||||
await runner.run(<String>['license-check']);
|
||||
|
||||
// Sanity check that the test did actually check the file.
|
||||
expect(printedMessages,
|
||||
contains('Checking a_plugin/lib/src/third_party/first_party.cc'));
|
||||
expect(printedMessages, contains('All source files passed validation!'));
|
||||
});
|
||||
|
||||
test('fails for licenses that the tool does not expect', () async {
|
||||
final File good = root.childFile('good.cc');
|
||||
good.createSync();
|
||||
|
Reference in New Issue
Block a user