Skip to content

Commit

Permalink
[tools] Don't check license of generated Swift package
Browse files Browse the repository at this point in the history
  • Loading branch information
loic-sharma committed Nov 21, 2024
1 parent 2703b67 commit 5bdf0ff
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 10 deletions.
38 changes: 28 additions & 10 deletions script/tool/lib/src/license_check_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ const Set<String> _ignoredFullBasenameList = <String>{
'resource.h', // Generated by VS.
};

// Path parts to ignore. Used to ignore entire subdirectories.
const Set<String> _ignorePathPartList = <String>{
'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.
Expand Down Expand Up @@ -227,7 +232,7 @@ class LicenseCheckCommand extends PackageCommand {
final List<File> unrecognizedThirdPartyFiles = <File>[];

// 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<String, String> firstPartyLicenseBlockByExtension =
<String, String>{
Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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<String> parts = path.split(file.path);
if (parts.any(_ignorePathPartList.contains)) {
return true;
}

return false;
}

bool _isThirdParty(File file) {
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 @@ -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<String> output =
await runCapturingPrint(runner, <String>['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();
Expand Down

0 comments on commit 5bdf0ff

Please sign in to comment.