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 {
webAssetServer.webRenderer = WebRendererMode.autoDetect;
} else if (buildInfo.dartDefines.contains('FLUTTER_WEB_USE_SKIA=true')) {
webAssetServer.webRenderer = WebRendererMode.canvaskit;
}
}
if (hostname == 'any') {
_baseUri = Uri.http('localhost:$port', '');
} else {
......
......@@ -838,12 +838,12 @@ abstract class FlutterCommand extends Command<void> {
? stringArg(FlutterOptions.kPerformanceMeasurementFile)
: null;
final List<String> dartDefines = argParser.options.containsKey(FlutterOptions.kDartDefinesOption)
List<String> dartDefines = argParser.options.containsKey(FlutterOptions.kDartDefinesOption)
? stringsArg(FlutterOptions.kDartDefinesOption)
: <String>[];
if (argParser.options.containsKey('web-renderer') && argResults.wasParsed('web-renderer')) {
_updateDartDefines(dartDefines, stringArg('web-renderer'));
dartDefines = updateDartDefines(dartDefines, stringArg('web-renderer'));
}
return BuildInfo(buildMode,
......@@ -944,12 +944,15 @@ abstract class FlutterCommand extends Command<void> {
}
/// Updates dart-defines based on [webRenderer].
void _updateDartDefines(List<String> dartDefines, String webRenderer) {
if (dartDefines.any((String d) => d.startsWith('FLUTTER_WEB_USE_SKIA='))) {
throwToolExit('Only one of "--web-renderer" and '
'"--dart-defines=FLUTTER_WEB_USE_SKIA" may be specified.');
@visibleForTesting
static List<String> updateDartDefines(List<String> dartDefines, String webRenderer) {
final Set<String> dartDefinesSet = dartDefines.toSet();
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) {
......
......@@ -505,6 +505,47 @@ void main() {
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 {}
......
......@@ -942,12 +942,12 @@ void main() {
useSseForDebugBackend: true,
nullAssertions: true,
buildInfo: const BuildInfo(
BuildMode.debug,
'',
treeShakeIcons: false,
dartDefines: <String>[
'FLUTTER_WEB_AUTO_DETECT=true',
]
BuildMode.debug,
'',
treeShakeIcons: false,
dartDefines: <String>[
'FLUTTER_WEB_AUTO_DETECT=true',
]
),
enableDwds: false,
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