Unverified Commit 3056f419 authored by Angjie Li's avatar Angjie Li Committed by GitHub

Fix issue with --web-renderer. (#69319)

parent 2fa03438
...@@ -814,7 +814,7 @@ class WebDevFS implements DevFS { ...@@ -814,7 +814,7 @@ class WebDevFS implements DevFS {
webAssetServer.webRenderer = WebRendererMode.autoDetect; webAssetServer.webRenderer = WebRendererMode.autoDetect;
} else if (buildInfo.dartDefines.contains('FLUTTER_WEB_USE_SKIA=true')) { } else if (buildInfo.dartDefines.contains('FLUTTER_WEB_USE_SKIA=true')) {
webAssetServer.webRenderer = WebRendererMode.canvaskit; webAssetServer.webRenderer = WebRendererMode.canvaskit;
} }
if (hostname == 'any') { if (hostname == 'any') {
_baseUri = Uri.http('localhost:$port', ''); _baseUri = Uri.http('localhost:$port', '');
} else { } else {
......
...@@ -838,12 +838,12 @@ abstract class FlutterCommand extends Command<void> { ...@@ -838,12 +838,12 @@ abstract class FlutterCommand extends Command<void> {
? stringArg(FlutterOptions.kPerformanceMeasurementFile) ? stringArg(FlutterOptions.kPerformanceMeasurementFile)
: null; : null;
final List<String> dartDefines = argParser.options.containsKey(FlutterOptions.kDartDefinesOption) List<String> dartDefines = argParser.options.containsKey(FlutterOptions.kDartDefinesOption)
? stringsArg(FlutterOptions.kDartDefinesOption) ? stringsArg(FlutterOptions.kDartDefinesOption)
: <String>[]; : <String>[];
if (argParser.options.containsKey('web-renderer') && argResults.wasParsed('web-renderer')) { if (argParser.options.containsKey('web-renderer') && argResults.wasParsed('web-renderer')) {
_updateDartDefines(dartDefines, stringArg('web-renderer')); dartDefines = updateDartDefines(dartDefines, stringArg('web-renderer'));
} }
return BuildInfo(buildMode, return BuildInfo(buildMode,
...@@ -944,12 +944,15 @@ abstract class FlutterCommand extends Command<void> { ...@@ -944,12 +944,15 @@ abstract class FlutterCommand extends Command<void> {
} }
/// Updates dart-defines based on [webRenderer]. /// Updates dart-defines based on [webRenderer].
void _updateDartDefines(List<String> dartDefines, String webRenderer) { @visibleForTesting
if (dartDefines.any((String d) => d.startsWith('FLUTTER_WEB_USE_SKIA='))) { static List<String> updateDartDefines(List<String> dartDefines, String webRenderer) {
throwToolExit('Only one of "--web-renderer" and ' final Set<String> dartDefinesSet = dartDefines.toSet();
'"--dart-defines=FLUTTER_WEB_USE_SKIA" may be specified.'); if (!dartDefines.any((String d) => d.startsWith('FLUTTER_WEB_AUTO_DETECT='))
&& dartDefines.any((String d) => d.startsWith('FLUTTER_WEB_USE_SKIA='))) {
dartDefinesSet.removeWhere((String d) => d.startsWith('FLUTTER_WEB_USE_SKIA='));
} }
dartDefines.addAll(_webRendererDartDefines[webRenderer]); dartDefinesSet.addAll(_webRendererDartDefines[webRenderer]);
return dartDefinesSet.toList();
} }
void _registerSignalHandlers(String commandPath, DateTime startTime) { void _registerSignalHandlers(String commandPath, DateTime startTime) {
......
...@@ -505,6 +505,47 @@ void main() { ...@@ -505,6 +505,47 @@ void main() {
DeviceManager: () => mockDeviceManager, DeviceManager: () => mockDeviceManager,
}); });
}); });
group('dart-defines and web-renderer options', () {
List<String> dartDefines;
setUp(() {
dartDefines = <String>[];
});
test('auto web-renderer with no dart-defines', () {
dartDefines = FlutterCommand.updateDartDefines(dartDefines, 'auto');
expect(dartDefines, <String>['FLUTTER_WEB_AUTO_DETECT=true']);
});
test('canvaskit web-renderer with no dart-defines', () {
dartDefines = FlutterCommand.updateDartDefines(dartDefines, 'canvaskit');
expect(dartDefines, <String>['FLUTTER_WEB_AUTO_DETECT=false','FLUTTER_WEB_USE_SKIA=true']);
});
test('html web-renderer with no dart-defines', () {
dartDefines = FlutterCommand.updateDartDefines(dartDefines, 'html');
expect(dartDefines, <String>['FLUTTER_WEB_AUTO_DETECT=false','FLUTTER_WEB_USE_SKIA=false']);
});
test('auto web-renderer with existing dart-defines', () {
dartDefines = <String>['FLUTTER_WEB_USE_SKIA=false'];
dartDefines = FlutterCommand.updateDartDefines(dartDefines, 'auto');
expect(dartDefines, <String>['FLUTTER_WEB_AUTO_DETECT=true']);
});
test('canvaskit web-renderer with no dart-defines', () {
dartDefines = <String>['FLUTTER_WEB_USE_SKIA=false'];
dartDefines = FlutterCommand.updateDartDefines(dartDefines, 'canvaskit');
expect(dartDefines, <String>['FLUTTER_WEB_AUTO_DETECT=false','FLUTTER_WEB_USE_SKIA=true']);
});
test('html web-renderer with no dart-defines', () {
dartDefines = <String>['FLUTTER_WEB_USE_SKIA=true'];
dartDefines = FlutterCommand.updateDartDefines(dartDefines, 'html');
expect(dartDefines, <String>['FLUTTER_WEB_AUTO_DETECT=false','FLUTTER_WEB_USE_SKIA=false']);
});
});
} }
class MockCache extends Mock implements Cache {} class MockCache extends Mock implements Cache {}
......
...@@ -942,12 +942,12 @@ void main() { ...@@ -942,12 +942,12 @@ void main() {
useSseForDebugBackend: true, useSseForDebugBackend: true,
nullAssertions: true, nullAssertions: true,
buildInfo: const BuildInfo( buildInfo: const BuildInfo(
BuildMode.debug, BuildMode.debug,
'', '',
treeShakeIcons: false, treeShakeIcons: false,
dartDefines: <String>[ dartDefines: <String>[
'FLUTTER_WEB_AUTO_DETECT=true', 'FLUTTER_WEB_AUTO_DETECT=true',
] ]
), ),
enableDwds: false, enableDwds: false,
entrypoint: Uri.base, entrypoint: Uri.base,
......
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