flutter_tool: DeferredComponent and LoadingUnit classes, Manifest deferred-components parsing (#75394)
This commit is contained in:
@@ -0,0 +1,351 @@
|
||||
// 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.
|
||||
|
||||
// @dart = 2.8
|
||||
|
||||
import 'package:file/memory.dart';
|
||||
import 'package:flutter_tools/src/base/deferred_component.dart';
|
||||
import 'package:flutter_tools/src/base/file_system.dart';
|
||||
import 'package:flutter_tools/src/base/logger.dart';
|
||||
|
||||
import '../../src/common.dart';
|
||||
import '../../src/context.dart';
|
||||
|
||||
void main() {
|
||||
group('DeferredComponent basics', () {
|
||||
test('constructor sets values', () {
|
||||
final DeferredComponent component = DeferredComponent(
|
||||
name: 'bestcomponent',
|
||||
libraries: <String>['lib1', 'lib2'],
|
||||
assets: <Uri>[Uri.file('asset1'), Uri.file('asset2')],
|
||||
);
|
||||
expect(component.name, 'bestcomponent');
|
||||
expect(component.libraries, <String>['lib1', 'lib2']);
|
||||
expect(component.assets, <Uri>[Uri.file('asset1'), Uri.file('asset2')]);
|
||||
});
|
||||
|
||||
test('assignLoadingUnits selects the needed loading units and sets assigned', () {
|
||||
final DeferredComponent component = DeferredComponent(
|
||||
name: 'bestcomponent',
|
||||
libraries: <String>['lib1', 'lib2'],
|
||||
assets: <Uri>[Uri.file('asset1'), Uri.file('asset2')],
|
||||
);
|
||||
expect(component.libraries, <String>['lib1', 'lib2']);
|
||||
expect(component.assigned, false);
|
||||
expect(component.loadingUnits, null);
|
||||
|
||||
final List<LoadingUnit> loadingUnits1 = <LoadingUnit>[
|
||||
LoadingUnit(
|
||||
id: 2,
|
||||
path: 'path/to/so.so',
|
||||
libraries: <String>['lib1', 'lib4'],
|
||||
),
|
||||
LoadingUnit(
|
||||
id: 3,
|
||||
path: 'path/to/so.so',
|
||||
libraries: <String>['lib2', 'lib5'],
|
||||
),
|
||||
LoadingUnit(
|
||||
id: 4,
|
||||
path: 'path/to/so.so',
|
||||
libraries: <String>['lib6', 'lib7'],
|
||||
),
|
||||
];
|
||||
|
||||
component.assignLoadingUnits(loadingUnits1);
|
||||
|
||||
expect(component.assigned, true);
|
||||
expect(component.loadingUnits.length, 2);
|
||||
expect(component.loadingUnits.contains(loadingUnits1[0]), true);
|
||||
expect(component.loadingUnits.contains(loadingUnits1[1]), true);
|
||||
expect(component.loadingUnits.contains(loadingUnits1[2]), false);
|
||||
|
||||
final List<LoadingUnit> loadingUnits2 = <LoadingUnit>[
|
||||
LoadingUnit(
|
||||
id: 2,
|
||||
path: 'path/to/so.so',
|
||||
libraries: <String>['lib1', 'lib2'],
|
||||
),
|
||||
LoadingUnit(
|
||||
id: 3,
|
||||
path: 'path/to/so.so',
|
||||
libraries: <String>['lib5', 'lib6'],
|
||||
),
|
||||
LoadingUnit(
|
||||
id: 4,
|
||||
path: 'path/to/so.so',
|
||||
libraries: <String>['lib7', 'lib8'],
|
||||
),
|
||||
];
|
||||
// Can reassign loading units.
|
||||
component.assignLoadingUnits(loadingUnits2);
|
||||
|
||||
expect(component.assigned, true);
|
||||
expect(component.loadingUnits.length, 1);
|
||||
expect(component.loadingUnits.contains(loadingUnits2[0]), true);
|
||||
expect(component.loadingUnits.contains(loadingUnits2[1]), false);
|
||||
expect(component.loadingUnits.contains(loadingUnits2[2]), false);
|
||||
|
||||
component.assignLoadingUnits(<LoadingUnit>[]);
|
||||
|
||||
expect(component.assigned, true);
|
||||
expect(component.loadingUnits.length, 0);
|
||||
});
|
||||
|
||||
test('toString produces correct string for unassigned component', () {
|
||||
final DeferredComponent component = DeferredComponent(
|
||||
name: 'bestcomponent',
|
||||
libraries: <String>['lib1', 'lib2'],
|
||||
assets: <Uri>[Uri.file('asset1'), Uri.file('asset2')],
|
||||
);
|
||||
expect(component.toString(), '\nDeferredComponent: bestcomponent\n Libraries:\n - lib1\n - lib2\n Assets:\n - asset1\n - asset2');
|
||||
});
|
||||
|
||||
test('toString produces correct string for assigned component', () {
|
||||
final DeferredComponent component = DeferredComponent(
|
||||
name: 'bestcomponent',
|
||||
libraries: <String>['lib1', 'lib2'],
|
||||
assets: <Uri>[Uri.file('asset1'), Uri.file('asset2')],
|
||||
);
|
||||
component.assignLoadingUnits(<LoadingUnit>[LoadingUnit(id: 2, libraries: <String>['lib1'])]);
|
||||
expect(component.toString(), '\nDeferredComponent: bestcomponent\n Libraries:\n - lib1\n - lib2\n LoadingUnits:\n - 2\n Assets:\n - asset1\n - asset2');
|
||||
});
|
||||
});
|
||||
|
||||
group('LoadingUnit basics', () {
|
||||
test('constructor sets values', () {
|
||||
final LoadingUnit unit = LoadingUnit(
|
||||
id: 2,
|
||||
path: 'path/to/so.so',
|
||||
libraries: <String>['lib1', 'lib4'],
|
||||
);
|
||||
expect(unit.id, 2);
|
||||
expect(unit.path, 'path/to/so.so');
|
||||
expect(unit.libraries, <String>['lib1', 'lib4']);
|
||||
});
|
||||
|
||||
test('toString produces correct string', () {
|
||||
final LoadingUnit unit = LoadingUnit(
|
||||
id: 2,
|
||||
path: 'path/to/so.so',
|
||||
libraries: <String>['lib1', 'lib4'],
|
||||
);
|
||||
expect(unit.toString(),'\nLoadingUnit 2\n Libraries:\n - lib1\n - lib4');
|
||||
});
|
||||
|
||||
test('equalsIgnoringPath works for various input', () {
|
||||
final LoadingUnit unit1 = LoadingUnit(
|
||||
id: 2,
|
||||
path: 'path/to/so.so',
|
||||
libraries: <String>['lib1', 'lib4'],
|
||||
);
|
||||
final LoadingUnit unit2 = LoadingUnit(
|
||||
id: 2,
|
||||
path: 'path/to/other/so.so',
|
||||
libraries: <String>['lib1', 'lib4'],
|
||||
);
|
||||
final LoadingUnit unit3 = LoadingUnit(
|
||||
id: 1,
|
||||
path: 'path/to/other/so.so',
|
||||
libraries: <String>['lib1', 'lib4'],
|
||||
);
|
||||
final LoadingUnit unit4 = LoadingUnit(
|
||||
id: 1,
|
||||
path: 'path/to/other/so.so',
|
||||
libraries: <String>['lib1'],
|
||||
);
|
||||
final LoadingUnit unit5 = LoadingUnit(
|
||||
id: 1,
|
||||
path: 'path/to/other/so.so',
|
||||
libraries: <String>['lib2'],
|
||||
);
|
||||
final LoadingUnit unit6 = LoadingUnit(
|
||||
id: 1,
|
||||
path: 'path/to/other/so.so',
|
||||
libraries: <String>['lib1', 'lib5'],
|
||||
);
|
||||
expect(unit1.equalsIgnoringPath(unit2), true);
|
||||
expect(unit2.equalsIgnoringPath(unit3), false);
|
||||
expect(unit3.equalsIgnoringPath(unit4), false);
|
||||
expect(unit4.equalsIgnoringPath(unit5), false);
|
||||
expect(unit5.equalsIgnoringPath(unit6), false);
|
||||
});
|
||||
|
||||
test('parseLoadingUnitManifest parses single manifest file', () {
|
||||
final FileSystem fileSystem = MemoryFileSystem.test();
|
||||
final File manifest = fileSystem.file('/manifest.json');
|
||||
manifest.createSync(recursive: true);
|
||||
manifest.writeAsStringSync(r'''
|
||||
{ "loadingUnits": [
|
||||
{ "id": 1, "path": "\/arm64-v8a\/app.so", "libraries": [
|
||||
"dart:core"]}
|
||||
,
|
||||
{ "id": 2, "path": "\/arm64-v8a\/app.so-2.part.so", "libraries": [
|
||||
"lib2"]}
|
||||
,
|
||||
{ "id": 3, "path": "\/arm64-v8a\/app.so-3.part.so", "libraries": [
|
||||
"lib3", "lib4"]}
|
||||
] }
|
||||
|
||||
''', flush: true);
|
||||
final List<LoadingUnit> loadingUnits = LoadingUnit.parseLoadingUnitManifest(manifest, BufferLogger.test());
|
||||
expect(loadingUnits.length, 2); // base module (id 1) is not parsed.
|
||||
expect(loadingUnits[0].id, 2);
|
||||
expect(loadingUnits[0].path, '/arm64-v8a/app.so-2.part.so');
|
||||
expect(loadingUnits[0].libraries.length, 1);
|
||||
expect(loadingUnits[0].libraries[0], 'lib2');
|
||||
expect(loadingUnits[1].id, 3);
|
||||
expect(loadingUnits[1].path, '/arm64-v8a/app.so-3.part.so');
|
||||
expect(loadingUnits[1].libraries.length, 2);
|
||||
expect(loadingUnits[1].libraries[0], 'lib3');
|
||||
expect(loadingUnits[1].libraries[1], 'lib4');
|
||||
});
|
||||
|
||||
testUsingContext('parseLoadingUnitManifest returns empty when manifest is invalid JSON', () {
|
||||
final FileSystem fileSystem = MemoryFileSystem.test();
|
||||
final File manifest = fileSystem.file('/manifest.json');
|
||||
manifest.createSync(recursive: true);
|
||||
// invalid due to missing closing brace `}`
|
||||
manifest.writeAsStringSync(r'''
|
||||
{ "loadingUnits": [
|
||||
{ "id": 1, "path": "\/arm64-v8a\/app.so", "libraries": [
|
||||
"dart:core"]}
|
||||
,
|
||||
{ "id": 2, "path": "\/arm64-v8a\/app.so-2.part.so", "libraries": [
|
||||
"lib2"]}
|
||||
,
|
||||
{ "id": 3, "path": "\/arm64-v8a\/app.so-3.part.so", "libraries": [
|
||||
"lib3", "lib4"]}
|
||||
]
|
||||
|
||||
''', flush: true);
|
||||
final List<LoadingUnit> loadingUnits = LoadingUnit.parseLoadingUnitManifest(manifest, BufferLogger.test());
|
||||
expect(loadingUnits.length, 0);
|
||||
expect(loadingUnits.isEmpty, true);
|
||||
});
|
||||
|
||||
testUsingContext('parseLoadingUnitManifest does not exist', () {
|
||||
final FileSystem fileSystem = MemoryFileSystem.test();
|
||||
final File manifest = fileSystem.file('/manifest.json');
|
||||
if (manifest.existsSync()) {
|
||||
manifest.deleteSync(recursive: true);
|
||||
}
|
||||
final List<LoadingUnit> loadingUnits = LoadingUnit.parseLoadingUnitManifest(manifest, BufferLogger.test());
|
||||
expect(loadingUnits.length, 0);
|
||||
expect(loadingUnits.isEmpty, true);
|
||||
});
|
||||
|
||||
test('parseGeneratedLoadingUnits parses all abis if no abis provided', () {
|
||||
final FileSystem fileSystem = MemoryFileSystem.test();
|
||||
final File manifest1 = fileSystem.file('/test-abi1/manifest.json');
|
||||
manifest1.createSync(recursive: true);
|
||||
manifest1.writeAsStringSync(r'''
|
||||
{ "loadingUnits": [
|
||||
{ "id": 1, "path": "\/test-abi1\/app.so", "libraries": [
|
||||
"dart:core"]}
|
||||
,
|
||||
{ "id": 2, "path": "\/test-abi1\/app.so-2.part.so", "libraries": [
|
||||
"lib2"]}
|
||||
,
|
||||
{ "id": 3, "path": "\/test-abi1\/app.so-3.part.so", "libraries": [
|
||||
"lib3", "lib4"]}
|
||||
] }
|
||||
|
||||
''', flush: true);
|
||||
final File manifest2 = fileSystem.file('/test-abi2/manifest.json');
|
||||
manifest2.createSync(recursive: true);
|
||||
manifest2.writeAsStringSync(r'''
|
||||
{ "loadingUnits": [
|
||||
{ "id": 1, "path": "\/test-abi2\/app.so", "libraries": [
|
||||
"dart:core"]}
|
||||
,
|
||||
{ "id": 2, "path": "\/test-abi2\/app.so-2.part.so", "libraries": [
|
||||
"lib2"]}
|
||||
,
|
||||
{ "id": 3, "path": "\/test-abi2\/app.so-3.part.so", "libraries": [
|
||||
"lib3", "lib4"]}
|
||||
] }
|
||||
|
||||
''', flush: true);
|
||||
final List<LoadingUnit> loadingUnits =
|
||||
LoadingUnit.parseGeneratedLoadingUnits(fileSystem.directory('/'), BufferLogger.test());
|
||||
expect(loadingUnits.length, 4); // base module (id 1) is not parsed.
|
||||
|
||||
expect(loadingUnits[0].id, 2);
|
||||
expect(loadingUnits[0].path, '/test-abi2/app.so-2.part.so');
|
||||
expect(loadingUnits[0].libraries.length, 1);
|
||||
expect(loadingUnits[0].libraries[0], 'lib2');
|
||||
expect(loadingUnits[1].id, 3);
|
||||
expect(loadingUnits[1].path, '/test-abi2/app.so-3.part.so');
|
||||
expect(loadingUnits[1].libraries.length, 2);
|
||||
expect(loadingUnits[1].libraries[0], 'lib3');
|
||||
expect(loadingUnits[1].libraries[1], 'lib4');
|
||||
|
||||
expect(loadingUnits[2].id, 2);
|
||||
expect(loadingUnits[2].path, '/test-abi1/app.so-2.part.so');
|
||||
expect(loadingUnits[2].libraries.length, 1);
|
||||
expect(loadingUnits[2].libraries[0], 'lib2');
|
||||
expect(loadingUnits[3].id, 3);
|
||||
expect(loadingUnits[3].path, '/test-abi1/app.so-3.part.so');
|
||||
expect(loadingUnits[3].libraries.length, 2);
|
||||
expect(loadingUnits[3].libraries[0], 'lib3');
|
||||
expect(loadingUnits[3].libraries[1], 'lib4');
|
||||
});
|
||||
|
||||
test('parseGeneratedLoadingUnits only parses provided abis', () {
|
||||
final FileSystem fileSystem = MemoryFileSystem.test();
|
||||
final File manifest1 = fileSystem.file('/test-abi1/manifest.json');
|
||||
manifest1.createSync(recursive: true);
|
||||
manifest1.writeAsStringSync(r'''
|
||||
{ "loadingUnits": [
|
||||
{ "id": 1, "path": "\/test-abi1\/app.so", "libraries": [
|
||||
"dart:core"]}
|
||||
,
|
||||
{ "id": 2, "path": "\/test-abi1\/app.so-2.part.so", "libraries": [
|
||||
"lib2"]}
|
||||
,
|
||||
{ "id": 3, "path": "\/test-abi1\/app.so-3.part.so", "libraries": [
|
||||
"lib3", "lib4"]}
|
||||
] }
|
||||
|
||||
''', flush: true);
|
||||
final File manifest2 = fileSystem.file('/test-abi2/manifest.json');
|
||||
manifest2.createSync(recursive: true);
|
||||
manifest2.writeAsStringSync(r'''
|
||||
{ "loadingUnits": [
|
||||
{ "id": 1, "path": "\/test-abi2\/app.so", "libraries": [
|
||||
"dart:core"]}
|
||||
,
|
||||
{ "id": 2, "path": "\/test-abi2\/app.so-2.part.so", "libraries": [
|
||||
"lib2"]}
|
||||
,
|
||||
{ "id": 3, "path": "\/test-abi2\/app.so-3.part.so", "libraries": [
|
||||
"lib3", "lib4"]}
|
||||
] }
|
||||
|
||||
''', flush: true);
|
||||
final List<LoadingUnit> loadingUnits =
|
||||
LoadingUnit.parseGeneratedLoadingUnits(fileSystem.directory('/'), BufferLogger.test(), abis: <String>['test-abi2']);
|
||||
expect(loadingUnits.length, 2); // base module (id 1) is not parsed.
|
||||
|
||||
expect(loadingUnits[0].id, 2);
|
||||
expect(loadingUnits[0].path, '/test-abi2/app.so-2.part.so');
|
||||
expect(loadingUnits[0].libraries.length, 1);
|
||||
expect(loadingUnits[0].libraries[0], 'lib2');
|
||||
expect(loadingUnits[1].id, 3);
|
||||
expect(loadingUnits[1].path, '/test-abi2/app.so-3.part.so');
|
||||
expect(loadingUnits[1].libraries.length, 2);
|
||||
expect(loadingUnits[1].libraries[0], 'lib3');
|
||||
expect(loadingUnits[1].libraries[1], 'lib4');
|
||||
});
|
||||
|
||||
test('parseGeneratedLoadingUnits returns empty when no manifest files exist', () {
|
||||
final FileSystem fileSystem = MemoryFileSystem.test();
|
||||
final List<LoadingUnit> loadingUnits =
|
||||
LoadingUnit.parseGeneratedLoadingUnits(fileSystem.directory('/'), BufferLogger.test());
|
||||
expect(loadingUnits.isEmpty, true);
|
||||
expect(loadingUnits.length, 0);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -7,11 +7,13 @@
|
||||
import 'package:file/memory.dart';
|
||||
import 'package:file_testing/file_testing.dart';
|
||||
import 'package:flutter_tools/src/artifacts.dart';
|
||||
import 'package:flutter_tools/src/base/deferred_component.dart';
|
||||
import 'package:flutter_tools/src/base/file_system.dart';
|
||||
import 'package:flutter_tools/src/base/logger.dart';
|
||||
import 'package:flutter_tools/src/base/platform.dart';
|
||||
import 'package:flutter_tools/src/build_info.dart';
|
||||
import 'package:flutter_tools/src/build_system/build_system.dart';
|
||||
import 'package:flutter_tools/src/build_system/depfile.dart';
|
||||
import 'package:flutter_tools/src/build_system/targets/android.dart';
|
||||
import 'package:flutter_tools/src/build_system/targets/assets.dart';
|
||||
import 'package:flutter_tools/src/build_system/targets/common.dart';
|
||||
@@ -362,4 +364,168 @@ void main() {
|
||||
.childDirectory('arm64-v8a')
|
||||
.childFile('app.so').existsSync(), true);
|
||||
});
|
||||
|
||||
test('copyDeferredComponentSoFiles copies all files to correct locations', () {
|
||||
final Environment environment = Environment.test(
|
||||
fileSystem.currentDirectory,
|
||||
outputDir: fileSystem.directory('/out')..createSync(),
|
||||
defines: <String, String>{
|
||||
kBuildMode: 'release',
|
||||
},
|
||||
processManager: processManager,
|
||||
artifacts: artifacts,
|
||||
fileSystem: fileSystem,
|
||||
logger: logger,
|
||||
);
|
||||
final File so1 = fileSystem.file('/unit2/abi1/part.so');
|
||||
so1.createSync(recursive: true);
|
||||
so1.writeAsStringSync('lib1');
|
||||
final File so2 = fileSystem.file('/unit3/abi1/part.so');
|
||||
so2.createSync(recursive: true);
|
||||
so2.writeAsStringSync('lib2');
|
||||
final File so3 = fileSystem.file('/unit4/abi1/part.so');
|
||||
so3.createSync(recursive: true);
|
||||
so3.writeAsStringSync('lib3');
|
||||
|
||||
final File so4 = fileSystem.file('/unit2/abi2/part.so');
|
||||
so4.createSync(recursive: true);
|
||||
so4.writeAsStringSync('lib1');
|
||||
final File so5 = fileSystem.file('/unit3/abi2/part.so');
|
||||
so5.createSync(recursive: true);
|
||||
so5.writeAsStringSync('lib2');
|
||||
final File so6 = fileSystem.file('/unit4/abi2/part.so');
|
||||
so6.createSync(recursive: true);
|
||||
so6.writeAsStringSync('lib3');
|
||||
|
||||
final List<DeferredComponent> components = <DeferredComponent>[
|
||||
DeferredComponent(name: 'component2', libraries: <String>['lib1']),
|
||||
DeferredComponent(name: 'component3', libraries: <String>['lib2']),
|
||||
];
|
||||
final List<LoadingUnit> loadingUnits = <LoadingUnit>[
|
||||
LoadingUnit(id: 2, libraries: <String>['lib1'], path: '/unit2/abi1/part.so'),
|
||||
LoadingUnit(id: 3, libraries: <String>['lib2'], path: '/unit3/abi1/part.so'),
|
||||
LoadingUnit(id: 4, libraries: <String>['lib3'], path: '/unit4/abi1/part.so'),
|
||||
|
||||
LoadingUnit(id: 2, libraries: <String>['lib1'], path: '/unit2/abi2/part.so'),
|
||||
LoadingUnit(id: 3, libraries: <String>['lib2'], path: '/unit3/abi2/part.so'),
|
||||
LoadingUnit(id: 4, libraries: <String>['lib3'], path: '/unit4/abi2/part.so'),
|
||||
];
|
||||
for (final DeferredComponent component in components) {
|
||||
component.assignLoadingUnits(loadingUnits);
|
||||
}
|
||||
final Directory buildDir = fileSystem.directory('/build');
|
||||
if (!buildDir.existsSync()) {
|
||||
buildDir.createSync(recursive: true);
|
||||
}
|
||||
final Depfile depfile = copyDeferredComponentSoFiles(
|
||||
environment,
|
||||
components,
|
||||
loadingUnits,
|
||||
buildDir,
|
||||
<String>['abi1', 'abi2'],
|
||||
BuildMode.release
|
||||
);
|
||||
expect(depfile.inputs.length, 6);
|
||||
expect(depfile.outputs.length, 6);
|
||||
|
||||
expect(depfile.inputs[0].path, so1.path);
|
||||
expect(depfile.inputs[1].path, so2.path);
|
||||
expect(depfile.inputs[2].path, so4.path);
|
||||
expect(depfile.inputs[3].path, so5.path);
|
||||
expect(depfile.inputs[4].path, so3.path);
|
||||
expect(depfile.inputs[5].path, so6.path);
|
||||
|
||||
expect(depfile.outputs[0].readAsStringSync(), so1.readAsStringSync());
|
||||
expect(depfile.outputs[1].readAsStringSync(), so2.readAsStringSync());
|
||||
expect(depfile.outputs[2].readAsStringSync(), so4.readAsStringSync());
|
||||
expect(depfile.outputs[3].readAsStringSync(), so5.readAsStringSync());
|
||||
expect(depfile.outputs[4].readAsStringSync(), so3.readAsStringSync());
|
||||
expect(depfile.outputs[5].readAsStringSync(), so6.readAsStringSync());
|
||||
|
||||
expect(depfile.outputs[0].path, '/build/component2/intermediates/flutter/release/deferred_libs/abi1/libapp.so-2.part.so');
|
||||
expect(depfile.outputs[1].path, '/build/component3/intermediates/flutter/release/deferred_libs/abi1/libapp.so-3.part.so');
|
||||
|
||||
expect(depfile.outputs[2].path, '/build/component2/intermediates/flutter/release/deferred_libs/abi2/libapp.so-2.part.so');
|
||||
expect(depfile.outputs[3].path, '/build/component3/intermediates/flutter/release/deferred_libs/abi2/libapp.so-3.part.so');
|
||||
|
||||
expect(depfile.outputs[4].path, '/out/abi1/app.so-4.part.so');
|
||||
expect(depfile.outputs[5].path, '/out/abi2/app.so-4.part.so');
|
||||
});
|
||||
|
||||
test('copyDeferredComponentSoFiles copies files for only listed abis', () {
|
||||
final Environment environment = Environment.test(
|
||||
fileSystem.currentDirectory,
|
||||
outputDir: fileSystem.directory('/out')..createSync(),
|
||||
defines: <String, String>{
|
||||
kBuildMode: 'release',
|
||||
},
|
||||
processManager: processManager,
|
||||
artifacts: artifacts,
|
||||
fileSystem: fileSystem,
|
||||
logger: logger,
|
||||
);
|
||||
final File so1 = fileSystem.file('/unit2/abi1/part.so');
|
||||
so1.createSync(recursive: true);
|
||||
so1.writeAsStringSync('lib1');
|
||||
final File so2 = fileSystem.file('/unit3/abi1/part.so');
|
||||
so2.createSync(recursive: true);
|
||||
so2.writeAsStringSync('lib2');
|
||||
final File so3 = fileSystem.file('/unit4/abi1/part.so');
|
||||
so3.createSync(recursive: true);
|
||||
so3.writeAsStringSync('lib3');
|
||||
|
||||
final File so4 = fileSystem.file('/unit2/abi2/part.so');
|
||||
so4.createSync(recursive: true);
|
||||
so4.writeAsStringSync('lib1');
|
||||
final File so5 = fileSystem.file('/unit3/abi2/part.so');
|
||||
so5.createSync(recursive: true);
|
||||
so5.writeAsStringSync('lib2');
|
||||
final File so6 = fileSystem.file('/unit4/abi2/part.so');
|
||||
so6.createSync(recursive: true);
|
||||
so6.writeAsStringSync('lib3');
|
||||
|
||||
final List<DeferredComponent> components = <DeferredComponent>[
|
||||
DeferredComponent(name: 'component2', libraries: <String>['lib1']),
|
||||
DeferredComponent(name: 'component3', libraries: <String>['lib2']),
|
||||
];
|
||||
final List<LoadingUnit> loadingUnits = <LoadingUnit>[
|
||||
LoadingUnit(id: 2, libraries: <String>['lib1'], path: '/unit2/abi1/part.so'),
|
||||
LoadingUnit(id: 3, libraries: <String>['lib2'], path: '/unit3/abi1/part.so'),
|
||||
LoadingUnit(id: 4, libraries: <String>['lib3'], path: '/unit4/abi1/part.so'),
|
||||
|
||||
LoadingUnit(id: 2, libraries: <String>['lib1'], path: '/unit2/abi2/part.so'),
|
||||
LoadingUnit(id: 3, libraries: <String>['lib2'], path: '/unit3/abi2/part.so'),
|
||||
LoadingUnit(id: 4, libraries: <String>['lib3'], path: '/unit4/abi2/part.so'),
|
||||
];
|
||||
for (final DeferredComponent component in components) {
|
||||
component.assignLoadingUnits(loadingUnits);
|
||||
}
|
||||
final Directory buildDir = fileSystem.directory('/build');
|
||||
if (!buildDir.existsSync()) {
|
||||
buildDir.createSync(recursive: true);
|
||||
}
|
||||
final Depfile depfile = copyDeferredComponentSoFiles(
|
||||
environment,
|
||||
components,
|
||||
loadingUnits,
|
||||
buildDir,
|
||||
<String>['abi1'],
|
||||
BuildMode.release
|
||||
);
|
||||
expect(depfile.inputs.length, 3);
|
||||
expect(depfile.outputs.length, 3);
|
||||
|
||||
expect(depfile.inputs[0].path, so1.path);
|
||||
expect(depfile.inputs[1].path, so2.path);
|
||||
expect(depfile.inputs[2].path, so3.path);
|
||||
|
||||
expect(depfile.outputs[0].readAsStringSync(), so1.readAsStringSync());
|
||||
expect(depfile.outputs[1].readAsStringSync(), so2.readAsStringSync());
|
||||
expect(depfile.outputs[2].readAsStringSync(), so3.readAsStringSync());
|
||||
|
||||
expect(depfile.outputs[0].path, '/build/component2/intermediates/flutter/release/deferred_libs/abi1/libapp.so-2.part.so');
|
||||
expect(depfile.outputs[1].path, '/build/component3/intermediates/flutter/release/deferred_libs/abi1/libapp.so-3.part.so');
|
||||
|
||||
expect(depfile.outputs[2].path, '/out/abi1/app.so-4.part.so');
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1144,6 +1144,303 @@ flutter:
|
||||
expect(flutterManifest, null);
|
||||
expect(logger.errorText, 'Expected "licenses" to be a list of files, but element 1 was a YamlMap\n');
|
||||
});
|
||||
|
||||
testWithoutContext('FlutterManifest parses single deferred components', () async {
|
||||
const String manifest = '''
|
||||
name: test
|
||||
dependencies:
|
||||
flutter:
|
||||
sdk: flutter
|
||||
flutter:
|
||||
deferred-components:
|
||||
- name: component1
|
||||
libraries:
|
||||
- lib1
|
||||
assets:
|
||||
- path/to/asset.jpg
|
||||
''';
|
||||
final BufferLogger logger = BufferLogger.test();
|
||||
final FlutterManifest flutterManifest = FlutterManifest.createFromString(
|
||||
manifest,
|
||||
logger: logger,
|
||||
);
|
||||
|
||||
expect(flutterManifest, isNotNull);
|
||||
expect(flutterManifest.deferredComponents.length, 1);
|
||||
expect(flutterManifest.deferredComponents[0].name, 'component1');
|
||||
expect(flutterManifest.deferredComponents[0].libraries.length, 1);
|
||||
expect(flutterManifest.deferredComponents[0].libraries[0], 'lib1');
|
||||
expect(flutterManifest.deferredComponents[0].assets.length, 1);
|
||||
expect(flutterManifest.deferredComponents[0].assets[0].path, 'path/to/asset.jpg');
|
||||
});
|
||||
|
||||
testWithoutContext('FlutterManifest parses multiple deferred components', () async {
|
||||
const String manifest = '''
|
||||
name: test
|
||||
dependencies:
|
||||
flutter:
|
||||
sdk: flutter
|
||||
flutter:
|
||||
deferred-components:
|
||||
- name: component1
|
||||
libraries:
|
||||
- lib1
|
||||
assets:
|
||||
- path/to/asset.jpg
|
||||
- name: component2
|
||||
libraries:
|
||||
- lib2
|
||||
- lib3
|
||||
assets:
|
||||
- path/to/asset2.jpg
|
||||
''';
|
||||
final BufferLogger logger = BufferLogger.test();
|
||||
final FlutterManifest flutterManifest = FlutterManifest.createFromString(
|
||||
manifest,
|
||||
logger: logger,
|
||||
);
|
||||
|
||||
expect(flutterManifest, isNotNull);
|
||||
expect(flutterManifest.deferredComponents.length, 2);
|
||||
expect(flutterManifest.deferredComponents[0].name, 'component1');
|
||||
expect(flutterManifest.deferredComponents[0].libraries.length, 1);
|
||||
expect(flutterManifest.deferredComponents[0].libraries[0], 'lib1');
|
||||
expect(flutterManifest.deferredComponents[0].assets.length, 1);
|
||||
expect(flutterManifest.deferredComponents[0].assets[0].path, 'path/to/asset.jpg');
|
||||
|
||||
expect(flutterManifest.deferredComponents[1].name, 'component2');
|
||||
expect(flutterManifest.deferredComponents[1].libraries.length, 2);
|
||||
expect(flutterManifest.deferredComponents[1].libraries[0], 'lib2');
|
||||
expect(flutterManifest.deferredComponents[1].libraries[1], 'lib3');
|
||||
expect(flutterManifest.deferredComponents[1].assets.length, 1);
|
||||
expect(flutterManifest.deferredComponents[1].assets[0].path, 'path/to/asset2.jpg');
|
||||
});
|
||||
|
||||
testWithoutContext('FlutterManifest parses empty deferred components', () async {
|
||||
const String manifest = '''
|
||||
name: test
|
||||
dependencies:
|
||||
flutter:
|
||||
sdk: flutter
|
||||
flutter:
|
||||
deferred-components:
|
||||
''';
|
||||
final BufferLogger logger = BufferLogger.test();
|
||||
final FlutterManifest flutterManifest = FlutterManifest.createFromString(
|
||||
manifest,
|
||||
logger: logger,
|
||||
);
|
||||
|
||||
expect(flutterManifest, isNotNull);
|
||||
expect(flutterManifest.deferredComponents.length, 0);
|
||||
});
|
||||
|
||||
testWithoutContext('FlutterManifest deferred component requires name', () async {
|
||||
const String manifest = '''
|
||||
name: test
|
||||
dependencies:
|
||||
flutter:
|
||||
sdk: flutter
|
||||
flutter:
|
||||
deferred-components:
|
||||
- libraries:
|
||||
- lib1
|
||||
''';
|
||||
final BufferLogger logger = BufferLogger.test();
|
||||
final FlutterManifest flutterManifest = FlutterManifest.createFromString(
|
||||
manifest,
|
||||
logger: logger,
|
||||
);
|
||||
|
||||
expect(flutterManifest, null);
|
||||
expect(logger.errorText, 'Expected the 0 element in "deferred-components" to have required key "name" of type String\n');
|
||||
});
|
||||
|
||||
testWithoutContext('FlutterManifest deferred component is list', () async {
|
||||
const String manifest = '''
|
||||
name: test
|
||||
dependencies:
|
||||
flutter:
|
||||
sdk: flutter
|
||||
flutter:
|
||||
deferred-components: blah
|
||||
''';
|
||||
final BufferLogger logger = BufferLogger.test();
|
||||
final FlutterManifest flutterManifest = FlutterManifest.createFromString(
|
||||
manifest,
|
||||
logger: logger,
|
||||
);
|
||||
|
||||
expect(flutterManifest, null);
|
||||
expect(logger.errorText, 'Expected "deferred-components" to be a list, but got blah (String).\n');
|
||||
});
|
||||
|
||||
testWithoutContext('FlutterManifest deferred component libraries is list', () async {
|
||||
const String manifest = '''
|
||||
name: test
|
||||
dependencies:
|
||||
flutter:
|
||||
sdk: flutter
|
||||
flutter:
|
||||
deferred-components:
|
||||
- name: blah
|
||||
libraries: blah
|
||||
''';
|
||||
final BufferLogger logger = BufferLogger.test();
|
||||
final FlutterManifest flutterManifest = FlutterManifest.createFromString(
|
||||
manifest,
|
||||
logger: logger,
|
||||
);
|
||||
|
||||
expect(flutterManifest, null);
|
||||
expect(logger.errorText, 'Expected "libraries" key in the 0 element of "deferred-components" to be a list, but got blah (String).\n');
|
||||
});
|
||||
|
||||
testWithoutContext('FlutterManifest deferred component libraries is string', () async {
|
||||
const String manifest = '''
|
||||
name: test
|
||||
dependencies:
|
||||
flutter:
|
||||
sdk: flutter
|
||||
flutter:
|
||||
deferred-components:
|
||||
- name: blah
|
||||
libraries:
|
||||
- not-a-string:
|
||||
''';
|
||||
final BufferLogger logger = BufferLogger.test();
|
||||
final FlutterManifest flutterManifest = FlutterManifest.createFromString(
|
||||
manifest,
|
||||
logger: logger,
|
||||
);
|
||||
|
||||
expect(flutterManifest, null);
|
||||
expect(logger.errorText, 'Expected "libraries" key in the 0 element of "deferred-components" to be a list of dart library Strings, but element 0 was a YamlMap\n');
|
||||
});
|
||||
|
||||
testWithoutContext('FlutterManifest deferred component assets is string', () async {
|
||||
const String manifest = '''
|
||||
name: test
|
||||
dependencies:
|
||||
flutter:
|
||||
sdk: flutter
|
||||
flutter:
|
||||
deferred-components:
|
||||
- name: blah
|
||||
assets:
|
||||
- not-a-string:
|
||||
''';
|
||||
final BufferLogger logger = BufferLogger.test();
|
||||
final FlutterManifest flutterManifest = FlutterManifest.createFromString(
|
||||
manifest,
|
||||
logger: logger,
|
||||
);
|
||||
|
||||
expect(flutterManifest, null);
|
||||
expect(logger.errorText, 'Expected "assets" key in the 0 element of "deferred-components" to be a list of file paths, but element 0 was a YamlMap\n');
|
||||
});
|
||||
|
||||
testWithoutContext('FlutterManifest deferred component multiple assets is string', () async {
|
||||
const String manifest = '''
|
||||
name: test
|
||||
dependencies:
|
||||
flutter:
|
||||
sdk: flutter
|
||||
flutter:
|
||||
deferred-components:
|
||||
- name: blah
|
||||
assets:
|
||||
- path/to/file.so
|
||||
- also-not-a-string:
|
||||
- woo
|
||||
''';
|
||||
final BufferLogger logger = BufferLogger.test();
|
||||
final FlutterManifest flutterManifest = FlutterManifest.createFromString(
|
||||
manifest,
|
||||
logger: logger,
|
||||
);
|
||||
|
||||
expect(flutterManifest, null);
|
||||
expect(logger.errorText, 'Expected "assets" key in the 0 element of "deferred-components" to be a list of file paths, but element 1 was a YamlMap\n');
|
||||
});
|
||||
|
||||
testWithoutContext('FlutterManifest multiple deferred components assets is string', () async {
|
||||
const String manifest = '''
|
||||
name: test
|
||||
dependencies:
|
||||
flutter:
|
||||
sdk: flutter
|
||||
flutter:
|
||||
deferred-components:
|
||||
- name: blah
|
||||
assets:
|
||||
- path/to/file.so
|
||||
- name: blah2
|
||||
assets:
|
||||
- path/to/other/file.so
|
||||
- not-a-string:
|
||||
- woo
|
||||
''';
|
||||
final BufferLogger logger = BufferLogger.test();
|
||||
final FlutterManifest flutterManifest = FlutterManifest.createFromString(
|
||||
manifest,
|
||||
logger: logger,
|
||||
);
|
||||
|
||||
expect(flutterManifest, null);
|
||||
expect(logger.errorText, 'Expected "assets" key in the 1 element of "deferred-components" to be a list of file paths, but element 1 was a YamlMap\n');
|
||||
});
|
||||
|
||||
testWithoutContext('FlutterManifest deferred component assets is list', () async {
|
||||
const String manifest = '''
|
||||
name: test
|
||||
dependencies:
|
||||
flutter:
|
||||
sdk: flutter
|
||||
flutter:
|
||||
deferred-components:
|
||||
- name: blah
|
||||
assets: blah
|
||||
''';
|
||||
final BufferLogger logger = BufferLogger.test();
|
||||
final FlutterManifest flutterManifest = FlutterManifest.createFromString(
|
||||
manifest,
|
||||
logger: logger,
|
||||
);
|
||||
|
||||
expect(flutterManifest, null);
|
||||
expect(logger.errorText, 'Expected "assets" key in the 0 element of "deferred-components" to be a list, but got blah (String).\n');
|
||||
});
|
||||
|
||||
testWithoutContext('FlutterManifest parses asset-only deferred components', () async {
|
||||
const String manifest = '''
|
||||
name: test
|
||||
dependencies:
|
||||
flutter:
|
||||
sdk: flutter
|
||||
flutter:
|
||||
deferred-components:
|
||||
- name: component1
|
||||
assets:
|
||||
- path/to/asset1.jpg
|
||||
- path/to/asset2.jpg
|
||||
- path/to/asset3.jpg
|
||||
''';
|
||||
final BufferLogger logger = BufferLogger.test();
|
||||
final FlutterManifest flutterManifest = FlutterManifest.createFromString(
|
||||
manifest,
|
||||
logger: logger,
|
||||
);
|
||||
|
||||
expect(flutterManifest, isNotNull);
|
||||
expect(flutterManifest.deferredComponents.length, 1);
|
||||
expect(flutterManifest.deferredComponents[0].name, 'component1');
|
||||
expect(flutterManifest.deferredComponents[0].libraries.length, 0);
|
||||
expect(flutterManifest.deferredComponents[0].assets.length, 3);
|
||||
expect(flutterManifest.deferredComponents[0].assets[0].path, 'path/to/asset1.jpg');
|
||||
expect(flutterManifest.deferredComponents[0].assets[1].path, 'path/to/asset2.jpg');
|
||||
expect(flutterManifest.deferredComponents[0].assets[2].path, 'path/to/asset3.jpg');
|
||||
});
|
||||
}
|
||||
|
||||
Matcher matchesManifest({
|
||||
|
||||
Reference in New Issue
Block a user