diff --git a/packages/flutter_tools/lib/src/android/android_studio.dart b/packages/flutter_tools/lib/src/android/android_studio.dart index 65c9fc24131..29ec328d6fe 100644 --- a/packages/flutter_tools/lib/src/android/android_studio.dart +++ b/packages/flutter_tools/lib/src/android/android_studio.dart @@ -100,7 +100,7 @@ class AndroidStudio implements Comparable { String configuredStudio = config.getValue('android-studio-dir'); if (configuredStudio != null) { String configuredStudioPath = configuredStudio; - if (os.isMacOS && !configuredStudioPath.endsWith('Contents')) + if (platform.isMacOS && !configuredStudioPath.endsWith('Contents')) configuredStudioPath = fs.path.join(configuredStudioPath, 'Contents'); return new AndroidStudio(configuredStudioPath, configured: configuredStudio); diff --git a/packages/flutter_tools/lib/src/base/os.dart b/packages/flutter_tools/lib/src/base/os.dart index 82fa562ca00..f5a3026c830 100644 --- a/packages/flutter_tools/lib/src/base/os.dart +++ b/packages/flutter_tools/lib/src/base/os.dart @@ -27,13 +27,6 @@ abstract class OperatingSystemUtils { OperatingSystemUtils._private(); - - // TODO(tvolkert): Remove these and migrate callers to Platform - String get operatingSystem => platform.operatingSystem; - bool get isMacOS => operatingSystem == 'macos'; - bool get isWindows => operatingSystem == 'windows'; - bool get isLinux => operatingSystem == 'linux'; - /// Make the given file executable. This may be a no-op on some platforms. ProcessResult makeExecutable(File file); diff --git a/packages/flutter_tools/lib/src/commands/drive.dart b/packages/flutter_tools/lib/src/commands/drive.dart index 727216840f3..4d843fa508c 100644 --- a/packages/flutter_tools/lib/src/commands/drive.dart +++ b/packages/flutter_tools/lib/src/commands/drive.dart @@ -8,7 +8,7 @@ import '../android/android_device.dart' show AndroidDevice; import '../application_package.dart'; import '../base/file_system.dart'; import '../base/common.dart'; -import '../base/os.dart'; +import '../base/platform.dart'; import '../base/process.dart'; import '../build_info.dart'; import '../cache.dart'; @@ -199,7 +199,7 @@ Future findTargetDevice() async { } - if (os.isMacOS) { + if (platform.isMacOS) { // On Mac we look for the iOS Simulator. If available, we use that. Then // we look for an Android device. If there's one, we use that. Otherwise, // we launch a new iOS Simulator. @@ -225,7 +225,7 @@ Future findTargetDevice() async { printError('Failed to start iOS Simulator.'); return null; } - } else if (os.isLinux || os.isWindows) { + } else if (platform.isLinux || platform.isWindows) { // On Linux and Windows, for now, we just grab the first connected device we can find. if (devices.isEmpty) { printError('No devices found.'); diff --git a/packages/flutter_tools/lib/src/commands/test.dart b/packages/flutter_tools/lib/src/commands/test.dart index 3f67022bb17..319a52f7fca 100644 --- a/packages/flutter_tools/lib/src/commands/test.dart +++ b/packages/flutter_tools/lib/src/commands/test.dart @@ -11,8 +11,9 @@ import '../base/common.dart'; import '../base/file_system.dart'; import '../base/io.dart'; import '../base/logger.dart'; -import '../base/process_manager.dart'; import '../base/os.dart'; +import '../base/platform.dart'; +import '../base/process_manager.dart'; import '../cache.dart'; import '../dart/package_map.dart'; import '../globals.dart'; @@ -112,7 +113,7 @@ class TestCommand extends FlutterCommand { String baseCoverageData = 'coverage/lcov.base.info'; if (mergeCoverageData) { - if (!os.isLinux) { + if (!platform.isLinux) { printError( 'Merging coverage data is supported only on Linux because it ' 'requires the "lcov" tool.' @@ -127,9 +128,9 @@ class TestCommand extends FlutterCommand { if (os.which('lcov') == null) { String installMessage = 'Please install lcov.'; - if (os.isLinux) + if (platform.isLinux) installMessage = 'Consider running "sudo apt-get install lcov".'; - else if (os.isMacOS) + else if (platform.isMacOS) installMessage = 'Consider running "brew install lcov".'; printError('Missing "lcov" tool. Unable to merge coverage data.\n$installMessage'); return false; diff --git a/packages/flutter_tools/lib/src/resident_runner.dart b/packages/flutter_tools/lib/src/resident_runner.dart index 6bda33fe381..b09fdf4d845 100644 --- a/packages/flutter_tools/lib/src/resident_runner.dart +++ b/packages/flutter_tools/lib/src/resident_runner.dart @@ -13,7 +13,7 @@ import 'base/common.dart'; import 'base/file_system.dart'; import 'base/io.dart'; import 'base/logger.dart'; -import 'base/os.dart'; +import 'base/platform.dart'; import 'base/utils.dart'; import 'build_info.dart'; import 'dart/dependencies.dart'; @@ -157,7 +157,7 @@ abstract class ResidentRunner { void registerSignalHandlers() { assert(stayResident); ProcessSignal.SIGINT.watch().listen(_cleanUpAndExit); - if (!os.isWindows) // TODO(goderbauer): enable on Windows when https://github.com/dart-lang/sdk/issues/28603 is fixed + if (!platform.isWindows) // TODO(goderbauer): enable on Windows when https://github.com/dart-lang/sdk/issues/28603 is fixed ProcessSignal.SIGTERM.watch().listen(_cleanUpAndExit); if (!supportsServiceProtocol || !supportsRestart) return; diff --git a/packages/flutter_tools/test/drive_test.dart b/packages/flutter_tools/test/drive_test.dart index 0acef186d43..baa8fc95f77 100644 --- a/packages/flutter_tools/test/drive_test.dart +++ b/packages/flutter_tools/test/drive_test.dart @@ -7,7 +7,7 @@ import 'package:flutter_tools/src/android/android_device.dart'; import 'package:flutter_tools/src/base/common.dart'; import 'package:flutter_tools/src/base/file_system.dart'; import 'package:flutter_tools/src/base/io.dart'; -import 'package:flutter_tools/src/base/os.dart'; +import 'package:flutter_tools/src/base/platform.dart'; import 'package:flutter_tools/src/commands/drive.dart'; import 'package:flutter_tools/src/device.dart'; import 'package:flutter_tools/src/ios/simulators.dart'; @@ -232,14 +232,9 @@ void main() { }); group('findTargetDevice on iOS', () { - void setOs() { - when(os.isMacOS).thenReturn(true); - when(os.isLinux).thenReturn(false); - when(os.isWindows).thenReturn(false); - } + Platform macOsPlatform() => new FakePlatform(operatingSystem: 'macos'); testUsingContext('uses existing emulator', () async { - setOs(); withMockDevice(); when(mockDevice.name).thenReturn('mock-simulator'); when(mockDevice.isLocalEmulator).thenReturn(true); @@ -248,10 +243,10 @@ void main() { expect(device.name, 'mock-simulator'); }, overrides: { FileSystem: () => fs, + Platform: () => macOsPlatform(), }); testUsingContext('uses existing Android device if and there are no simulators', () async { - setOs(); mockDevice = new MockAndroidDevice(); when(mockDevice.name).thenReturn('mock-android-device'); when(mockDevice.isLocalEmulator).thenReturn(false); @@ -261,10 +256,10 @@ void main() { expect(device.name, 'mock-android-device'); }, overrides: { FileSystem: () => fs, + Platform: () => macOsPlatform(), }); testUsingContext('launches emulator', () async { - setOs(); when(SimControl.instance.boot()).thenReturn(true); Device emulator = new MockDevice(); when(emulator.name).thenReturn('new-simulator'); @@ -275,26 +270,23 @@ void main() { expect(device.name, 'new-simulator'); }, overrides: { FileSystem: () => fs, + Platform: () => macOsPlatform(), }); }); - void findTargetDeviceOnLinuxOrWindows({bool isWindows: false, bool isLinux: false}) { - assert(isWindows != isLinux); - void setOs() { - when(os.isMacOS).thenReturn(false); - when(os.isLinux).thenReturn(isLinux); - when(os.isWindows).thenReturn(isWindows); - } + void findTargetDeviceOnOperatingSystem(String operatingSystem) { + assert(operatingSystem == 'windows' || operatingSystem == 'linux'); + + Platform platform() => new FakePlatform(operatingSystem: operatingSystem); testUsingContext('returns null if no devices found', () async { - setOs(); expect(await findTargetDevice(), isNull); }, overrides: { FileSystem: () => fs, + Platform: () => platform(), }); testUsingContext('uses existing Android device', () async { - setOs(); mockDevice = new MockAndroidDevice(); when(mockDevice.name).thenReturn('mock-android-device'); withMockDevice(mockDevice); @@ -303,15 +295,16 @@ void main() { expect(device.name, 'mock-android-device'); }, overrides: { FileSystem: () => fs, + Platform: () => platform(), }); } group('findTargetDevice on Linux', () { - findTargetDeviceOnLinuxOrWindows(isLinux: true); + findTargetDeviceOnOperatingSystem('linux'); }); group('findTargetDevice on Windows', () { - findTargetDeviceOnLinuxOrWindows(isWindows: true); + findTargetDeviceOnOperatingSystem('windows'); }); }); } diff --git a/packages/flutter_tools/test/src/context.dart b/packages/flutter_tools/test/src/context.dart index cf9561ae8c5..04aa87f60d1 100644 --- a/packages/flutter_tools/test/src/context.dart +++ b/packages/flutter_tools/test/src/context.dart @@ -42,7 +42,7 @@ void testUsingContext(String description, dynamic testMethod(), { // Initialize the test context with some default mocks. // Seed these context entries first since others depend on them - testContext.putIfAbsent(Platform, () => const LocalPlatform()); + testContext.putIfAbsent(Platform, () => new _FakePlatform()); testContext.putIfAbsent(FileSystem, () => const LocalFileSystem()); testContext.putIfAbsent(ProcessManager, () => const LocalProcessManager()); testContext.putIfAbsent(Logger, () => new BufferLogger()); @@ -55,11 +55,7 @@ void testUsingContext(String description, dynamic testMethod(), { testContext.putIfAbsent(HotRunnerConfig, () => new HotRunnerConfig()); testContext.putIfAbsent(Cache, () => new Cache()); testContext.putIfAbsent(Artifacts, () => new CachedArtifacts()); - testContext.putIfAbsent(OperatingSystemUtils, () { - MockOperatingSystemUtils os = new MockOperatingSystemUtils(); - when(os.isWindows).thenReturn(false); - return os; - }); + testContext.putIfAbsent(OperatingSystemUtils, () => new MockOperatingSystemUtils()); testContext.putIfAbsent(Xcode, () => new Xcode()); testContext.putIfAbsent(IOSSimulatorUtils, () { MockIOSSimulatorUtils mock = new MockIOSSimulatorUtils(); @@ -144,6 +140,13 @@ class MockSimControl extends Mock implements SimControl { } } +class _FakePlatform extends FakePlatform { + _FakePlatform() : super.fromPlatform(const LocalPlatform()); + + @override + bool get isWindows => false; +} + class MockOperatingSystemUtils extends Mock implements OperatingSystemUtils {} class MockIOSSimulatorUtils extends Mock implements IOSSimulatorUtils {}