Unverified Commit 895879c1 authored by Kevin Moore's avatar Kevin Moore Committed by GitHub

flutter_tools: Flutter Web CLI cleanup (#124564)

flutter_tools: Flutter Web CLI cleanup
parent 328635b3
......@@ -35,7 +35,7 @@ class BuildInfo {
List<String>? dartDefines,
this.bundleSkSLPath,
List<String>? dartExperiments,
this.webRenderer = WebRendererMode.autoDetect,
this.webRenderer = WebRendererMode.auto,
required this.treeShakeIcons,
this.performanceMeasurementFile,
this.dartDefineConfigJsonMap,
......
......@@ -778,7 +778,7 @@ class WebDevFS implements DevFS {
final int selectedPort = webAssetServer.selectedPort;
if (buildInfo.dartDefines.contains('FLUTTER_WEB_AUTO_DETECT=true')) {
webAssetServer.webRenderer = WebRendererMode.autoDetect;
webAssetServer.webRenderer = WebRendererMode.auto;
} else if (buildInfo.dartDefines.contains('FLUTTER_WEB_USE_SKIA=true')) {
webAssetServer.webRenderer = WebRendererMode.canvaskit;
}
......
......@@ -157,36 +157,6 @@ abstract class FlutterCommand extends Command<void> {
/// The flag name for whether or not to use ipv6.
static const String ipv6Flag = 'ipv6';
/// Maps command line web renderer strings to the corresponding web renderer mode
static const Map<String, WebRendererMode> _webRendererModeMap =
<String, WebRendererMode> {
'auto': WebRendererMode.autoDetect,
'canvaskit': WebRendererMode.canvaskit,
'html': WebRendererMode.html,
'skwasm': WebRendererMode.skwasm,
};
/// The map used to convert web renderer mode to a List of dart-defines.
static const Map<WebRendererMode, Iterable<String>> _webRendererDartDefines =
<WebRendererMode, Iterable<String>> {
WebRendererMode.autoDetect: <String>[
'FLUTTER_WEB_AUTO_DETECT=true',
],
WebRendererMode.canvaskit: <String>[
'FLUTTER_WEB_AUTO_DETECT=false',
'FLUTTER_WEB_USE_SKIA=true',
],
WebRendererMode.html: <String>[
'FLUTTER_WEB_AUTO_DETECT=false',
'FLUTTER_WEB_USE_SKIA=false',
],
WebRendererMode.skwasm: <String>[
'FLUTTER_WEB_AUTO_DETECT=false',
'FLUTTER_WEB_USE_SKIA=false',
'FLUTTER_WEB_USE_SKWASM=true',
]
};
@override
ArgParser get argParser => _argParser;
final ArgParser _argParser = ArgParser(
......@@ -668,15 +638,10 @@ abstract class FlutterCommand extends Command<void> {
void usesWebRendererOption() {
argParser.addOption(
FlutterOptions.kWebRendererFlag,
defaultsTo: 'auto',
allowed: <String>['auto', 'canvaskit', 'html', 'skwasm'],
defaultsTo: WebRendererMode.auto.name,
allowed: WebRendererMode.values.map((WebRendererMode e) => e.name),
help: 'The renderer implementation to use when building for the web.',
allowedHelp: <String, String>{
'html': 'Always use the HTML renderer. This renderer uses a combination of HTML, CSS, SVG, 2D Canvas, and WebGL.',
'canvaskit': 'Always use the CanvasKit renderer. This renderer uses WebGL and WebAssembly to render graphics.',
'auto': 'Use the HTML renderer on mobile devices, and CanvasKit on desktop devices.',
'skwasm': 'Always use the experimental skwasm renderer.',
}
allowedHelp: Map<String, String>.fromEntries(WebRendererMode.values.map((WebRendererMode e) => MapEntry<String, String>(e.name, e.helpText)))
);
}
......@@ -1236,12 +1201,9 @@ abstract class FlutterCommand extends Command<void> {
final Map<String, Object>? defineConfigJsonMap = extractDartDefineConfigJsonMap();
List<String> dartDefines = extractDartDefines(defineConfigJsonMap: defineConfigJsonMap);
WebRendererMode webRenderer = WebRendererMode.autoDetect;
WebRendererMode webRenderer = WebRendererMode.auto;
if (argParser.options.containsKey(FlutterOptions.kWebRendererFlag)) {
final WebRendererMode? mappedMode = _webRendererModeMap[stringArg(FlutterOptions.kWebRendererFlag)!];
if (mappedMode != null) {
webRenderer = mappedMode;
}
webRenderer = WebRendererMode.values.byName(stringArg(FlutterOptions.kWebRendererFlag)!);
dartDefines = updateDartDefines(dartDefines, webRenderer);
}
......@@ -1427,10 +1389,7 @@ abstract class FlutterCommand extends Command<void> {
&& dartDefines.any((String d) => d.startsWith('FLUTTER_WEB_USE_SKIA='))) {
dartDefinesSet.removeWhere((String d) => d.startsWith('FLUTTER_WEB_USE_SKIA='));
}
final Iterable<String>? webRendererDefine = _webRendererDartDefines[webRenderer];
if (webRendererDefine != null) {
dartDefinesSet.addAll(webRendererDefine);
}
dartDefinesSet.addAll(webRenderer.dartDefines);
return dartDefinesSet.toList();
}
......
......@@ -135,18 +135,50 @@ class WebBuilder {
/// Web rendering backend mode.
enum WebRendererMode {
/// Auto detects which rendering backend to use.
autoDetect,
auto,
/// Always uses canvaskit.
canvaskit,
/// Always uses html.
html,
/// Always use skwasm.
skwasm,
skwasm;
String get helpText => switch (this) {
auto =>
'Use the HTML renderer on mobile devices, and CanvasKit on desktop devices.',
canvaskit =>
'Always use the CanvasKit renderer. This renderer uses WebGL and WebAssembly to render graphics.',
html =>
'Always use the HTML renderer. This renderer uses a combination of HTML, CSS, SVG, 2D Canvas, and WebGL.',
skwasm => 'Always use the experimental skwasm renderer.'
};
Iterable<String> get dartDefines => switch (this) {
WebRendererMode.auto => <String>[
'FLUTTER_WEB_AUTO_DETECT=true',
],
WebRendererMode.canvaskit => <String>[
'FLUTTER_WEB_AUTO_DETECT=false',
'FLUTTER_WEB_USE_SKIA=true',
],
WebRendererMode.html => <String>[
'FLUTTER_WEB_AUTO_DETECT=false',
'FLUTTER_WEB_USE_SKIA=false',
],
WebRendererMode.skwasm => <String>[
'FLUTTER_WEB_AUTO_DETECT=false',
'FLUTTER_WEB_USE_SKIA=false',
'FLUTTER_WEB_USE_SKWASM=true',
]
};
}
/// The correct precompiled artifact to use for each build and render mode.
const Map<WebRendererMode, Map<NullSafetyMode, HostArtifact>> kDartSdkJsArtifactMap = <WebRendererMode, Map<NullSafetyMode, HostArtifact>>{
WebRendererMode.autoDetect: <NullSafetyMode, HostArtifact> {
WebRendererMode.auto: <NullSafetyMode, HostArtifact> {
NullSafetyMode.sound: HostArtifact.webPrecompiledCanvaskitAndHtmlSoundSdk,
NullSafetyMode.unsound: HostArtifact.webPrecompiledCanvaskitAndHtmlSdk,
},
......@@ -162,7 +194,7 @@ const Map<WebRendererMode, Map<NullSafetyMode, HostArtifact>> kDartSdkJsArtifact
/// The correct source map artifact to use for each build and render mode.
const Map<WebRendererMode, Map<NullSafetyMode, HostArtifact>> kDartSdkJsMapArtifactMap = <WebRendererMode, Map<NullSafetyMode, HostArtifact>>{
WebRendererMode.autoDetect: <NullSafetyMode, HostArtifact> {
WebRendererMode.auto: <NullSafetyMode, HostArtifact> {
NullSafetyMode.sound: HostArtifact.webPrecompiledCanvaskitAndHtmlSoundSdkSourcemaps,
NullSafetyMode.unsound: HostArtifact.webPrecompiledCanvaskitAndHtmlSdkSourcemaps,
},
......
......@@ -929,7 +929,7 @@ void main() {
});
test('auto web-renderer with no dart-defines', () {
dartDefines = FlutterCommand.updateDartDefines(dartDefines, WebRendererMode.autoDetect);
dartDefines = FlutterCommand.updateDartDefines(dartDefines, WebRendererMode.auto);
expect(dartDefines, <String>['FLUTTER_WEB_AUTO_DETECT=true']);
});
......@@ -945,7 +945,7 @@ void main() {
test('auto web-renderer with existing dart-defines', () {
dartDefines = <String>['FLUTTER_WEB_USE_SKIA=false'];
dartDefines = FlutterCommand.updateDartDefines(dartDefines, WebRendererMode.autoDetect);
dartDefines = FlutterCommand.updateDartDefines(dartDefines, WebRendererMode.auto);
expect(dartDefines, <String>['FLUTTER_WEB_AUTO_DETECT=true']);
});
......
......@@ -101,7 +101,7 @@ void main() {
webResources.childFile('index.html')
.createSync(recursive: true);
environment.buildDir.childFile('main.dart.js').createSync();
await const WebReleaseBundle(WebRendererMode.autoDetect, isWasm: false).build(environment);
await const WebReleaseBundle(WebRendererMode.auto, isWasm: false).build(environment);
expect(environment.outputDir.childFile('version.json'), exists);
}));
......@@ -113,7 +113,7 @@ void main() {
final Directory webResources = environment.projectDir.childDirectory('web');
webResources.childFile('index.html').createSync(recursive: true);
environment.buildDir.childFile('main.dart.js').createSync();
await const WebReleaseBundle(WebRendererMode.autoDetect, isWasm: false).build(environment);
await const WebReleaseBundle(WebRendererMode.auto, isWasm: false).build(environment);
final String versionFile = environment.outputDir
.childFile('version.json')
......@@ -131,7 +131,7 @@ void main() {
<!DOCTYPE html><html><base href="$kBaseHrefPlaceholder"><head></head></html>
''');
environment.buildDir.childFile('main.dart.js').createSync();
await const WebReleaseBundle(WebRendererMode.autoDetect, isWasm: false).build(environment);
await const WebReleaseBundle(WebRendererMode.auto, isWasm: false).build(environment);
expect(environment.outputDir.childFile('index.html').readAsStringSync(), contains('/basehreftest/'));
}));
......@@ -144,7 +144,7 @@ void main() {
<!DOCTYPE html><html><head><base href='/basehreftest/'></head></html>
''');
environment.buildDir.childFile('main.dart.js').createSync();
await const WebReleaseBundle(WebRendererMode.autoDetect, isWasm: false).build(environment);
await const WebReleaseBundle(WebRendererMode.auto, isWasm: false).build(environment);
expect(environment.outputDir.childFile('index.html').readAsStringSync(), contains('/basehreftest/'));
}));
......@@ -166,7 +166,7 @@ void main() {
.writeAsStringSync('A');
environment.buildDir.childFile('main.dart.js').createSync();
await const WebReleaseBundle(WebRendererMode.autoDetect, isWasm: false).build(environment);
await const WebReleaseBundle(WebRendererMode.auto, isWasm: false).build(environment);
expect(environment.outputDir.childFile('foo.txt')
.readAsStringSync(), 'A');
......@@ -178,7 +178,7 @@ void main() {
// Update to arbitrary resource file triggers rebuild.
webResources.childFile('foo.txt').writeAsStringSync('B');
await const WebReleaseBundle(WebRendererMode.autoDetect, isWasm: false).build(environment);
await const WebReleaseBundle(WebRendererMode.auto, isWasm: false).build(environment);
expect(environment.outputDir.childFile('foo.txt')
.readAsStringSync(), 'B');
......@@ -361,7 +361,7 @@ void main() {
]
));
await Dart2JSTarget(WebRendererMode.autoDetect).build(environment);
await Dart2JSTarget(WebRendererMode.auto).build(environment);
}, overrides: <Type, Generator>{
ProcessManager: () => processManager,
}));
......@@ -401,7 +401,7 @@ void main() {
]
));
await Dart2JSTarget(WebRendererMode.autoDetect).build(environment);
await Dart2JSTarget(WebRendererMode.auto).build(environment);
}, overrides: <Type, Generator>{
ProcessManager: () => processManager,
}));
......@@ -437,7 +437,7 @@ void main() {
]
));
await Dart2JSTarget(WebRendererMode.autoDetect).build(environment);
await Dart2JSTarget(WebRendererMode.auto).build(environment);
}, overrides: <Type, Generator>{
ProcessManager: () => processManager,
}));
......@@ -472,7 +472,7 @@ void main() {
]
));
await Dart2JSTarget(WebRendererMode.autoDetect).build(environment);
await Dart2JSTarget(WebRendererMode.auto).build(environment);
}, overrides: <Type, Generator>{
ProcessManager: () => processManager,
}));
......@@ -510,7 +510,7 @@ void main() {
]
));
await Dart2JSTarget(WebRendererMode.autoDetect).build(environment);
await Dart2JSTarget(WebRendererMode.auto).build(environment);
}, overrides: <Type, Generator>{
ProcessManager: () => processManager,
}));
......@@ -546,7 +546,7 @@ void main() {
]
));
await Dart2JSTarget(WebRendererMode.autoDetect).build(environment);
await Dart2JSTarget(WebRendererMode.auto).build(environment);
}, overrides: <Type, Generator>{
ProcessManager: () => processManager,
}));
......@@ -570,7 +570,7 @@ void main() {
.writeAsStringSync('file:///a.dart');
},
));
await Dart2JSTarget(WebRendererMode.autoDetect).build(environment);
await Dart2JSTarget(WebRendererMode.auto).build(environment);
expect(environment.buildDir.childFile('dart2js.d'), exists);
final Depfile depfile = depfileService.parse(environment.buildDir.childFile('dart2js.d'));
......@@ -617,7 +617,7 @@ void main() {
]
));
await Dart2JSTarget(WebRendererMode.autoDetect).build(environment);
await Dart2JSTarget(WebRendererMode.auto).build(environment);
}, overrides: <Type, Generator>{
ProcessManager: () => processManager,
}));
......@@ -651,7 +651,7 @@ void main() {
]
));
await Dart2JSTarget(WebRendererMode.autoDetect).build(environment);
await Dart2JSTarget(WebRendererMode.auto).build(environment);
}, overrides: <Type, Generator>{
ProcessManager: () => processManager,
}));
......@@ -693,7 +693,7 @@ void main() {
]
));
await Dart2JSTarget(WebRendererMode.autoDetect).build(environment);
await Dart2JSTarget(WebRendererMode.auto).build(environment);
}, overrides: <Type, Generator>{
ProcessManager: () => processManager,
}));
......@@ -922,7 +922,7 @@ void main() {
environment.outputDir.childDirectory('a').childFile('a.txt')
..createSync(recursive: true)
..writeAsStringSync('A');
await WebServiceWorker(globals.fs, WebRendererMode.autoDetect, isWasm: false).build(environment);
await WebServiceWorker(globals.fs, WebRendererMode.auto, isWasm: false).build(environment);
expect(environment.outputDir.childFile('flutter_service_worker.js'), exists);
// Contains file hash.
......@@ -941,7 +941,7 @@ void main() {
environment.outputDir
.childFile('index.html')
.createSync(recursive: true);
await WebServiceWorker(globals.fs, WebRendererMode.autoDetect, isWasm: false).build(environment);
await WebServiceWorker(globals.fs, WebRendererMode.auto, isWasm: false).build(environment);
expect(environment.outputDir.childFile('flutter_service_worker.js'), exists);
// Contains file hash for both `/` and index.html.
......@@ -959,7 +959,7 @@ void main() {
environment.outputDir
.childFile('main.dart.js.map')
.createSync(recursive: true);
await WebServiceWorker(globals.fs, WebRendererMode.autoDetect, isWasm: false).build(environment);
await WebServiceWorker(globals.fs, WebRendererMode.auto, isWasm: false).build(environment);
// No caching of source maps.
expect(environment.outputDir.childFile('flutter_service_worker.js').readAsStringSync(),
......@@ -991,7 +991,7 @@ void main() {
..createSync(recursive: true)
..writeAsStringSync('OL');
await WebBuiltInAssets(globals.fs, WebRendererMode.autoDetect, isWasm: false).build(environment);
await WebBuiltInAssets(globals.fs, WebRendererMode.auto, isWasm: false).build(environment);
// No caching of source maps.
final String fileGeneratorsPath = environment.artifacts
......@@ -1008,7 +1008,7 @@ void main() {
globals.fs.file('bin/cache/flutter_web_sdk/canvaskit/canvaskit.wasm')
.createSync(recursive: true);
await WebBuiltInAssets(globals.fs, WebRendererMode.autoDetect, isWasm: true).build(environment);
await WebBuiltInAssets(globals.fs, WebRendererMode.auto, isWasm: true).build(environment);
expect(environment.outputDir.childFile('main.dart.js').existsSync(), true);
expect(environment.outputDir.childDirectory('canvaskit')
......@@ -1021,7 +1021,7 @@ void main() {
..createSync(recursive: true);
canvasKitInput.writeAsStringSync('foo', flush: true);
await WebBuiltInAssets(globals.fs, WebRendererMode.autoDetect, isWasm: true).build(environment);
await WebBuiltInAssets(globals.fs, WebRendererMode.auto, isWasm: true).build(environment);
final File canvasKitOutputBefore = environment.outputDir.childDirectory('canvaskit')
.childFile('canvaskit.wasm');
......@@ -1030,7 +1030,7 @@ void main() {
canvasKitInput.writeAsStringSync('bar', flush: true);
await WebBuiltInAssets(globals.fs, WebRendererMode.autoDetect, isWasm: true).build(environment);
await WebBuiltInAssets(globals.fs, WebRendererMode.auto, isWasm: true).build(environment);
final File canvasKitOutputAfter = environment.outputDir.childDirectory('canvaskit')
.childFile('canvaskit.wasm');
......
......@@ -39,7 +39,7 @@ void main() {
TestBuildSystem.all(BuildResult(success: true), (Target target, Environment environment) {
final WebServiceWorker webServiceWorker = target as WebServiceWorker;
expect(webServiceWorker.isWasm, isTrue, reason: 'should be wasm');
expect(webServiceWorker.webRenderer, WebRendererMode.autoDetect);
expect(webServiceWorker.webRenderer, WebRendererMode.auto);
expect(environment.defines, <String, String>{
'TargetFile': 'target',
......
......@@ -1052,7 +1052,7 @@ void main() {
await webDevFS.create();
expect(webDevFS.webAssetServer.webRenderer, WebRendererMode.autoDetect);
expect(webDevFS.webAssetServer.webRenderer, WebRendererMode.auto);
await webDevFS.destroy();
}));
......
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