Unverified Commit 42ae15f4 authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

[flutter_tools] remove LinuxWorkflow from injection and clean up tests (#51597)

parent bae79599
...@@ -40,7 +40,6 @@ import 'ios/ios_workflow.dart'; ...@@ -40,7 +40,6 @@ import 'ios/ios_workflow.dart';
import 'ios/mac.dart'; import 'ios/mac.dart';
import 'ios/simulators.dart'; import 'ios/simulators.dart';
import 'ios/xcodeproj.dart'; import 'ios/xcodeproj.dart';
import 'linux/linux_workflow.dart';
import 'macos/cocoapods.dart'; import 'macos/cocoapods.dart';
import 'macos/cocoapods_validator.dart'; import 'macos/cocoapods_validator.dart';
import 'macos/macos_workflow.dart'; import 'macos/macos_workflow.dart';
...@@ -141,7 +140,6 @@ Future<T> runInContext<T>( ...@@ -141,7 +140,6 @@ Future<T> runInContext<T>(
IOSSimulatorUtils: () => IOSSimulatorUtils(), IOSSimulatorUtils: () => IOSSimulatorUtils(),
IOSWorkflow: () => const IOSWorkflow(), IOSWorkflow: () => const IOSWorkflow(),
KernelCompilerFactory: () => const KernelCompilerFactory(), KernelCompilerFactory: () => const KernelCompilerFactory(),
LinuxWorkflow: () => const LinuxWorkflow(),
Logger: () => globals.platform.isWindows Logger: () => globals.platform.isWindows
? WindowsStdoutLogger( ? WindowsStdoutLogger(
terminal: globals.terminal, terminal: globals.terminal,
......
...@@ -15,6 +15,7 @@ import 'base/file_system.dart'; ...@@ -15,6 +15,7 @@ import 'base/file_system.dart';
import 'base/io.dart'; import 'base/io.dart';
import 'base/utils.dart'; import 'base/utils.dart';
import 'build_info.dart'; import 'build_info.dart';
import 'features.dart';
import 'fuchsia/fuchsia_device.dart'; import 'fuchsia/fuchsia_device.dart';
import 'globals.dart' as globals; import 'globals.dart' as globals;
import 'ios/devices.dart'; import 'ios/devices.dart';
...@@ -74,7 +75,10 @@ class DeviceManager { ...@@ -74,7 +75,10 @@ class DeviceManager {
FuchsiaDevices(), FuchsiaDevices(),
FlutterTesterDevices(), FlutterTesterDevices(),
MacOSDevices(), MacOSDevices(),
LinuxDevices(), LinuxDevices(
platform: globals.platform,
featureFlags: featureFlags,
),
WindowsDevices(), WindowsDevices(),
WebDevices(), WebDevices(),
]); ]);
......
...@@ -20,6 +20,7 @@ import 'base/utils.dart'; ...@@ -20,6 +20,7 @@ import 'base/utils.dart';
import 'base/version.dart'; import 'base/version.dart';
import 'cache.dart'; import 'cache.dart';
import 'device.dart'; import 'device.dart';
import 'features.dart';
import 'fuchsia/fuchsia_workflow.dart'; import 'fuchsia/fuchsia_workflow.dart';
import 'globals.dart' as globals; import 'globals.dart' as globals;
import 'intellij/intellij.dart'; import 'intellij/intellij.dart';
...@@ -67,6 +68,10 @@ class _DefaultDoctorValidatorsProvider implements DoctorValidatorsProvider { ...@@ -67,6 +68,10 @@ class _DefaultDoctorValidatorsProvider implements DoctorValidatorsProvider {
...IntelliJValidator.installedValidators, ...IntelliJValidator.installedValidators,
...VsCodeValidator.installedValidators, ...VsCodeValidator.installedValidators,
]; ];
final LinuxWorkflow linuxWorkflow = LinuxWorkflow(
platform: globals.platform,
featureFlags: featureFlags,
);
_validators = <DoctorValidator>[ _validators = <DoctorValidator>[
FlutterValidator(), FlutterValidator(),
...@@ -115,6 +120,10 @@ class _DefaultDoctorValidatorsProvider implements DoctorValidatorsProvider { ...@@ -115,6 +120,10 @@ class _DefaultDoctorValidatorsProvider implements DoctorValidatorsProvider {
_workflows.add(fuchsiaWorkflow); _workflows.add(fuchsiaWorkflow);
} }
final LinuxWorkflow linuxWorkflow = LinuxWorkflow(
platform: globals.platform,
featureFlags: featureFlags,
);
if (linuxWorkflow.appliesToHostPlatform) { if (linuxWorkflow.appliesToHostPlatform) {
_workflows.add(linuxWorkflow); _workflows.add(linuxWorkflow);
} }
......
...@@ -2,10 +2,13 @@ ...@@ -2,10 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
import 'package:meta/meta.dart';
import 'package:platform/platform.dart';
import '../build_info.dart'; import '../build_info.dart';
import '../desktop_device.dart'; import '../desktop_device.dart';
import '../device.dart'; import '../device.dart';
import '../globals.dart' as globals; import '../features.dart';
import '../project.dart'; import '../project.dart';
import 'application_package.dart'; import 'application_package.dart';
import 'build_linux.dart'; import 'build_linux.dart';
...@@ -53,13 +56,24 @@ class LinuxDevice extends DesktopDevice { ...@@ -53,13 +56,24 @@ class LinuxDevice extends DesktopDevice {
} }
class LinuxDevices extends PollingDeviceDiscovery { 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 @override
bool get supportsPlatform => globals.platform.isLinux; bool get supportsPlatform => _platform.isLinux;
@override @override
bool get canListAnything => linuxWorkflow.canListDevices; bool get canListAnything => _linuxWorkflow.canListDevices;
@override @override
Future<List<Device>> pollingGetDevices() async { Future<List<Device>> pollingGetDevices() async {
......
...@@ -2,29 +2,34 @@ ...@@ -2,29 +2,34 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
import '../base/context.dart'; import 'package:meta/meta.dart';
import 'package:platform/platform.dart';
import '../doctor.dart'; import '../doctor.dart';
import '../features.dart'; import '../features.dart';
import '../globals.dart' as globals;
/// The [WindowsWorkflow] instance.
LinuxWorkflow get linuxWorkflow => context.get<LinuxWorkflow>();
/// The windows-specific implementation of a [Workflow]. /// The windows-specific implementation of a [Workflow].
/// ///
/// This workflow requires the flutter-desktop-embedding as a sibling /// This workflow requires the flutter-desktop-embedding as a sibling
/// repository to the flutter repo. /// repository to the flutter repo.
class LinuxWorkflow implements Workflow { 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 @override
bool get appliesToHostPlatform => globals.platform.isLinux && featureFlags.isLinuxEnabled; bool get appliesToHostPlatform => _platform.isLinux && _featureFlags.isLinuxEnabled;
@override @override
bool get canLaunchDevices => globals.platform.isLinux && featureFlags.isLinuxEnabled; bool get canLaunchDevices => _platform.isLinux && _featureFlags.isLinuxEnabled;
@override @override
bool get canListDevices => globals.platform.isLinux && featureFlags.isLinuxEnabled; bool get canListDevices => _platform.isLinux && _featureFlags.isLinuxEnabled;
@override @override
bool get canListEmulators => false; bool get canListEmulators => false;
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
import 'package:file/memory.dart'; import 'package:file/memory.dart';
import 'package:flutter_tools/src/base/file_system.dart'; import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/build_info.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/application_package.dart';
import 'package:flutter_tools/src/linux/linux_device.dart'; import 'package:flutter_tools/src/linux/linux_device.dart';
import 'package:flutter_tools/src/device.dart'; import 'package:flutter_tools/src/device.dart';
...@@ -36,9 +37,10 @@ void main() { ...@@ -36,9 +37,10 @@ void main() {
}); });
testUsingContext('LinuxDevice: no devices listed if platform unsupported', () async { testUsingContext('LinuxDevice: no devices listed if platform unsupported', () async {
expect(await LinuxDevices().devices, <Device>[]); expect(await LinuxDevices(
}, overrides: <Type, Generator>{ platform: notLinux,
Platform: () => notLinux, featureFlags: featureFlags,
).devices, <Device>[]);
}); });
testUsingContext('LinuxDevice.isSupportedForProject is true with editable host app', () async { testUsingContext('LinuxDevice.isSupportedForProject is true with editable host app', () async {
......
...@@ -2,61 +2,60 @@ ...@@ -2,61 +2,60 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
import 'package:flutter_tools/src/features.dart';
import 'package:mockito/mockito.dart';
import 'package:platform/platform.dart'; import 'package:platform/platform.dart';
import 'package:flutter_tools/src/features.dart';
import 'package:flutter_tools/src/linux/linux_workflow.dart'; import 'package:flutter_tools/src/linux/linux_workflow.dart';
import '../../src/common.dart'; import '../../src/common.dart';
import '../../src/context.dart';
import '../../src/testbed.dart'; import '../../src/testbed.dart';
void main() { void main() {
MockPlatform linux; final Platform linux = FakePlatform(
MockPlatform notLinux; operatingSystem: 'linux',
Testbed testbed; environment: <String, String>{},
);
setUp(() { final Platform notLinux = FakePlatform(
linux = MockPlatform(); operatingSystem: 'windows',
notLinux = MockPlatform(); environment: <String, String>{},
when(linux.isLinux).thenReturn(true); );
when(notLinux.isLinux).thenReturn(false); final FeatureFlags enabledFlags = TestFeatureFlags(
testbed = Testbed( isLinuxEnabled: true,
overrides: <Type, Generator>{ );
Platform: () => linux, final FeatureFlags disabledFlags = TestFeatureFlags(isLinuxEnabled: false);
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.appliesToHostPlatform, true);
expect(linuxWorkflow.canLaunchDevices, true); expect(linuxWorkflow.canLaunchDevices, true);
expect(linuxWorkflow.canListDevices, true); expect(linuxWorkflow.canListDevices, true);
expect(linuxWorkflow.canListEmulators, false); 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.appliesToHostPlatform, false);
expect(linuxWorkflow.canLaunchDevices, false); expect(linuxWorkflow.canLaunchDevices, false);
expect(linuxWorkflow.canListDevices, false); expect(linuxWorkflow.canListDevices, false);
expect(linuxWorkflow.canListEmulators, false); expect(linuxWorkflow.canListEmulators, false);
}, overrides: <Type, Generator>{ });
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.appliesToHostPlatform, false);
expect(linuxWorkflow.canLaunchDevices, false); expect(linuxWorkflow.canLaunchDevices, false);
expect(linuxWorkflow.canListDevices, false); expect(linuxWorkflow.canListDevices, false);
expect(linuxWorkflow.canListEmulators, false); expect(linuxWorkflow.canListEmulators, false);
}, overrides: <Type, Generator>{ });
FeatureFlags: () => TestFeatureFlags(isLinuxEnabled: false),
}));
}
class MockPlatform extends Mock implements Platform {
@override
final Map<String, String> environment = <String, String>{};
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment