mirror of
https://github.com/flutter/flutter
synced 2024-10-13 19:52:53 +00:00
Resolve TODOs to migrate from OperatingSystemUtils to Platform (#8314)
This commit is contained in:
parent
ac7954c11a
commit
0d2c9670fd
|
@ -100,7 +100,7 @@ class AndroidStudio implements Comparable<AndroidStudio> {
|
|||
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);
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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<Device> 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<Device> 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.');
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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: <Type, Generator>{
|
||||
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: <Type, Generator>{
|
||||
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: <Type, Generator>{
|
||||
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: <Type, Generator>{
|
||||
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: <Type, Generator>{
|
||||
FileSystem: () => fs,
|
||||
Platform: () => platform(),
|
||||
});
|
||||
}
|
||||
|
||||
group('findTargetDevice on Linux', () {
|
||||
findTargetDeviceOnLinuxOrWindows(isLinux: true);
|
||||
findTargetDeviceOnOperatingSystem('linux');
|
||||
});
|
||||
|
||||
group('findTargetDevice on Windows', () {
|
||||
findTargetDeviceOnLinuxOrWindows(isWindows: true);
|
||||
findTargetDeviceOnOperatingSystem('windows');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -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 {}
|
||||
|
|
Loading…
Reference in a new issue