未验证 提交 03a4e53a 编写于 作者: M Michael Goderbauer 提交者: GitHub

Update license script & analyze it on CI (#5917)

上级 9f9a564e
......@@ -2,9 +2,9 @@
analyzer:
language:
enableStrictCallChecks: true
enableSuperMixins: true
strong-mode: true
strong-mode:
implicit-dynamic: false
errors:
strong_mode_invalid_field_override: ignore
strong_mode_down_cast_composite: ignore
......@@ -19,7 +19,7 @@ linter:
- control_flow_in_finally
- empty_statements
- hash_and_equals
- invariant_booleans
# - invariant_booleans # Produces false positives, see https://github.com/flutter/flutter/issues/5790
- iterable_contains_unrelated_type
- list_remove_unrelated_type
- literal_only_boolean_expressions
......@@ -53,6 +53,6 @@ linter:
- type_annotate_public_apis
- type_init_formals
- unawaited_futures
- unnecessary_brace_in_string_interp
- unnecessary_brace_in_string_interps
- unnecessary_getters_setters
- package_names
......@@ -59,7 +59,7 @@ const String kMultiLicenseFileHeader = 'Notices for files contained in';
bool isMultiLicenseNotice(Reader reader) {
List<int> bytes = reader();
return (ASCII.decode(bytes.take(kMultiLicenseFileHeader.length).toList(), allowInvalid: true) == kMultiLicenseFileHeader);
return (ascii.decode(bytes.take(kMultiLicenseFileHeader.length).toList(), allowInvalid: true) == kMultiLicenseFileHeader);
}
FileType identifyFile(String name, Reader reader) {
......@@ -314,7 +314,7 @@ abstract class UTF8TextFile extends TextFile {
@override
String readString() {
try {
return cache(new UTF8Of(this), () => UTF8.decode(readBytes()));
return cache(new UTF8Of(this), () => utf8.decode(readBytes()));
} on FormatException {
print(fullName);
rethrow;
......@@ -332,13 +332,13 @@ abstract class Latin1TextFile extends TextFile {
throw '$fullName contains a U+0000 NULL and is probably not actually encoded as Win1252';
bool isUTF8 = false;
try {
cache(new UTF8Of(this), () => UTF8.decode(readBytes()));
cache(new UTF8Of(this), () => utf8.decode(readBytes()));
isUTF8 = true;
} on FormatException {
}
if (isUTF8)
throw '$fullName contains valid UTF-8 and is probably not actually encoded as Win1252';
return LATIN1.decode(bytes);
return latin1.decode(bytes);
});
}
}
......
......@@ -325,19 +325,19 @@ abstract class License implements Comparable<License> {
bool isUTF8 = true;
List<int> latin1Encoded;
try {
latin1Encoded = LATIN1.encode(body);
latin1Encoded = latin1.encode(body);
isUTF8 = false;
} on ArgumentError { }
if (!isUTF8) {
bool isAscii = false;
try {
ASCII.decode(latin1Encoded);
ascii.decode(latin1Encoded);
isAscii = true;
} on FormatException { }
if (isAscii)
return;
try {
UTF8.decode(latin1Encoded);
utf8.decode(latin1Encoded);
isUTF8 = true;
} on FormatException { }
if (isUTF8)
......@@ -530,7 +530,7 @@ _SplitLicense _splitLicense(String body, { bool verifyResults: true }) {
if (!lines.moveNext())
throw 'tried to split empty license';
int end = 0;
while (true) {
while (true) { // ignore: literal_only_boolean_expressions
final String line = lines.current.value;
if (line == 'Author:' ||
line == 'This code is derived from software contributed to Berkeley by' ||
......
......@@ -736,33 +736,33 @@ class RepositoryMultiLicenseNoticesForFilesFile extends RepositoryLicenseFile {
// "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')
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')
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]));
names.add(ascii.decode(contents[index]));
index += 1;
} while (ASCII.decode(contents[index]) != '------------------------------------------------------------\n');
} 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');
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);
bodyText = utf8.decode(bodyBytes);
} on FormatException {
bodyText = LATIN1.decode(bodyBytes);
bodyText = latin1.decode(bodyBytes);
}
License license = new License.unique(bodyText, LicenseType.unknown, origin: io.fullName);
for (String name in names) {
......@@ -2545,7 +2545,7 @@ Future<Null> main(List<String> arguments) async {
system.File goldenFile = new system.File(
path.join(argResults['golden'], 'licenses_${component.io.name}'));
String goldenSignature = await goldenFile.openRead()
.transform(UTF8.decoder).transform(new LineSplitter()).first;
.transform(utf8.decoder).transform(new LineSplitter()).first;
Match goldenMatch = signaturePattern.matchAsPrefix(goldenSignature);
if (goldenMatch != null && goldenMatch.group(1) == signature) {
system.stderr.writeln(' Skipping this component - no change in signature');
......
......@@ -46,3 +46,18 @@ if [ -n "$RESULTS" ]; then
echo "Failed."
exit 1;
fi
echo "Analyzing tools/licenses..."
(cd flutter/tools/licenses && pub get)
RESULTS=`dartanalyzer \
--packages=flutter/tools/licenses/.packages \
--options flutter/tools/licenses/analysis_options.yaml \
flutter/tools/licenses \
2>&1 \
| grep -Ev "No issues found!" \
| grep -Ev "Analyzing.+tools/licenses"`
echo "$RESULTS"
if [ -n "$RESULTS" ]; then
echo "Failed."
exit 1;
fi
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册