diff --git a/dev/devicelab/lib/framework/utils.dart b/dev/devicelab/lib/framework/utils.dart index 3f87268ea9..d1fa4b8136 100644 --- a/dev/devicelab/lib/framework/utils.dart +++ b/dev/devicelab/lib/framework/utils.dart @@ -13,6 +13,8 @@ import 'package:path/path.dart' as path; import 'package:process/process.dart'; import 'package:stack_trace/stack_trace.dart'; +import 'adb.dart'; + /// Virtual current working directory, which affect functions, such as [exec]. String cwd = Directory.current.path; @@ -498,3 +500,36 @@ int parseServicePort(String line) { final Match match = _kObservatoryRegExp.firstMatch(line); return match == null ? null : int.parse(match.group(2)); } + +/// If FLUTTER_ENGINE environment variable is set then we need to pass +/// correct --local-engine setting too. +void setLocalEngineOptionIfNecessary(List options, [String flavor]) { + if (Platform.environment['FLUTTER_ENGINE'] != null) { + if (flavor == null) { + // If engine flavor was not specified explicitly then scan options looking + // for flags that specify the engine flavor (--release, --profile or + // --debug). Default flavor to debug if no flags were found. + const Map optionToFlavor = const { + '--release': 'release', + '--debug': 'debug', + '--profile': 'profile', + }; + + for (String option in options) { + flavor = optionToFlavor[option]; + if (flavor != null) { + break; + } + } + + flavor ??= 'debug'; + } + + const Map osNames = const { + DeviceOperatingSystem.ios: 'ios', + DeviceOperatingSystem.android: 'android', + }; + + options.add('--local-engine=${osNames[deviceOperatingSystem]}_$flavor'); + } +} diff --git a/dev/devicelab/lib/tasks/hot_mode_tests.dart b/dev/devicelab/lib/tasks/hot_mode_tests.dart index 03b5ffee82..b675453c71 100644 --- a/dev/devicelab/lib/tasks/hot_mode_tests.dart +++ b/dev/devicelab/lib/tasks/hot_mode_tests.dart @@ -26,6 +26,7 @@ TaskFunction createHotModeTest({ bool isPreviewDart2: false }) { ]; if (isPreviewDart2) options.add('--preview-dart-2'); + setLocalEngineOptionIfNecessary(options); int hotReloadCount = 0; await inDirectory(flutterDirectory, () async { rmTree(_editedFlutterGalleryDir); diff --git a/dev/devicelab/lib/tasks/microbenchmarks.dart b/dev/devicelab/lib/tasks/microbenchmarks.dart index e632b406b7..41f0c553a6 100644 --- a/dev/devicelab/lib/tasks/microbenchmarks.dart +++ b/dev/devicelab/lib/tasks/microbenchmarks.dart @@ -40,6 +40,7 @@ TaskFunction createMicrobenchmarkTask() { ]; if (previewDart2) options.add('--preview-dart-2'); + setLocalEngineOptionIfNecessary(options); options.add(benchmarkPath); return await _startFlutter( options: options, diff --git a/dev/devicelab/lib/tasks/perf_tests.dart b/dev/devicelab/lib/tasks/perf_tests.dart index 4986de7e60..1348fbc758 100644 --- a/dev/devicelab/lib/tasks/perf_tests.dart +++ b/dev/devicelab/lib/tasks/perf_tests.dart @@ -235,6 +235,7 @@ class CompileTest { } if (previewDart2) options.add('--preview-dart-2'); + setLocalEngineOptionIfNecessary(options); final String compileLog = await evalFlutter('build', options: options); watch.stop(); @@ -256,6 +257,7 @@ class CompileTest { final List options = ['--release']; if (previewDart2) options.add('--preview-dart-2'); + setLocalEngineOptionIfNecessary(options); switch (deviceOperatingSystem) { case DeviceOperatingSystem.ios: options.insert(0, 'ios'); @@ -288,6 +290,7 @@ class CompileTest { final List options = ['--debug']; if (previewDart2) options.add('--preview-dart-2'); + setLocalEngineOptionIfNecessary(options); switch (deviceOperatingSystem) { case DeviceOperatingSystem.ios: options.insert(0, 'ios');