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();
}
}
// 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:file/memory.dart';
import 'package:flutter_tools/src/aot.dart';
import 'package:flutter_tools/src/artifacts.dart';
import 'package:flutter_tools/src/base/process.dart';
import 'package:flutter_tools/src/build_info.dart';
import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/build_system/build_system.dart';
import 'package:flutter_tools/src/ios/bitcode.dart';
import 'package:flutter_tools/src/ios/plist_parser.dart';
import 'package:flutter_tools/src/macos/xcode.dart';
import 'package:mockito/mockito.dart';
import 'package:process/process.dart';
import 'package:flutter_tools/src/globals.dart' as globals;
import '../../src/common.dart';
import '../../src/context.dart';
import '../../src/mocks.dart';
void main() {
MockXcode mockXcode;
MemoryFileSystem memoryFileSystem;
MockProcessManager mockProcessManager;
MockPlistUtils mockPlistUtils;
setUp(() {
mockXcode = MockXcode();
memoryFileSystem = MemoryFileSystem(style: FileSystemStyle.posix);
mockProcessManager = MockProcessManager();
mockPlistUtils = MockPlistUtils();
});
testUsingContext('build aot validates existence of Flutter.framework in engine', () async {
await expectToolExitLater(
validateBitcode(BuildMode.release, TargetPlatform.ios),
equals('Flutter.framework not found at ios_profile/Flutter.framework'),
);
}, overrides: <Type, Generator>{
Artifacts: () => LocalEngineArtifacts('ios_profile', 'host_profile',
fileSystem: memoryFileSystem,
cache: globals.cache,
platform: globals.platform,
processManager: mockProcessManager,
),
FileSystem: () => memoryFileSystem,
ProcessManager: () => FakeProcessManager.any(),
});
testUsingContext('build aot prints error if Clang version invalid', () async {
final Directory flutterFramework = memoryFileSystem.directory('ios_profile/Flutter.framework')
..createSync(recursive: true);
flutterFramework.childFile('Flutter').createSync();
final File infoPlist = flutterFramework.childFile('Info.plist')..createSync();
final RunResult clangResult = RunResult(
FakeProcessResult(stdout: 'Apple pie version 10.1.0 (clang-4567.1.1.1)\nBlahBlah\n', stderr: ''),
const <String>['foo'],
);
when(mockXcode.clang(any)).thenAnswer((_) => Future<RunResult>.value(clangResult));
when(mockPlistUtils.getValueFromFile(infoPlist.path, 'ClangVersion')).thenReturn('Apple LLVM version 10.0.1 (clang-1234.1.12.1)');
await expectToolExitLater(
validateBitcode(BuildMode.profile, TargetPlatform.ios),
equals('Unable to parse Clang version from "Apple pie version 10.1.0 (clang-4567.1.1.1)". '
'Expected a string like "Apple (LLVM|clang) #.#.# (clang-####.#.##.#)".'),
);
}, overrides: <Type, Generator>{
Artifacts: () => LocalEngineArtifacts('ios_profile', 'host_profile',
fileSystem: memoryFileSystem,
cache: globals.cache,
platform: globals.platform,
processManager: mockProcessManager,
),
FileSystem: () => memoryFileSystem,
ProcessManager: () => mockProcessManager,
Xcode: () => mockXcode,
PlistParser: () => mockPlistUtils,
});
testUsingContext('build aot can parse valid Xcode Clang version (10)', () async {
final Directory flutterFramework = memoryFileSystem.directory('ios_profile/Flutter.framework')
..createSync(recursive: true);
flutterFramework.childFile('Flutter').createSync();
final File infoPlist = flutterFramework.childFile('Info.plist')..createSync();
final RunResult clangResult = RunResult(
FakeProcessResult(stdout: 'Apple LLVM version 10.1.0 (clang-4567.1.1.1)\nBlahBlah\n', stderr: ''),
const <String>['foo'],
);
when(mockXcode.clang(any)).thenAnswer((_) => Future<RunResult>.value(clangResult));
when(mockPlistUtils.getValueFromFile(infoPlist.path, 'ClangVersion')).thenReturn('Apple LLVM version 10.0.1 (clang-1234.1.12.1)');
await validateBitcode(BuildMode.profile, TargetPlatform.ios);
}, overrides: <Type, Generator>{
Artifacts: () => LocalEngineArtifacts('ios_profile', 'host_profile',
fileSystem: memoryFileSystem,
cache: globals.cache,
platform: globals.platform,
processManager: mockProcessManager,
),
FileSystem: () => memoryFileSystem,
ProcessManager: () => mockProcessManager,
Xcode: () => mockXcode,
PlistParser: () => mockPlistUtils,
});
testUsingContext('build aot outputs timing info', () async {
globals.fs
.file('.dart_tool/flutter_build/3f206b606f73e08587a94405f2e86fad/app.so')
.createSync(recursive: true);
when(globals.buildSystem.build(any, any))
.thenAnswer((Invocation invocation) async {
return BuildResult(success: true, performance: <String, PerformanceMeasurement>{
'kernel_snapshot': PerformanceMeasurement(
analyticsName: 'kernel_snapshot',
target: 'kernel_snapshot',
elapsedMilliseconds: 1000,
succeeded: true,
skipped: false,
),
'anything': PerformanceMeasurement(
analyticsName: 'android_aot',
target: 'anything',
elapsedMilliseconds: 1000,
succeeded: true,
skipped: false,
),
});
});
await AotBuilder().build(
platform: TargetPlatform.android_arm64,
outputPath: '/',
buildInfo: BuildInfo.release,
mainDartFile: globals.fs.path.join('lib', 'main.dart'),
reportTimings: true,
);
expect(testLogger.statusText, allOf(
contains('frontend(CompileTime): 1000 ms.'),
contains('snapshot(CompileTime): 1000 ms.'),
));
}, overrides: <Type, Generator>{
BuildSystem: () => MockBuildSystem(),
FileSystem: () => MemoryFileSystem.test(),
ProcessManager: () => FakeProcessManager.any(),
});
testUsingContext('build aot can parse valid Xcode Clang version (11)', () async {
final Directory flutterFramework = memoryFileSystem.directory('ios_profile/Flutter.framework')
..createSync(recursive: true);
flutterFramework.childFile('Flutter').createSync();
final File infoPlist = flutterFramework.childFile('Info.plist')..createSync();
final RunResult clangResult = RunResult(
FakeProcessResult(stdout: 'Apple clang version 11.0.0 (clang-4567.1.1.1)\nBlahBlah\n', stderr: ''),
const <String>['foo'],
);
when(mockXcode.clang(any)).thenAnswer((_) => Future<RunResult>.value(clangResult));
when(mockPlistUtils.getValueFromFile(infoPlist.path, 'ClangVersion')).thenReturn('Apple LLVM version 10.0.1 (clang-1234.1.12.1)');
await validateBitcode(BuildMode.profile, TargetPlatform.ios);
}, overrides: <Type, Generator>{
Artifacts: () => LocalEngineArtifacts('ios_profile', 'host_profile',
fileSystem: memoryFileSystem,
cache: globals.cache,
platform: globals.platform,
processManager: mockProcessManager,
),
FileSystem: () => memoryFileSystem,
ProcessManager: () => mockProcessManager,
Xcode: () => mockXcode,
PlistParser: () => mockPlistUtils,
});
testUsingContext('build aot validates Flutter.framework/Flutter was built with same toolchain', () async {
final Directory flutterFramework = memoryFileSystem.directory('ios_profile/Flutter.framework')
..createSync(recursive: true);
flutterFramework.childFile('Flutter').createSync();
final File infoPlist = flutterFramework.childFile('Info.plist')..createSync();
final RunResult clangResult = RunResult(
FakeProcessResult(stdout: 'Apple LLVM version 10.0.0 (clang-4567.1.1.1)\nBlahBlah\n', stderr: ''),
const <String>['foo'],
);
when(mockXcode.clang(any)).thenAnswer((_) => Future<RunResult>.value(clangResult));
when(mockPlistUtils.getValueFromFile(infoPlist.path, 'ClangVersion')).thenReturn('Apple LLVM version 10.0.1 (clang-1234.1.12.1)');
await expectToolExitLater(
validateBitcode(BuildMode.release, TargetPlatform.ios),
equals('The Flutter.framework at ios_profile/Flutter.framework was built with "Apple LLVM version 10.0.1 '
'(clang-1234.1.12.1)", but the current version of clang is "Apple LLVM version 10.0.0 (clang-4567.1.1.1)". '
'This will result in failures when trying to archive an IPA. To resolve this issue, update your version '
'of Xcode to at least 10.0.1.'),
);
}, overrides: <Type, Generator>{
Artifacts: () => LocalEngineArtifacts('ios_profile', 'host_profile',
fileSystem: memoryFileSystem,
cache: globals.cache,
platform: globals.platform,
processManager: mockProcessManager,
),
FileSystem: () => memoryFileSystem,
ProcessManager: () => mockProcessManager,
Xcode: () => mockXcode,
PlistParser: () => mockPlistUtils,
});
testUsingContext('build aot validates and succeeds - same version of Xcode', () async {
final Directory flutterFramework = memoryFileSystem.directory('ios_profile/Flutter.framework')
..createSync(recursive: true);
flutterFramework.childFile('Flutter').createSync();
final File infoPlist = flutterFramework.childFile('Info.plist')..createSync();
final RunResult clangResult = RunResult(
FakeProcessResult(stdout: 'Apple LLVM version 10.0.1 (clang-1234.1.12.1)\nBlahBlah\n', stderr: ''),
const <String>['foo'],
);
when(mockXcode.clang(any)).thenAnswer((_) => Future<RunResult>.value(clangResult));
when(mockPlistUtils.getValueFromFile(infoPlist.path, 'ClangVersion')).thenReturn('Apple LLVM version 10.0.1 (clang-1234.1.12.1)');
await validateBitcode(BuildMode.release, TargetPlatform.ios);
expect(testLogger.statusText, '');
}, overrides: <Type, Generator>{
Artifacts: () => LocalEngineArtifacts('ios_profile', 'host_profile',
fileSystem: memoryFileSystem,
cache: globals.cache,
platform: globals.platform,
processManager: mockProcessManager,
),
FileSystem: () => memoryFileSystem,
ProcessManager: () => mockProcessManager,
Xcode: () => mockXcode,
PlistParser: () => mockPlistUtils,
});
testUsingContext('build aot validates and succeeds when user has newer version of Xcode', () async {
final Directory flutterFramework = memoryFileSystem.directory('ios_profile/Flutter.framework')
..createSync(recursive: true);
flutterFramework.childFile('Flutter').createSync();
final File infoPlist = flutterFramework.childFile('Info.plist')..createSync();
final RunResult clangResult = RunResult(
FakeProcessResult(stdout: 'Apple LLVM version 11.0.1 (clang-1234.1.12.1)\nBlahBlah\n', stderr: ''),
const <String>['foo'],
);
when(mockXcode.clang(any)).thenAnswer((_) => Future<RunResult>.value(clangResult));
when(mockPlistUtils.getValueFromFile(infoPlist.path, 'ClangVersion')).thenReturn('Apple LLVM version 10.0.1 (clang-1234.1.12.1)');
await validateBitcode(BuildMode.release, TargetPlatform.ios);
expect(testLogger.statusText, '');
}, overrides: <Type, Generator>{
Artifacts: () => LocalEngineArtifacts('ios_profile', 'host_profile',
fileSystem: memoryFileSystem,
cache: globals.cache,
platform: globals.platform,
processManager: mockProcessManager,
),
FileSystem: () => memoryFileSystem,
ProcessManager: () => mockProcessManager,
Xcode: () => mockXcode,
PlistParser: () => mockPlistUtils,
});
}
class MockXcode extends Mock implements Xcode {}
class MockPlistUtils extends Mock implements PlistParser {}
class MockBuildSystem extends Mock implements BuildSystem {}
......@@ -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