Consider all non-interactive terminals to be bots (#34179)

This commit is contained in:
Todd Volkert
2019-06-10 16:32:08 -07:00
committed by GitHub
parent 0bbac72558
commit 1b3fc53595
4 changed files with 120 additions and 11 deletions

View File

@@ -26,7 +26,7 @@
/// increase the API surface that we have to test in Flutter tools, and the APIs
/// in `dart:io` can sometimes be hard to use in tests.
import 'dart:async';
import 'dart:io' as io show exit, IOSink, ProcessSignal, stderr, stdin, stdout;
import 'dart:io' as io show exit, IOSink, ProcessSignal, stderr, stdin, Stdout, stdout;
import 'package:meta/meta.dart';
@@ -72,6 +72,7 @@ export 'dart:io'
Stdin,
StdinException,
// stdout, NO! Use `io.dart`
Stdout,
Socket,
SocketException,
systemEncoding,
@@ -156,7 +157,7 @@ class Stdio {
const Stdio();
Stream<List<int>> get stdin => io.stdin;
io.IOSink get stdout => io.stdout;
io.Stdout get stdout => io.stdout;
io.IOSink get stderr => io.stderr;
bool get hasTerminal => io.stdout.hasTerminal;
@@ -165,7 +166,7 @@ class Stdio {
bool get supportsAnsiEscapes => hasTerminal ? io.stdout.supportsAnsiEscapes : false;
}
Stdio get stdio => context.get<Stdio>();
io.IOSink get stdout => stdio.stdout;
Stdio get stdio => context.get<Stdio>() ?? const Stdio();
io.Stdout get stdout => stdio.stdout;
Stream<List<int>> get stdin => stdio.stdin;
io.IOSink get stderr => stdio.stderr;

View File

@@ -21,8 +21,20 @@ class BotDetector {
const BotDetector();
bool get isRunningOnBot {
return platform.environment['BOT'] != 'false'
&& (platform.environment['BOT'] == 'true'
if (
// Explicitly stated to not be a bot.
platform.environment['BOT'] == 'false'
// Set by the IDEs to the IDE name, so a strong signal that this is not a bot.
|| platform.environment.containsKey('FLUTTER_HOST')
) {
return false;
}
return platform.environment['BOT'] == 'true'
// Non-interactive terminals are assumed to be bots.
|| !io.stdout.hasTerminal
// https://docs.travis-ci.com/user/environment-variables/#Default-Environment-Variables
|| platform.environment['TRAVIS'] == 'true'
@@ -43,7 +55,8 @@ class BotDetector {
// Properties on Flutter's Chrome Infra bots.
|| platform.environment['CHROME_HEADLESS'] == '1'
|| platform.environment.containsKey('BUILDBOT_BUILDERNAME'));
|| platform.environment.containsKey('BUILDBOT_BUILDERNAME')
|| platform.environment.containsKey('SWARMING_TASK_ID');
}
}