Skip to content

Commit 5bdf0ff

Browse files
committed
[tools] Don't check license of generated Swift package
1 parent 2703b67 commit 5bdf0ff

File tree

2 files changed

+46
-10
lines changed

2 files changed

+46
-10
lines changed

script/tool/lib/src/license_check_command.dart

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ const Set<String> _ignoredFullBasenameList = <String>{
4343
'resource.h', // Generated by VS.
4444
};
4545

46+
// Path parts to ignore. Used to ignore entire subdirectories.
47+
const Set<String> _ignorePathPartList = <String>{
48+
'FlutterGeneratedPluginSwiftPackage', // Generated by Flutter tool.
49+
};
50+
4651
// Third-party packages where the code doesn't have file-level annotation, just
4752
// the package-level LICENSE file. Each entry must be a directory relative to
4853
// third_party/packages, as that is the only directory where this is allowed.
@@ -227,7 +232,7 @@ class LicenseCheckCommand extends PackageCommand {
227232
final List<File> unrecognizedThirdPartyFiles = <File>[];
228233

229234
// Most code file types in the repository use '//' comments.
230-
final String defaultFirstParyLicenseBlock = _generateLicenseBlock('// ');
235+
final String defaultFirstPartyLicenseBlock = _generateLicenseBlock('// ');
231236
// A few file types have a different comment structure.
232237
final Map<String, String> firstPartyLicenseBlockByExtension =
233238
<String, String>{
@@ -258,19 +263,19 @@ class LicenseCheckCommand extends PackageCommand {
258263
// still pass since they will be converted back on commit.
259264
content = content.replaceAll('\r\n', '\n');
260265

261-
final String firstParyLicense =
266+
final String firstPartyLicense =
262267
firstPartyLicenseBlockByExtension[p.extension(file.path)] ??
263-
defaultFirstParyLicenseBlock;
268+
defaultFirstPartyLicenseBlock;
264269
if (_isThirdParty(file)) {
265270
// Third-party directories allow either known third-party licenses, our
266271
// the first-party license, as there may be local additions.
267272
if (!_thirdPartyLicenseBlockRegexes
268273
.any((RegExp regex) => regex.hasMatch(content)) &&
269-
!content.contains(firstParyLicense)) {
274+
!content.contains(firstPartyLicense)) {
270275
unrecognizedThirdPartyFiles.add(file);
271276
}
272277
} else {
273-
if (!content.contains(firstParyLicense)) {
278+
if (!content.contains(firstPartyLicense)) {
274279
incorrectFirstPartyFiles.add(file);
275280
}
276281
}
@@ -305,11 +310,24 @@ class LicenseCheckCommand extends PackageCommand {
305310
}
306311

307312
bool _shouldIgnoreFile(File file) {
308-
final String path = file.path;
309-
return _ignoreBasenameList.contains(p.basenameWithoutExtension(path)) ||
310-
_ignoreSuffixList.any((String suffix) =>
311-
path.endsWith(suffix) ||
312-
_ignoredFullBasenameList.contains(p.basename(path)));
313+
if (_ignoreBasenameList.contains(p.basenameWithoutExtension(file.path))) {
314+
return true;
315+
}
316+
317+
if (_ignoreSuffixList.any(file.path.endsWith)) {
318+
return true;
319+
}
320+
321+
if (_ignoredFullBasenameList.contains(p.basename(file.path))) {
322+
return true;
323+
}
324+
325+
final List<String> parts = path.split(file.path);
326+
if (parts.any(_ignorePathPartList.contains)) {
327+
return true;
328+
}
329+
330+
return false;
313331
}
314332

315333
bool _isThirdParty(File file) {

script/tool/test/license_check_command_test.dart

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,24 @@ void main() {
162162
}
163163
});
164164

165+
test('ignores FlutterGeneratedPluginSwiftPackage', () async {
166+
final Directory packageDir = root
167+
.childDirectory('FlutterGeneratedPluginSwiftPackage')
168+
..createSync();
169+
packageDir.childFile('Package.swift').createSync();
170+
packageDir
171+
.childDirectory('Sources')
172+
.childDirectory('FlutterGeneratedPluginSwiftPackage')
173+
.childFile('FlutterGeneratedPluginSwiftPackage.swift')
174+
.createSync(recursive: true);
175+
176+
final List<String> output =
177+
await runCapturingPrint(runner, <String>['license-check']);
178+
179+
expect(output,
180+
isNot(contains('Checking FlutterGeneratedPluginSwiftPackage')));
181+
});
182+
165183
test('passes if all checked files have license blocks', () async {
166184
final File checked = root.childFile('checked.cc');
167185
checked.createSync();

0 commit comments

Comments
 (0)