Unverified Commit 3fe66688 authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

[flutter_tool] ensure extraGenSnapshotArguments are forwarded to gen_snapshot...

[flutter_tool] ensure extraGenSnapshotArguments are forwarded to gen_snapshot from Android builds (#47059)
parent 4ad8271b
...@@ -824,7 +824,7 @@ abstract class BaseFlutterTask extends DefaultTask { ...@@ -824,7 +824,7 @@ abstract class BaseFlutterTask extends DefaultTask {
args "-dExtraFrontEndOptions=${extraFrontEndOptions}" args "-dExtraFrontEndOptions=${extraFrontEndOptions}"
} }
if (extraGenSnapshotOptions != null) { if (extraGenSnapshotOptions != null) {
args "-dExtraGenSnapshotOptions=${extraGenSnapshotOptions}" args "--ExtraGenSnapshotOptions=${extraGenSnapshotOptions}"
} }
args ruleNames args ruleNames
} }
......
...@@ -208,6 +208,8 @@ class AndroidAot extends AotElfBase { ...@@ -208,6 +208,8 @@ class AndroidAot extends AotElfBase {
if (!output.existsSync()) { if (!output.existsSync()) {
output.createSync(recursive: true); output.createSync(recursive: true);
} }
final List<String> extraGenSnapshotOptions = environment.defines[kExtraGenSnapshotOptions]?.split(',')
?? const <String>[];
final BuildMode buildMode = getBuildModeForName(environment.defines[kBuildMode]); final BuildMode buildMode = getBuildModeForName(environment.defines[kBuildMode]);
final int snapshotExitCode = await snapshotter.build( final int snapshotExitCode = await snapshotter.build(
platform: targetPlatform, platform: targetPlatform,
...@@ -216,6 +218,7 @@ class AndroidAot extends AotElfBase { ...@@ -216,6 +218,7 @@ class AndroidAot extends AotElfBase {
packagesPath: environment.projectDir.childFile('.packages').path, packagesPath: environment.projectDir.childFile('.packages').path,
outputPath: output.path, outputPath: output.path,
bitcode: false, bitcode: false,
extraGenSnapshotOptions: extraGenSnapshotOptions,
); );
if (snapshotExitCode != 0) { if (snapshotExitCode != 0) {
throw Exception('AOT snapshotter exited with code $snapshotExitCode'); throw Exception('AOT snapshotter exited with code $snapshotExitCode');
......
...@@ -253,6 +253,8 @@ abstract class AotElfBase extends Target { ...@@ -253,6 +253,8 @@ abstract class AotElfBase extends Target {
if (environment.defines[kTargetPlatform] == null) { if (environment.defines[kTargetPlatform] == null) {
throw MissingDefineException(kTargetPlatform, 'aot_elf'); throw MissingDefineException(kTargetPlatform, 'aot_elf');
} }
final List<String> extraGenSnapshotOptions = environment.defines[kExtraGenSnapshotOptions]?.split(',')
?? const <String>[];
final BuildMode buildMode = getBuildModeForName(environment.defines[kBuildMode]); final BuildMode buildMode = getBuildModeForName(environment.defines[kBuildMode]);
final TargetPlatform targetPlatform = getTargetPlatformForName(environment.defines[kTargetPlatform]); final TargetPlatform targetPlatform = getTargetPlatformForName(environment.defines[kTargetPlatform]);
final int snapshotExitCode = await snapshotter.build( final int snapshotExitCode = await snapshotter.build(
...@@ -262,6 +264,7 @@ abstract class AotElfBase extends Target { ...@@ -262,6 +264,7 @@ abstract class AotElfBase extends Target {
packagesPath: environment.projectDir.childFile('.packages').path, packagesPath: environment.projectDir.childFile('.packages').path,
outputPath: outputPath, outputPath: outputPath,
bitcode: false, bitcode: false,
extraGenSnapshotOptions: extraGenSnapshotOptions,
); );
if (snapshotExitCode != 0) { if (snapshotExitCode != 0) {
throw Exception('AOT snapshotter exited with code $snapshotExitCode'); throw Exception('AOT snapshotter exited with code $snapshotExitCode');
......
...@@ -77,6 +77,7 @@ class AssembleCommand extends FlutterCommand { ...@@ -77,6 +77,7 @@ class AssembleCommand extends FlutterCommand {
'files will be written. Must be either absolute or relative from the ' 'files will be written. Must be either absolute or relative from the '
'root of the current Flutter project.', 'root of the current Flutter project.',
); );
argParser.addOption(kExtraGenSnapshotOptions);
argParser.addOption( argParser.addOption(
'resource-pool-size', 'resource-pool-size',
help: 'The maximum number of concurrent tasks the build system will run.', help: 'The maximum number of concurrent tasks the build system will run.',
...@@ -150,17 +151,21 @@ class AssembleCommand extends FlutterCommand { ...@@ -150,17 +151,21 @@ class AssembleCommand extends FlutterCommand {
return result; return result;
} }
static Map<String, String> _parseDefines(List<String> values) { Map<String, String> _parseDefines(List<String> values) {
final Map<String, String> results = <String, String>{}; final Map<String, String> results = <String, String>{};
for (String chunk in values) { for (String chunk in values) {
final List<String> parts = chunk.split('='); final int indexEquals = chunk.indexOf('=');
if (parts.length != 2) { if (indexEquals == -1) {
throwToolExit('Improperly formatted define flag: $chunk'); throwToolExit('Improperly formatted define flag: $chunk');
} }
final String key = parts[0]; final String key = chunk.substring(0, indexEquals);
final String value = parts[1]; final String value = chunk.substring(indexEquals + 1);
results[key] = value; results[key] = value;
} }
// Workaround for extraGenSnapshot formatting.
if (argResults.wasParsed(kExtraGenSnapshotOptions)) {
results[kExtraGenSnapshotOptions] = argResults[kExtraGenSnapshotOptions] as String;
}
return results; return results;
} }
......
...@@ -32,6 +32,18 @@ void main() { ...@@ -32,6 +32,18 @@ void main() {
expect(testLogger.traceText, contains('build succeeded.')); expect(testLogger.traceText, contains('build succeeded.'));
}); });
testbed.test('Can parse defines whose values contain =', () async {
when(buildSystem.build(any, any, buildSystemConfig: anyNamed('buildSystemConfig')))
.thenAnswer((Invocation invocation) async {
expect((invocation.positionalArguments[1] as Environment).defines, containsPair('FooBar', 'fizz=2'));
return BuildResult(success: true);
});
final CommandRunner<void> commandRunner = createTestCommandRunner(AssembleCommand());
await commandRunner.run(<String>['assemble', '-o Output', '-dFooBar=fizz=2', 'debug_macos_bundle_flutter_assets']);
expect(testLogger.traceText, contains('build succeeded.'));
});
testbed.test('Throws ToolExit if not provided with output', () async { testbed.test('Throws ToolExit if not provided with output', () async {
when(buildSystem.build(any, any, buildSystemConfig: anyNamed('buildSystemConfig'))) when(buildSystem.build(any, any, buildSystemConfig: anyNamed('buildSystemConfig')))
.thenAnswer((Invocation invocation) async { .thenAnswer((Invocation invocation) async {
......
...@@ -123,6 +123,41 @@ void main() { ...@@ -123,6 +123,41 @@ void main() {
GenSnapshot: () => MockGenSnapshot(), GenSnapshot: () => MockGenSnapshot(),
}); });
testbed.test('kExtraGenSnapshotOptions passes values to gen_snapshot', () async {
final Environment environment = Environment(
outputDir: fs.directory('out')..createSync(),
projectDir: fs.currentDirectory,
buildDir: fs.currentDirectory,
defines: <String, String>{
kBuildMode: 'release',
kExtraGenSnapshotOptions: 'foo,bar,baz=2',
kTargetPlatform: 'android-arm',
}
);
environment.buildDir.createSync(recursive: true);
environment.buildDir.childFile('app.dill').createSync();
environment.projectDir.childFile('.packages')
.writeAsStringSync('sky_engine:file:///\n');
when(genSnapshot.run(
snapshotType: anyNamed('snapshotType'),
darwinArch: anyNamed('darwinArch'),
additionalArgs: captureAnyNamed('additionalArgs'),
)).thenAnswer((Invocation invocation) async {
expect(invocation.namedArguments[#additionalArgs], containsAll(<String>[
'foo',
'bar',
'baz=2',
]));
return 0;
});
await const AndroidAot(TargetPlatform.android_arm64, BuildMode.release)
.build(environment);
}, overrides: <Type, Generator>{
GenSnapshot: () => MockGenSnapshot(),
});
testbed.test('android aot bundle copies so from abi directory', () async { testbed.test('android aot bundle copies so from abi directory', () async {
final Environment environment = Environment( final Environment environment = Environment(
outputDir: fs.directory('out')..createSync(), outputDir: fs.directory('out')..createSync(),
......
...@@ -413,10 +413,32 @@ flutter_tools:lib/'''); ...@@ -413,10 +413,32 @@ flutter_tools:lib/''');
expect(androidEnvironment.outputDir.childFile('app.so').existsSync(), true); expect(androidEnvironment.outputDir.childFile('app.so').existsSync(), true);
})); }));
test('kExtraGenSnapshotOptions passes values to gen_snapshot', () => testbed.run(() async {
androidEnvironment.defines[kExtraGenSnapshotOptions] = 'foo,bar,baz=2';
when(genSnapshot.run(
snapshotType: anyNamed('snapshotType'),
darwinArch: anyNamed('darwinArch'),
additionalArgs: captureAnyNamed('additionalArgs'),
)).thenAnswer((Invocation invocation) async {
expect(invocation.namedArguments[#additionalArgs], containsAll(<String>[
'foo',
'bar',
'baz=2',
]));
return 0;
});
await const AotElfRelease().build(androidEnvironment);
}, overrides: <Type, Generator>{
GenSnapshot: () => MockGenSnapshot(),
}));
} }
class MockProcessManager extends Mock implements ProcessManager {} class MockProcessManager extends Mock implements ProcessManager {}
class MockGenSnapshot extends Mock implements GenSnapshot {}
class MockXcode extends Mock implements Xcode {} class MockXcode extends Mock implements Xcode {}
class FakeGenSnapshot implements GenSnapshot { class FakeGenSnapshot implements GenSnapshot {
......
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