Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Commit f13a39e

Browse files
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
1 parent a2ce3da commit f13a39e

File tree

4 files changed

+37
-8
lines changed

4 files changed

+37
-8
lines changed

script/tool/CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.1.1
2+
3+
- Update the allowed third-party licenses for flutter/packages.
4+
15
## 0.1.0+1
26

37
- Re-add the bin/ directory.

script/tool/lib/src/license_check_command.dart

+14-7
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,14 @@ const Set<String> _ignoredFullBasenameList = <String>{
5252
final List<RegExp> _thirdPartyLicenseBlockRegexes = <RegExp>[
5353
// Third-party code used in url_launcher_web.
5454
RegExp(
55-
r'^// Copyright 2017 Workiva Inc..*'
56-
'^// Licensed under the Apache License, Version 2.0',
55+
r'^// Copyright 2017 Workiva Inc\..*'
56+
r'^// Licensed under the Apache License, Version 2\.0',
5757
multiLine: true,
5858
dotAll: true),
59+
// bsdiff in flutter/packages.
60+
RegExp(r'// Copyright 2003-2005 Colin Percival\. All rights reserved\.\n'
61+
r'// Use of this source code is governed by a BSD-style license that can be\n'
62+
r'// found in the LICENSE file\.\n'),
5963
];
6064

6165
// The exact format of the BSD license that our license files should contain.
@@ -158,16 +162,19 @@ class LicenseCheckCommand extends PluginCommand {
158162
_print('Checking ${file.path}');
159163
final String content = await file.readAsString();
160164

165+
final String firstParyLicense =
166+
firstPartyLicenseBlockByExtension[p.extension(file.path)] ??
167+
defaultFirstParyLicenseBlock;
161168
if (_isThirdParty(file)) {
169+
// Third-party directories allow either known third-party licenses, our
170+
// the first-party license, as there may be local additions.
162171
if (!_thirdPartyLicenseBlockRegexes
163-
.any((RegExp regex) => regex.hasMatch(content))) {
172+
.any((RegExp regex) => regex.hasMatch(content)) &&
173+
!content.contains(firstParyLicense)) {
164174
unrecognizedThirdPartyFiles.add(file);
165175
}
166176
} else {
167-
final String license =
168-
firstPartyLicenseBlockByExtension[p.extension(file.path)] ??
169-
defaultFirstParyLicenseBlock;
170-
if (!content.contains(license)) {
177+
if (!content.contains(firstParyLicense)) {
171178
incorrectFirstPartyFiles.add(file);
172179
}
173180
}

script/tool/pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: flutter_plugin_tools
22
description: Productivity utils for flutter/plugins and flutter/packages
33
repository: https://github.com/flutter/plugins/tree/master/script/tool
4-
version: 0.1.0+1
4+
version: 0.1.1
55

66
dependencies:
77
args: "^1.4.3"

script/tool/test/license_check_command_test.dart

+18
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,24 @@ void main() {
269269
expect(printedMessages, contains('All source files passed validation!'));
270270
});
271271

272+
test('allows first-party code in a third_party directory', () async {
273+
final File firstPartyFileInThirdParty = root
274+
.childDirectory('a_plugin')
275+
.childDirectory('lib')
276+
.childDirectory('src')
277+
.childDirectory('third_party')
278+
.childFile('first_party.cc');
279+
firstPartyFileInThirdParty.createSync(recursive: true);
280+
_writeLicense(firstPartyFileInThirdParty);
281+
282+
await runner.run(<String>['license-check']);
283+
284+
// Sanity check that the test did actually check the file.
285+
expect(printedMessages,
286+
contains('Checking a_plugin/lib/src/third_party/first_party.cc'));
287+
expect(printedMessages, contains('All source files passed validation!'));
288+
});
289+
272290
test('fails for licenses that the tool does not expect', () async {
273291
final File good = root.childFile('good.cc');
274292
good.createSync();

0 commit comments

Comments
 (0)