Unverified Commit c2d1203f authored by Jenn Magder's avatar Jenn Magder Committed by GitHub

Remove deprecated 'flutter build aot' (#70898)

parent e5118376
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:meta/meta.dart';
import 'base/common.dart';
import 'base/logger.dart';
import 'build_info.dart';
import 'build_system/build_system.dart';
import 'build_system/targets/common.dart';
import 'build_system/targets/icon_tree_shaker.dart';
import 'build_system/targets/ios.dart';
import 'cache.dart';
import 'globals.dart' as globals;
import 'ios/bitcode.dart';
import 'macos/xcode.dart';
import 'project.dart';
/// Builds AOT snapshots given a platform, build mode and a path to a Dart
/// library.
class AotBuilder {
Future<void> build({
@required TargetPlatform platform,
@required String outputPath,
@required BuildInfo buildInfo,
@required String mainDartFile,
bool bitcode = kBitcodeEnabledDefault,
bool quiet = true,
Iterable<DarwinArch> iosBuildArchs,
bool reportTimings = false,
}) async {
if (platform == null) {
throwToolExit('No AOT build platform specified');
}
iosBuildArchs ??= defaultIOSArchsForSdk(SdkType.iPhone);
Target target;
bool expectSo = false;
switch (platform) {
case TargetPlatform.android:
case TargetPlatform.darwin_x64:
case TargetPlatform.linux_x64:
case TargetPlatform.windows_x64:
case TargetPlatform.fuchsia_arm64:
case TargetPlatform.tester:
case TargetPlatform.web_javascript:
case TargetPlatform.android_x86:
throwToolExit('$platform is not supported in AOT.');
break;
case TargetPlatform.fuchsia_x64:
throwToolExit(
"To build release for fuchsia, use 'flutter build fuchsia --release'"
);
break;
case TargetPlatform.ios:
target = buildInfo.isRelease
? const AotAssemblyRelease()
: const AotAssemblyProfile();
break;
case TargetPlatform.android_arm:
case TargetPlatform.android_arm64:
case TargetPlatform.android_x64:
expectSo = true;
target = buildInfo.isRelease
? const AotElfRelease(TargetPlatform.android_arm)
: const AotElfProfile(TargetPlatform.android_arm);
}
Status status;
if (!quiet) {
final String typeName = globals.artifacts.getEngineType(platform, buildInfo.mode);
status = globals.logger.startProgress(
'Building AOT snapshot in ${getFriendlyModeName(buildInfo.mode)} mode ($typeName)...',
);
}
final Environment environment = Environment(
projectDir: globals.fs.currentDirectory,
outputDir: globals.fs.directory(outputPath),
buildDir: FlutterProject.current().dartTool.childDirectory('flutter_build'),
cacheDir: null,
flutterRootDir: globals.fs.directory(Cache.flutterRoot),
engineVersion: globals.artifacts.isLocalEngine
? null
: globals.flutterVersion.engineRevision,
defines: <String, String>{
kTargetFile: mainDartFile ?? globals.fs.path.join('lib', 'main.dart'),
kBuildMode: getNameForBuildMode(buildInfo.mode),
kTargetPlatform: getNameForTargetPlatform(platform),
kIconTreeShakerFlag: buildInfo.treeShakeIcons.toString(),
kDartDefines: buildInfo.dartDefines.join(','),
kBitcodeFlag: bitcode.toString(),
if (buildInfo?.extraGenSnapshotOptions?.isNotEmpty ?? false)
kExtraGenSnapshotOptions: buildInfo.extraGenSnapshotOptions.join(','),
if (buildInfo?.extraFrontEndOptions?.isNotEmpty ?? false)
kExtraFrontEndOptions: buildInfo.extraFrontEndOptions.join(','),
if (platform == TargetPlatform.ios)
kIosArchs: iosBuildArchs.map(getNameForDarwinArch).join(' ')
},
artifacts: globals.artifacts,
fileSystem: globals.fs,
logger: globals.logger,
processManager: globals.processManager,
);
final BuildResult result = await globals.buildSystem.build(target, environment);
status?.stop();
if (!result.success) {
for (final ExceptionMeasurement measurement in result.exceptions.values) {
globals.printError(measurement.exception.toString());
}
throwToolExit('The aot build failed.');
}
// This print output is used by the dart team for build benchmarks.
if (reportTimings) {
final PerformanceMeasurement kernel = result.performance['kernel_snapshot'];
PerformanceMeasurement aot;
if (expectSo) {
aot = result.performance.values.firstWhere(
(PerformanceMeasurement measurement) => measurement.analyticsName == 'android_aot');
} else {
aot = result.performance.values.firstWhere(
(PerformanceMeasurement measurement) => measurement.analyticsName == 'ios_aot');
}
globals.printStatus('frontend(CompileTime): ${kernel.elapsedMilliseconds} ms.');
globals.printStatus('snapshot(CompileTime): ${aot.elapsedMilliseconds} ms.');
}
if (expectSo) {
environment.buildDir.childFile('app.so')
.copySync(globals.fs.path.join(outputPath, 'app.so'));
} else {
globals.fs.directory(globals.fs.path.join(outputPath, 'App.framework'))
.createSync(recursive: true);
environment.buildDir.childDirectory('App.framework').childFile('App')
.copySync(globals.fs.path.join(outputPath, 'App.framework', 'App'));
}
final String builtMessage = 'Built to $outputPath${globals.fs.path.separator}.';
if (quiet) {
globals.printTrace(builtMessage);
} else {
globals.printStatus(builtMessage);
}
return;
}
}
......@@ -8,7 +8,6 @@ import '../commands/build_windows.dart';
import '../globals.dart' as globals;
import '../runner/flutter_command.dart';
import 'build_aar.dart';
import 'build_aot.dart';
import 'build_apk.dart';
import 'build_appbundle.dart';
import 'build_bundle.dart';
......@@ -22,7 +21,6 @@ class BuildCommand extends FlutterCommand {
addSubcommand(BuildAarCommand(verboseHelp: verboseHelp));
addSubcommand(BuildApkCommand(verboseHelp: verboseHelp));
addSubcommand(BuildAppBundleCommand(verboseHelp: verboseHelp));
addSubcommand(BuildAotCommand());
addSubcommand(BuildIOSCommand(verboseHelp: verboseHelp));
addSubcommand(BuildIOSFrameworkCommand(
buildSystem: globals.buildSystem,
......
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import '../aot.dart';
import '../base/common.dart';
import '../build_info.dart';
import '../ios/bitcode.dart';
import '../resident_runner.dart';
import '../runner/flutter_command.dart';
import 'build.dart';
/// Builds AOT executables into platform specific library containers.
class BuildAotCommand extends BuildSubCommand with TargetPlatformBasedDevelopmentArtifacts {
BuildAotCommand({this.aotBuilder}) {
addTreeShakeIconsFlag();
usesTargetOption();
addBuildModeFlags();
usesPubOption();
usesDartDefineOption();
usesExtraDartFlagOptions();
argParser
..addOption('output-dir', defaultsTo: getAotBuildDirectory())
..addOption('target-platform',
defaultsTo: 'android-arm',
allowed: <String>['android-arm', 'android-arm64', 'ios', 'android-x64'],
)
..addFlag('quiet', defaultsTo: false)
..addMultiOption('ios-arch',
splitCommas: true,
defaultsTo: <String>[getNameForDarwinArch(DarwinArch.arm64)],
allowed: DarwinArch.values.map<String>(getNameForDarwinArch),
help: 'iOS architectures to build.',
)
..addFlag('bitcode',
defaultsTo: kBitcodeEnabledDefault,
help: 'Build the AOT bundle with bitcode. Requires a compatible bitcode engine.',
hide: true,
)
..addFlag('report-timings', hide: true);
}
AotBuilder aotBuilder;
@override
final String name = 'aot';
// TODO(jonahwilliams): remove after https://github.com/flutter/flutter/issues/49562 is resolved.
@override
bool get deprecated => true;
@override
final String description = "(deprecated) Build an ahead-of-time compiled snapshot of your app's Dart code.";
@override
Future<FlutterCommandResult> runCommand() async {
final String targetPlatform = stringArg('target-platform');
final TargetPlatform platform = getTargetPlatformForName(targetPlatform);
final String outputPath = stringArg('output-dir') ?? getAotBuildDirectory();
final BuildInfo buildInfo = await getBuildInfo();
if (platform == null) {
throwToolExit('Unknown platform: $targetPlatform');
}
aotBuilder ??= AotBuilder();
await aotBuilder.build(
platform: platform,
outputPath: outputPath,
buildInfo: buildInfo,
mainDartFile: findMainDartFile(targetFile),
bitcode: boolArg('bitcode'),
quiet: boolArg('quiet'),
iosBuildArchs: stringsArg('ios-arch').map<DarwinArch>(getIOSArchForName),
reportTimings: boolArg('report-timings'),
);
return FlutterCommandResult.success();
}
}
......@@ -132,23 +132,6 @@ void main() {
expect(result.stderr, contains('Target file')); // Target file not found, but different paths on Windows and Linux/macOS.
});
testWithoutContext('flutter build aot is deprecated', () async {
final String flutterBin = fileSystem.path.join(getFlutterRoot(), 'bin', 'flutter');
final ProcessResult result = await processManager.run(<String>[
flutterBin,
...getLocalEngineArguments(),
'build',
'-h',
'-v',
]);
// Deprecated.
expect(result.stdout, isNot(contains('aot')));
// Only printed by verbose tool.
expect(result.stdout, isNot(contains('exiting with code 0')));
});
testWithoutContext('flutter --version --machine outputs JSON with flutterRoot', () async {
final String flutterBin = fileSystem.path.join(getFlutterRoot(), 'bin', 'flutter');
final ProcessResult result = await processManager.run(<String>[
......
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