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

Download platform artifacts from assemble if needed (#78272)

parent 2584afd7
...@@ -147,9 +147,8 @@ class AssembleCommand extends FlutterCommand { ...@@ -147,9 +147,8 @@ class AssembleCommand extends FlutterCommand {
return const <CustomDimensions, String>{}; return const <CustomDimensions, String>{};
} }
try { try {
final Environment localEnvironment = createEnvironment();
return <CustomDimensions, String>{ return <CustomDimensions, String>{
CustomDimensions.commandBuildBundleTargetPlatform: localEnvironment.defines['TargetPlatform'], CustomDimensions.commandBuildBundleTargetPlatform: environment.defines[kTargetPlatform],
CustomDimensions.commandBuildBundleIsModule: '${flutterProject.isModule}', CustomDimensions.commandBuildBundleIsModule: '${flutterProject.isModule}',
}; };
} on Exception { } on Exception {
...@@ -158,6 +157,21 @@ class AssembleCommand extends FlutterCommand { ...@@ -158,6 +157,21 @@ class AssembleCommand extends FlutterCommand {
return const <CustomDimensions, String>{}; return const <CustomDimensions, String>{};
} }
@override
Future<Set<DevelopmentArtifact>> get requiredArtifacts async {
final String platform = environment.defines[kTargetPlatform];
if (platform == null) {
return super.requiredArtifacts;
}
final TargetPlatform targetPlatform = getTargetPlatformForName(platform);
final DevelopmentArtifact artifact = artifactFromTargetPlatform(targetPlatform);
if (artifact != null) {
return <DevelopmentArtifact>{artifact};
}
return super.requiredArtifacts;
}
/// The target(s) we are building. /// The target(s) we are building.
List<Target> createTargets() { List<Target> createTargets() {
if (argResults.rest.isEmpty) { if (argResults.rest.isEmpty) {
...@@ -197,6 +211,9 @@ class AssembleCommand extends FlutterCommand { ...@@ -197,6 +211,9 @@ class AssembleCommand extends FlutterCommand {
return false; return false;
} }
Environment get environment => _environment ??= createEnvironment();
Environment _environment;
/// The environmental configuration for a build invocation. /// The environmental configuration for a build invocation.
Environment createEnvironment() { Environment createEnvironment() {
final FlutterProject flutterProject = FlutterProject.current(); final FlutterProject flutterProject = FlutterProject.current();
...@@ -259,7 +276,6 @@ class AssembleCommand extends FlutterCommand { ...@@ -259,7 +276,6 @@ class AssembleCommand extends FlutterCommand {
@override @override
Future<FlutterCommandResult> runCommand() async { Future<FlutterCommandResult> runCommand() async {
final Environment env = createEnvironment();
final List<Target> targets = createTargets(); final List<Target> targets = createTargets();
final List<Target> nonDeferredTargets = <Target>[]; final List<Target> nonDeferredTargets = <Target>[];
final List<Target> deferredTargets = <AndroidAotDeferredComponentsBundle>[]; final List<Target> deferredTargets = <AndroidAotDeferredComponentsBundle>[];
...@@ -271,7 +287,7 @@ class AssembleCommand extends FlutterCommand { ...@@ -271,7 +287,7 @@ class AssembleCommand extends FlutterCommand {
} }
} }
Target target; Target target;
final List<String> decodedDefines = decodeDartDefines(env.defines, kDartDefines); final List<String> decodedDefines = decodeDartDefines(environment.defines, kDartDefines);
if (FlutterProject.current().manifest.deferredComponents != null if (FlutterProject.current().manifest.deferredComponents != null
&& decodedDefines.contains('validate-deferred-components=true') && decodedDefines.contains('validate-deferred-components=true')
&& deferredTargets.isNotEmpty && deferredTargets.isNotEmpty
...@@ -289,7 +305,7 @@ class AssembleCommand extends FlutterCommand { ...@@ -289,7 +305,7 @@ class AssembleCommand extends FlutterCommand {
} }
final BuildResult result = await _buildSystem.build( final BuildResult result = await _buildSystem.build(
target, target,
env, environment,
buildSystemConfig: BuildSystemConfig( buildSystemConfig: BuildSystemConfig(
resourcePoolSize: argResults.wasParsed('resource-pool-size') resourcePoolSize: argResults.wasParsed('resource-pool-size')
? int.tryParse(stringArg('resource-pool-size')) ? int.tryParse(stringArg('resource-pool-size'))
......
...@@ -1365,7 +1365,7 @@ mixin DeviceBasedDevelopmentArtifacts on FlutterCommand { ...@@ -1365,7 +1365,7 @@ mixin DeviceBasedDevelopmentArtifacts on FlutterCommand {
}; };
for (final Device device in devices) { for (final Device device in devices) {
final TargetPlatform targetPlatform = await device.targetPlatform; final TargetPlatform targetPlatform = await device.targetPlatform;
final DevelopmentArtifact developmentArtifact = _artifactFromTargetPlatform(targetPlatform); final DevelopmentArtifact developmentArtifact = artifactFromTargetPlatform(targetPlatform);
if (developmentArtifact != null) { if (developmentArtifact != null) {
artifacts.add(developmentArtifact); artifacts.add(developmentArtifact);
} }
...@@ -1374,31 +1374,10 @@ mixin DeviceBasedDevelopmentArtifacts on FlutterCommand { ...@@ -1374,31 +1374,10 @@ mixin DeviceBasedDevelopmentArtifacts on FlutterCommand {
} }
} }
/// A mixin which applies an implementation of [requiredArtifacts] that only
/// downloads artifacts corresponding to a target device.
mixin TargetPlatformBasedDevelopmentArtifacts on FlutterCommand {
@override
Future<Set<DevelopmentArtifact>> get requiredArtifacts async {
// If there is no specified target device, fallback to the default
// configuration.
final String rawTargetPlatform = stringArg('target-platform');
final TargetPlatform targetPlatform = getTargetPlatformForName(rawTargetPlatform);
if (targetPlatform == null) {
return super.requiredArtifacts;
}
final Set<DevelopmentArtifact> artifacts = <DevelopmentArtifact>{};
final DevelopmentArtifact developmentArtifact = _artifactFromTargetPlatform(targetPlatform);
if (developmentArtifact != null) {
artifacts.add(developmentArtifact);
}
return artifacts;
}
}
// Returns the development artifact for the target platform, or null // Returns the development artifact for the target platform, or null
// if none is supported // if none is supported
DevelopmentArtifact _artifactFromTargetPlatform(TargetPlatform targetPlatform) { @protected
DevelopmentArtifact artifactFromTargetPlatform(TargetPlatform targetPlatform) {
switch (targetPlatform) { switch (targetPlatform) {
case TargetPlatform.android: case TargetPlatform.android:
case TargetPlatform.android_arm: case TargetPlatform.android_arm:
......
...@@ -13,6 +13,7 @@ import 'package:flutter_tools/src/build_system/build_system.dart'; ...@@ -13,6 +13,7 @@ import 'package:flutter_tools/src/build_system/build_system.dart';
import 'package:flutter_tools/src/cache.dart'; import 'package:flutter_tools/src/cache.dart';
import 'package:flutter_tools/src/commands/assemble.dart'; import 'package:flutter_tools/src/commands/assemble.dart';
import 'package:flutter_tools/src/convert.dart'; import 'package:flutter_tools/src/convert.dart';
import 'package:flutter_tools/src/features.dart';
import 'package:flutter_tools/src/globals.dart' as globals; import 'package:flutter_tools/src/globals.dart' as globals;
import '../../src/common.dart'; import '../../src/common.dart';
...@@ -54,18 +55,35 @@ void main() { ...@@ -54,18 +55,35 @@ void main() {
}); });
testUsingContext('flutter assemble can parse inputs', () async { testUsingContext('flutter assemble can parse inputs', () async {
final CommandRunner<void> commandRunner = createTestCommandRunner(AssembleCommand( final AssembleCommand command = AssembleCommand(
buildSystem: TestBuildSystem.all(BuildResult(success: true), (Target target, Environment environment) { buildSystem: TestBuildSystem.all(BuildResult(success: true), (Target target, Environment environment) {
expect(environment.inputs, containsPair('Foo', 'Bar.txt')); expect(environment.inputs, containsPair('Foo', 'Bar.txt'));
}) }));
)); final CommandRunner<void> commandRunner = createTestCommandRunner(command);
await commandRunner.run(<String>['assemble', '-o Output', '-iFoo=Bar.txt', 'debug_macos_bundle_flutter_assets']); await commandRunner.run(<String>['assemble', '-o Output', '-iFoo=Bar.txt', 'debug_macos_bundle_flutter_assets']);
expect(testLogger.traceText, contains('build succeeded.')); expect(testLogger.traceText, contains('build succeeded.'));
expect(await command.requiredArtifacts, isEmpty);
}, overrides: <Type, Generator>{
Cache: () => Cache.test(processManager: FakeProcessManager.any()),
FileSystem: () => MemoryFileSystem.test(),
ProcessManager: () => FakeProcessManager.any(),
});
testUsingContext('flutter assemble sets required artifacts from target platform', () async {
final AssembleCommand command = AssembleCommand(
buildSystem: TestBuildSystem.all(BuildResult(success: true)));
final CommandRunner<void> commandRunner = createTestCommandRunner(command);
await commandRunner.run(<String>['assemble', '-o Output', '-dTargetPlatform=darwin-x64', 'debug_macos_bundle_flutter_assets']);
expect(await command.requiredArtifacts, <DevelopmentArtifact>{
DevelopmentArtifact.macOS,
});
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
Cache: () => Cache.test(processManager: FakeProcessManager.any()), Cache: () => Cache.test(processManager: FakeProcessManager.any()),
FileSystem: () => MemoryFileSystem.test(), FileSystem: () => MemoryFileSystem.test(),
ProcessManager: () => FakeProcessManager.any(), ProcessManager: () => FakeProcessManager.any(),
FeatureFlags: () => TestFeatureFlags(isMacOSEnabled: true),
}); });
testUsingContext('flutter assemble throws ToolExit if not provided with output', () async { testUsingContext('flutter assemble throws ToolExit if not provided with output', () async {
......
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