Unverified Commit 22ec357b authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

[flutter_tools] make getBuildInfo async (#70320)

parent 0f80116a
......@@ -12,6 +12,7 @@ import '../base/common.dart';
import '../base/context.dart';
import '../base/file_system.dart';
import '../base/io.dart';
import '../build_info.dart';
import '../commands/daemon.dart';
import '../compile.dart';
import '../device.dart';
......@@ -381,6 +382,7 @@ known, it can be explicitly provided to attach via the command-line, e.g.
assert(device != null);
assert(flutterProject != null);
assert(usesIpv6 != null);
final BuildInfo buildInfo = await getBuildInfo();
final FlutterDevice flutterDevice = await FlutterDevice.create(
device,
......@@ -388,15 +390,15 @@ known, it can be explicitly provided to attach via the command-line, e.g.
fileSystemScheme: stringArg('filesystem-scheme'),
target: stringArg('target'),
targetModel: TargetModel(stringArg('target-model')),
buildInfo: getBuildInfo(),
buildInfo: buildInfo,
userIdentifier: userIdentifier,
platform: globals.platform,
);
flutterDevice.observatoryUris = observatoryUris;
final List<FlutterDevice> flutterDevices = <FlutterDevice>[flutterDevice];
final DebuggingOptions debuggingOptions = DebuggingOptions.enabled(getBuildInfo(), disableDds: boolArg('disable-dds'));
final DebuggingOptions debuggingOptions = DebuggingOptions.enabled(buildInfo, disableDds: boolArg('disable-dds'));
return getBuildInfo().isDebug
return buildInfo.isDebug
? hotRunnerFactory.build(
flutterDevices,
target: targetFile,
......
......@@ -112,7 +112,7 @@ class BuildAarCommand extends BuildSubCommand {
if (boolArg(buildMode)) {
androidBuildInfo.add(
AndroidBuildInfo(
getBuildInfo(forcedBuildMode: BuildMode.fromName(buildMode)),
await getBuildInfo(forcedBuildMode: BuildMode.fromName(buildMode)),
targetArchs: targetArchitectures,
)
);
......
......@@ -57,7 +57,7 @@ class BuildAotCommand extends BuildSubCommand with TargetPlatformBasedDevelopmen
final String targetPlatform = stringArg('target-platform');
final TargetPlatform platform = getTargetPlatformForName(targetPlatform);
final String outputPath = stringArg('output-dir') ?? getAotBuildDirectory();
final BuildInfo buildInfo = getBuildInfo();
final BuildInfo buildInfo = await getBuildInfo();
if (platform == null) {
throwToolExit('Unknown platform: $targetPlatform');
}
......
......@@ -90,7 +90,7 @@ class BuildApkCommand extends BuildSubCommand {
if (globals.androidSdk == null) {
exitWithNoSdkMessage();
}
final BuildInfo buildInfo = getBuildInfo();
final BuildInfo buildInfo = await getBuildInfo();
final AndroidBuildInfo androidBuildInfo = AndroidBuildInfo(
buildInfo,
splitPerAbi: boolArg('split-per-abi'),
......
......@@ -82,7 +82,7 @@ class BuildAppBundleCommand extends BuildSubCommand {
if (globals.androidSdk == null) {
exitWithNoSdkMessage();
}
final AndroidBuildInfo androidBuildInfo = AndroidBuildInfo(getBuildInfo(),
final AndroidBuildInfo androidBuildInfo = AndroidBuildInfo(await getBuildInfo(),
targetArchs: stringsArg('target-platform').map<AndroidArch>(getAndroidArchForName),
shrink: boolArg('shrink'),
);
......
......@@ -113,7 +113,7 @@ class BuildBundleCommand extends BuildSubCommand {
break;
}
final BuildInfo buildInfo = getBuildInfo();
final BuildInfo buildInfo = await getBuildInfo();
await bundleBuilder.build(
platform: platform,
......
......@@ -64,7 +64,7 @@ class BuildFuchsiaCommand extends BuildSubCommand {
'information.'
);
}
final BuildInfo buildInfo = getBuildInfo();
final BuildInfo buildInfo = await getBuildInfo();
final FlutterProject flutterProject = FlutterProject.current();
if (!globals.platform.isLinux && !globals.platform.isMacOS) {
throwToolExit('"build fuchsia" is only supported on Linux and MacOS hosts.');
......
......@@ -109,6 +109,7 @@ class BuildIOSArchiveCommand extends _BuildIOSSubCommand {
}
}
final FlutterCommandResult xcarchiveResult = await super.runCommand();
final BuildInfo buildInfo = await getBuildInfo();
if (exportOptionsPlist == null) {
return xcarchiveResult;
......@@ -121,7 +122,7 @@ class BuildIOSArchiveCommand extends _BuildIOSSubCommand {
}
// Build IPA from generated xcarchive.
final BuildableIOSApp app = await buildableIOSApp;
final BuildableIOSApp app = await buildableIOSApp(buildInfo);
Status status;
RunResult result;
final String outputPath = globals.fs.path.absolute(app.ipaOutputPath);
......@@ -195,14 +196,7 @@ abstract class _BuildIOSSubCommand extends BuildSubCommand {
bool get configOnly;
bool get shouldCodesign;
BuildInfo get buildInfo {
_buildInfo ??= getBuildInfo();
return _buildInfo;
}
BuildInfo _buildInfo;
Future<BuildableIOSApp> get buildableIOSApp async {
Future<BuildableIOSApp> buildableIOSApp(BuildInfo buildInfo) async {
_buildableIOSApp ??= await applicationPackages.getPackageForPlatform(
TargetPlatform.ios,
buildInfo: buildInfo,
......@@ -215,6 +209,7 @@ abstract class _BuildIOSSubCommand extends BuildSubCommand {
@override
Future<FlutterCommandResult> runCommand() async {
defaultBuildMode = forSimulator ? BuildMode.debug : BuildMode.release;
final BuildInfo buildInfo = await getBuildInfo();
if (!globals.platform.isMacOS) {
throwToolExit('Building for iOS is only supported on macOS.');
......@@ -232,7 +227,7 @@ abstract class _BuildIOSSubCommand extends BuildSubCommand {
);
}
final BuildableIOSApp app = await buildableIOSApp;
final BuildableIOSApp app = await buildableIOSApp(buildInfo);
if (app == null) {
throwToolExit('Application not configured for iOS');
......
......@@ -124,17 +124,17 @@ class BuildIOSFrameworkCommand extends BuildSubCommand {
FlutterProject _project;
List<BuildInfo> get buildInfos {
Future<List<BuildInfo>> get buildInfos async {
final List<BuildInfo> buildInfos = <BuildInfo>[];
if (boolArg('debug')) {
buildInfos.add(getBuildInfo(forcedBuildMode: BuildMode.debug));
buildInfos.add(await getBuildInfo(forcedBuildMode: BuildMode.debug));
}
if (boolArg('profile')) {
buildInfos.add(getBuildInfo(forcedBuildMode: BuildMode.profile));
buildInfos.add(await getBuildInfo(forcedBuildMode: BuildMode.profile));
}
if (boolArg('release')) {
buildInfos.add(getBuildInfo(forcedBuildMode: BuildMode.release));
buildInfos.add(await getBuildInfo(forcedBuildMode: BuildMode.release));
}
return buildInfos;
......@@ -163,7 +163,7 @@ class BuildIOSFrameworkCommand extends BuildSubCommand {
'Silicon ARM simulators and will be removed in a future version of '
'Flutter. Use --xcframework instead.');
}
if (buildInfos.isEmpty) {
if ((await buildInfos).isEmpty) {
throwToolExit('At least one of "--debug" or "--profile", or "--release" is required.');
}
}
......@@ -183,7 +183,7 @@ class BuildIOSFrameworkCommand extends BuildSubCommand {
final Directory outputDirectory = globals.fs.directory(globals.fs.path.absolute(globals.fs.path.normalize(outputArgument)));
for (final BuildInfo buildInfo in buildInfos) {
for (final BuildInfo buildInfo in await buildInfos) {
final String productBundleIdentifier = await _project.ios.productBundleIdentifier(buildInfo);
globals.printStatus('Building frameworks for $productBundleIdentifier in ${getNameForBuildMode(buildInfo.mode)} mode...');
final String xcodeBuildConfiguration = toTitleCase(getNameForBuildMode(buildInfo.mode));
......
......@@ -35,7 +35,7 @@ class BuildLinuxCommand extends BuildSubCommand {
@override
Future<FlutterCommandResult> runCommand() async {
final BuildInfo buildInfo = getBuildInfo();
final BuildInfo buildInfo = await getBuildInfo();
final FlutterProject flutterProject = FlutterProject.current();
if (!featureFlags.isLinuxEnabled) {
throwToolExit('"build linux" is not currently supported.');
......
......@@ -39,7 +39,7 @@ class BuildMacosCommand extends BuildSubCommand {
@override
Future<FlutterCommandResult> runCommand() async {
final BuildInfo buildInfo = getBuildInfo();
final BuildInfo buildInfo = await getBuildInfo();
final FlutterProject flutterProject = FlutterProject.current();
if (!featureFlags.isMacOSEnabled) {
throwToolExit('"build macos" is not currently supported.');
......
......@@ -79,7 +79,7 @@ class BuildWebCommand extends BuildSubCommand {
}
final FlutterProject flutterProject = FlutterProject.current();
final String target = stringArg('target');
final BuildInfo buildInfo = getBuildInfo();
final BuildInfo buildInfo = await getBuildInfo();
if (buildInfo.isDebug) {
throwToolExit('debug builds cannot be built directly for the web. Try using "flutter run"');
}
......
......@@ -42,7 +42,7 @@ class BuildWindowsCommand extends BuildSubCommand {
@override
Future<FlutterCommandResult> runCommand() async {
final FlutterProject flutterProject = FlutterProject.current();
final BuildInfo buildInfo = getBuildInfo();
final BuildInfo buildInfo = await getBuildInfo();
if (!featureFlags.isWindowsEnabled) {
throwToolExit('"build windows" is not currently supported.');
}
......
......@@ -195,8 +195,8 @@ class DriveCommand extends RunCommandBase {
throwOnError: false,
) ?? PackageConfig.empty;
final DriverService driverService = _flutterDriverFactory.createDriverService(web);
final BuildInfo buildInfo = getBuildInfo();
final DebuggingOptions debuggingOptions = createDebuggingOptions();
final BuildInfo buildInfo = await getBuildInfo();
final DebuggingOptions debuggingOptions = await createDebuggingOptions();
final File applicationBinary = stringArg('use-application-binary') == null
? null
: _fileSystem.file(stringArg('use-application-binary'));
......
......@@ -152,8 +152,8 @@ abstract class RunCommandBase extends FlutterCommand with DeviceBasedDevelopment
String get traceAllowlist => stringArg('trace-allowlist');
/// Create a debugging options instance for the current `run` or `drive` invocation.
DebuggingOptions createDebuggingOptions() {
final BuildInfo buildInfo = getBuildInfo();
Future<DebuggingOptions> createDebuggingOptions() async {
final BuildInfo buildInfo = await getBuildInfo();
final int browserDebugPort = featureFlags.isWebEnabled && argResults.wasParsed('web-browser-debug-port')
? int.parse(stringArg('web-browser-debug-port'))
: null;
......@@ -384,7 +384,8 @@ class RunCommand extends RunCommandBase {
}
}
final String modeName = getBuildInfo().modeName;
final BuildInfo buildInfo = await getBuildInfo();
final String modeName = buildInfo.modeName;
return <CustomDimensions, String>{
CustomDimensions.commandRunIsEmulator: '$isEmulator',
CustomDimensions.commandRunTargetName: deviceType,
......@@ -407,10 +408,10 @@ class RunCommand extends RunCommandBase {
return super.shouldRunPub;
}
bool shouldUseHotMode() {
bool shouldUseHotMode(BuildInfo buildInfo) {
final bool hotArg = boolArg('hot') ?? false;
final bool shouldUseHotMode = hotArg && !traceStartup;
return getBuildInfo().isDebug && shouldUseHotMode;
return buildInfo.isDebug && shouldUseHotMode;
}
bool get stayResident => boolArg('resident');
......@@ -444,7 +445,8 @@ class RunCommand extends RunCommandBase {
Future<FlutterCommandResult> runCommand() async {
// Enable hot mode by default if `--no-hot` was not passed and we are in
// debug mode.
final bool hotMode = shouldUseHotMode();
final BuildInfo buildInfo = await getBuildInfo();
final bool hotMode = shouldUseHotMode(buildInfo);
writePidFile(stringArg('pid-file'));
......@@ -465,7 +467,7 @@ class RunCommand extends RunCommandBase {
final String applicationBinaryPath = stringArg('use-application-binary');
app = await daemon.appDomain.startApp(
devices.first, globals.fs.currentDirectory.path, targetFile, route,
createDebuggingOptions(), hotMode,
await createDebuggingOptions(), hotMode,
applicationBinary: applicationBinaryPath == null
? null
: globals.fs.file(applicationBinaryPath),
......@@ -534,7 +536,7 @@ class RunCommand extends RunCommandBase {
fileSystemScheme: stringArg('filesystem-scheme'),
experimentalFlags: expFlags,
target: stringArg('target'),
buildInfo: getBuildInfo(),
buildInfo: buildInfo,
userIdentifier: userIdentifier,
platform: globals.platform,
),
......@@ -551,7 +553,7 @@ class RunCommand extends RunCommandBase {
runner = HotRunner(
flutterDevices,
target: targetFile,
debuggingOptions: createDebuggingOptions(),
debuggingOptions: await createDebuggingOptions(),
benchmarkMode: boolArg('benchmark'),
applicationBinary: applicationBinaryPath == null
? null
......@@ -567,7 +569,7 @@ class RunCommand extends RunCommandBase {
target: targetFile,
flutterProject: flutterProject,
ipv6: ipv6,
debuggingOptions: createDebuggingOptions(),
debuggingOptions: await createDebuggingOptions(),
stayResident: stayResident,
urlTunneller: null,
);
......@@ -575,7 +577,7 @@ class RunCommand extends RunCommandBase {
runner = ColdRunner(
flutterDevices,
target: targetFile,
debuggingOptions: createDebuggingOptions(),
debuggingOptions: await createDebuggingOptions(),
traceStartup: traceStartup,
awaitFirstFrameWhenTracing: awaitFirstFrameWhenTracing,
applicationBinary: applicationBinaryPath == null
......
......@@ -171,7 +171,7 @@ class TestCommand extends FlutterCommand {
final List<String> plainNames = stringsArg('plain-name');
final String tags = stringArg('tags');
final String excludeTags = stringArg('exclude-tags');
final BuildInfo buildInfo = getBuildInfo(forcedBuildMode: BuildMode.debug);
final BuildInfo buildInfo = await getBuildInfo(forcedBuildMode: BuildMode.debug);
if (buildTestAssets && flutterProject.manifest.assets.isNotEmpty) {
await _buildTestAsset();
......@@ -226,7 +226,7 @@ class TestCommand extends FlutterCommand {
collector = CoverageCollector(
verbose: !machine,
libraryPredicate: (String libraryName) => libraryName.contains(projectName),
// TODO(jonahwilliams): file bug for incorrect URI handling on windws
// TODO(jonahwilliams): file bug for incorrect URI handling on windows
packagesPath: globals.fs.path.absolute('.packages'),
);
}
......
......@@ -750,7 +750,7 @@ abstract class FlutterCommand extends Command<void> {
///
/// Throws a [ToolExit] if the current set of options is not compatible with
/// each other.
BuildInfo getBuildInfo({ BuildMode forcedBuildMode }) {
Future<BuildInfo> getBuildInfo({ BuildMode forcedBuildMode }) async {
final bool trackWidgetCreation = argParser.options.containsKey('track-widget-creation') &&
boolArg('track-widget-creation');
......
......@@ -35,7 +35,7 @@ class FakeBuildCommand extends FlutterCommand {
@override
Future<FlutterCommandResult> runCommand() async {
getBuildInfo();
await getBuildInfo();
return FlutterCommandResult.success();
}
}
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