Default --no-tree-shake-icons to false for 'flutter build bundle' (#82773)

This commit is contained in:
Jenn Magder 2021-05-18 20:34:04 -07:00 committed by GitHub
parent 2acd0007d6
commit 8f536ec17b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 111 additions and 1 deletions

View File

@ -16,7 +16,6 @@ import 'build.dart';
class BuildBundleCommand extends BuildSubCommand { class BuildBundleCommand extends BuildSubCommand {
BuildBundleCommand({bool verboseHelp = false, this.bundleBuilder}) { BuildBundleCommand({bool verboseHelp = false, this.bundleBuilder}) {
addTreeShakeIconsFlag();
usesTargetOption(); usesTargetOption();
usesFilesystemOptions(hide: !verboseHelp); usesFilesystemOptions(hide: !verboseHelp);
usesBuildNumberOption(); usesBuildNumberOption();
@ -48,6 +47,13 @@ class BuildBundleCommand extends BuildSubCommand {
defaultsTo: getAssetBuildDirectory(), defaultsTo: getAssetBuildDirectory(),
help: 'The output directory for the kernel_blob.bin file, the native snapshet, the assets, etc. ' help: 'The output directory for the kernel_blob.bin file, the native snapshet, the assets, etc. '
'Can be used to redirect the output when driving the Flutter toolchain from another build system.', 'Can be used to redirect the output when driving the Flutter toolchain from another build system.',
)
..addFlag(
'tree-shake-icons',
negatable: true,
defaultsTo: false,
hide: !verboseHelp,
help: '(deprecated) Icon font tree shaking is not supported by this command.',
); );
usesPubOption(); usesPubOption();
usesTrackWidgetCreation(verboseHelp: verboseHelp); usesTrackWidgetCreation(verboseHelp: verboseHelp);
@ -81,6 +87,14 @@ class BuildBundleCommand extends BuildSubCommand {
); );
} }
@override
Future<void> validateCommand() async {
if (argResults['tree-shake-icons'] as bool) {
throwToolExit('The "--tree-shake-icons" flag is deprecated for "build bundle" and will be removed in a future version of Flutter.');
}
return super.validateCommand();
}
@override @override
Future<FlutterCommandResult> runCommand() async { Future<FlutterCommandResult> runCommand() async {
final String targetPlatform = stringArg('target-platform'); final String targetPlatform = stringArg('target-platform');

View File

@ -132,6 +132,24 @@ void main() {
FeatureFlags: () => TestFeatureFlags(isMacOSEnabled: false), FeatureFlags: () => TestFeatureFlags(isMacOSEnabled: false),
}); });
testUsingContext('bundle --tree-shake-icons fails', () async {
globals.fs.file('lib/main.dart').createSync(recursive: true);
globals.fs.file('pubspec.yaml').createSync();
globals.fs.file('.packages').createSync();
final CommandRunner<void> runner = createTestCommandRunner(BuildBundleCommand()
..bundleBuilder = FakeBundleBuilder());
expect(() => runner.run(<String>[
'bundle',
'--no-pub',
'--release',
'--tree-shake-icons',
]), throwsToolExit(message: 'tree-shake-icons'));
}, overrides: <Type, Generator>{
FileSystem: () => MemoryFileSystem.test(),
ProcessManager: () => FakeProcessManager.any(),
});
testUsingContext('bundle can build for Windows if feature is enabled', () async { testUsingContext('bundle can build for Windows if feature is enabled', () async {
globals.fs.file('lib/main.dart').createSync(recursive: true); globals.fs.file('lib/main.dart').createSync(recursive: true);
globals.fs.file('pubspec.yaml').createSync(); globals.fs.file('pubspec.yaml').createSync();
@ -369,6 +387,84 @@ void main() {
FileSystem: () => MemoryFileSystem.test(), FileSystem: () => MemoryFileSystem.test(),
ProcessManager: () => FakeProcessManager.any(), ProcessManager: () => FakeProcessManager.any(),
}); });
testUsingContext('passes profile options through', () async {
globals.fs.file('lib/main.dart').createSync(recursive: true);
globals.fs.file('pubspec.yaml').createSync();
globals.fs.file('.packages').createSync();
final CommandRunner<void> runner = createTestCommandRunner(BuildBundleCommand());
await runner.run(<String>[
'bundle',
'--no-pub',
'--profile',
'--dart-define=foo=bar',
'--target-platform=android-arm',
'--track-widget-creation',
'--filesystem-scheme=org-dartlang-root',
'--filesystem-root=test1,test2',
'--extra-gen-snapshot-options=--testflag,--testflag2',
'--extra-front-end-options=--testflagFront,--testflagFront2',
]);
}, overrides: <Type, Generator>{
BuildSystem: () => TestBuildSystem.all(BuildResult(success: true), (Target target, Environment environment) {
expect(environment.defines, <String, String>{
kBuildMode: 'profile',
kTargetPlatform: 'android-arm',
kTargetFile: globals.fs.path.join('lib', 'main.dart'),
kDartDefines: 'Zm9vPWJhcg==',
kTrackWidgetCreation: 'true',
kFileSystemScheme: 'org-dartlang-root',
kFileSystemRoots: 'test1,test2',
kExtraGenSnapshotOptions: '--testflag,--testflag2',
kExtraFrontEndOptions: '--testflagFront,--testflagFront2',
kIconTreeShakerFlag: 'false',
kDeferredComponents: 'false',
kDartObfuscation: 'false',
});
}),
FileSystem: () => MemoryFileSystem.test(),
ProcessManager: () => FakeProcessManager.any(),
});
testUsingContext('passes release options through', () async {
globals.fs.file('lib/main.dart').createSync(recursive: true);
globals.fs.file('pubspec.yaml').createSync();
globals.fs.file('.packages').createSync();
final CommandRunner<void> runner = createTestCommandRunner(BuildBundleCommand());
await runner.run(<String>[
'bundle',
'--no-pub',
'--release',
'--dart-define=foo=bar',
'--target-platform=android-arm',
'--track-widget-creation',
'--filesystem-scheme=org-dartlang-root',
'--filesystem-root=test1,test2',
'--extra-gen-snapshot-options=--testflag,--testflag2',
'--extra-front-end-options=--testflagFront,--testflagFront2',
]);
}, overrides: <Type, Generator>{
BuildSystem: () => TestBuildSystem.all(BuildResult(success: true), (Target target, Environment environment) {
expect(environment.defines, <String, String>{
kBuildMode: 'release',
kTargetPlatform: 'android-arm',
kTargetFile: globals.fs.path.join('lib', 'main.dart'),
kDartDefines: 'Zm9vPWJhcg==',
kTrackWidgetCreation: 'true',
kFileSystemScheme: 'org-dartlang-root',
kFileSystemRoots: 'test1,test2',
kExtraGenSnapshotOptions: '--testflag,--testflag2',
kExtraFrontEndOptions: '--testflagFront,--testflagFront2',
kIconTreeShakerFlag: 'false',
kDeferredComponents: 'false',
kDartObfuscation: 'false',
});
}),
FileSystem: () => MemoryFileSystem.test(),
ProcessManager: () => FakeProcessManager.any(),
});
} }
class FakeBundleBuilder extends Fake implements BundleBuilder { class FakeBundleBuilder extends Fake implements BundleBuilder {