If the machine is a bot such as a CI machine, prevent the 'The Dart tool uses Google Analytics to anonymously report feature usage...' message from being printed from dartdev.

Bug: https://github.com/dart-lang/sdk/issues/43046
Change-Id: I63c1d73bfd31af14e0a93669a43994222e2f3a50
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/158920
Reviewed-by: Jonas Jensen <jonasfj@google.com>
Commit-Queue: Jaime Wren <jwren@google.com>
This commit is contained in:
Jaime Wren 2020-08-18 17:04:40 +00:00 committed by commit-bot@chromium.org
parent 96ed2afae6
commit 90756064f9
2 changed files with 9 additions and 4 deletions

View file

@ -48,11 +48,12 @@ Future<void> runDartdev(List<String> args, SendPort port) async {
createAnalyticsInstance(args.contains('--disable-dartdev-analytics'));
// If we have not printed the analyticsNoticeOnFirstRunMessage to stdout,
// and the user is on a terminal, then print the disclosure and set
// analytics.disclosureShownOnTerminal.
// the user is on a terminal, and the machine is not a bot, then print the
// disclosure and set analytics.disclosureShownOnTerminal to true.
if (analytics is DartdevAnalytics &&
!analytics.disclosureShownOnTerminal &&
io.stdout.hasTerminal) {
io.stdout.hasTerminal &&
!isBot()) {
print(analyticsNoticeOnFirstRunMessage);
analytics.disclosureShownOnTerminal = true;
}

View file

@ -138,6 +138,10 @@ Directory getDartStorageDirectory() {
return Directory(path.join(homeDir.path, _dartDirectoryName));
}
/// The method used by dartdev to determine if this machine is a bot such as a
/// CI machine.
bool isBot() => telemetry.isRunningOnBot();
class DartdevAnalytics extends AnalyticsImpl {
DartdevAnalytics(String trackingId, File settingsFile, String appName)
: super(
@ -152,7 +156,7 @@ class DartdevAnalytics extends AnalyticsImpl {
bool get enabled {
// Don't enable if the user hasn't been shown the disclosure or if this
// machine is bot.
if (!disclosureShownOnTerminal || telemetry.isRunningOnBot()) {
if (!disclosureShownOnTerminal || isBot()) {
return false;
}