Unverified Commit d05d4343 authored by Jason Simmons's avatar Jason Simmons Committed by GitHub

Provide a flag for controlling the dart2js optimization level when building...

Provide a flag for controlling the dart2js optimization level when building for web targets (#101945)
parent df8d0eac
...@@ -63,7 +63,10 @@ class BuildWebCommand extends BuildSubCommand { ...@@ -63,7 +63,10 @@ class BuildWebCommand extends BuildSubCommand {
'The value has to start and end with a slash "/". ' 'The value has to start and end with a slash "/". '
'For more information: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/base' 'For more information: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/base'
); );
argParser.addOption('dart2js-optimization',
help: 'Sets the optimization level used for Dart compilation to JavaScript. '
'Valid values range from O0 to O4.'
);
} }
@override @override
...@@ -120,6 +123,7 @@ class BuildWebCommand extends BuildSubCommand { ...@@ -120,6 +123,7 @@ class BuildWebCommand extends BuildSubCommand {
boolArg('source-maps'), boolArg('source-maps'),
boolArg('native-null-assertions'), boolArg('native-null-assertions'),
baseHref, baseHref,
stringArg('dart2js-optimization'),
); );
return FlutterCommandResult.success(); return FlutterCommandResult.success();
} }
......
...@@ -302,6 +302,7 @@ class ResidentWebRunner extends ResidentRunner { ...@@ -302,6 +302,7 @@ class ResidentWebRunner extends ResidentRunner {
true, true,
debuggingOptions.nativeNullAssertions, debuggingOptions.nativeNullAssertions,
null, null,
null,
); );
} }
await device.device.startApp( await device.device.startApp(
...@@ -375,6 +376,7 @@ class ResidentWebRunner extends ResidentRunner { ...@@ -375,6 +376,7 @@ class ResidentWebRunner extends ResidentRunner {
true, true,
debuggingOptions.nativeNullAssertions, debuggingOptions.nativeNullAssertions,
kBaseHref, kBaseHref,
null,
); );
} on ToolExit { } on ToolExit {
return OperationResult(1, 'Failed to recompile application.'); return OperationResult(1, 'Failed to recompile application.');
......
...@@ -25,6 +25,7 @@ Future<void> buildWeb( ...@@ -25,6 +25,7 @@ Future<void> buildWeb(
bool sourceMaps, bool sourceMaps,
bool nativeNullAssertions, bool nativeNullAssertions,
String? baseHref, String? baseHref,
String? dart2jsOptimization,
) async { ) async {
final bool hasWebPlugins = (await findPlugins(flutterProject)) final bool hasWebPlugins = (await findPlugins(flutterProject))
.any((Plugin p) => p.platforms.containsKey(WebPlugin.kConfigKey)); .any((Plugin p) => p.platforms.containsKey(WebPlugin.kConfigKey));
...@@ -51,6 +52,8 @@ Future<void> buildWeb( ...@@ -51,6 +52,8 @@ Future<void> buildWeb(
kNativeNullAssertions: nativeNullAssertions.toString(), kNativeNullAssertions: nativeNullAssertions.toString(),
if (serviceWorkerStrategy != null) if (serviceWorkerStrategy != null)
kServiceWorkerStrategy: serviceWorkerStrategy, kServiceWorkerStrategy: serviceWorkerStrategy,
if (dart2jsOptimization != null)
kDart2jsOptimization: dart2jsOptimization,
...buildInfo.toBuildSystemEnvironment(), ...buildInfo.toBuildSystemEnvironment(),
}, },
artifacts: globals.artifacts!, artifacts: globals.artifacts!,
......
...@@ -90,7 +90,7 @@ void main() { ...@@ -90,7 +90,7 @@ void main() {
final BuildCommand buildCommand = BuildCommand(); final BuildCommand buildCommand = BuildCommand();
final CommandRunner<void> runner = createTestCommandRunner(buildCommand); final CommandRunner<void> runner = createTestCommandRunner(buildCommand);
setupFileSystemForEndToEndTest(fileSystem); setupFileSystemForEndToEndTest(fileSystem);
await runner.run(<String>['build', 'web', '--no-pub', '--dart-define=foo=a']); await runner.run(<String>['build', 'web', '--no-pub', '--dart-define=foo=a', '--dart2js-optimization=O3']);
expect(fileSystem.file(fileSystem.path.join('lib', 'generated_plugin_registrant.dart')).existsSync(), true); expect(fileSystem.file(fileSystem.path.join('lib', 'generated_plugin_registrant.dart')).existsSync(), true);
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
...@@ -106,6 +106,7 @@ void main() { ...@@ -106,6 +106,7 @@ void main() {
'SourceMaps': 'false', 'SourceMaps': 'false',
'NativeNullAssertions': 'true', 'NativeNullAssertions': 'true',
'ServiceWorkerStrategy': 'offline-first', 'ServiceWorkerStrategy': 'offline-first',
'Dart2jsOptimization': 'O3',
'BuildMode': 'release', 'BuildMode': 'release',
'DartDefines': 'Zm9vPWE=,RkxVVFRFUl9XRUJfQVVUT19ERVRFQ1Q9dHJ1ZQ==', 'DartDefines': 'Zm9vPWE=,RkxVVFRFUl9XRUJfQVVUT19ERVRFQ1Q9dHJ1ZQ==',
'DartObfuscation': 'false', 'DartObfuscation': 'false',
......
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