forked from flutter/engine
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmain.dart
More file actions
3054 lines (2684 loc) · 108 KB
/
main.dart
File metadata and controls
3054 lines (2684 loc) · 108 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// See README in this directory for information on how this code is organized.
import 'dart:async';
import 'dart:collection';
import 'dart:convert';
import 'dart:io' as system;
import 'dart:math' as math;
import 'package:args/args.dart';
import 'package:collection/collection.dart'
show IterableExtension, IterableNullableExtension;
import 'package:crypto/crypto.dart' as crypto;
import 'package:path/path.dart' as path;
import 'filesystem.dart' as fs;
import 'licenses.dart';
import 'patterns.dart';
// REPOSITORY OBJECTS
abstract class _RepositoryEntry implements Comparable<_RepositoryEntry> {
_RepositoryEntry(this.parent, this.io);
final _RepositoryDirectory? parent;
final fs.IoNode io;
String get name => io.name;
String get libraryName;
@override
int compareTo(_RepositoryEntry other) => toString().compareTo(other.toString());
@override
String toString() => io.fullName;
}
abstract class _RepositoryFile extends _RepositoryEntry {
_RepositoryFile(_RepositoryDirectory parent, fs.File io) : super(parent, io);
Iterable<License>? get licenses;
@override
String get libraryName => parent!.libraryName;
fs.File get ioFile => super.io as fs.File;
}
abstract class _RepositoryLicensedFile extends _RepositoryFile {
_RepositoryLicensedFile(_RepositoryDirectory parent, fs.File io) : super(parent, io);
// file names that we are confident won't be included in the final build product
static final RegExp _readmeNamePattern = RegExp(r'\b_*(?:readme|contributing|patents)_*\b', caseSensitive: false);
static final RegExp _buildTimePattern = RegExp(r'^(?!.*gen$)(?:CMakeLists\.txt|(?:pkgdata)?Makefile(?:\.inc)?(?:\.am|\.in|)|configure(?:\.ac|\.in)?|config\.(?:sub|guess)|.+\.m4|install-sh|.+\.sh|.+\.bat|.+\.pyc?|.+\.pl|icu-configure|.+\.gypi?|.*\.gni?|.+\.mk|.+\.cmake|.+\.gradle|.+\.yaml|pubspec\.lock|\.packages|vms_make\.com|pom\.xml|\.project|source\.properties|.+\.obj|.+\.autopkg|Brewfile)$', caseSensitive: false);
static final RegExp _docsPattern = RegExp(r'^(?:INSTALL|NEWS|OWNERS|AUTHORS|ChangeLog(?:\.rst|\.[0-9]+)?|.+\.txt|.+\.md|.+\.log|.+\.css|.+\.1|doxygen\.config|Doxyfile|.+\.spec(?:\.in)?)$', caseSensitive: false);
static final RegExp _devPattern = RegExp(r'^(?:codereview\.settings|.+\.~|.+\.~[0-9]+~|\.clang-format|swift\.swiftformat|\.gitattributes|\.landmines|\.DS_Store|\.travis\.yml|\.cirrus\.yml|\.cache|\.mailmap|CODEOWNERS|TESTOWNERS)$', caseSensitive: false);
static final RegExp _testsPattern = RegExp(r'^(?:tj(?:bench|example)test\.(?:java\.)?in|example\.c)$', caseSensitive: false);
// The ICU library has sample code that will never get linked.
static final RegExp _icuSamplesPattern = RegExp(r'.*(?:icu\/source\/samples).*$', caseSensitive: false);
bool get isIncludedInBuildProducts {
return !io.name.contains(_readmeNamePattern)
&& !io.name.contains(_buildTimePattern)
&& !io.name.contains(_docsPattern)
&& !io.name.contains(_devPattern)
&& !io.name.contains(_testsPattern)
&& !io.toString().contains(_icuSamplesPattern)
&& !isShellScript;
}
bool get isShellScript => false;
}
class _RepositorySourceFile extends _RepositoryLicensedFile {
_RepositorySourceFile(_RepositoryDirectory parent, fs.TextFile io) : super(parent, io);
fs.TextFile get ioTextFile => super.io as fs.TextFile;
static final RegExp _hashBangPattern = RegExp(r'^#! *(?:/bin/sh|/bin/bash|/usr/bin/env +(?:python[23]?|bash))\b');
@override
bool get isShellScript {
return ioTextFile.readString().startsWith(_hashBangPattern);
}
List<License>? _licenses;
@override
Iterable<License> get licenses {
if (_licenses != null) {
return _licenses!;
}
late String contents;
try {
contents = ioTextFile.readString();
} on FormatException {
print('non-UTF8 data in $io');
system.exit(2);
}
_licenses = determineLicensesFor(contents, name, parent, origin: '$this');
if (_licenses == null || _licenses!.isEmpty) {
_licenses = parent?.nearestLicensesFor(name);
if (_licenses == null || _licenses!.isEmpty) {
throw 'file has no detectable license and no in-scope default license file';
}
}
_licenses!.sort();
for (final License license in _licenses!) {
license.markUsed(io.fullName, libraryName);
}
assert(_licenses != null && _licenses!.isNotEmpty);
return _licenses!;
}
}
class _RepositoryBinaryFile extends _RepositoryLicensedFile {
_RepositoryBinaryFile(_RepositoryDirectory parent, fs.File io) : super(parent, io);
List<License>? _licenses;
@override
List<License>? get licenses {
if (_licenses == null) {
_licenses = parent?.nearestLicensesFor(name);
if (_licenses == null || _licenses!.isEmpty) {
throw 'no license file found in scope for ${io.fullName}';
}
for (final License license in _licenses!) {
license.markUsed(io.fullName, libraryName);
}
}
return _licenses;
}
}
// LICENSES
abstract class _RepositoryLicenseFile extends _RepositoryFile {
_RepositoryLicenseFile(_RepositoryDirectory parent, fs.File io) : super(parent, io);
List<License>? licensesFor(String name);
License? licenseOfType(LicenseType type);
License? licenseWithName(String name);
License? get defaultLicense;
}
abstract class _RepositorySingleLicenseFile extends _RepositoryLicenseFile {
_RepositorySingleLicenseFile(_RepositoryDirectory parent, fs.TextFile io, this.license)
: super(parent, io);
final License license;
@override
List<License>? licensesFor(String name) {
if (license != null) {
return <License>[license];
}
return null;
}
@override
License? licenseWithName(String name) {
if (this.name == name) {
return license;
}
return null;
}
@override
License get defaultLicense => license;
@override
Iterable<License> get licenses sync* { yield license; }
}
class _RepositoryGeneralSingleLicenseFile extends _RepositorySingleLicenseFile {
_RepositoryGeneralSingleLicenseFile(_RepositoryDirectory parent, fs.TextFile io)
: super(parent, io, License.fromBodyAndName(io.readString(), io.name, origin: io.fullName));
@override
License? licenseOfType(LicenseType type) {
if (type == license.type) {
return license;
}
return null;
}
}
class _RepositoryApache4DNoticeFile extends _RepositorySingleLicenseFile {
_RepositoryApache4DNoticeFile(_RepositoryDirectory parent, fs.TextFile io)
: super(parent, io, _parseLicense(io));
@override
License? licenseOfType(LicenseType type) => null;
static final RegExp _pattern = RegExp(
r'^(// ------------------------------------------------------------------\n'
r'// NOTICE file corresponding to the section 4d of The Apache License,\n'
r'// Version 2\.0, in this case for (?:.+)\n'
r'// ------------------------------------------------------------------\n)'
r'((?:.|\n)+)$',
caseSensitive: false
);
static bool consider(fs.TextFile io) {
return io.readString().contains(_pattern);
}
static License _parseLicense(fs.TextFile io) {
final Match match = _pattern.allMatches(io.readString()).single;
assert(match.groupCount == 2);
return License.unique(match.group(2)!, LicenseType.apacheNotice, origin: io.fullName);
}
}
class _RepositoryLicenseRedirectFile extends _RepositorySingleLicenseFile {
_RepositoryLicenseRedirectFile(_RepositoryDirectory parent, fs.TextFile io, License license)
: super(parent, io, license);
@override
License? licenseOfType(LicenseType type) {
if (type == license.type) {
return license;
}
return null;
}
static _RepositoryLicenseRedirectFile? maybeCreateFrom(_RepositoryDirectory parent, fs.TextFile io) {
final String contents = io.readString();
final License? license = interpretAsRedirectLicense(contents, parent, origin: io.fullName);
if (license != null) {
return _RepositoryLicenseRedirectFile(parent, io, license);
}
return null;
}
}
class _RepositoryLicenseFileWithLeader extends _RepositorySingleLicenseFile {
_RepositoryLicenseFileWithLeader(_RepositoryDirectory parent, fs.TextFile io, RegExp leader)
: super(parent, io, _parseLicense(io, leader));
@override
License? licenseOfType(LicenseType type) => null;
static License _parseLicense(fs.TextFile io, RegExp leader) {
final String body = io.readString();
final Match? match = leader.firstMatch(body);
if (match == null) {
throw 'failed to strip leader from $io\nleader: /$leader/\nbody:\n---\n$body\n---';
}
return License.fromBodyAndName(body.substring(match.end), io.name, origin: io.fullName);
}
}
class _RepositoryReadmeIjgFile extends _RepositorySingleLicenseFile {
_RepositoryReadmeIjgFile(_RepositoryDirectory parent, fs.TextFile io)
: super(parent, io, _parseLicense(io));
static final RegExp _pattern = RegExp(
r'Permission is hereby granted to use, copy, modify, and distribute this\n'
r'software \(or portions thereof\) for any purpose, without fee, subject to these\n'
r'conditions:\n'
r'\(1\) If any part of the source code for this software is distributed, then this\n'
r'README file must be included, with this copyright and no-warranty notice\n'
r'unaltered; and any additions, deletions, or changes to the original files\n'
r'must be clearly indicated in accompanying documentation\.\n'
r'\(2\) If only executable code is distributed, then the accompanying\n'
r'documentation must state that "this software is based in part on the work of\n'
r'the Independent JPEG Group"\.\n'
r'\(3\) Permission for use of this software is granted only if the user accepts\n'
r'full responsibility for any undesirable consequences; the authors accept\n'
r'NO LIABILITY for damages of any kind\.\n',
caseSensitive: false
);
static License _parseLicense(fs.TextFile io) {
final String body = io.readString();
if (!body.contains(_pattern)) {
throw 'unexpected contents in IJG README';
}
return License.message(body, LicenseType.ijg, origin: io.fullName);
}
@override
License? licenseWithName(String name) {
if (this.name == name) {
return license;
}
return null;
}
@override
License? licenseOfType(LicenseType type) {
return null;
}
}
class _RepositoryDartLicenseFile extends _RepositorySingleLicenseFile {
_RepositoryDartLicenseFile(_RepositoryDirectory parent, fs.TextFile io)
: super(parent, io, _parseLicense(io));
static final RegExp _pattern = RegExp(
r'(Copyright (?:.|\n)+)$',
caseSensitive: false
);
static License _parseLicense(fs.TextFile io) {
final Match? match = _pattern.firstMatch(io.readString());
if (match == null || match.groupCount != 1) {
throw 'unexpected Dart license file contents';
}
return License.template(match.group(1)!, LicenseType.bsd, origin: io.fullName);
}
@override
License? licenseOfType(LicenseType type) {
return null;
}
}
class _RepositoryLibPngLicenseFile extends _RepositorySingleLicenseFile {
_RepositoryLibPngLicenseFile(_RepositoryDirectory parent, fs.TextFile io)
: super(parent, io, License.blank(io.readString(), LicenseType.libpng, origin: io.fullName)) {
_verifyLicense(io);
}
static void _verifyLicense(fs.TextFile io) {
final String contents = io.readString();
if (!contents.contains(RegExp('COPYRIGHT NOTICE, DISCLAIMER, and LICENSE:?')) ||
!contents.contains('png')) {
throw 'unexpected libpng license file contents:\n----8<----\n$contents\n----<8----';
}
}
@override
License? licenseOfType(LicenseType type) {
if (type == LicenseType.libpng) {
return license;
}
return null;
}
}
class _RepositoryBlankLicenseFile extends _RepositorySingleLicenseFile {
_RepositoryBlankLicenseFile(_RepositoryDirectory parent, fs.TextFile io, String sanityCheck)
: super(parent, io, License.blank(io.readString(), LicenseType.unknown)) {
_verifyLicense(io, sanityCheck);
}
static void _verifyLicense(fs.TextFile io, String sanityCheck) {
final String contents = io.readString();
if (!contents.contains(sanityCheck)) {
throw 'unexpected file contents; wanted "$sanityCheck", but got:\n----8<----\n$contents\n----<8----';
}
}
@override
License? licenseOfType(LicenseType type) => null;
}
class _RepositoryCatapultApiClientLicenseFile extends _RepositorySingleLicenseFile {
_RepositoryCatapultApiClientLicenseFile(_RepositoryDirectory parent, fs.TextFile io)
: super(parent, io, _parseLicense(io));
static final RegExp _pattern = RegExp(
r' *Licensed under the Apache License, Version 2\.0 \(the "License"\);\n'
r' *you may not use this file except in compliance with the License\.\n'
r' *You may obtain a copy of the License at\n'
r' *\n'
r' *(http://www\.apache\.org/licenses/LICENSE-2\.0)\n'
r' *\n'
r' *Unless required by applicable law or agreed to in writing, software\n'
r' *distributed under the License is distributed on an "AS IS" BASIS,\n'
r' *WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied\.\n'
r' *See the License for the specific language governing permissions and\n'
r' *limitations under the License\.\n',
multiLine: true,
caseSensitive: false,
);
static License _parseLicense(fs.TextFile io) {
final Match? match = _pattern.firstMatch(io.readString());
if (match == null || match.groupCount != 1) {
throw 'unexpected apiclient license file contents';
}
return License.fromUrl(match.group(1)!, origin: io.fullName);
}
@override
License? licenseOfType(LicenseType type) {
return null;
}
}
class _RepositoryCatapultCoverageLicenseFile extends _RepositorySingleLicenseFile {
_RepositoryCatapultCoverageLicenseFile(_RepositoryDirectory parent, fs.TextFile io)
: super(parent, io, _parseLicense(io));
static final RegExp _pattern = RegExp(
r' *Except where noted otherwise, this software is licensed under the Apache\n'
r' *License, Version 2.0 \(the "License"\); you may not use this work except in\n'
r' *compliance with the License\. You may obtain a copy of the License at\n'
r' *\n'
r' *(http://www\.apache\.org/licenses/LICENSE-2\.0)\n'
r' *\n'
r' *Unless required by applicable law or agreed to in writing, software\n'
r' *distributed under the License is distributed on an "AS IS" BASIS,\n'
r' *WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied\.\n'
r' *See the License for the specific language governing permissions and\n'
r' *limitations under the License\.\n',
multiLine: true,
caseSensitive: false,
);
static License _parseLicense(fs.TextFile io) {
final Match? match = _pattern.firstMatch(io.readString());
if (match == null || match.groupCount != 1) {
throw 'unexpected coverage license file contents';
}
return License.fromUrl(match.group(1)!, origin: io.fullName);
}
@override
License? licenseOfType(LicenseType type) {
return null;
}
}
class _RepositoryLibJpegTurboLicense extends _RepositoryLicenseFile {
_RepositoryLibJpegTurboLicense(_RepositoryDirectory parent, fs.TextFile io)
: super(parent, io) {
_parseLicense(io);
}
static final RegExp _pattern = RegExp(
r'libjpeg-turbo is covered by three compatible BSD-style open source licenses:\n'
r'\n'
r'- The IJG \(Independent JPEG Group\) License, which is listed in\n'
r' \[README\.ijg\]\(README\.ijg\)\n'
r'\n'
r' This license applies to the libjpeg API library and associated programs\n'
r' \(any code inherited from libjpeg, and any modifications to that code\.\)\n'
r'\n'
r'- The Modified \(3-clause\) BSD License, which is listed in\n'
r' \[turbojpeg\.c\]\(turbojpeg\.c\)\n'
r'\n'
r' This license covers the TurboJPEG API library and associated programs\.\n'
r'\n'
r'- The zlib License, which is listed in \[simd/jsimdext\.inc\]\(simd/jsimdext\.inc\)\n'
r'\n'
r' This license is a subset of the other two, and it covers the libjpeg-turbo\n'
r' SIMD extensions\.\n'
);
static void _parseLicense(fs.TextFile io) {
final String body = io.readString();
if (!body.contains(_pattern)) {
throw 'unexpected contents in libjpeg-turbo LICENSE';
}
}
List<License>? _licenses;
@override
List<License>? get licenses {
if (_licenses == null) {
final _RepositoryReadmeIjgFile readme = parent!.getChildByName('README.ijg') as _RepositoryReadmeIjgFile;
final _RepositorySourceFile main = parent!.getChildByName('turbojpeg.c') as _RepositorySourceFile;
final _RepositoryDirectory simd = parent!.getChildByName('simd') as _RepositoryDirectory;
final _RepositorySourceFile zlib = simd.getChildByName('jsimdext.inc') as _RepositorySourceFile;
_licenses = <License>[];
_licenses!.add(readme.license);
_licenses!.add(main.licenses.single);
_licenses!.add(zlib.licenses.single);
}
return _licenses;
}
@override
License? licenseWithName(String name) {
return null;
}
@override
List<License>? licensesFor(String name) {
return licenses;
}
@override
License? licenseOfType(LicenseType type) {
return null;
}
@override
License? get defaultLicense => null;
}
class _RepositoryFreetypeLicenseFile extends _RepositoryLicenseFile {
_RepositoryFreetypeLicenseFile(_RepositoryDirectory parent, fs.TextFile io)
: _target = _parseLicense(io), super(parent, io);
static final RegExp _pattern = RegExp(
r'FREETYPE LICENSES\n'
r'-----------------\n'
r'\n'
r'The FreeType 2 font engine is copyrighted work and cannot be used\n'
r'legally without a software license\. In order to make this project\n'
r'usable to a vast majority of developers, we distribute it under two\n'
r'mutually exclusive open-source licenses\.\n'
r'\n'
r'This means that \*you\* must choose \*one\* of the two licenses described\n'
r'below, then obey all its terms and conditions when using FreeType 2 in\n'
r'any of your projects or products\.\n'
r'\n'
r' - The FreeType License, found in the file `docs/(FTL\.TXT)`, which is\n'
r' similar to the original BSD license \*with\* an advertising clause\n'
r' that forces you to explicitly cite the FreeType project in your\n'
r" product's documentation\. All details are in the license file\.\n"
r" This license is suited to products which don't use the GNU General\n"
r' Public License\.\n'
r'\n'
r' Note that this license is compatible to the GNU General Public\n'
r' License version 3, but not version 2\.\n'
r'\n'
r' - The GNU General Public License version 2, found in\n'
r' `docs/GPLv2\.TXT` \(any later version can be used also\), for\n'
r' programs which already use the GPL\. Note that the FTL is\n'
r' incompatible with GPLv2 due to its advertisement clause\.\n'
r'\n'
r'The contributed BDF and PCF drivers come with a license similar to\n'
r'that of the X Window System\. It is compatible to the above two\n'
r'licenses \(see files `src/bdf/README` and `src/pcf/README`\)\. The same\n'
r'holds for the source code files `src/base/fthash\.c` and\n'
r'`include/freetype/internal/fthash\.h`; they wer part of the BDF driver\n'
r'in earlier FreeType versions\.\n'
r'\n'
r'The gzip module uses the zlib license \(see `src/gzip/zlib\.h`\) which\n'
r'too is compatible to the above two licenses\.\n'
r'\n'
r'The MD5 checksum support \(only used for debugging in development\n'
r'builds\) is in the public domain\.\n'
r'\n*'
r'--- end of LICENSE\.TXT ---\n*$'
);
static String? _parseLicense(fs.TextFile io) {
final Match? match = _pattern.firstMatch(io.readString());
if (match == null || match.groupCount != 1) {
throw 'unexpected Freetype license file contents';
}
return match.group(1);
}
final String? _target;
List<License>? _targetLicense;
void _warmCache() {
if (parent != null && _targetLicense == null) {
final License? license = parent!.nearestLicenseWithName(_target);
_targetLicense = <License>[license!];
}
}
@override
List<License>? licensesFor(String name) {
_warmCache();
return _targetLicense;
}
@override
License? licenseOfType(LicenseType type) => null;
@override
License? licenseWithName(String name) => null;
@override
License get defaultLicense {
_warmCache();
return _targetLicense!.single;
}
@override
Iterable<License> get licenses sync* { }
}
class _RepositoryIcuLicenseFile extends _RepositoryLicenseFile {
_RepositoryIcuLicenseFile(_RepositoryDirectory parent, fs.TextFile io)
: _licenses = _parseLicense(io),
super(parent, io);
final List<License> _licenses;
static final RegExp _pattern = RegExp(
r'^UNICODE, INC\. LICENSE AGREEMENT - DATA FILES AND SOFTWARE\n+'
r'( *See Terms of Use (?:.|\n)+?)\n+' // 1
r'-+\n'
r'\n'
r'Third-Party Software Licenses\n+'
r' *This section contains third-party software notices and/or additional\n'
r' *terms for licensed third-party software components included within ICU\n'
r' *libraries\.\n+'
r'-+\n'
r'\n'
r' *ICU License - ICU 1\.8\.1 to ICU 57.1[ \n]+?'
r' *COPYRIGHT AND PERMISSION NOTICE\n+'
r'(Copyright (?:.|\n)+?)\n+' // 2
r'-+\n'
r'\n'
r'Chinese/Japanese Word Break Dictionary Data \(cjdict\.txt\)\n+'
r' # The Google Chrome software developed by Google is licensed under\n?'
r' # the BSD license\. Other software included in this distribution is\n?'
r' # provided under other licenses, as set forth below\.\n'
r' #\n'
r'( # The BSD License\n'
r' # http://opensource\.org/licenses/bsd-license\.php\n'
r' # +Copyright(?:.|\n)+?)\n' // 3
r' #\n'
r' #\n'
r' # The word list in cjdict.txt are generated by combining three word lists\n?'
r' # listed below with further processing for compound word breaking\. The\n?'
r' # frequency is generated with an iterative training against Google web\n?'
r' # corpora\.\n'
r' #\n'
r' # \* Libtabe \(Chinese\)\n'
r' # - https://sourceforge\.net/project/\?group_id=1519\n'
r' # - Its license terms and conditions are shown below\.\n'
r' #\n'
r' # \* IPADIC \(Japanese\)\n'
r' # - http://chasen\.aist-nara\.ac\.jp/chasen/distribution\.html\n'
r' # - Its license terms and conditions are shown below\.\n'
r' #\n'
r' # ---------COPYING\.libtabe ---- BEGIN--------------------\n'
r' #\n'
r' # +/\*\n'
r'( # +\* Copyright (?:.|\n)+?)\n' // 4
r' # +\*/\n'
r' #\n'
r' # +/\*\n'
r'( # +\* Copyright (?:.|\n)+?)\n' // 5
r' # +\*/\n'
r' #\n'
r'( # +Copyright (?:.|\n)+?)\n' // 6
r' #\n'
r' # +---------------COPYING\.libtabe-----END--------------------------------\n'
r' #\n'
r' #\n'
r' # +---------------COPYING\.ipadic-----BEGIN-------------------------------\n'
r' #\n'
r'( # +Copyright (?:.|\n)+?)\n' // 7
r' #\n'
r' # +---------------COPYING\.ipadic-----END----------------------------------\n'
r'\n'
r'-+\n'
r'\n'
r' *Lao Word Break Dictionary Data \(laodict\.txt\)\n'
r'\n'
r'( # +Copyright(?:.|\n)+?)\n' // 8
r'\n'
r'-+\n'
r'\n'
r' *Burmese Word Break Dictionary Data \(burmesedict\.txt\)\n'
r'\n'
r'( # +Copyright(?:.|\n)+?)\n' // 9
r'\n'
r'-+\n'
r'\n'
r' *Time Zone Database\n'
r'((?:.|\n)+)\n' // 10
r'\n'
r'-+\n'
r'\n'
r' *Google double-conversion\n'
r'\n'
r'(Copyright(?:.|\n)+)\n' // 11
r'\n'
r'-+\n'
r'\n'
r' *File: aclocal\.m4 \(only for ICU4C\)\n'
r' *Section: pkg\.m4 - Macros to locate and utilise pkg-config\.\n+'
r'(Copyright (?:.|\n)+?)\n' // 12
r'\n'
r'-+\n'
r'\n'
r' *File: config\.guess \(only for ICU4C\)\n+'
r'(This file is free software(?:.|\n)+?)\n' // 13
r'\n'
r'-+\n'
r'\n'
r' *File: install-sh \(only for ICU4C\)\n+'
r'(Copyright(?:.|\n)+?)\n$', // 14
multiLine: true,
caseSensitive: false
);
static final RegExp _unexpectedHash = RegExp(r'^.+ #', multiLine: true);
static final RegExp _newlineHash = RegExp(r' # ?');
static const String gplExceptionExplanation1 =
'As a special exception to the GNU General Public License, if you\n'
'distribute this file as part of a program that contains a\n'
'configuration script generated by Autoconf, you may include it under\n'
'the same distribution terms that you use for the rest of that\n'
'program.\n'
'\n'
'\n'
'(The condition for the exception is fulfilled because\n'
'ICU4C includes a configuration script generated by Autoconf,\n'
'namely the `configure` script.)';
static const String gplExceptionExplanation2 =
'As a special exception to the GNU General Public License, if you\n'
'distribute this file as part of a program that contains a\n'
'configuration script generated by Autoconf, you may include it under\n'
'the same distribution terms that you use for the rest of that\n'
'program. This Exception is an additional permission under section 7\n'
'of the GNU General Public License, version 3 ("GPLv3").\n'
'\n'
'\n'
'(The condition for the exception is fulfilled because\n'
'ICU4C includes a configuration script generated by Autoconf,\n'
'namely the `configure` script.)';
static String _dewrap(String s) {
if (!s.startsWith(' # ')) {
return s;
}
if (s.contains(_unexpectedHash)) {
throw 'ICU license file contained unexpected hash sequence';
}
if (s.contains('\x2028')) {
throw 'ICU license file contained unexpected line separator';
}
return s.replaceAll(_newlineHash, '\x2028').replaceAll('\n', '').replaceAll('\x2028', '\n');
}
static List<License> _parseLicense(fs.TextFile io) {
final Match? match = _pattern.firstMatch(io.readString());
if (match == null) {
throw 'could not parse ICU license file';
}
assert(match.groupCount == 14);
if (match.group(10)!.contains(copyrightMentionPattern) || match.group(11)!.contains('7.')) {
throw 'unexpected copyright in ICU license file';
}
if (!match.group(12)!.contains(gplExceptionExplanation1) || !match.group(13)!.contains(gplExceptionExplanation2)) {
throw 'did not find GPL exception in GPL-licensed files';
}
final List<License> result = <License>[
License.fromBodyAndType(_dewrap(match.group(1)!), LicenseType.unknown, origin: io.fullName),
License.fromBodyAndType(_dewrap(match.group(2)!), LicenseType.icu, origin: io.fullName),
License.fromBodyAndType(_dewrap(match.group(3)!), LicenseType.bsd, origin: io.fullName),
License.fromBodyAndType(_dewrap(match.group(4)!), LicenseType.bsd, origin: io.fullName),
License.fromBodyAndType(_dewrap(match.group(5)!), LicenseType.bsd, origin: io.fullName),
License.fromBodyAndType(_dewrap(match.group(6)!), LicenseType.unknown, origin: io.fullName),
License.fromBodyAndType(_dewrap(match.group(7)!), LicenseType.unknown, origin: io.fullName),
License.fromBodyAndType(_dewrap(match.group(8)!), LicenseType.bsd, origin: io.fullName),
License.fromBodyAndType(_dewrap(match.group(9)!), LicenseType.bsd, origin: io.fullName),
License.fromBodyAndType(_dewrap(match.group(11)!), LicenseType.bsd, origin: io.fullName),
// Matches 12 and 13 are for the GPL3 license. However, they are covered by an exemption
// (they are exempt because ICU4C includes a configuration script generated by Autoconf)
License.fromBodyAndType(_dewrap(match.group(14)!), LicenseType.mit, origin: io.fullName),
];
return result;
}
@override
List<License> licensesFor(String name) {
return _licenses;
}
@override
License licenseOfType(LicenseType type) {
if (type == LicenseType.icu) {
return _licenses[0];
}
throw "tried to use ICU license file to find a license by type but type wasn't ICU";
}
@override
License licenseWithName(String name) {
throw 'tried to use ICU license file to find a license by name';
}
@override
License get defaultLicense => _licenses[0];
@override
Iterable<License> get licenses => _licenses;
}
Iterable<List<int>> splitIntList(List<int> data, int boundary) sync* {
int index = 0;
List<int> getOne() {
final int start = index;
int end = index;
while ((end < data.length) && (data[end] != boundary)) {
end += 1;
}
end += 1;
index = end;
return data.sublist(start, end).toList();
}
while (index < data.length) {
yield getOne();
}
}
class _RepositoryMultiLicenseNoticesForFilesFile extends _RepositoryLicenseFile {
_RepositoryMultiLicenseNoticesForFilesFile(_RepositoryDirectory parent, fs.File io)
: _licenses = _parseLicense(io),
super(parent, io);
final Map<String, License> _licenses;
static Map<String, License> _parseLicense(fs.File io) {
final Map<String, License> result = <String, License>{};
// Files of this type should begin with:
// "Notices for files contained in the"
// ...then have a second line which is 60 "=" characters
final List<List<int>> contents = splitIntList(io.readBytes()!, 0x0A).toList();
if (!ascii.decode(contents[0]).startsWith('Notices for files contained in') ||
ascii.decode(contents[1]) != '============================================================\n') {
throw 'unrecognised syntax: ${io.fullName}';
}
int index = 2;
while (index < contents.length) {
if (ascii.decode(contents[index]) != 'Notices for file(s):\n') {
throw 'unrecognised syntax on line ${index + 1}: ${io.fullName}';
}
index += 1;
final List<String> names = <String>[];
do {
names.add(ascii.decode(contents[index]));
index += 1;
} while (ascii.decode(contents[index]) != '------------------------------------------------------------\n');
index += 1;
final List<List<int>> body = <List<int>>[];
do {
body.add(contents[index]);
index += 1;
} while (index < contents.length &&
ascii.decode(contents[index], allowInvalid: true) != '============================================================\n');
index += 1;
final List<int> bodyBytes = body.expand((List<int> line) => line).toList();
String bodyText;
try {
bodyText = utf8.decode(bodyBytes);
} on FormatException {
bodyText = latin1.decode(bodyBytes);
}
final License license = License.unique(bodyText, LicenseType.unknown, origin: io.fullName);
for (final String name in names) {
if (result[name] != null) {
throw 'conflicting license information for $name in ${io.fullName}';
}
result[name] = license;
}
}
return result;
}
@override
List<License>? licensesFor(String name) {
final License? license = _licenses[name];
if (license != null) {
return <License>[license];
}
return null;
}
@override
License licenseOfType(LicenseType type) {
throw 'tried to use multi-license license file to find a license by type';
}
@override
License licenseWithName(String name) {
throw 'tried to use multi-license license file to find a license by name';
}
@override
License get defaultLicense {
assert(false);
throw '$this ($runtimeType) does not have a concept of a "default" license';
}
@override
Iterable<License> get licenses => _licenses.values;
}
class _RepositoryCxxStlDualLicenseFile extends _RepositoryLicenseFile {
_RepositoryCxxStlDualLicenseFile(_RepositoryDirectory parent, fs.TextFile io)
: _licenses = _parseLicenses(io), super(parent, io);
static final RegExp _pattern = RegExp(
r'==============================================================================\n'
r'.+ License.*\n'
r'==============================================================================\n'
r'\n'
r'The .+ library is dual licensed under both the University of Illinois\n'
r'"BSD-Like" license and the MIT license\. +As a user of this code you may choose\n'
r'to use it under either license\. +As a contributor, you agree to allow your code\n'
r'to be used under both\.\n'
r'\n'
r'Full text of the relevant licenses is included below\.\n'
r'\n'
r'==============================================================================\n'
r'((?:.|\n)+)\n'
r'==============================================================================\n'
r'((?:.|\n)+)'
r'$'
);
static List<License> _parseLicenses(fs.TextFile io) {
final Match? match = _pattern.firstMatch(io.readString());
if (match == null || match.groupCount != 2) {
throw 'unexpected dual license file contents';
}
return <License>[
License.fromBodyAndType(match.group(1)!, LicenseType.bsd),
License.fromBodyAndType(match.group(2)!, LicenseType.mit),
];
}
final List<License> _licenses;
@override
List<License> licensesFor(String name) {
return _licenses;
}
@override
License licenseOfType(LicenseType type) {
throw 'tried to look up a dual-license license by type ("$type")';
}
@override
License licenseWithName(String name) {
throw 'tried to look up a dual-license license by name ("$name")';
}
@override
License get defaultLicense => _licenses[0];
@override
Iterable<License> get licenses => _licenses;
}
// DIRECTORIES
class _RepositoryDirectory extends _RepositoryEntry implements LicenseSource {
_RepositoryDirectory(_RepositoryDirectory? parent, fs.Directory io) : super(parent, io) {
crawl();
}
fs.Directory get ioDirectory => super.io as fs.Directory;
final List<_RepositoryDirectory> _subdirectories = <_RepositoryDirectory>[];
final List<_RepositoryLicensedFile> _files = <_RepositoryLicensedFile>[];
final List<_RepositoryLicenseFile> _licenses = <_RepositoryLicenseFile>[];
List<_RepositoryDirectory> get subdirectories => _subdirectories;
final Map<String, _RepositoryEntry> _childrenByName = <String, _RepositoryEntry>{};
// the bit at the beginning excludes files like "license.py".
static final RegExp _licenseNamePattern = RegExp(r'^(?!.*\.py$)(?!.*(?:no|update)-copyright)(?!.*mh-bsd-gcc).*\b_*(?:license(?!\.html)|copying|copyright|notice|l?gpl|bsd|mpl?|ftl\.txt)_*\b', caseSensitive: false);
void crawl() {
for (final fs.IoNode entry in ioDirectory.walk) {
if (shouldRecurse(entry)) {
assert(!_childrenByName.containsKey(entry.name));
if (entry is fs.Directory) {
final _RepositoryDirectory child = createSubdirectory(entry);
_subdirectories.add(child);
_childrenByName[child.name] = child;
} else if (entry is fs.File) {
try {
final _RepositoryFile child = createFile(entry);
assert(child != null);
if (child is _RepositoryLicensedFile) {
_files.add(child);
} else {
assert(child is _RepositoryLicenseFile);
_licenses.add(child as _RepositoryLicenseFile);
}
_childrenByName[child.name] = child;
} catch (e) {
system.stderr.writeln('failed to handle $entry: $e');
rethrow;
}
} else {
assert(entry is fs.Link);
}
}
}