diff --git a/script/tool/lib/src/license_check_command.dart b/script/tool/lib/src/license_check_command.dart index 223735ccbc09..7112a36e1cd3 100644 --- a/script/tool/lib/src/license_check_command.dart +++ b/script/tool/lib/src/license_check_command.dart @@ -43,6 +43,11 @@ const Set _ignoredFullBasenameList = { 'resource.h', // Generated by VS. }; +// Path parts to ignore. Used to ignore entire subdirectories. +const Set _ignorePathPartList = { + 'FlutterGeneratedPluginSwiftPackage', // Generated by Flutter tool. +}; + // Third-party packages where the code doesn't have file-level annotation, just // the package-level LICENSE file. Each entry must be a directory relative to // third_party/packages, as that is the only directory where this is allowed. @@ -227,7 +232,7 @@ class LicenseCheckCommand extends PackageCommand { final List unrecognizedThirdPartyFiles = []; // Most code file types in the repository use '//' comments. - final String defaultFirstParyLicenseBlock = _generateLicenseBlock('// '); + final String defaultFirstPartyLicenseBlock = _generateLicenseBlock('// '); // A few file types have a different comment structure. final Map firstPartyLicenseBlockByExtension = { @@ -258,19 +263,19 @@ class LicenseCheckCommand extends PackageCommand { // still pass since they will be converted back on commit. content = content.replaceAll('\r\n', '\n'); - final String firstParyLicense = + final String firstPartyLicense = firstPartyLicenseBlockByExtension[p.extension(file.path)] ?? - defaultFirstParyLicenseBlock; + defaultFirstPartyLicenseBlock; 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)) && - !content.contains(firstParyLicense)) { + !content.contains(firstPartyLicense)) { unrecognizedThirdPartyFiles.add(file); } } else { - if (!content.contains(firstParyLicense)) { + if (!content.contains(firstPartyLicense)) { incorrectFirstPartyFiles.add(file); } } @@ -305,11 +310,24 @@ class LicenseCheckCommand extends PackageCommand { } bool _shouldIgnoreFile(File file) { - final String path = file.path; - return _ignoreBasenameList.contains(p.basenameWithoutExtension(path)) || - _ignoreSuffixList.any((String suffix) => - path.endsWith(suffix) || - _ignoredFullBasenameList.contains(p.basename(path))); + if (_ignoreBasenameList.contains(p.basenameWithoutExtension(file.path))) { + return true; + } + + if (_ignoreSuffixList.any(file.path.endsWith)) { + return true; + } + + if (_ignoredFullBasenameList.contains(p.basename(file.path))) { + return true; + } + + final List parts = path.split(file.path); + if (parts.any(_ignorePathPartList.contains)) { + return true; + } + + return false; } bool _isThirdParty(File file) { diff --git a/script/tool/test/license_check_command_test.dart b/script/tool/test/license_check_command_test.dart index aee3b3a1959c..0ad40e175e49 100644 --- a/script/tool/test/license_check_command_test.dart +++ b/script/tool/test/license_check_command_test.dart @@ -162,6 +162,24 @@ void main() { } }); + test('ignores FlutterGeneratedPluginSwiftPackage', () async { + final Directory packageDir = root + .childDirectory('FlutterGeneratedPluginSwiftPackage') + ..createSync(); + packageDir.childFile('Package.swift').createSync(); + packageDir + .childDirectory('Sources') + .childDirectory('FlutterGeneratedPluginSwiftPackage') + .childFile('FlutterGeneratedPluginSwiftPackage.swift') + .createSync(recursive: true); + + final List output = + await runCapturingPrint(runner, ['license-check']); + + expect(output, + isNot(contains('Checking FlutterGeneratedPluginSwiftPackage'))); + }); + test('passes if all checked files have license blocks', () async { final File checked = root.childFile('checked.cc'); checked.createSync();