diff --git a/packages/flutter_tools/lib/src/context_runner.dart b/packages/flutter_tools/lib/src/context_runner.dart index b9a3297ea0..39043f9790 100644 --- a/packages/flutter_tools/lib/src/context_runner.dart +++ b/packages/flutter_tools/lib/src/context_runner.dart @@ -40,7 +40,6 @@ import 'ios/ios_workflow.dart'; import 'ios/mac.dart'; import 'ios/simulators.dart'; import 'ios/xcodeproj.dart'; -import 'linux/linux_workflow.dart'; import 'macos/cocoapods.dart'; import 'macos/cocoapods_validator.dart'; import 'macos/macos_workflow.dart'; @@ -141,7 +140,6 @@ Future runInContext( IOSSimulatorUtils: () => IOSSimulatorUtils(), IOSWorkflow: () => const IOSWorkflow(), KernelCompilerFactory: () => const KernelCompilerFactory(), - LinuxWorkflow: () => const LinuxWorkflow(), Logger: () => globals.platform.isWindows ? WindowsStdoutLogger( terminal: globals.terminal, diff --git a/packages/flutter_tools/lib/src/device.dart b/packages/flutter_tools/lib/src/device.dart index 0a28259143..5eef0b4827 100644 --- a/packages/flutter_tools/lib/src/device.dart +++ b/packages/flutter_tools/lib/src/device.dart @@ -15,6 +15,7 @@ import 'base/file_system.dart'; import 'base/io.dart'; import 'base/utils.dart'; import 'build_info.dart'; +import 'features.dart'; import 'fuchsia/fuchsia_device.dart'; import 'globals.dart' as globals; import 'ios/devices.dart'; @@ -74,7 +75,10 @@ class DeviceManager { FuchsiaDevices(), FlutterTesterDevices(), MacOSDevices(), - LinuxDevices(), + LinuxDevices( + platform: globals.platform, + featureFlags: featureFlags, + ), WindowsDevices(), WebDevices(), ]); diff --git a/packages/flutter_tools/lib/src/doctor.dart b/packages/flutter_tools/lib/src/doctor.dart index 5babf68f59..3a228fdd87 100644 --- a/packages/flutter_tools/lib/src/doctor.dart +++ b/packages/flutter_tools/lib/src/doctor.dart @@ -20,6 +20,7 @@ import 'base/utils.dart'; import 'base/version.dart'; import 'cache.dart'; import 'device.dart'; +import 'features.dart'; import 'fuchsia/fuchsia_workflow.dart'; import 'globals.dart' as globals; import 'intellij/intellij.dart'; @@ -67,6 +68,10 @@ class _DefaultDoctorValidatorsProvider implements DoctorValidatorsProvider { ...IntelliJValidator.installedValidators, ...VsCodeValidator.installedValidators, ]; + final LinuxWorkflow linuxWorkflow = LinuxWorkflow( + platform: globals.platform, + featureFlags: featureFlags, + ); _validators = [ FlutterValidator(), @@ -115,6 +120,10 @@ class _DefaultDoctorValidatorsProvider implements DoctorValidatorsProvider { _workflows.add(fuchsiaWorkflow); } + final LinuxWorkflow linuxWorkflow = LinuxWorkflow( + platform: globals.platform, + featureFlags: featureFlags, + ); if (linuxWorkflow.appliesToHostPlatform) { _workflows.add(linuxWorkflow); } diff --git a/packages/flutter_tools/lib/src/linux/linux_device.dart b/packages/flutter_tools/lib/src/linux/linux_device.dart index 2ab1b615ff..06c3e1cf9f 100644 --- a/packages/flutter_tools/lib/src/linux/linux_device.dart +++ b/packages/flutter_tools/lib/src/linux/linux_device.dart @@ -2,10 +2,13 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +import 'package:meta/meta.dart'; +import 'package:platform/platform.dart'; + import '../build_info.dart'; import '../desktop_device.dart'; import '../device.dart'; -import '../globals.dart' as globals; +import '../features.dart'; import '../project.dart'; import 'application_package.dart'; import 'build_linux.dart'; @@ -53,13 +56,24 @@ class LinuxDevice extends DesktopDevice { } class LinuxDevices extends PollingDeviceDiscovery { - LinuxDevices() : super('linux devices'); + LinuxDevices({ + @required Platform platform, + @required FeatureFlags featureFlags, + }) : _platform = platform, + _linuxWorkflow = LinuxWorkflow( + platform: platform, + featureFlags: featureFlags, + ), + super('linux devices'); + + final Platform _platform; + final LinuxWorkflow _linuxWorkflow; @override - bool get supportsPlatform => globals.platform.isLinux; + bool get supportsPlatform => _platform.isLinux; @override - bool get canListAnything => linuxWorkflow.canListDevices; + bool get canListAnything => _linuxWorkflow.canListDevices; @override Future> pollingGetDevices() async { diff --git a/packages/flutter_tools/lib/src/linux/linux_workflow.dart b/packages/flutter_tools/lib/src/linux/linux_workflow.dart index 11423d3464..caea987539 100644 --- a/packages/flutter_tools/lib/src/linux/linux_workflow.dart +++ b/packages/flutter_tools/lib/src/linux/linux_workflow.dart @@ -2,29 +2,34 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import '../base/context.dart'; +import 'package:meta/meta.dart'; +import 'package:platform/platform.dart'; + import '../doctor.dart'; import '../features.dart'; -import '../globals.dart' as globals; - -/// The [WindowsWorkflow] instance. -LinuxWorkflow get linuxWorkflow => context.get(); /// The windows-specific implementation of a [Workflow]. /// /// This workflow requires the flutter-desktop-embedding as a sibling /// repository to the flutter repo. class LinuxWorkflow implements Workflow { - const LinuxWorkflow(); + const LinuxWorkflow({ + @required Platform platform, + @required FeatureFlags featureFlags, + }) : _platform = platform, + _featureFlags = featureFlags; + + final Platform _platform; + final FeatureFlags _featureFlags; @override - bool get appliesToHostPlatform => globals.platform.isLinux && featureFlags.isLinuxEnabled; + bool get appliesToHostPlatform => _platform.isLinux && _featureFlags.isLinuxEnabled; @override - bool get canLaunchDevices => globals.platform.isLinux && featureFlags.isLinuxEnabled; + bool get canLaunchDevices => _platform.isLinux && _featureFlags.isLinuxEnabled; @override - bool get canListDevices => globals.platform.isLinux && featureFlags.isLinuxEnabled; + bool get canListDevices => _platform.isLinux && _featureFlags.isLinuxEnabled; @override bool get canListEmulators => false; diff --git a/packages/flutter_tools/test/general.shard/linux/linux_device_test.dart b/packages/flutter_tools/test/general.shard/linux/linux_device_test.dart index 5bfe7b4b6b..63a1ead16b 100644 --- a/packages/flutter_tools/test/general.shard/linux/linux_device_test.dart +++ b/packages/flutter_tools/test/general.shard/linux/linux_device_test.dart @@ -5,6 +5,7 @@ import 'package:file/memory.dart'; import 'package:flutter_tools/src/base/file_system.dart'; import 'package:flutter_tools/src/build_info.dart'; +import 'package:flutter_tools/src/features.dart'; import 'package:flutter_tools/src/linux/application_package.dart'; import 'package:flutter_tools/src/linux/linux_device.dart'; import 'package:flutter_tools/src/device.dart'; @@ -36,9 +37,10 @@ void main() { }); testUsingContext('LinuxDevice: no devices listed if platform unsupported', () async { - expect(await LinuxDevices().devices, []); - }, overrides: { - Platform: () => notLinux, + expect(await LinuxDevices( + platform: notLinux, + featureFlags: featureFlags, + ).devices, []); }); testUsingContext('LinuxDevice.isSupportedForProject is true with editable host app', () async { diff --git a/packages/flutter_tools/test/general.shard/linux/linux_workflow_test.dart b/packages/flutter_tools/test/general.shard/linux/linux_workflow_test.dart index 563043150b..389842d890 100644 --- a/packages/flutter_tools/test/general.shard/linux/linux_workflow_test.dart +++ b/packages/flutter_tools/test/general.shard/linux/linux_workflow_test.dart @@ -2,61 +2,60 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import 'package:flutter_tools/src/features.dart'; -import 'package:mockito/mockito.dart'; import 'package:platform/platform.dart'; - +import 'package:flutter_tools/src/features.dart'; import 'package:flutter_tools/src/linux/linux_workflow.dart'; import '../../src/common.dart'; -import '../../src/context.dart'; import '../../src/testbed.dart'; void main() { - MockPlatform linux; - MockPlatform notLinux; - Testbed testbed; + final Platform linux = FakePlatform( + operatingSystem: 'linux', + environment: {}, + ); + final Platform notLinux = FakePlatform( + operatingSystem: 'windows', + environment: {}, + ); + final FeatureFlags enabledFlags = TestFeatureFlags( + isLinuxEnabled: true, + ); + final FeatureFlags disabledFlags = TestFeatureFlags(isLinuxEnabled: false); - setUp(() { - linux = MockPlatform(); - notLinux = MockPlatform(); - when(linux.isLinux).thenReturn(true); - when(notLinux.isLinux).thenReturn(false); - testbed = Testbed( - overrides: { - Platform: () => linux, - FeatureFlags: () => TestFeatureFlags(isLinuxEnabled: true), - }, + testWithoutContext('Applies to Linux platform', () { + final LinuxWorkflow linuxWorkflow = LinuxWorkflow( + platform: linux, + featureFlags: enabledFlags, ); - }); - test('Applies to linux platform', () => testbed.run(() { expect(linuxWorkflow.appliesToHostPlatform, true); expect(linuxWorkflow.canLaunchDevices, true); expect(linuxWorkflow.canListDevices, true); expect(linuxWorkflow.canListEmulators, false); - })); + }); + + testWithoutContext('Does not apply to non-Linux platform', () { + final LinuxWorkflow linuxWorkflow = LinuxWorkflow( + platform: notLinux, + featureFlags: enabledFlags, + ); - test('Does not apply to non-linux platform', () => testbed.run(() { expect(linuxWorkflow.appliesToHostPlatform, false); expect(linuxWorkflow.canLaunchDevices, false); expect(linuxWorkflow.canListDevices, false); expect(linuxWorkflow.canListEmulators, false); - }, overrides: { - Platform: () => notLinux, - })); + }); + + testWithoutContext('Does not apply when the Linux desktop feature is disabled', () { + final LinuxWorkflow linuxWorkflow = LinuxWorkflow( + platform: linux, + featureFlags: disabledFlags, + ); - test('Does not apply when feature is disabled', () => testbed.run(() { expect(linuxWorkflow.appliesToHostPlatform, false); expect(linuxWorkflow.canLaunchDevices, false); expect(linuxWorkflow.canListDevices, false); expect(linuxWorkflow.canListEmulators, false); - }, overrides: { - FeatureFlags: () => TestFeatureFlags(isLinuxEnabled: false), - })); -} - -class MockPlatform extends Mock implements Platform { - @override - final Map environment = {}; + }); }