Update platform shims in dev/manual_tests (#94616)
Updates the platform shims in dev/manual_tests so that Windows and Linux can be built. I had to update the Windows shims, because I was unable to build a Windows app there. Also updates the analyze.dart script to report all license issues simultaneously instead of just dying after the first failure. The only substantive code changes are in dev/bots/analyze.dart and dev/bots/test/analyze_test.dart
This commit is contained in:
@@ -406,42 +406,62 @@ String _generateLicense(String prefix) {
|
||||
|
||||
Future<void> verifyNoMissingLicense(String workingDirectory, { bool checkMinimums = true }) async {
|
||||
final int? overrideMinimumMatches = checkMinimums ? null : 0;
|
||||
await _verifyNoMissingLicenseForExtension(workingDirectory, 'dart', overrideMinimumMatches ?? 2000, _generateLicense('// '));
|
||||
await _verifyNoMissingLicenseForExtension(workingDirectory, 'java', overrideMinimumMatches ?? 39, _generateLicense('// '));
|
||||
await _verifyNoMissingLicenseForExtension(workingDirectory, 'h', overrideMinimumMatches ?? 30, _generateLicense('// '));
|
||||
await _verifyNoMissingLicenseForExtension(workingDirectory, 'm', overrideMinimumMatches ?? 30, _generateLicense('// '));
|
||||
await _verifyNoMissingLicenseForExtension(workingDirectory, 'swift', overrideMinimumMatches ?? 10, _generateLicense('// '));
|
||||
await _verifyNoMissingLicenseForExtension(workingDirectory, 'gradle', overrideMinimumMatches ?? 80, _generateLicense('// '));
|
||||
await _verifyNoMissingLicenseForExtension(workingDirectory, 'gn', overrideMinimumMatches ?? 0, _generateLicense('# '));
|
||||
await _verifyNoMissingLicenseForExtension(workingDirectory, 'sh', overrideMinimumMatches ?? 1, '#!/usr/bin/env bash\n${_generateLicense('# ')}');
|
||||
await _verifyNoMissingLicenseForExtension(workingDirectory, 'bat', overrideMinimumMatches ?? 1, '@ECHO off\n${_generateLicense('REM ')}');
|
||||
await _verifyNoMissingLicenseForExtension(workingDirectory, 'ps1', overrideMinimumMatches ?? 1, _generateLicense('# '));
|
||||
await _verifyNoMissingLicenseForExtension(workingDirectory, 'html', overrideMinimumMatches ?? 1, '<!DOCTYPE HTML>\n<!-- ${_generateLicense('')} -->', trailingBlank: false);
|
||||
await _verifyNoMissingLicenseForExtension(workingDirectory, 'xml', overrideMinimumMatches ?? 1, '<!-- ${_generateLicense('')} -->');
|
||||
int failed = 0;
|
||||
failed += await _verifyNoMissingLicenseForExtension(workingDirectory, 'dart', overrideMinimumMatches ?? 2000, _generateLicense('// '));
|
||||
failed += await _verifyNoMissingLicenseForExtension(workingDirectory, 'java', overrideMinimumMatches ?? 39, _generateLicense('// '));
|
||||
failed += await _verifyNoMissingLicenseForExtension(workingDirectory, 'h', overrideMinimumMatches ?? 30, _generateLicense('// '));
|
||||
failed += await _verifyNoMissingLicenseForExtension(workingDirectory, 'm', overrideMinimumMatches ?? 30, _generateLicense('// '));
|
||||
failed += await _verifyNoMissingLicenseForExtension(workingDirectory, 'swift', overrideMinimumMatches ?? 10, _generateLicense('// '));
|
||||
failed += await _verifyNoMissingLicenseForExtension(workingDirectory, 'gradle', overrideMinimumMatches ?? 80, _generateLicense('// '));
|
||||
failed += await _verifyNoMissingLicenseForExtension(workingDirectory, 'gn', overrideMinimumMatches ?? 0, _generateLicense('# '));
|
||||
failed += await _verifyNoMissingLicenseForExtension(workingDirectory, 'sh', overrideMinimumMatches ?? 1, _generateLicense('# '), header: r'#!/usr/bin/env bash\n',);
|
||||
failed += await _verifyNoMissingLicenseForExtension(workingDirectory, 'bat', overrideMinimumMatches ?? 1, _generateLicense('REM '), header: r'@ECHO off\n');
|
||||
failed += await _verifyNoMissingLicenseForExtension(workingDirectory, 'ps1', overrideMinimumMatches ?? 1, _generateLicense('# '));
|
||||
failed += await _verifyNoMissingLicenseForExtension(workingDirectory, 'html', overrideMinimumMatches ?? 1, '<!-- ${_generateLicense('')} -->', trailingBlank: false, header: r'<!DOCTYPE HTML>\n');
|
||||
failed += await _verifyNoMissingLicenseForExtension(workingDirectory, 'xml', overrideMinimumMatches ?? 1, '<!-- ${_generateLicense('')} -->', header: r'(<\?xml version="1.0" encoding="utf-8"\?>\n)?');
|
||||
if (failed > 0) {
|
||||
exitWithError(<String>['License check failed.']);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _verifyNoMissingLicenseForExtension(String workingDirectory, String extension, int minimumMatches, String license, { bool trailingBlank = true }) async {
|
||||
Future<int> _verifyNoMissingLicenseForExtension(
|
||||
String workingDirectory,
|
||||
String extension,
|
||||
int minimumMatches,
|
||||
String license, {
|
||||
bool trailingBlank = true,
|
||||
// The "header" is a regular expression matching the header that comes before
|
||||
// the license in some files.
|
||||
String header = '',
|
||||
}) async {
|
||||
assert(!license.endsWith('\n'));
|
||||
final String licensePattern = '$license\n${trailingBlank ? '\n' : ''}';
|
||||
final String licensePattern = RegExp.escape('$license\n${trailingBlank ? '\n' : ''}');
|
||||
final List<String> errors = <String>[];
|
||||
await for (final File file in _allFiles(workingDirectory, extension, minimumMatches: minimumMatches)) {
|
||||
final String contents = file.readAsStringSync().replaceAll('\r\n', '\n');
|
||||
if (contents.isEmpty)
|
||||
continue; // let's not go down the /bin/true rabbit hole
|
||||
if (!contents.startsWith(licensePattern))
|
||||
if (!contents.startsWith(RegExp(header + licensePattern)))
|
||||
errors.add(file.path);
|
||||
}
|
||||
// Fail if any errors
|
||||
if (errors.isNotEmpty) {
|
||||
final String s = errors.length == 1 ? ' does' : 's do';
|
||||
exitWithError(<String>[
|
||||
'${bold}The following ${errors.length} file$s not have the right license header:$reset',
|
||||
...errors,
|
||||
final String redLine = '$red━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━$reset';
|
||||
final String fileDoes = errors.length == 1 ? 'file does' : '${errors.length} files do';
|
||||
print(<String>[
|
||||
redLine,
|
||||
'${bold}The following $fileDoes not have the right license header for $extension files:$reset',
|
||||
...errors.map<String>((String error) => ' $error'),
|
||||
'The expected license header is:',
|
||||
if (header.isNotEmpty) 'A header matching the regular expression "$header",',
|
||||
if (header.isNotEmpty) 'followed by the following license text:',
|
||||
license,
|
||||
if (trailingBlank) '...followed by a blank line.',
|
||||
]);
|
||||
redLine,
|
||||
].join('\n'));
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
class _TestSkip {
|
||||
|
||||
@@ -120,18 +120,21 @@ void main() {
|
||||
|
||||
test('analyze.dart - verifyNoMissingLicense', () async {
|
||||
final String result = await capture(() => verifyNoMissingLicense(testRootPath, checkMinimums: false), exitCode: 1);
|
||||
final String lines = 'test/analyze-test-input/root/packages/foo/foo.dart'
|
||||
final String file = 'test/analyze-test-input/root/packages/foo/foo.dart'
|
||||
.replaceAll('/', Platform.isWindows ? r'\' : '/');
|
||||
expect(result,
|
||||
'━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n'
|
||||
'The following 1 file does not have the right license header:\n'
|
||||
'$lines\n'
|
||||
'The following file does not have the right license header for dart files:\n'
|
||||
' $file\n'
|
||||
'The expected license header is:\n'
|
||||
'// Copyright 2014 The Flutter Authors. All rights reserved.\n'
|
||||
'// Use of this source code is governed by a BSD-style license that can be\n'
|
||||
'// found in the LICENSE file.\n'
|
||||
'...followed by a blank line.\n'
|
||||
'━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n'
|
||||
'━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n'
|
||||
'License check failed.\n'
|
||||
'━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n'
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user