|
5 | 5 | import 'dart:io'; |
6 | 6 |
|
7 | 7 | import 'package:path/path.dart' as path; |
8 | | -import 'package:telemetry/telemetry.dart' as telemetry show isRunningOnBot; |
9 | 8 | import 'package:unified_analytics/unified_analytics.dart'; |
10 | 9 |
|
11 | 10 | import 'sdk.dart'; |
12 | 11 |
|
13 | 12 | const String _dartDirectoryName = '.dart'; |
14 | 13 |
|
15 | | -const String analyticsDisabledNoticeMessage = |
16 | | - 'Analytics reporting disabled. In order to enable it, run: dart --enable-analytics'; |
| 14 | +const String analyticsDisabledNoticeMessage = 'Analytics reporting disabled. ' |
| 15 | + 'In order to enable it, run: dart --enable-analytics'; |
17 | 16 |
|
18 | 17 | /// Create the `Analytics` instance to be used to report analytics. |
19 | 18 | Analytics createUnifiedAnalytics({bool disableAnalytics = false}) { |
@@ -56,7 +55,7 @@ Directory? getDartStorageDirectory() { |
56 | 55 |
|
57 | 56 | /// The method used by dartdev to determine if this machine is a bot such as a |
58 | 57 | /// CI machine. |
59 | | -bool isBot() => telemetry.isRunningOnBot(); |
| 58 | +bool isBot() => _isRunningOnBot(); |
60 | 59 |
|
61 | 60 | // Matches file:/, non-ws, /, non-ws, .dart |
62 | 61 | final RegExp _pathRegex = RegExp(r'file:/\S+/(\S+\.dart)'); |
@@ -91,3 +90,70 @@ String sanitizeStacktrace(dynamic st, {bool shorten = true}) { |
91 | 90 |
|
92 | 91 | return str; |
93 | 92 | } |
| 93 | + |
| 94 | +/// Detect whether we're running on a bot / a continuous testing environment. |
| 95 | +/// |
| 96 | +/// We should periodically keep this code up to date with: |
| 97 | +/// https://github.com/flutter/flutter/blob/master/packages/flutter_tools/lib/src/base/bot_detector.dart#L30 |
| 98 | +/// and |
| 99 | +/// https://github.com/flutter/flutter/blob/master/packages/flutter_tools/lib/src/reporting/usage.dart#L200. |
| 100 | +bool _isRunningOnBot() { |
| 101 | + final Map<String, String> env = Platform.environment; |
| 102 | + |
| 103 | + if ( |
| 104 | + // Explicitly stated to not be a bot. |
| 105 | + env['BOT'] == 'false' |
| 106 | + // Set by the IDEs to the IDE name, so a strong signal that this is |
| 107 | + // not a bot. |
| 108 | + || |
| 109 | + env.containsKey('FLUTTER_HOST') |
| 110 | + // When set, GA logs to a local file (normally for tests) so we don't |
| 111 | + // need to filter. |
| 112 | + || |
| 113 | + env.containsKey('FLUTTER_ANALYTICS_LOG_FILE')) { |
| 114 | + return false; |
| 115 | + } |
| 116 | + |
| 117 | + // TODO(jwren): Azure detection -- each call for this detection requires an |
| 118 | + // http connection, the flutter cli tool captures the result on the first run, |
| 119 | + // we should consider the same caching here. |
| 120 | + |
| 121 | + return env.containsKey('BOT') |
| 122 | + // https://docs.travis-ci.com/user/environment-variables/ |
| 123 | + // Example .travis.yml file: |
| 124 | + // https://github.com/flutter/devtools/blob/master/.travis.yml |
| 125 | + || |
| 126 | + env['TRAVIS'] == 'true' || |
| 127 | + env['CONTINUOUS_INTEGRATION'] == 'true' || |
| 128 | + env.containsKey('CI') // Travis and AppVeyor |
| 129 | + |
| 130 | + // https://www.appveyor.com/docs/environment-variables/ |
| 131 | + || |
| 132 | + env.containsKey('APPVEYOR') |
| 133 | + |
| 134 | + // https://cirrus-ci.org/guide/writing-tasks/#environment-variables |
| 135 | + || |
| 136 | + env.containsKey('CIRRUS_CI') |
| 137 | + |
| 138 | + // https://docs.aws.amazon.com/codebuild/latest/userguide/build-env-ref-env-vars.html |
| 139 | + || |
| 140 | + (env.containsKey('AWS_REGION') && env.containsKey('CODEBUILD_INITIATOR')) |
| 141 | + |
| 142 | + // https://wiki.jenkins.io/display/JENKINS/Building+a+software+project#Buildingasoftwareproject-belowJenkinsSetEnvironmentVariables |
| 143 | + || |
| 144 | + env.containsKey('JENKINS_URL') |
| 145 | + |
| 146 | + // https://help.github.com/en/actions/configuring-and-managing-workflows/using-environment-variables#default-environment-variables |
| 147 | + || |
| 148 | + env.containsKey('GITHUB_ACTIONS') |
| 149 | + |
| 150 | + // Properties on Flutter's Chrome Infra bots. |
| 151 | + || |
| 152 | + env['CHROME_HEADLESS'] == '1' || |
| 153 | + env.containsKey('BUILDBOT_BUILDERNAME') || |
| 154 | + env.containsKey('SWARMING_TASK_ID') |
| 155 | + |
| 156 | + // Property when running on borg. |
| 157 | + || |
| 158 | + env.containsKey('BORG_ALLOC_DIR'); |
| 159 | +} |
0 commit comments