Skip to content

Commit

Permalink
[flutter_releases] Flutter Dev 2.2.0-10.1.pre Framework Cherrypicks (#…
Browse files Browse the repository at this point in the history
…80459)

* [flutter_tools] fix null check in crash reporter (#80382)
* roll engine cherrypicks
* Roll engine with dart_style cp

Co-authored-by: Jonah Williams <jonahwilliams@google.com>
  • Loading branch information
christopherfujino and jonahwilliams committed Apr 15, 2021
1 parent e65692c commit 0941968
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 5 deletions.
2 changes: 1 addition & 1 deletion bin/internal/engine.version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
56b13559807bf4cb83d16c659757d6ae4f209490
d2a2e93510ad6cfc3d62a90d903b7056e4da8264
7 changes: 4 additions & 3 deletions packages/flutter_tools/lib/src/base/bot_detector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ class BotDetector {
final PersistentToolState _persistentToolState;

Future<bool> get isRunningOnBot async {
if (_persistentToolState.isRunningOnBot != null) {
return _persistentToolState.isRunningOnBot;
}
if (
// Explicitly stated to not be a bot.
_platform.environment['BOT'] == 'false'
Expand All @@ -45,6 +42,10 @@ class BotDetector {
return _persistentToolState.isRunningOnBot = false;
}

if (_persistentToolState.isRunningOnBot != null) {
return _persistentToolState.isRunningOnBot;
}

return _persistentToolState.isRunningOnBot = _platform.environment['BOT'] == 'true'

// https://docs.travis-ci.com/user/environment-variables/#Default-Environment-Variables
Expand Down
11 changes: 11 additions & 0 deletions packages/flutter_tools/lib/src/commands/update_packages.dart
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,12 @@ class UpdatePackagesCommand extends FlutterCommand {
help: 'Use cached packages instead of accessing the network.',
defaultsTo: false,
negatable: false,
)
..addFlag(
'crash',
help: 'For Flutter CLI testing only, forces this command to throw an unhandled exception.',
defaultsTo: false,
negatable: false,
);
}

Expand Down Expand Up @@ -179,6 +185,11 @@ class UpdatePackagesCommand extends FlutterCommand {
final bool isVerifyOnly = boolArg('verify-only');
final bool isConsumerOnly = boolArg('consumer-only');
final bool offline = boolArg('offline');
final bool crash = boolArg('crash');

if (crash) {
throw StateError('test crash please ignore.');
}

if (upgrade && offline) {
throwToolExit(
Expand Down
2 changes: 1 addition & 1 deletion packages/flutter_tools/lib/src/globals_null_migrated.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import 'ios/plist_parser.dart';

Cache get cache => context.get<Cache>()!;
Config get config => context.get<Config>()!;
HttpClientFactory get httpClientFactory => context.get<HttpClientFactory>()!;
HttpClientFactory? get httpClientFactory => context.get<HttpClientFactory>();
Logger get logger => context.get<Logger>()!;
OperatingSystemUtils get os => context.get<OperatingSystemUtils>()!;
Signals get signals => context.get<Signals>() ?? LocalSignals.instance;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,24 @@ void main() {
expect(persistentToolState.isRunningOnBot, isFalse);
});

testWithoutContext('does not cache BOT environment variable', () async {
fakePlatform.environment['BOT'] = 'true';

final BotDetector botDetector = BotDetector(
platform: fakePlatform,
httpClientFactory: () => FakeHttpClient.any(),
persistentToolState: persistentToolState,
);

expect(await botDetector.isRunningOnBot, isTrue);
expect(persistentToolState.isRunningOnBot, isTrue);

fakePlatform.environment['BOT'] = 'false';

expect(await botDetector.isRunningOnBot, isFalse);
expect(persistentToolState.isRunningOnBot, isFalse);
});

testWithoutContext('returns false unconditionally if FLUTTER_HOST is set', () async {
fakePlatform.environment['FLUTTER_HOST'] = 'foo';
fakePlatform.environment['TRAVIS'] = 'true';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,4 +221,22 @@ void main() {
expect(result.exitCode, isNot(0));
expect(result.stderr, contains('Could not find an option named "release"'));
});

testWithoutContext('flutter can report crashes', () async {
final String flutterBin = fileSystem.path.join(getFlutterRoot(), 'bin', 'flutter');
final ProcessResult result = await processManager.run(<String>[
flutterBin,
...getLocalEngineArguments(),
'update-packages',
'--crash',
], environment: <String, String>{
'BOT': 'false',
});

expect(result.exitCode, isNot(0));
expect(result.stderr, contains(
'Oops; flutter has exited unexpectedly: "Bad state: test crash please ignore.".\n'
'A crash report has been written to',
));
});
}

0 comments on commit 0941968

Please sign in to comment.