mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
Remove environment variable guards for command line desktop and web (#33867)
This commit is contained in:
parent
42d8383c9e
commit
0d9a1b201e
@ -28,6 +28,10 @@ import '../vmservice.dart';
|
||||
|
||||
const String protocolVersion = '0.5.2';
|
||||
|
||||
/// Whether the tool started from the daemon, as opposed to the command line.
|
||||
bool get isRunningFromDaemon => _isRunningFromDaemon;
|
||||
bool _isRunningFromDaemon = false;
|
||||
|
||||
/// A server process command. This command will start up a long-lived server.
|
||||
/// It reads JSON-RPC based commands from stdin, executes them, and returns
|
||||
/// JSON-RPC based responses and events to stdout.
|
||||
@ -49,6 +53,7 @@ class DaemonCommand extends FlutterCommand {
|
||||
@override
|
||||
Future<FlutterCommandResult> runCommand() async {
|
||||
printStatus('Starting device daemon...');
|
||||
_isRunningFromDaemon = true;
|
||||
|
||||
final NotifyingLogger notifyingLogger = NotifyingLogger();
|
||||
|
||||
|
@ -4,20 +4,32 @@
|
||||
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
import 'base/io.dart';
|
||||
import 'base/platform.dart';
|
||||
import 'base/process_manager.dart';
|
||||
import 'commands/daemon.dart' show isRunningFromDaemon;
|
||||
import 'convert.dart';
|
||||
import 'device.dart';
|
||||
import 'version.dart';
|
||||
|
||||
// Only launch or display desktop embedding devices if
|
||||
// `ENABLE_FLUTTER_DESKTOP` environment variable is set to true.
|
||||
@visibleForTesting
|
||||
bool debugDisableDesktop = false;
|
||||
|
||||
/// Only launch or display desktop embedding devices from the command line
|
||||
/// or if `ENABLE_FLUTTER_DESKTOP` environment variable is set to true.
|
||||
bool get flutterDesktopEnabled {
|
||||
_flutterDesktopEnabled ??= platform.environment['ENABLE_FLUTTER_DESKTOP']?.toLowerCase() == 'true';
|
||||
return _flutterDesktopEnabled && !FlutterVersion.instance.isStable;
|
||||
if (debugDisableDesktop) {
|
||||
return false;
|
||||
}
|
||||
if (isRunningFromDaemon) {
|
||||
final bool platformEnabled = platform
|
||||
.environment['ENABLE_FLUTTER_DESKTOP']?.toLowerCase() == 'true';
|
||||
return platformEnabled && !FlutterVersion.instance.isStable;
|
||||
}
|
||||
return !FlutterVersion.instance.isStable;
|
||||
}
|
||||
bool _flutterDesktopEnabled;
|
||||
|
||||
/// Kills a process on linux or macOS.
|
||||
Future<bool> killProcess(String executable) async {
|
||||
|
@ -21,10 +21,10 @@ class LinuxWorkflow implements Workflow {
|
||||
bool get appliesToHostPlatform => platform.isLinux;
|
||||
|
||||
@override
|
||||
bool get canLaunchDevices => flutterDesktopEnabled;
|
||||
bool get canLaunchDevices => platform.isLinux && flutterDesktopEnabled;
|
||||
|
||||
@override
|
||||
bool get canListDevices => flutterDesktopEnabled;
|
||||
bool get canListDevices => platform.isLinux && flutterDesktopEnabled;
|
||||
|
||||
@override
|
||||
bool get canListEmulators => false;
|
||||
|
@ -21,10 +21,10 @@ class MacOSWorkflow implements Workflow {
|
||||
bool get appliesToHostPlatform => platform.isMacOS;
|
||||
|
||||
@override
|
||||
bool get canLaunchDevices => flutterDesktopEnabled;
|
||||
bool get canLaunchDevices => platform.isMacOS && flutterDesktopEnabled;
|
||||
|
||||
@override
|
||||
bool get canListDevices => flutterDesktopEnabled;
|
||||
bool get canListDevices => platform.isMacOS && flutterDesktopEnabled;
|
||||
|
||||
@override
|
||||
bool get canListEmulators => false;
|
||||
|
@ -12,8 +12,8 @@ import '../base/process_manager.dart';
|
||||
import '../build_info.dart';
|
||||
import '../device.dart';
|
||||
import '../project.dart';
|
||||
import '../web/workflow.dart';
|
||||
import 'chrome.dart';
|
||||
import 'workflow.dart';
|
||||
|
||||
class WebApplicationPackage extends ApplicationPackage {
|
||||
WebApplicationPackage(this.flutterProject) : super(id: flutterProject.manifest.appName);
|
||||
|
@ -2,20 +2,32 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
import '../base/context.dart';
|
||||
import '../base/platform.dart';
|
||||
import '../base/process_manager.dart';
|
||||
import '../commands/daemon.dart' show isRunningFromDaemon;
|
||||
import '../doctor.dart';
|
||||
import '../version.dart';
|
||||
import 'chrome.dart';
|
||||
|
||||
@visibleForTesting
|
||||
bool debugDisableWeb = false;
|
||||
|
||||
/// Only launch or display web devices if `FLUTTER_WEB`
|
||||
/// environment variable is set to true.
|
||||
/// environment variable is set to true from the daemon.
|
||||
bool get flutterWebEnabled {
|
||||
_flutterWebEnabled = platform.environment['FLUTTER_WEB']?.toLowerCase() == 'true';
|
||||
return _flutterWebEnabled && !FlutterVersion.instance.isStable;
|
||||
if (debugDisableWeb) {
|
||||
return false;
|
||||
}
|
||||
if (isRunningFromDaemon) {
|
||||
final bool platformEnabled = platform
|
||||
.environment['FLUTTER_WEB']?.toLowerCase() == 'true';
|
||||
return platformEnabled && !FlutterVersion.instance.isStable;
|
||||
}
|
||||
return !FlutterVersion.instance.isStable;
|
||||
}
|
||||
bool _flutterWebEnabled;
|
||||
|
||||
/// The web workflow instance.
|
||||
WebWorkflow get webWorkflow => context.get<WebWorkflow>();
|
||||
|
@ -21,10 +21,10 @@ class WindowsWorkflow implements Workflow {
|
||||
bool get appliesToHostPlatform => platform.isWindows;
|
||||
|
||||
@override
|
||||
bool get canLaunchDevices => flutterDesktopEnabled;
|
||||
bool get canLaunchDevices => platform.isWindows && flutterDesktopEnabled;
|
||||
|
||||
@override
|
||||
bool get canListDevices => flutterDesktopEnabled;
|
||||
bool get canListDevices => platform.isWindows && flutterDesktopEnabled;
|
||||
|
||||
@override
|
||||
bool get canListEmulators => false;
|
||||
|
@ -20,6 +20,9 @@ void main() {
|
||||
group('devices', () {
|
||||
setUpAll(() {
|
||||
Cache.disableLocking();
|
||||
// TODO(jonahwilliams): adjust the individual tests so they do not
|
||||
// depend on the host environment.
|
||||
debugDisableWebAndDesktop = true;
|
||||
});
|
||||
|
||||
testUsingContext('returns 0 when called', () async {
|
||||
|
@ -24,7 +24,6 @@ void main() {
|
||||
final MockProcessManager mockProcessManager = MockProcessManager();
|
||||
|
||||
when(notLinux.isLinux).thenReturn(false);
|
||||
when(notLinux.environment).thenReturn(const <String, String>{});
|
||||
when(mockProcessManager.run(<String>[
|
||||
'ps', 'aux',
|
||||
])).thenAnswer((Invocation invocation) async {
|
||||
|
@ -5,6 +5,8 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:args/command_runner.dart';
|
||||
import 'package:flutter_tools/src/desktop.dart';
|
||||
import 'package:flutter_tools/src/web/workflow.dart';
|
||||
import 'package:test_api/test_api.dart' hide TypeMatcher, isInstanceOf;
|
||||
import 'package:test_api/test_api.dart' as test_package show TypeMatcher;
|
||||
|
||||
@ -18,6 +20,19 @@ import 'package:flutter_tools/src/runner/flutter_command_runner.dart';
|
||||
|
||||
export 'package:test_api/test_api.dart' hide TypeMatcher, isInstanceOf; // Defines a 'package:test' shim.
|
||||
|
||||
/// Disable both web and desktop to make testing easier. For example, prevent
|
||||
/// them from showing up in the devices list if the host happens to be setup
|
||||
/// properly.
|
||||
set debugDisableWebAndDesktop(bool value) {
|
||||
if (value) {
|
||||
debugDisableDesktop = true;
|
||||
debugDisableWeb = true;
|
||||
} else {
|
||||
debugDisableDesktop = false;
|
||||
debugDisableWeb = false;
|
||||
}
|
||||
}
|
||||
|
||||
/// A matcher that compares the type of the actual value to the type argument T.
|
||||
// TODO(ianh): Remove this once https://github.com/dart-lang/matcher/issues/98 is fixed
|
||||
Matcher isInstanceOf<T>() => test_package.TypeMatcher<T>();
|
||||
|
@ -17,7 +17,6 @@ import '../src/testbed.dart';
|
||||
void main() {
|
||||
group('WebWorkflow', () {
|
||||
Testbed testbed;
|
||||
MockPlatform noEnvironment;
|
||||
MockPlatform notSupported;
|
||||
MockPlatform windows;
|
||||
MockPlatform linux;
|
||||
@ -30,7 +29,6 @@ void main() {
|
||||
setUpAll(() {
|
||||
unstable = MockFlutterVersion(false);
|
||||
stable = MockFlutterVersion(true);
|
||||
noEnvironment = MockPlatform(environment: const <String, String>{});
|
||||
notSupported = MockPlatform(linux: false, windows: false, macos: false);
|
||||
windows = MockPlatform(windows: true);
|
||||
linux = MockPlatform(linux: true);
|
||||
@ -46,15 +44,6 @@ void main() {
|
||||
});
|
||||
});
|
||||
|
||||
test('does not apply if FLUTTER_WEB is not true', ()=> testbed.run(() {
|
||||
expect(workflow.appliesToHostPlatform, false);
|
||||
expect(workflow.canLaunchDevices, false);
|
||||
expect(workflow.canListDevices, false);
|
||||
expect(workflow.canListEmulators, false);
|
||||
}, overrides: <Type, Generator>{
|
||||
Platform: () => noEnvironment,
|
||||
}));
|
||||
|
||||
test('Applies on Linux', () => testbed.run(() {
|
||||
expect(workflow.appliesToHostPlatform, true);
|
||||
expect(workflow.canLaunchDevices, true);
|
||||
@ -92,7 +81,7 @@ void main() {
|
||||
Platform: () => notSupported,
|
||||
}));
|
||||
|
||||
test('does not apply on stable brnach', () => testbed.run(() {
|
||||
test('does not apply on stable branch', () => testbed.run(() {
|
||||
expect(workflow.appliesToHostPlatform, false);
|
||||
expect(workflow.canLaunchDevices, false);
|
||||
expect(workflow.canListDevices, false);
|
||||
@ -119,7 +108,6 @@ class MockPlatform extends Mock implements Platform {
|
||||
this.macos = false,
|
||||
this.linux = false,
|
||||
this.environment = const <String, String>{
|
||||
'FLUTTER_WEB': 'true',
|
||||
kChromeEnvironment: 'chrome',
|
||||
}});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user