@@ -42,6 +42,13 @@ const Set<String> _ignoredFullBasenameList = <String>{
4242 'resource.h' , // Generated by VS.
4343};
4444
45+ // Third-party packages where the code doesn't have file-level annotation, just
46+ // the package-level LICENSE file. Each entry must be a directory relative to
47+ // third_party/packages, as that is the only directory where this is allowed.
48+ const Set <String > _unannotatedFileThirdPartyDirectories = < String > {
49+ 'path_parsing' ,
50+ };
51+
4552// Copyright and license regexes for third-party code.
4653//
4754// These are intentionally very simple, since there is very little third-party
@@ -69,6 +76,16 @@ final List<RegExp> _thirdPartyLicenseBlockRegexes = <RegExp>[
6976 r'// Use of this source code is governed by a BSD-style license that can be\n'
7077 r'// found in the LICENSE file\.\n' ,
7178 ),
79+ // packages/third_party/path_parsing.
80+ RegExp (
81+ r'Copyright \(c\) 2018 Dan Field\n\n'
82+ r'Permission is hereby granted, free of charge, to any person obtaining a copy\n'
83+ r'of this software and associated documentation files \(the "Software"\), to deal\n'
84+ r'in the Software without restriction, including without limitation the rights\n'
85+ r'to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n'
86+ r'copies of the Software, and to permit persons to whom the Software is\n'
87+ r'furnished to do so, subject to the following conditions:' ,
88+ ),
7289];
7390
7491// The exact format of the BSD license that our license files should contain.
@@ -217,10 +234,26 @@ class LicenseCheckCommand extends PackageCommand {
217234
218235 for (final File file in codeFiles) {
219236 print ('Checking ${file .path }' );
237+ // Some third-party directories have code that doesn't annotate each file,
238+ // so for those check the LICENSE file instead. This is done even though
239+ // it's redundant to re-check it for each file because it ensures that we
240+ // are still validating every file individually, rather than having a
241+ // codepath where whole directories of files are ignored, which would have
242+ // a much worse failure mode.
243+ String content;
244+ if (_unannotatedFileThirdPartyDirectories.any (
245+ (String dir) => file.path.contains ('/third_party/packages/$dir /' ))) {
246+ Directory packageDir = file.parent;
247+ while (packageDir.parent.basename != 'packages' ) {
248+ packageDir = packageDir.parent;
249+ }
250+ content = await packageDir.childFile ('LICENSE' ).readAsString ();
251+ } else {
252+ content = await file.readAsString ();
253+ }
220254 // On Windows, git may auto-convert line endings on checkout; this should
221255 // still pass since they will be converted back on commit.
222- final String content =
223- (await file.readAsString ()).replaceAll ('\r\n ' , '\n ' );
256+ content = content.replaceAll ('\r\n ' , '\n ' );
224257
225258 final String firstParyLicense =
226259 firstPartyLicenseBlockByExtension[p.extension (file.path)] ??
0 commit comments