Unverified Commit b76b82aa authored by Christopher Fujino's avatar Christopher Fujino Committed by GitHub

[flutter_tools] disallow -O0 for flutter build web (#134185)

Fixes https://github.com/flutter/flutter/issues/133404.

Per the dart2js team on the linked issue, `-O0` is not intended for end users, but more for actual debugging/development of the compiler.
parent adaf78a6
...@@ -72,8 +72,9 @@ class BuildWebCommand extends BuildSubCommand { ...@@ -72,8 +72,9 @@ 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 O1 to O4.',
defaultsTo: JsCompilerConfig.kDart2jsDefaultOptimizationLevel defaultsTo: JsCompilerConfig.kDart2jsDefaultOptimizationLevel,
allowed: const <String>['O1', 'O2', 'O3', 'O4'],
); );
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 '
......
...@@ -142,6 +142,52 @@ void main() { ...@@ -142,6 +142,52 @@ void main() {
}), }),
}); });
testUsingContext('Does not allow -O0 optimization level', () async {
final BuildCommand buildCommand = BuildCommand(
androidSdk: FakeAndroidSdk(),
buildSystem: TestBuildSystem.all(BuildResult(success: true)),
fileSystem: fileSystem,
logger: BufferLogger.test(),
osUtils: FakeOperatingSystemUtils(),
);
final CommandRunner<void> runner = createTestCommandRunner(buildCommand);
setupFileSystemForEndToEndTest(fileSystem);
await expectLater(
() => runner.run(<String>[
'build',
'web',
'--no-pub', '--no-web-resources-cdn', '--dart-define=foo=a', '--dart2js-optimization=O0']),
throwsUsageException(message: '"O0" is not an allowed value for option "dart2js-optimization"'),
);
final Directory buildDir = fileSystem.directory(fileSystem.path.join('build', 'web'));
expect(buildDir.existsSync(), isFalse);
}, overrides: <Type, Generator>{
Platform: () => fakePlatform,
FileSystem: () => fileSystem,
FeatureFlags: () => TestFeatureFlags(isWebEnabled: true),
ProcessManager: () => FakeProcessManager.any(),
BuildSystem: () => TestBuildSystem.all(BuildResult(success: true), (Target target, Environment environment) {
expect(environment.defines, <String, String>{
'TargetFile': 'lib/main.dart',
'HasWebPlugins': 'true',
'cspMode': 'false',
'SourceMaps': 'false',
'NativeNullAssertions': 'true',
'ServiceWorkerStrategy': 'offline-first',
'Dart2jsDumpInfo': 'false',
'Dart2jsNoFrequencyBasedMinification': 'false',
'Dart2jsOptimization': 'O3',
'BuildMode': 'release',
'DartDefines': 'Zm9vPWE=,RkxVVFRFUl9XRUJfQVVUT19ERVRFQ1Q9dHJ1ZQ==',
'DartObfuscation': 'false',
'TrackWidgetCreation': 'false',
'TreeShakeIcons': 'true',
});
}),
});
testUsingContext('Setup for a web build with a user specified output directory', testUsingContext('Setup for a web build with a user specified output directory',
() async { () async {
final BuildCommand buildCommand = BuildCommand( final BuildCommand buildCommand = BuildCommand(
......
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