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