Unverified Commit 0cd6f1fb authored by Kevin Moore's avatar Kevin Moore Committed by GitHub

[flutter_tool] advertise the default value for --dart2js-optimization (#121621)

[flutter_tool] advertise the default value for --dart2js-optimization
parent b10f25c6
...@@ -39,6 +39,11 @@ const String kHasWebPlugins = 'HasWebPlugins'; ...@@ -39,6 +39,11 @@ const String kHasWebPlugins = 'HasWebPlugins';
/// Valid values are O1 (lowest, profile default) to O4 (highest, release default). /// Valid values are O1 (lowest, profile default) to O4 (highest, release default).
const String kDart2jsOptimization = 'Dart2jsOptimization'; const String kDart2jsOptimization = 'Dart2jsOptimization';
/// The default optimization level for dart2js.
///
/// Maps to [kDart2jsOptimization].
const String kDart2jsDefaultOptimizationLevel = 'O4';
/// If `--dump-info` should be passed to dart2js. /// If `--dump-info` should be passed to dart2js.
const String kDart2jsDumpInfo = 'Dart2jsDumpInfo'; const String kDart2jsDumpInfo = 'Dart2jsDumpInfo';
...@@ -235,7 +240,7 @@ class Dart2JSTarget extends Dart2WebTarget { ...@@ -235,7 +240,7 @@ class Dart2JSTarget extends Dart2WebTarget {
throw Exception(_collectOutput(kernelResult)); throw Exception(_collectOutput(kernelResult));
} }
final String? dart2jsOptimization = environment.defines[kDart2jsOptimization]; final String dart2jsOptimization = environment.defines[kDart2jsOptimization] ?? kDart2jsDefaultOptimizationLevel;
final bool dumpInfo = environment.defines[kDart2jsDumpInfo] == 'true'; final bool dumpInfo = environment.defines[kDart2jsDumpInfo] == 'true';
final bool noFrequencyBasedMinification = environment.defines[kDart2jsNoFrequencyBasedMinification] == 'true'; final bool noFrequencyBasedMinification = environment.defines[kDart2jsNoFrequencyBasedMinification] == 'true';
final File outputJSFile = environment.buildDir.childFile('main.dart.js'); final File outputJSFile = environment.buildDir.childFile('main.dart.js');
...@@ -243,7 +248,7 @@ class Dart2JSTarget extends Dart2WebTarget { ...@@ -243,7 +248,7 @@ class Dart2JSTarget extends Dart2WebTarget {
final ProcessResult javaScriptResult = await environment.processManager.run(<String>[ final ProcessResult javaScriptResult = await environment.processManager.run(<String>[
...sharedCommandOptions, ...sharedCommandOptions,
if (dart2jsOptimization != null) '-$dart2jsOptimization' else '-O4', '-$dart2jsOptimization',
if (buildMode == BuildMode.profile) '--no-minify', if (buildMode == BuildMode.profile) '--no-minify',
if (dumpInfo) '--dump-info', if (dumpInfo) '--dump-info',
if (noFrequencyBasedMinification) '--no-frequency-based-minification', if (noFrequencyBasedMinification) '--no-frequency-based-minification',
......
...@@ -73,7 +73,8 @@ class BuildWebCommand extends BuildSubCommand { ...@@ -73,7 +73,8 @@ class BuildWebCommand extends BuildSubCommand {
); );
argParser.addOption('dart2js-optimization', argParser.addOption('dart2js-optimization',
help: 'Sets the optimization level used for Dart compilation to JavaScript. ' help: 'Sets the optimization level used for Dart compilation to JavaScript. '
'Valid values range from O0 to O4.' 'Valid values range from O0 to O4.',
defaultsTo: kDart2jsDefaultOptimizationLevel
); );
argParser.addFlag('dump-info', negatable: false, argParser.addFlag('dump-info', negatable: false,
help: 'Passes "--dump-info" to the Javascript compiler which generates ' help: 'Passes "--dump-info" to the Javascript compiler which generates '
...@@ -147,7 +148,7 @@ class BuildWebCommand extends BuildSubCommand { ...@@ -147,7 +148,7 @@ class BuildWebCommand extends BuildSubCommand {
boolArgDeprecated('native-null-assertions'), boolArgDeprecated('native-null-assertions'),
boolArgDeprecated('wasm'), boolArgDeprecated('wasm'),
baseHref: baseHref, baseHref: baseHref,
dart2jsOptimization: stringArgDeprecated('dart2js-optimization'), dart2jsOptimization: stringArgDeprecated('dart2js-optimization') ?? kDart2jsDefaultOptimizationLevel,
outputDirectoryPath: outputDirectoryPath, outputDirectoryPath: outputDirectoryPath,
dumpInfo: boolArgDeprecated('dump-info'), dumpInfo: boolArgDeprecated('dump-info'),
noFrequencyBasedMinification: boolArgDeprecated('no-frequency-based-minification'), noFrequencyBasedMinification: boolArgDeprecated('no-frequency-based-minification'),
......
...@@ -18,6 +18,8 @@ import '../plugins.dart'; ...@@ -18,6 +18,8 @@ import '../plugins.dart';
import '../project.dart'; import '../project.dart';
import 'migrations/scrub_generated_plugin_registrant.dart'; import 'migrations/scrub_generated_plugin_registrant.dart';
export '../build_system/targets/web.dart' show kDart2jsDefaultOptimizationLevel;
Future<void> buildWeb( Future<void> buildWeb(
FlutterProject flutterProject, FlutterProject flutterProject,
String target, String target,
...@@ -27,7 +29,7 @@ Future<void> buildWeb( ...@@ -27,7 +29,7 @@ Future<void> buildWeb(
bool sourceMaps, bool sourceMaps,
bool nativeNullAssertions, bool nativeNullAssertions,
bool isWasm, { bool isWasm, {
String? dart2jsOptimization, String dart2jsOptimization = kDart2jsDefaultOptimizationLevel,
String? baseHref, String? baseHref,
bool dumpInfo = false, bool dumpInfo = false,
bool noFrequencyBasedMinification = false, bool noFrequencyBasedMinification = false,
...@@ -68,8 +70,7 @@ Future<void> buildWeb( ...@@ -68,8 +70,7 @@ Future<void> buildWeb(
kSourceMapsEnabled: sourceMaps.toString(), kSourceMapsEnabled: sourceMaps.toString(),
kNativeNullAssertions: nativeNullAssertions.toString(), kNativeNullAssertions: nativeNullAssertions.toString(),
kServiceWorkerStrategy: serviceWorkerStrategy, kServiceWorkerStrategy: serviceWorkerStrategy,
if (dart2jsOptimization != null) kDart2jsOptimization: dart2jsOptimization,
kDart2jsOptimization: dart2jsOptimization,
kDart2jsDumpInfo: dumpInfo.toString(), kDart2jsDumpInfo: dumpInfo.toString(),
kDart2jsNoFrequencyBasedMinification: noFrequencyBasedMinification.toString(), kDart2jsNoFrequencyBasedMinification: noFrequencyBasedMinification.toString(),
...buildInfo.toBuildSystemEnvironment(), ...buildInfo.toBuildSystemEnvironment(),
......
...@@ -183,6 +183,7 @@ void main() { ...@@ -183,6 +183,7 @@ void main() {
'ServiceWorkerStrategy': 'offline-first', 'ServiceWorkerStrategy': 'offline-first',
'Dart2jsDumpInfo': 'false', 'Dart2jsDumpInfo': 'false',
'Dart2jsNoFrequencyBasedMinification': 'false', 'Dart2jsNoFrequencyBasedMinification': 'false',
'Dart2jsOptimization': 'O4',
'BuildMode': 'release', 'BuildMode': 'release',
'DartDefines': 'RkxVVFRFUl9XRUJfQVVUT19ERVRFQ1Q9dHJ1ZQ==', 'DartDefines': '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