Unverified Commit c1fabb98 authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

make FDE opt-in via the environment variable (#26898)

parent 450abfe9
// Copyright 2018 The Chromium Authors. All rights reserved. // Copyright 2019 The Chromium Authors. All rights reserved.
// 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/file_system.dart';
import 'base/platform.dart'; import 'base/platform.dart';
import 'cache.dart';
// Only launch or display desktop embedding devices if there is a sibling // Only launch or display desktop embedding devices if
// FDE repository or a `FLUTTER_DESKTOP_EMBEDDING` environment variable which // `FLUTTER_DESKTOP_EMBEDDING` environment variable is set to true.
// contains a FDE repo. bool get flutterDesktopEnabled {
bool get hasFlutterDesktopRepository { _flutterDesktopEnabled ??= platform.environment['FLUTTER_DESKTOP_EMBEDDING']?.toLowerCase() == 'true';
if (_hasFlutterDesktopRepository == null) { return _flutterDesktopEnabled;
final String desktopLocation = platform.environment['FLUTTER_DESKTOP_EMBEDDING'];
if (desktopLocation != null && desktopLocation.isNotEmpty) {
_hasFlutterDesktopRepository = fs.directory(desktopLocation)
.existsSync();
} else {
final Directory parent = fs.directory(Cache.flutterRoot).parent;
_hasFlutterDesktopRepository = parent
.childDirectory('flutter-desktop-embedding')
.existsSync();
}
}
return _hasFlutterDesktopRepository;
} }
bool _hasFlutterDesktopRepository; bool _flutterDesktopEnabled;
...@@ -21,10 +21,10 @@ class LinuxWorkflow implements Workflow { ...@@ -21,10 +21,10 @@ class LinuxWorkflow implements Workflow {
bool get appliesToHostPlatform => platform.isLinux; bool get appliesToHostPlatform => platform.isLinux;
@override @override
bool get canLaunchDevices => hasFlutterDesktopRepository; bool get canLaunchDevices => flutterDesktopEnabled;
@override @override
bool get canListDevices => hasFlutterDesktopRepository; bool get canListDevices => flutterDesktopEnabled;
@override @override
bool get canListEmulators => false; bool get canListEmulators => false;
......
...@@ -21,10 +21,10 @@ class MacOSWorkflow implements Workflow { ...@@ -21,10 +21,10 @@ class MacOSWorkflow implements Workflow {
bool get appliesToHostPlatform => platform.isMacOS; bool get appliesToHostPlatform => platform.isMacOS;
@override @override
bool get canLaunchDevices => hasFlutterDesktopRepository; bool get canLaunchDevices => flutterDesktopEnabled;
@override @override
bool get canListDevices => hasFlutterDesktopRepository; bool get canListDevices => flutterDesktopEnabled;
@override @override
bool get canListEmulators => false; bool get canListEmulators => false;
......
...@@ -21,10 +21,10 @@ class WindowsWorkflow implements Workflow { ...@@ -21,10 +21,10 @@ class WindowsWorkflow implements Workflow {
bool get appliesToHostPlatform => platform.isWindows; bool get appliesToHostPlatform => platform.isWindows;
@override @override
bool get canLaunchDevices => hasFlutterDesktopRepository; bool get canLaunchDevices => flutterDesktopEnabled;
@override @override
bool get canListDevices => hasFlutterDesktopRepository; bool get canListDevices => flutterDesktopEnabled;
@override @override
bool get canListEmulators => false; bool get canListEmulators => false;
......
...@@ -4,9 +4,7 @@ ...@@ -4,9 +4,7 @@
import 'package:mockito/mockito.dart'; import 'package:mockito/mockito.dart';
import 'package:flutter_tools/src/linux/linux_workflow.dart'; import 'package:flutter_tools/src/linux/linux_workflow.dart';
import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/base/platform.dart'; import 'package:flutter_tools/src/base/platform.dart';
import 'package:flutter_tools/src/cache.dart';
import '../src/common.dart'; import '../src/common.dart';
import '../src/context.dart'; import '../src/context.dart';
...@@ -14,8 +12,11 @@ import '../src/context.dart'; ...@@ -14,8 +12,11 @@ import '../src/context.dart';
void main() { void main() {
group(LinuxWorkflow, () { group(LinuxWorkflow, () {
final MockPlatform linux = MockPlatform(); final MockPlatform linux = MockPlatform();
final MockPlatform linuxWithFde = MockPlatform()
..environment['FLUTTER_DESKTOP_EMBEDDING'] = 'true';
final MockPlatform notLinux = MockPlatform(); final MockPlatform notLinux = MockPlatform();
when(linux.isLinux).thenReturn(true); when(linux.isLinux).thenReturn(true);
when(linuxWithFde.isLinux).thenReturn(true);
when(notLinux.isLinux).thenReturn(false); when(notLinux.isLinux).thenReturn(false);
testUsingContext('Applies to linux platform', () { testUsingContext('Applies to linux platform', () {
...@@ -29,30 +30,17 @@ void main() { ...@@ -29,30 +30,17 @@ void main() {
Platform: () => notLinux, Platform: () => notLinux,
}); });
final MockFileSystem fileSystem = MockFileSystem();
final MockDirectory directory = MockDirectory();
Cache.flutterRoot = '';
when(fileSystem.directory(Cache.flutterRoot)).thenReturn(directory);
when(directory.parent).thenReturn(directory);
when(directory.childDirectory('flutter-desktop-embedding')).thenReturn(directory);
when(directory.existsSync()).thenReturn(true);
testUsingContext('defaults', () { testUsingContext('defaults', () {
expect(linuxWorkflow.canListEmulators, false); expect(linuxWorkflow.canListEmulators, false);
expect(linuxWorkflow.canLaunchDevices, true); expect(linuxWorkflow.canLaunchDevices, true);
expect(linuxWorkflow.canListDevices, true); expect(linuxWorkflow.canListDevices, true);
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
Platform: () => linux, Platform: () => linuxWithFde
FileSystem: () => fileSystem,
}); });
}); });
} }
class MockFileSystem extends Mock implements FileSystem {}
class MockDirectory extends Mock implements Directory {}
class MockPlatform extends Mock implements Platform { class MockPlatform extends Mock implements Platform {
@override @override
Map<String, String> get environment => const <String, String>{}; final Map<String, String> environment = <String, String>{};
} }
...@@ -4,9 +4,7 @@ ...@@ -4,9 +4,7 @@
import 'package:mockito/mockito.dart'; import 'package:mockito/mockito.dart';
import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/base/platform.dart'; import 'package:flutter_tools/src/base/platform.dart';
import 'package:flutter_tools/src/cache.dart';
import 'package:flutter_tools/src/macos/macos_workflow.dart'; import 'package:flutter_tools/src/macos/macos_workflow.dart';
import '../src/common.dart'; import '../src/common.dart';
...@@ -15,8 +13,11 @@ import '../src/context.dart'; ...@@ -15,8 +13,11 @@ import '../src/context.dart';
void main() { void main() {
group(MacOSWorkflow, () { group(MacOSWorkflow, () {
final MockPlatform mac = MockPlatform(); final MockPlatform mac = MockPlatform();
final MockPlatform macWithFde = MockPlatform()
..environment['FLUTTER_DESKTOP_EMBEDDING'] = 'true';
final MockPlatform notMac = MockPlatform(); final MockPlatform notMac = MockPlatform();
when(mac.isMacOS).thenReturn(true); when(mac.isMacOS).thenReturn(true);
when(macWithFde.isMacOS).thenReturn(true);
when(notMac.isMacOS).thenReturn(false); when(notMac.isMacOS).thenReturn(false);
testUsingContext('Applies to mac platform', () { testUsingContext('Applies to mac platform', () {
...@@ -30,30 +31,17 @@ void main() { ...@@ -30,30 +31,17 @@ void main() {
Platform: () => notMac, Platform: () => notMac,
}); });
final MockFileSystem fileSystem = MockFileSystem();
final MockDirectory directory = MockDirectory();
Cache.flutterRoot = '';
when(fileSystem.directory(Cache.flutterRoot)).thenReturn(directory);
when(directory.parent).thenReturn(directory);
when(directory.childDirectory('flutter-desktop-embedding')).thenReturn(directory);
when(directory.existsSync()).thenReturn(true);
testUsingContext('defaults', () { testUsingContext('defaults', () {
expect(macOSWorkflow.canListEmulators, false); expect(macOSWorkflow.canListEmulators, false);
expect(macOSWorkflow.canLaunchDevices, true); expect(macOSWorkflow.canLaunchDevices, true);
expect(macOSWorkflow.canListDevices, true); expect(macOSWorkflow.canListDevices, true);
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
Platform: () => mac, Platform: () => macWithFde,
FileSystem: () => fileSystem,
}); });
}); });
} }
class MockFileSystem extends Mock implements FileSystem {}
class MockDirectory extends Mock implements Directory {}
class MockPlatform extends Mock implements Platform { class MockPlatform extends Mock implements Platform {
@override @override
Map<String, String> get environment => const <String, String>{}; Map<String, String> environment = <String, String>{};
} }
...@@ -4,9 +4,7 @@ ...@@ -4,9 +4,7 @@
import 'package:mockito/mockito.dart'; import 'package:mockito/mockito.dart';
import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/base/platform.dart'; import 'package:flutter_tools/src/base/platform.dart';
import 'package:flutter_tools/src/cache.dart';
import 'package:flutter_tools/src/windows/windows_workflow.dart'; import 'package:flutter_tools/src/windows/windows_workflow.dart';
import '../src/common.dart'; import '../src/common.dart';
...@@ -15,8 +13,11 @@ import '../src/context.dart'; ...@@ -15,8 +13,11 @@ import '../src/context.dart';
void main() { void main() {
group(WindowsWorkflow, () { group(WindowsWorkflow, () {
final MockPlatform windows = MockPlatform(); final MockPlatform windows = MockPlatform();
final MockPlatform windowsWithFde = MockPlatform()
..environment['FLUTTER_DESKTOP_EMBEDDING'] = 'true';
final MockPlatform notWindows = MockPlatform(); final MockPlatform notWindows = MockPlatform();
when(windows.isWindows).thenReturn(true); when(windows.isWindows).thenReturn(true);
when(windowsWithFde.isWindows).thenReturn(true);
when(notWindows.isWindows).thenReturn(false); when(notWindows.isWindows).thenReturn(false);
testUsingContext('Applies to windows platform', () { testUsingContext('Applies to windows platform', () {
...@@ -30,30 +31,17 @@ void main() { ...@@ -30,30 +31,17 @@ void main() {
Platform: () => notWindows, Platform: () => notWindows,
}); });
final MockFileSystem fileSystem = MockFileSystem();
final MockDirectory directory = MockDirectory();
Cache.flutterRoot = '';
when(fileSystem.directory(Cache.flutterRoot)).thenReturn(directory);
when(directory.parent).thenReturn(directory);
when(directory.childDirectory('flutter-desktop-embedding')).thenReturn(directory);
when(directory.existsSync()).thenReturn(true);
testUsingContext('defaults', () { testUsingContext('defaults', () {
expect(windowsWorkflow.canListEmulators, false); expect(windowsWorkflow.canListEmulators, false);
expect(windowsWorkflow.canLaunchDevices, true); expect(windowsWorkflow.canLaunchDevices, true);
expect(windowsWorkflow.canListDevices, true); expect(windowsWorkflow.canListDevices, true);
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
Platform: () => windows, Platform: () => windowsWithFde,
FileSystem: () => fileSystem,
}); });
}); });
} }
class MockFileSystem extends Mock implements FileSystem {}
class MockDirectory extends Mock implements Directory {}
class MockPlatform extends Mock implements Platform { class MockPlatform extends Mock implements Platform {
@override @override
Map<String, String> get environment => const <String, String>{}; 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