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

Update third_party license checking #3844

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions script/tool/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
21 changes: 14 additions & 7 deletions script/tool/lib/src/license_check_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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);
}
}
Expand Down
2 changes: 1 addition & 1 deletion script/tool/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
18 changes: 18 additions & 0 deletions script/tool/test/license_check_command_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down