mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
[flutter_tool] ensure extraGenSnapshotArguments are forwarded to gen_snapshot from Android builds (#47059)
This commit is contained in:
parent
4ad8271bf5
commit
3fe6668849
@ -824,7 +824,7 @@ abstract class BaseFlutterTask extends DefaultTask {
|
||||
args "-dExtraFrontEndOptions=${extraFrontEndOptions}"
|
||||
}
|
||||
if (extraGenSnapshotOptions != null) {
|
||||
args "-dExtraGenSnapshotOptions=${extraGenSnapshotOptions}"
|
||||
args "--ExtraGenSnapshotOptions=${extraGenSnapshotOptions}"
|
||||
}
|
||||
args ruleNames
|
||||
}
|
||||
|
@ -208,6 +208,8 @@ class AndroidAot extends AotElfBase {
|
||||
if (!output.existsSync()) {
|
||||
output.createSync(recursive: true);
|
||||
}
|
||||
final List<String> extraGenSnapshotOptions = environment.defines[kExtraGenSnapshotOptions]?.split(',')
|
||||
?? const <String>[];
|
||||
final BuildMode buildMode = getBuildModeForName(environment.defines[kBuildMode]);
|
||||
final int snapshotExitCode = await snapshotter.build(
|
||||
platform: targetPlatform,
|
||||
@ -216,6 +218,7 @@ class AndroidAot extends AotElfBase {
|
||||
packagesPath: environment.projectDir.childFile('.packages').path,
|
||||
outputPath: output.path,
|
||||
bitcode: false,
|
||||
extraGenSnapshotOptions: extraGenSnapshotOptions,
|
||||
);
|
||||
if (snapshotExitCode != 0) {
|
||||
throw Exception('AOT snapshotter exited with code $snapshotExitCode');
|
||||
|
@ -253,6 +253,8 @@ abstract class AotElfBase extends Target {
|
||||
if (environment.defines[kTargetPlatform] == null) {
|
||||
throw MissingDefineException(kTargetPlatform, 'aot_elf');
|
||||
}
|
||||
final List<String> extraGenSnapshotOptions = environment.defines[kExtraGenSnapshotOptions]?.split(',')
|
||||
?? const <String>[];
|
||||
final BuildMode buildMode = getBuildModeForName(environment.defines[kBuildMode]);
|
||||
final TargetPlatform targetPlatform = getTargetPlatformForName(environment.defines[kTargetPlatform]);
|
||||
final int snapshotExitCode = await snapshotter.build(
|
||||
@ -262,6 +264,7 @@ abstract class AotElfBase extends Target {
|
||||
packagesPath: environment.projectDir.childFile('.packages').path,
|
||||
outputPath: outputPath,
|
||||
bitcode: false,
|
||||
extraGenSnapshotOptions: extraGenSnapshotOptions,
|
||||
);
|
||||
if (snapshotExitCode != 0) {
|
||||
throw Exception('AOT snapshotter exited with code $snapshotExitCode');
|
||||
|
@ -77,6 +77,7 @@ class AssembleCommand extends FlutterCommand {
|
||||
'files will be written. Must be either absolute or relative from the '
|
||||
'root of the current Flutter project.',
|
||||
);
|
||||
argParser.addOption(kExtraGenSnapshotOptions);
|
||||
argParser.addOption(
|
||||
'resource-pool-size',
|
||||
help: 'The maximum number of concurrent tasks the build system will run.',
|
||||
@ -150,17 +151,21 @@ class AssembleCommand extends FlutterCommand {
|
||||
return result;
|
||||
}
|
||||
|
||||
static Map<String, String> _parseDefines(List<String> values) {
|
||||
Map<String, String> _parseDefines(List<String> values) {
|
||||
final Map<String, String> results = <String, String>{};
|
||||
for (String chunk in values) {
|
||||
final List<String> parts = chunk.split('=');
|
||||
if (parts.length != 2) {
|
||||
final int indexEquals = chunk.indexOf('=');
|
||||
if (indexEquals == -1) {
|
||||
throwToolExit('Improperly formatted define flag: $chunk');
|
||||
}
|
||||
final String key = parts[0];
|
||||
final String value = parts[1];
|
||||
final String key = chunk.substring(0, indexEquals);
|
||||
final String value = chunk.substring(indexEquals + 1);
|
||||
results[key] = value;
|
||||
}
|
||||
// Workaround for extraGenSnapshot formatting.
|
||||
if (argResults.wasParsed(kExtraGenSnapshotOptions)) {
|
||||
results[kExtraGenSnapshotOptions] = argResults[kExtraGenSnapshotOptions] as String;
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
|
@ -32,6 +32,18 @@ void main() {
|
||||
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 {
|
||||
when(buildSystem.build(any, any, buildSystemConfig: anyNamed('buildSystemConfig')))
|
||||
.thenAnswer((Invocation invocation) async {
|
||||
|
@ -123,6 +123,41 @@ void main() {
|
||||
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 {
|
||||
final Environment environment = Environment(
|
||||
outputDir: fs.directory('out')..createSync(),
|
||||
|
@ -413,10 +413,32 @@ flutter_tools:lib/''');
|
||||
|
||||
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 MockGenSnapshot extends Mock implements GenSnapshot {}
|
||||
class MockXcode extends Mock implements Xcode {}
|
||||
|
||||
class FakeGenSnapshot implements GenSnapshot {
|
||||
|
Loading…
Reference in New Issue
Block a user