Adds tool warning log level and command line options to fail on warning/error output (#92031)

This commit is contained in:
Greg Spencer
2021-11-10 16:13:04 -08:00
committed by GitHub
parent 02cfbc320e
commit 52ae102f18
60 changed files with 873 additions and 262 deletions

View File

@@ -170,6 +170,7 @@ Future<void> main(List<String> args) async {
try {
flutterTestArgs.addAll(args);
final Set<String> removeArgs = <String>{};
bool runSmokeTests = true;
for (final String arg in args) {
if (arg.startsWith('--local-engine=')) {
localEngineEnv['FLUTTER_LOCAL_ENGINE'] = arg.substring('--local-engine='.length);
@@ -181,12 +182,18 @@ Future<void> main(List<String> args) async {
_shuffleSeed = arg.substring('--test-randomize-ordering-seed='.length);
removeArgs.add(arg);
}
if (arg == '--no-smoke-tests') {
runSmokeTests = false;
removeArgs.add(arg);
}
}
flutterTestArgs.removeWhere((String arg) => removeArgs.contains(arg));
if (Platform.environment.containsKey(CIRRUS_TASK_NAME))
print('Running task: ${Platform.environment[CIRRUS_TASK_NAME]}');
print('═' * 80);
await _runSmokeTests();
if (runSmokeTests) {
await _runSmokeTests();
}
print('═' * 80);
await selectShard(<String, ShardRunner>{
'add_to_app_life_cycle_tests': _runAddToAppLifeCycleTests,
@@ -474,7 +481,7 @@ Future<void> _runBuildTests() async {
Future<void> _runExampleProjectBuildTests(Directory exampleDirectory, [File? mainFile]) async {
// Only verify caching with flutter gallery.
final bool verifyCaching = exampleDirectory.path.contains('flutter_gallery');
final String examplePath = exampleDirectory.path;
final String examplePath = path.relative(exampleDirectory.path, from: Directory.current.path);
final bool hasNullSafety = File(path.join(examplePath, 'null_safety')).existsSync();
final List<String> additionalArgs = <String>[
if (hasNullSafety) '--no-sound-null-safety',
@@ -786,7 +793,8 @@ Future<void> _runFrameworkTests() async {
await _pubRunTest(path.join(flutterRoot, 'dev', 'bots'));
await _pubRunTest(path.join(flutterRoot, 'dev', 'devicelab'), ensurePrecompiledTool: false); // See https://github.com/flutter/flutter/issues/86209
await _pubRunTest(path.join(flutterRoot, 'dev', 'conductor', 'core'), forceSingleCore: true);
await _runFlutterTest(path.join(flutterRoot, 'dev', 'integration_tests', 'android_semantics_testing'));
// TODO(gspencergoog): Remove the exception for fatalWarnings once https://github.com/flutter/flutter/pull/91127 has landed.
await _runFlutterTest(path.join(flutterRoot, 'dev', 'integration_tests', 'android_semantics_testing'), fatalWarnings: false);
await _runFlutterTest(path.join(flutterRoot, 'dev', 'manual_tests'));
await _runFlutterTest(path.join(flutterRoot, 'dev', 'tools', 'vitool'));
await _runFlutterTest(path.join(flutterRoot, 'dev', 'tools', 'gen_keycodes'));
@@ -1621,6 +1629,7 @@ Future<void> _runFlutterTest(String workingDirectory, {
Map<String, String>? environment,
List<String> tests = const <String>[],
bool shuffleTests = true,
bool fatalWarnings = true,
}) async {
assert(!printOutput || outputChecker == null, 'Output either can be printed or checked but not both');
@@ -1634,6 +1643,7 @@ Future<void> _runFlutterTest(String workingDirectory, {
final List<String> args = <String>[
'test',
if (shuffleTests) '--test-randomize-ordering-seed=$shuffleSeed',
if (fatalWarnings) '--fatal-warnings',
...options,
...tags,
...flutterTestArgs,

View File

@@ -43,15 +43,13 @@ class CodesignCommand extends Command<void> {
}
argParser.addFlag(
kVerify,
help:
'Only verify expected binaries exist and are codesigned with entitlements.',
help: 'Only verify expected binaries exist and are codesigned with entitlements.',
);
argParser.addFlag(
kSignatures,
defaultsTo: true,
help:
'When off, this command will only verify the existence of binaries, and not their\n'
'signatures or entitlements. Must be used with --verify flag.',
help: 'When off, this command will only verify the existence of binaries, and not their\n'
'signatures or entitlements. Must be used with --verify flag.',
);
argParser.addOption(
kUpstream,
@@ -92,24 +90,25 @@ class CodesignCommand extends Command<void> {
Future<void> run() async {
if (!platform.isMacOS) {
throw ConductorException(
'Error! Expected operating system "macos", actual operating system is: '
'"${platform.operatingSystem}"');
'Error! Expected operating system "macos", actual operating system is: '
'"${platform.operatingSystem}"',
);
}
if (argResults!['verify'] as bool != true) {
throw ConductorException(
'Sorry, but codesigning is not implemented yet. Please pass the '
'--$kVerify flag to verify signatures.');
'Sorry, but codesigning is not implemented yet. Please pass the '
'--$kVerify flag to verify signatures.',
);
}
String revision;
if (argResults!.wasParsed(kRevision)) {
stdio.printError(
'Warning! When providing an arbitrary revision, the contents of the cache may not');
stdio.printError(
'match the expected binaries in the conductor tool. It is preferred to check out');
stdio.printError(
'the desired revision and run that version of the conductor.\n');
stdio.printWarning(
'Warning! When providing an arbitrary revision, the contents of the cache may not '
'match the expected binaries in the conductor tool. It is preferred to check out '
'the desired revision and run that version of the conductor.\n',
);
revision = argResults![kRevision] as String;
} else {
revision = ((await processManager.run(
@@ -225,13 +224,11 @@ class CodesignCommand extends Command<void> {
)
.toList();
stdio.printError(
'Expected binaries not found in cache:\n\n${unfoundFiles.join('\n')}\n');
stdio.printError(
'If this commit is removing binaries from the cache, this test should be fixed by');
stdio.printError(
'removing the relevant entry from either the `binariesWithEntitlements` or');
stdio.printError(
'`binariesWithoutEntitlements` getters in dev/tools/lib/codesign.dart.');
'Expected binaries not found in cache:\n\n${unfoundFiles.join('\n')}\n\n'
'If this commit is removing binaries from the cache, this test should be fixed by\n'
'removing the relevant entry from either the "binariesWithEntitlements" or\n'
'"binariesWithoutEntitlements" getters in dev/tools/lib/codesign.dart.',
);
throw ConductorException('Did not find all expected binaries!');
}
@@ -271,9 +268,10 @@ class CodesignCommand extends Command<void> {
if (codeSignResult.exitCode != 0) {
unsignedBinaries.add(binaryPath);
stdio.printError(
'File "$binaryPath" does not appear to be codesigned.\n'
'The `codesign` command failed with exit code ${codeSignResult.exitCode}:\n'
'${codeSignResult.stderr}\n');
'File "$binaryPath" does not appear to be codesigned.\n'
'The `codesign` command failed with exit code ${codeSignResult.exitCode}:\n'
'${codeSignResult.stderr}\n',
);
continue;
}
if (verifyEntitlements) {
@@ -291,42 +289,39 @@ class CodesignCommand extends Command<void> {
}
if (wrongEntitlementBinaries.isNotEmpty) {
stdio.printError(
'Found ${wrongEntitlementBinaries.length} binaries with unexpected entitlements:');
stdio.printError('Found ${wrongEntitlementBinaries.length} binaries with unexpected entitlements:');
wrongEntitlementBinaries.forEach(stdio.printError);
}
if (unexpectedBinaries.isNotEmpty) {
stdio.printError(
'Found ${unexpectedBinaries.length} unexpected binaries in the cache:');
stdio.printError('Found ${unexpectedBinaries.length} unexpected binaries in the cache:');
unexpectedBinaries.forEach(print);
}
// Finally, exit on any invalid state
if (unsignedBinaries.isNotEmpty) {
throw ConductorException(
'Test failed because unsigned binaries detected.');
throw ConductorException('Test failed because unsigned binaries detected.');
}
if (wrongEntitlementBinaries.isNotEmpty) {
throw ConductorException(
'Test failed because files found with the wrong entitlements:\n'
'${wrongEntitlementBinaries.join('\n')}');
'Test failed because files found with the wrong entitlements:\n'
'${wrongEntitlementBinaries.join('\n')}',
);
}
if (unexpectedBinaries.isNotEmpty) {
throw ConductorException(
'Test failed because unexpected binaries found in the cache.');
throw ConductorException('Test failed because unexpected binaries found in the cache.');
}
final String? desiredRevision = argResults![kRevision] as String?;
if (desiredRevision == null) {
stdio.printStatus(
'Verified that binaries are codesigned and have expected entitlements.');
stdio.printStatus('Verified that binaries are codesigned and have expected entitlements.');
} else {
stdio.printStatus(
'Verified that binaries for commit $desiredRevision are codesigned and have '
'expected entitlements.');
'Verified that binaries for commit $desiredRevision are codesigned and have '
'expected entitlements.',
);
}
}
@@ -387,8 +382,9 @@ class CodesignCommand extends Command<void> {
if (entitlementResult.exitCode != 0) {
stdio.printError(
'The `codesign --entitlements` command failed with exit code ${entitlementResult.exitCode}:\n'
'${entitlementResult.stderr}\n');
'The `codesign --entitlements` command failed with exit code ${entitlementResult.exitCode}:\n'
'${entitlementResult.stderr}\n',
);
return false;
}
@@ -399,8 +395,9 @@ class CodesignCommand extends Command<void> {
(await binariesWithEntitlements).contains(binaryPath);
if (output.contains(entitlement) != entitlementExpected) {
stdio.printError(
'File "$binaryPath" ${entitlementExpected ? 'does not have expected' : 'has unexpected'} '
'entitlement $entitlement.');
'File "$binaryPath" ${entitlementExpected ? 'does not have expected' : 'has unexpected'} '
'entitlement $entitlement.',
);
passes = false;
}
}

View File

@@ -9,25 +9,44 @@ import 'package:meta/meta.dart';
abstract class Stdio {
final List<String> logs = <String>[];
/// Error/warning messages printed to STDERR.
/// Error messages printed to STDERR.
///
/// Display an error `message` to the user on stderr. Print errors if the code
/// fails in some way. Errors are typically followed shortly by exiting the
/// app with a non-zero exit status.
@mustCallSuper
void printError(String message) {
logs.add('[error] $message');
}
/// Warning messages printed to STDERR.
///
/// Display a warning `message` to the user on stderr. Print warnings if there
/// is important information to convey to the user that is not fatal.
@mustCallSuper
void printWarning(String message) {
logs.add('[warning] $message');
}
/// Ordinary STDOUT messages.
///
/// Displays normal output on stdout. This should be used for things like
/// progress messages, success messages, or just normal command output.
@mustCallSuper
void printStatus(String message) {
logs.add('[status] $message');
}
/// Debug messages that are only printed in verbose mode.
///
/// Use this for verbose tracing output. Users can turn this output on in order
/// to help diagnose issues.
@mustCallSuper
void printTrace(String message) {
logs.add('[trace] $message');
}
/// Write string to STDOUT without trailing newline.
/// Write the `message` string to STDOUT without a trailing newline.
@mustCallSuper
void write(String message) {
logs.add('[write] $message');

View File

@@ -49,6 +49,7 @@ class TestCommand extends Command<void> {
'task, will write test results to the file.');
argParser.addFlag(
'silent',
help: 'Suppresses standard output and only print standard error output.',
);
}