Unverified Commit fa65ddf5 authored by Zachary Anderson's avatar Zachary Anderson Committed by GitHub

[flutter_tool] Allow analytics without a terminal attached (#36208)

parent 11660159
...@@ -33,9 +33,6 @@ class BotDetector { ...@@ -33,9 +33,6 @@ class BotDetector {
return platform.environment['BOT'] == 'true' 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 // https://docs.travis-ci.com/user/environment-variables/#Default-Environment-Variables
|| platform.environment['TRAVIS'] == 'true' || platform.environment['TRAVIS'] == 'true'
|| platform.environment['CONTINUOUS_INTEGRATION'] == 'true' || platform.environment['CONTINUOUS_INTEGRATION'] == 'true'
...@@ -48,7 +45,8 @@ class BotDetector { ...@@ -48,7 +45,8 @@ class BotDetector {
|| platform.environment.containsKey('CIRRUS_CI') || platform.environment.containsKey('CIRRUS_CI')
// https://docs.aws.amazon.com/codebuild/latest/userguide/build-env-ref-env-vars.html // https://docs.aws.amazon.com/codebuild/latest/userguide/build-env-ref-env-vars.html
|| (platform.environment.containsKey('AWS_REGION') && platform.environment.containsKey('CODEBUILD_INITIATOR')) || (platform.environment.containsKey('AWS_REGION') &&
platform.environment.containsKey('CODEBUILD_INITIATOR'))
// https://wiki.jenkins.io/display/JENKINS/Building+a+software+project#Buildingasoftwareproject-belowJenkinsSetEnvironmentVariables // https://wiki.jenkins.io/display/JENKINS/Building+a+software+project#Buildingasoftwareproject-belowJenkinsSetEnvironmentVariables
|| platform.environment.containsKey('JENKINS_URL') || platform.environment.containsKey('JENKINS_URL')
......
...@@ -13,6 +13,7 @@ import '../application_package.dart'; ...@@ -13,6 +13,7 @@ import '../application_package.dart';
import '../base/common.dart'; import '../base/common.dart';
import '../base/context.dart'; import '../base/context.dart';
import '../base/file_system.dart'; import '../base/file_system.dart';
import '../base/io.dart' as io;
import '../base/terminal.dart'; import '../base/terminal.dart';
import '../base/time.dart'; import '../base/time.dart';
import '../base/user_messages.dart'; import '../base/user_messages.dart';
...@@ -424,6 +425,7 @@ abstract class FlutterCommand extends Command<void> { ...@@ -424,6 +425,7 @@ abstract class FlutterCommand extends Command<void> {
break; break;
} }
} }
additionalUsageValues[kCommandHasTerminal] = io.stdout.hasTerminal ? 'true' : 'false';
flutterUsage.sendCommand(commandPath, parameters: additionalUsageValues); flutterUsage.sendCommand(commandPath, parameters: additionalUsageValues);
// Send timing. // Send timing.
......
...@@ -49,12 +49,13 @@ const String kCommandBuildBundleTargetPlatform = 'cd24'; ...@@ -49,12 +49,13 @@ const String kCommandBuildBundleTargetPlatform = 'cd24';
const String kCommandBuildBundleIsModule = 'cd25'; const String kCommandBuildBundleIsModule = 'cd25';
const String kCommandResult = 'cd26'; const String kCommandResult = 'cd26';
const String kCommandHasTerminal = 'cd31';
const String reloadExceptionTargetPlatform = 'cd27'; const String reloadExceptionTargetPlatform = 'cd27';
const String reloadExceptionSdkName = 'cd28'; const String reloadExceptionSdkName = 'cd28';
const String reloadExceptionEmulator = 'cd29'; const String reloadExceptionEmulator = 'cd29';
const String reloadExceptionFullRestart = 'cd30'; const String reloadExceptionFullRestart = 'cd30';
// Next ID: cd31 // Next ID: cd32
Usage get flutterUsage => Usage.instance; Usage get flutterUsage => Usage.instance;
......
...@@ -42,11 +42,11 @@ void main() { ...@@ -42,11 +42,11 @@ void main() {
Platform: () => fakePlatform, Platform: () => fakePlatform,
}); });
testUsingContext('returns true for non-interactive terminals', () async { testUsingContext('returns false with and without a terminal attached', () async {
mockStdio.stdout.hasTerminal = true; mockStdio.stdout.hasTerminal = true;
expect(botDetector.isRunningOnBot, isFalse); expect(botDetector.isRunningOnBot, isFalse);
mockStdio.stdout.hasTerminal = false; mockStdio.stdout.hasTerminal = false;
expect(botDetector.isRunningOnBot, isTrue); expect(botDetector.isRunningOnBot, isFalse);
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
Stdio: () => mockStdio, Stdio: () => mockStdio,
Platform: () => fakePlatform, Platform: () => fakePlatform,
......
...@@ -62,11 +62,8 @@ void main() { ...@@ -62,11 +62,8 @@ void main() {
expect( expect(
verify(usage.sendCommand(captureAny, verify(usage.sendCommand(captureAny,
parameters: captureAnyNamed('parameters'))).captured, parameters: captureAnyNamed('parameters'))).captured[1]['cd26'],
<dynamic>[ equals('success'),
'dummy',
const <String, String>{'cd26': 'success'}
],
); );
}, },
overrides: <Type, Generator>{ overrides: <Type, Generator>{
...@@ -87,11 +84,8 @@ void main() { ...@@ -87,11 +84,8 @@ void main() {
expect( expect(
verify(usage.sendCommand(captureAny, verify(usage.sendCommand(captureAny,
parameters: captureAnyNamed('parameters'))).captured, parameters: captureAnyNamed('parameters'))).captured[1]['cd26'],
<dynamic>[ equals('warning'),
'dummy',
const <String, String>{'cd26': 'warning'}
],
); );
}, },
overrides: <Type, Generator>{ overrides: <Type, Generator>{
...@@ -114,11 +108,8 @@ void main() { ...@@ -114,11 +108,8 @@ void main() {
} on ToolExit { } on ToolExit {
expect( expect(
verify(usage.sendCommand(captureAny, verify(usage.sendCommand(captureAny,
parameters: captureAnyNamed('parameters'))).captured, parameters: captureAnyNamed('parameters'))).captured[1]['cd26'],
<dynamic>[ equals('fail'),
'dummy',
const <String, String>{'cd26': 'fail'}
],
); );
} }
}, },
...@@ -144,11 +135,8 @@ void main() { ...@@ -144,11 +135,8 @@ void main() {
} on ToolExit { } on ToolExit {
expect( expect(
verify(usage.sendCommand(captureAny, verify(usage.sendCommand(captureAny,
parameters: captureAnyNamed('parameters'))).captured, parameters: captureAnyNamed('parameters'))).captured[1]['cd26'],
<dynamic>[ equals('fail'),
'dummy',
const <String, String>{'cd26': 'fail'}
],
); );
} }
}, },
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment