Commit 0d2c9670 authored by Todd Volkert's avatar Todd Volkert Committed by GitHub

Resolve TODOs to migrate from OperatingSystemUtils to Platform (#8314)

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