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';
|
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.
|
/// 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
|
/// It reads JSON-RPC based commands from stdin, executes them, and returns
|
||||||
/// JSON-RPC based responses and events to stdout.
|
/// JSON-RPC based responses and events to stdout.
|
||||||
@ -49,6 +53,7 @@ class DaemonCommand extends FlutterCommand {
|
|||||||
@override
|
@override
|
||||||
Future<FlutterCommandResult> runCommand() async {
|
Future<FlutterCommandResult> runCommand() async {
|
||||||
printStatus('Starting device daemon...');
|
printStatus('Starting device daemon...');
|
||||||
|
_isRunningFromDaemon = true;
|
||||||
|
|
||||||
final NotifyingLogger notifyingLogger = NotifyingLogger();
|
final NotifyingLogger notifyingLogger = NotifyingLogger();
|
||||||
|
|
||||||
|
@ -4,20 +4,32 @@
|
|||||||
|
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
|
||||||
|
import 'package:meta/meta.dart';
|
||||||
|
|
||||||
import 'base/io.dart';
|
import 'base/io.dart';
|
||||||
import 'base/platform.dart';
|
import 'base/platform.dart';
|
||||||
import 'base/process_manager.dart';
|
import 'base/process_manager.dart';
|
||||||
|
import 'commands/daemon.dart' show isRunningFromDaemon;
|
||||||
import 'convert.dart';
|
import 'convert.dart';
|
||||||
import 'device.dart';
|
import 'device.dart';
|
||||||
import 'version.dart';
|
import 'version.dart';
|
||||||
|
|
||||||
// Only launch or display desktop embedding devices if
|
@visibleForTesting
|
||||||
// `ENABLE_FLUTTER_DESKTOP` environment variable is set to true.
|
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 {
|
bool get flutterDesktopEnabled {
|
||||||
_flutterDesktopEnabled ??= platform.environment['ENABLE_FLUTTER_DESKTOP']?.toLowerCase() == 'true';
|
if (debugDisableDesktop) {
|
||||||
return _flutterDesktopEnabled && !FlutterVersion.instance.isStable;
|
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.
|
/// Kills a process on linux or macOS.
|
||||||
Future<bool> killProcess(String executable) async {
|
Future<bool> killProcess(String executable) async {
|
||||||
|
@ -21,10 +21,10 @@ class LinuxWorkflow implements Workflow {
|
|||||||
bool get appliesToHostPlatform => platform.isLinux;
|
bool get appliesToHostPlatform => platform.isLinux;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
bool get canLaunchDevices => flutterDesktopEnabled;
|
bool get canLaunchDevices => platform.isLinux && flutterDesktopEnabled;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
bool get canListDevices => flutterDesktopEnabled;
|
bool get canListDevices => platform.isLinux && flutterDesktopEnabled;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
bool get canListEmulators => false;
|
bool get canListEmulators => false;
|
||||||
|
@ -21,10 +21,10 @@ class MacOSWorkflow implements Workflow {
|
|||||||
bool get appliesToHostPlatform => platform.isMacOS;
|
bool get appliesToHostPlatform => platform.isMacOS;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
bool get canLaunchDevices => flutterDesktopEnabled;
|
bool get canLaunchDevices => platform.isMacOS && flutterDesktopEnabled;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
bool get canListDevices => flutterDesktopEnabled;
|
bool get canListDevices => platform.isMacOS && flutterDesktopEnabled;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
bool get canListEmulators => false;
|
bool get canListEmulators => false;
|
||||||
|
@ -12,8 +12,8 @@ import '../base/process_manager.dart';
|
|||||||
import '../build_info.dart';
|
import '../build_info.dart';
|
||||||
import '../device.dart';
|
import '../device.dart';
|
||||||
import '../project.dart';
|
import '../project.dart';
|
||||||
import '../web/workflow.dart';
|
|
||||||
import 'chrome.dart';
|
import 'chrome.dart';
|
||||||
|
import 'workflow.dart';
|
||||||
|
|
||||||
class WebApplicationPackage extends ApplicationPackage {
|
class WebApplicationPackage extends ApplicationPackage {
|
||||||
WebApplicationPackage(this.flutterProject) : super(id: flutterProject.manifest.appName);
|
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
|
// 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 'package:meta/meta.dart';
|
||||||
|
|
||||||
import '../base/context.dart';
|
import '../base/context.dart';
|
||||||
import '../base/platform.dart';
|
import '../base/platform.dart';
|
||||||
import '../base/process_manager.dart';
|
import '../base/process_manager.dart';
|
||||||
|
import '../commands/daemon.dart' show isRunningFromDaemon;
|
||||||
import '../doctor.dart';
|
import '../doctor.dart';
|
||||||
import '../version.dart';
|
import '../version.dart';
|
||||||
import 'chrome.dart';
|
import 'chrome.dart';
|
||||||
|
|
||||||
|
@visibleForTesting
|
||||||
|
bool debugDisableWeb = false;
|
||||||
|
|
||||||
/// Only launch or display web devices if `FLUTTER_WEB`
|
/// 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 {
|
bool get flutterWebEnabled {
|
||||||
_flutterWebEnabled = platform.environment['FLUTTER_WEB']?.toLowerCase() == 'true';
|
if (debugDisableWeb) {
|
||||||
return _flutterWebEnabled && !FlutterVersion.instance.isStable;
|
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.
|
/// The web workflow instance.
|
||||||
WebWorkflow get webWorkflow => context.get<WebWorkflow>();
|
WebWorkflow get webWorkflow => context.get<WebWorkflow>();
|
||||||
|
@ -21,10 +21,10 @@ class WindowsWorkflow implements Workflow {
|
|||||||
bool get appliesToHostPlatform => platform.isWindows;
|
bool get appliesToHostPlatform => platform.isWindows;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
bool get canLaunchDevices => flutterDesktopEnabled;
|
bool get canLaunchDevices => platform.isWindows && flutterDesktopEnabled;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
bool get canListDevices => flutterDesktopEnabled;
|
bool get canListDevices => platform.isWindows && flutterDesktopEnabled;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
bool get canListEmulators => false;
|
bool get canListEmulators => false;
|
||||||
|
@ -20,6 +20,9 @@ void main() {
|
|||||||
group('devices', () {
|
group('devices', () {
|
||||||
setUpAll(() {
|
setUpAll(() {
|
||||||
Cache.disableLocking();
|
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 {
|
testUsingContext('returns 0 when called', () async {
|
||||||
|
@ -24,7 +24,6 @@ void main() {
|
|||||||
final MockProcessManager mockProcessManager = MockProcessManager();
|
final MockProcessManager mockProcessManager = MockProcessManager();
|
||||||
|
|
||||||
when(notLinux.isLinux).thenReturn(false);
|
when(notLinux.isLinux).thenReturn(false);
|
||||||
when(notLinux.environment).thenReturn(const <String, String>{});
|
|
||||||
when(mockProcessManager.run(<String>[
|
when(mockProcessManager.run(<String>[
|
||||||
'ps', 'aux',
|
'ps', 'aux',
|
||||||
])).thenAnswer((Invocation invocation) async {
|
])).thenAnswer((Invocation invocation) async {
|
||||||
|
@ -5,6 +5,8 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
|
||||||
import 'package:args/command_runner.dart';
|
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' hide TypeMatcher, isInstanceOf;
|
||||||
import 'package:test_api/test_api.dart' as test_package show TypeMatcher;
|
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.
|
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.
|
/// 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
|
// TODO(ianh): Remove this once https://github.com/dart-lang/matcher/issues/98 is fixed
|
||||||
Matcher isInstanceOf<T>() => test_package.TypeMatcher<T>();
|
Matcher isInstanceOf<T>() => test_package.TypeMatcher<T>();
|
||||||
|
@ -17,7 +17,6 @@ import '../src/testbed.dart';
|
|||||||
void main() {
|
void main() {
|
||||||
group('WebWorkflow', () {
|
group('WebWorkflow', () {
|
||||||
Testbed testbed;
|
Testbed testbed;
|
||||||
MockPlatform noEnvironment;
|
|
||||||
MockPlatform notSupported;
|
MockPlatform notSupported;
|
||||||
MockPlatform windows;
|
MockPlatform windows;
|
||||||
MockPlatform linux;
|
MockPlatform linux;
|
||||||
@ -30,7 +29,6 @@ void main() {
|
|||||||
setUpAll(() {
|
setUpAll(() {
|
||||||
unstable = MockFlutterVersion(false);
|
unstable = MockFlutterVersion(false);
|
||||||
stable = MockFlutterVersion(true);
|
stable = MockFlutterVersion(true);
|
||||||
noEnvironment = MockPlatform(environment: const <String, String>{});
|
|
||||||
notSupported = MockPlatform(linux: false, windows: false, macos: false);
|
notSupported = MockPlatform(linux: false, windows: false, macos: false);
|
||||||
windows = MockPlatform(windows: true);
|
windows = MockPlatform(windows: true);
|
||||||
linux = MockPlatform(linux: 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(() {
|
test('Applies on Linux', () => testbed.run(() {
|
||||||
expect(workflow.appliesToHostPlatform, true);
|
expect(workflow.appliesToHostPlatform, true);
|
||||||
expect(workflow.canLaunchDevices, true);
|
expect(workflow.canLaunchDevices, true);
|
||||||
@ -92,7 +81,7 @@ void main() {
|
|||||||
Platform: () => notSupported,
|
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.appliesToHostPlatform, false);
|
||||||
expect(workflow.canLaunchDevices, false);
|
expect(workflow.canLaunchDevices, false);
|
||||||
expect(workflow.canListDevices, false);
|
expect(workflow.canListDevices, false);
|
||||||
@ -119,7 +108,6 @@ class MockPlatform extends Mock implements Platform {
|
|||||||
this.macos = false,
|
this.macos = false,
|
||||||
this.linux = false,
|
this.linux = false,
|
||||||
this.environment = const <String, String>{
|
this.environment = const <String, String>{
|
||||||
'FLUTTER_WEB': 'true',
|
|
||||||
kChromeEnvironment: 'chrome',
|
kChromeEnvironment: 'chrome',
|
||||||
}});
|
}});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user