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