From 358e1cd2e171e81067c9728df7508f0e72a76c3f Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Wed, 22 Mar 2017 13:25:38 -0700 Subject: [PATCH] Teach flutter_tools to populate PUB_ENVIRONMENT (#8962) * Teach flutter_tools to populate PUB_ENVIRONMENT Will allow telemetry reporting on pub.dartlang.org once flutter moves to 1.23.0-dev.10.0 * review changes --- packages/flutter_tools/lib/src/dart/pub.dart | 28 +++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/packages/flutter_tools/lib/src/dart/pub.dart b/packages/flutter_tools/lib/src/dart/pub.dart index fcd125c9e2..8f64421b32 100644 --- a/packages/flutter_tools/lib/src/dart/pub.dart +++ b/packages/flutter_tools/lib/src/dart/pub.dart @@ -7,7 +7,9 @@ import 'dart:async'; import '../base/common.dart'; import '../base/file_system.dart'; import '../base/logger.dart'; +import '../base/platform.dart'; import '../base/process.dart'; +import '../base/utils.dart'; import '../cache.dart'; import '../globals.dart'; import 'sdk.dart'; @@ -54,7 +56,7 @@ Future pubGet({ final int code = await runCommandAndStreamOutput(args, workingDirectory: directory, mapFunction: _filterOverrideWarnings, - environment: { 'FLUTTER_ROOT': Cache.flutterRoot } + environment: { 'FLUTTER_ROOT': Cache.flutterRoot, _pubEnvironmentKey: _getPubEnvironmentValue() } ); status.stop(); if (code != 0) @@ -70,6 +72,30 @@ Future pubGet({ final RegExp _analyzerWarning = new RegExp(r'^! \w+ [^ ]+ from path \.\./\.\./bin/cache/dart-sdk/lib/\w+$'); +/// The console environment key used by the pub tool. +const String _pubEnvironmentKey = 'PUB_ENVIRONMENT'; + +/// Returns the environment value that should be used when running pub. +/// +/// Includes any existing environment variable, if one exists. +String _getPubEnvironmentValue() { + final List values = []; + + final String existing = platform.environment[_pubEnvironmentKey]; + + if ((existing != null) && existing.isNotEmpty) { + values.add(existing); + } + + if (isRunningOnBot) { + values.add('flutter_bot'); + } + + values.add('flutter_cli'); + + return values.join(':'); +} + String _filterOverrideWarnings(String message) { // This function filters out these three messages: // Warning: You are using these overridden dependencies: