diff --git a/script/tool/CHANGELOG.md b/script/tool/CHANGELOG.md index 0411a9e53a..3a9736c35b 100644 --- a/script/tool/CHANGELOG.md +++ b/script/tool/CHANGELOG.md @@ -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. diff --git a/script/tool/lib/src/license_check_command.dart b/script/tool/lib/src/license_check_command.dart index adb2f93152..a6528640b8 100644 --- a/script/tool/lib/src/license_check_command.dart +++ b/script/tool/lib/src/license_check_command.dart @@ -52,10 +52,14 @@ const Set _ignoredFullBasenameList = { final List _thirdPartyLicenseBlockRegexes = [ // 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); } } diff --git a/script/tool/pubspec.yaml b/script/tool/pubspec.yaml index 18631fef02..58dfc9fbd8 100644 --- a/script/tool/pubspec.yaml +++ b/script/tool/pubspec.yaml @@ -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" diff --git a/script/tool/test/license_check_command_test.dart b/script/tool/test/license_check_command_test.dart index 94606f54b7..23de2581b9 100644 --- a/script/tool/test/license_check_command_test.dart +++ b/script/tool/test/license_check_command_test.dart @@ -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(['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();