Skip to content

Commit dec31cb

Browse files
authored
[native_assets] Roll dependencies (#166282)
Updating the dart-lang/native dependencies to the ones published today. No functional changes, but `CodeAsset` does not expose an `architecture` and `os ` anymore (dart-lang/native#2127). Instead these should be taken from what is passed in for the `CodeConfig`. This PR refactors the `DartBuildResult` to carry around the `Target` with `CodeAsset`s as `FlutterCodeAsset`s. (This PR avoid refactoring relevant code due to flutter/flutter#164094 already refactoring this code.)
1 parent b85c0fc commit dec31cb

12 files changed

Lines changed: 158 additions & 131 deletions

File tree

dev/integration_tests/link_hook/hook/build.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import 'package:native_toolchain_c/native_toolchain_c.dart';
99

1010
void main(List<String> args) async {
1111
await build(args, (BuildInput input, BuildOutputBuilder output) async {
12-
if (!input.config.buildAssetTypes.contains(CodeAsset.type)) {
12+
if (!input.config.buildCodeAssets) {
1313
return;
1414
}
1515

dev/integration_tests/link_hook/hook/link.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import 'package:native_assets_cli/code_assets.dart';
66

77
void main(List<String> args) async {
88
await link(args, (LinkInput input, LinkOutputBuilder output) async {
9-
if (!input.config.buildAssetTypes.contains(CodeAsset.type)) {
9+
if (!input.config.buildCodeAssets) {
1010
return;
1111
}
1212
final CodeAsset asset = input.assets.code.single;
@@ -17,8 +17,8 @@ void main(List<String> args) async {
1717
// Change the asset id to something that is used.
1818
name: '${packageName}_bindings_generated.dart',
1919
linkMode: asset.linkMode,
20-
os: asset.os,
21-
architecture: asset.architecture,
20+
os: input.config.code.targetOS,
21+
architecture: input.config.code.targetArchitecture,
2222
file: asset.file,
2323
),
2424
);

dev/integration_tests/link_hook/pubspec.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ environment:
77

88
dependencies:
99
logging: 1.3.0
10-
native_assets_cli: 0.12.0
11-
native_toolchain_c: 0.9.0
10+
native_assets_cli: 0.13.0
11+
native_toolchain_c: 0.10.0
1212

1313
async: 2.13.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
1414
collection: 1.19.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
@@ -68,4 +68,4 @@ dev_dependencies:
6868
webkit_inspection_protocol: 1.2.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
6969
yaml_edit: 2.2.2 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
7070

71-
# PUBSPEC CHECKSUM: 2038
71+
# PUBSPEC CHECKSUM: a861

packages/flutter_tools/lib/src/isolated/native_assets/android/native_assets.dart

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,15 @@ import '../../../android/gradle_utils.dart';
1010
import '../../../base/common.dart';
1111
import '../../../base/file_system.dart';
1212
import '../../../build_info.dart';
13+
import '../native_assets.dart';
1314

1415
int targetAndroidNdkApi(Map<String, String> environmentDefines) {
1516
return int.parse(environmentDefines[kMinSdkVersion] ?? minSdkVersion);
1617
}
1718

1819
Future<void> copyNativeCodeAssetsAndroid(
1920
Uri buildUri,
20-
Map<CodeAsset, KernelAsset> assetTargetLocations,
21+
Map<FlutterCodeAsset, KernelAsset> assetTargetLocations,
2122
FileSystem fileSystem,
2223
) async {
2324
assert(assetTargetLocations.isNotEmpty);
@@ -28,8 +29,8 @@ Future<void> copyNativeCodeAssetsAndroid(
2829
final Uri archUri = buildUri.resolve('jniLibs/lib/$jniArchDir/');
2930
await fileSystem.directory(archUri).create(recursive: true);
3031
}
31-
for (final MapEntry<CodeAsset, KernelAsset> assetMapping in assetTargetLocations.entries) {
32-
final Uri source = assetMapping.key.file!;
32+
for (final MapEntry<FlutterCodeAsset, KernelAsset> assetMapping in assetTargetLocations.entries) {
33+
final Uri source = assetMapping.key.codeAsset.file!;
3334
final Uri target = (assetMapping.value.path as KernelAssetAbsolutePath).uri;
3435
final AndroidArch androidArch = _getAndroidArch(assetMapping.value.target.architecture);
3536
final String jniArchDir = androidArch.archName;
@@ -62,16 +63,18 @@ AndroidArch _getAndroidArch(Architecture architecture) {
6263
};
6364
}
6465

65-
Map<CodeAsset, KernelAsset> assetTargetLocationsAndroid(List<CodeAsset> nativeAssets) {
66-
return <CodeAsset, KernelAsset>{
67-
for (final CodeAsset asset in nativeAssets) asset: _targetLocationAndroid(asset),
66+
Map<FlutterCodeAsset, KernelAsset> assetTargetLocationsAndroid(
67+
List<FlutterCodeAsset> nativeAssets,
68+
) {
69+
return <FlutterCodeAsset, KernelAsset>{
70+
for (final FlutterCodeAsset asset in nativeAssets) asset: _targetLocationAndroid(asset),
6871
};
6972
}
7073

7174
/// Converts the `path` of [asset] as output from a `build.dart` invocation to
7275
/// the path used inside the Flutter app bundle.
73-
KernelAsset _targetLocationAndroid(CodeAsset asset) {
74-
final LinkMode linkMode = asset.linkMode;
76+
KernelAsset _targetLocationAndroid(FlutterCodeAsset asset) {
77+
final LinkMode linkMode = asset.codeAsset.linkMode;
7578
final KernelAssetPath kernelAssetPath;
7679
switch (linkMode) {
7780
case DynamicLoadingSystem _:
@@ -81,16 +84,12 @@ KernelAsset _targetLocationAndroid(CodeAsset asset) {
8184
case LookupInProcess _:
8285
kernelAssetPath = KernelAssetInProcess();
8386
case DynamicLoadingBundled _:
84-
final String fileName = asset.file!.pathSegments.last;
87+
final String fileName = asset.codeAsset.file!.pathSegments.last;
8588
kernelAssetPath = KernelAssetAbsolutePath(Uri(path: fileName));
8689
default:
8790
throw Exception('Unsupported asset link mode $linkMode in asset $asset');
8891
}
89-
return KernelAsset(
90-
id: asset.id,
91-
target: Target.fromArchitectureAndOS(asset.architecture, asset.os),
92-
path: kernelAssetPath,
93-
);
92+
return KernelAsset(id: asset.codeAsset.id, target: asset.target, path: kernelAssetPath);
9493
}
9594

9695
/// Looks the NDK clang compiler tools.

packages/flutter_tools/lib/src/isolated/native_assets/ios/native_assets.dart

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import 'package:native_assets_cli/code_assets_builder.dart';
88
import '../../../base/file_system.dart';
99
import '../../../build_info.dart';
1010
import '../macos/native_assets_host.dart';
11+
import '../native_assets.dart';
1112

1213
// TODO(dcharkes): Fetch minimum iOS version from somewhere. https://github.com/flutter/flutter/issues/145104
1314
const int targetIOSVersion = 12;
@@ -28,40 +29,41 @@ Architecture getNativeIOSArchitecture(DarwinArch darwinArch) {
2829
};
2930
}
3031

31-
Map<KernelAssetPath, List<CodeAsset>> fatAssetTargetLocationsIOS(List<CodeAsset> nativeAssets) {
32+
Map<KernelAssetPath, List<FlutterCodeAsset>> fatAssetTargetLocationsIOS(
33+
List<FlutterCodeAsset> nativeAssets,
34+
) {
3235
final Set<String> alreadyTakenNames = <String>{};
33-
final Map<KernelAssetPath, List<CodeAsset>> result = <KernelAssetPath, List<CodeAsset>>{};
36+
final Map<KernelAssetPath, List<FlutterCodeAsset>> result =
37+
<KernelAssetPath, List<FlutterCodeAsset>>{};
3438
final Map<String, KernelAssetPath> idToPath = <String, KernelAssetPath>{};
35-
for (final CodeAsset asset in nativeAssets) {
39+
for (final FlutterCodeAsset asset in nativeAssets) {
3640
// Use same target path for all assets with the same id.
41+
final String assetId = asset.codeAsset.id;
3742
final KernelAssetPath path =
38-
idToPath[asset.id] ?? _targetLocationIOS(asset, alreadyTakenNames).path;
39-
idToPath[asset.id] = path;
40-
result[path] ??= <CodeAsset>[];
43+
idToPath[assetId] ?? _targetLocationIOS(asset, alreadyTakenNames).path;
44+
idToPath[assetId] = path;
45+
result[path] ??= <FlutterCodeAsset>[];
4146
result[path]!.add(asset);
4247
}
4348
return result;
4449
}
4550

46-
Map<CodeAsset, KernelAsset> assetTargetLocationsIOS(List<CodeAsset> nativeAssets) {
51+
Map<FlutterCodeAsset, KernelAsset> assetTargetLocationsIOS(List<FlutterCodeAsset> nativeAssets) {
4752
final Set<String> alreadyTakenNames = <String>{};
4853
final Map<String, KernelAssetPath> idToPath = <String, KernelAssetPath>{};
49-
final Map<CodeAsset, KernelAsset> result = <CodeAsset, KernelAsset>{};
50-
for (final CodeAsset asset in nativeAssets) {
54+
final Map<FlutterCodeAsset, KernelAsset> result = <FlutterCodeAsset, KernelAsset>{};
55+
for (final FlutterCodeAsset asset in nativeAssets) {
56+
final String assetId = asset.codeAsset.id;
5157
final KernelAssetPath path =
52-
idToPath[asset.id] ?? _targetLocationIOS(asset, alreadyTakenNames).path;
53-
idToPath[asset.id] = path;
54-
result[asset] = KernelAsset(
55-
id: asset.id,
56-
target: Target.fromArchitectureAndOS(asset.architecture, asset.os),
57-
path: path,
58-
);
58+
idToPath[assetId] ?? _targetLocationIOS(asset, alreadyTakenNames).path;
59+
idToPath[assetId] = path;
60+
result[asset] = KernelAsset(id: assetId, target: asset.target, path: path);
5961
}
6062
return result;
6163
}
6264

63-
KernelAsset _targetLocationIOS(CodeAsset asset, Set<String> alreadyTakenNames) {
64-
final LinkMode linkMode = asset.linkMode;
65+
KernelAsset _targetLocationIOS(FlutterCodeAsset asset, Set<String> alreadyTakenNames) {
66+
final LinkMode linkMode = asset.codeAsset.linkMode;
6567
final KernelAssetPath kernelAssetPath;
6668
switch (linkMode) {
6769
case DynamicLoadingSystem _:
@@ -71,16 +73,12 @@ KernelAsset _targetLocationIOS(CodeAsset asset, Set<String> alreadyTakenNames) {
7173
case LookupInProcess _:
7274
kernelAssetPath = KernelAssetInProcess();
7375
case DynamicLoadingBundled _:
74-
final String fileName = asset.file!.pathSegments.last;
76+
final String fileName = asset.codeAsset.file!.pathSegments.last;
7577
kernelAssetPath = KernelAssetAbsolutePath(frameworkUri(fileName, alreadyTakenNames));
7678
default:
7779
throw Exception('Unsupported asset link mode $linkMode in asset $asset');
7880
}
79-
return KernelAsset(
80-
id: asset.id,
81-
target: Target.fromArchitectureAndOS(asset.architecture, asset.os),
82-
path: kernelAssetPath,
83-
);
81+
return KernelAsset(id: asset.codeAsset.id, target: asset.target, path: kernelAssetPath);
8482
}
8583

8684
/// Copies native assets into a framework per dynamic library.
@@ -97,7 +95,7 @@ KernelAsset _targetLocationIOS(CodeAsset asset, Set<String> alreadyTakenNames) {
9795
/// in xcode_backend.dart.
9896
Future<void> copyNativeCodeAssetsIOS(
9997
Uri buildUri,
100-
Map<KernelAssetPath, List<CodeAsset>> assetTargetLocations,
98+
Map<KernelAssetPath, List<FlutterCodeAsset>> assetTargetLocations,
10199
String? codesignIdentity,
102100
BuildMode buildMode,
103101
FileSystem fileSystem,
@@ -106,11 +104,12 @@ Future<void> copyNativeCodeAssetsIOS(
106104
final Map<String, String> oldToNewInstallNames = <String, String>{};
107105
final List<(File, String, Directory)> dylibs = <(File, String, Directory)>[];
108106

109-
for (final MapEntry<KernelAssetPath, List<CodeAsset>> assetMapping
107+
for (final MapEntry<KernelAssetPath, List<FlutterCodeAsset>> assetMapping
110108
in assetTargetLocations.entries) {
111109
final Uri target = (assetMapping.key as KernelAssetAbsolutePath).uri;
112110
final List<File> sources = <File>[
113-
for (final CodeAsset source in assetMapping.value) fileSystem.file(source.file),
111+
for (final FlutterCodeAsset source in assetMapping.value)
112+
fileSystem.file(source.codeAsset.file),
114113
];
115114
final Uri targetUri = buildUri.resolveUri(target);
116115
final File dylibFile = fileSystem.file(targetUri);

packages/flutter_tools/lib/src/isolated/native_assets/macos/native_assets.dart

Lines changed: 30 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import 'package:native_assets_cli/code_assets_builder.dart';
77

88
import '../../../base/file_system.dart';
99
import '../../../build_info.dart';
10+
import '../native_assets.dart';
1011
import 'native_assets_host.dart';
1112

1213
// TODO(dcharkes): Fetch minimum MacOS version from somewhere. https://github.com/flutter/flutter/issues/145104
@@ -21,50 +22,49 @@ Architecture getNativeMacOSArchitecture(DarwinArch darwinArch) {
2122
};
2223
}
2324

24-
Map<KernelAssetPath, List<CodeAsset>> fatAssetTargetLocationsMacOS(
25-
List<CodeAsset> nativeAssets,
25+
Map<KernelAssetPath, List<FlutterCodeAsset>> fatAssetTargetLocationsMacOS(
26+
List<FlutterCodeAsset> nativeAssets,
2627
Uri? absolutePath,
2728
) {
2829
final Set<String> alreadyTakenNames = <String>{};
29-
final Map<KernelAssetPath, List<CodeAsset>> result = <KernelAssetPath, List<CodeAsset>>{};
30+
final Map<KernelAssetPath, List<FlutterCodeAsset>> result =
31+
<KernelAssetPath, List<FlutterCodeAsset>>{};
3032
final Map<String, KernelAssetPath> idToPath = <String, KernelAssetPath>{};
31-
for (final CodeAsset asset in nativeAssets) {
33+
for (final FlutterCodeAsset asset in nativeAssets) {
3234
// Use same target path for all assets with the same id.
35+
final String assetId = asset.codeAsset.id;
3336
final KernelAssetPath path =
34-
idToPath[asset.id] ?? _targetLocationMacOS(asset, absolutePath, alreadyTakenNames).path;
35-
idToPath[asset.id] = path;
36-
result[path] ??= <CodeAsset>[];
37+
idToPath[assetId] ?? _targetLocationMacOS(asset, absolutePath, alreadyTakenNames).path;
38+
idToPath[assetId] = path;
39+
result[path] ??= <FlutterCodeAsset>[];
3740
result[path]!.add(asset);
3841
}
3942
return result;
4043
}
4144

42-
Map<CodeAsset, KernelAsset> assetTargetLocationsMacOS(
43-
List<CodeAsset> nativeAssets,
45+
Map<FlutterCodeAsset, KernelAsset> assetTargetLocationsMacOS(
46+
List<FlutterCodeAsset> nativeAssets,
4447
Uri? absolutePath,
4548
) {
4649
final Set<String> alreadyTakenNames = <String>{};
4750
final Map<String, KernelAssetPath> idToPath = <String, KernelAssetPath>{};
48-
final Map<CodeAsset, KernelAsset> result = <CodeAsset, KernelAsset>{};
49-
for (final CodeAsset asset in nativeAssets) {
51+
final Map<FlutterCodeAsset, KernelAsset> result = <FlutterCodeAsset, KernelAsset>{};
52+
for (final FlutterCodeAsset asset in nativeAssets) {
53+
final String assetId = asset.codeAsset.id;
5054
final KernelAssetPath path =
51-
idToPath[asset.id] ?? _targetLocationMacOS(asset, absolutePath, alreadyTakenNames).path;
52-
idToPath[asset.id] = path;
53-
result[asset] = KernelAsset(
54-
id: asset.id,
55-
target: Target.fromArchitectureAndOS(asset.architecture, asset.os),
56-
path: path,
57-
);
55+
idToPath[assetId] ?? _targetLocationMacOS(asset, absolutePath, alreadyTakenNames).path;
56+
idToPath[assetId] = path;
57+
result[asset] = KernelAsset(id: assetId, target: asset.target, path: path);
5858
}
5959
return result;
6060
}
6161

6262
KernelAsset _targetLocationMacOS(
63-
CodeAsset asset,
63+
FlutterCodeAsset asset,
6464
Uri? absolutePath,
6565
Set<String> alreadyTakenNames,
6666
) {
67-
final LinkMode linkMode = asset.linkMode;
67+
final LinkMode linkMode = asset.codeAsset.linkMode;
6868
final KernelAssetPath kernelAssetPath;
6969
switch (linkMode) {
7070
case DynamicLoadingSystem _:
@@ -74,7 +74,7 @@ KernelAsset _targetLocationMacOS(
7474
case LookupInProcess _:
7575
kernelAssetPath = KernelAssetInProcess();
7676
case DynamicLoadingBundled _:
77-
final String fileName = asset.file!.pathSegments.last;
77+
final String fileName = asset.codeAsset.file!.pathSegments.last;
7878
Uri uri;
7979
if (absolutePath != null) {
8080
// Flutter tester needs full host paths.
@@ -89,11 +89,7 @@ KernelAsset _targetLocationMacOS(
8989
default:
9090
throw Exception('Unsupported asset link mode $linkMode in asset $asset');
9191
}
92-
return KernelAsset(
93-
id: asset.id,
94-
target: Target.fromArchitectureAndOS(asset.architecture, asset.os),
95-
path: kernelAssetPath,
96-
);
92+
return KernelAsset(id: asset.codeAsset.id, target: asset.target, path: kernelAssetPath);
9793
}
9894

9995
/// Copies native assets into a framework per dynamic library.
@@ -113,7 +109,7 @@ KernelAsset _targetLocationMacOS(
113109
/// in macos_assemble.sh.
114110
Future<void> copyNativeCodeAssetsMacOS(
115111
Uri buildUri,
116-
Map<KernelAssetPath, List<CodeAsset>> assetTargetLocations,
112+
Map<KernelAssetPath, List<FlutterCodeAsset>> assetTargetLocations,
117113
String? codesignIdentity,
118114
BuildMode buildMode,
119115
FileSystem fileSystem,
@@ -123,11 +119,12 @@ Future<void> copyNativeCodeAssetsMacOS(
123119
final Map<String, String> oldToNewInstallNames = <String, String>{};
124120
final List<(File, String, Directory)> dylibs = <(File, String, Directory)>[];
125121

126-
for (final MapEntry<KernelAssetPath, List<CodeAsset>> assetMapping
122+
for (final MapEntry<KernelAssetPath, List<FlutterCodeAsset>> assetMapping
127123
in assetTargetLocations.entries) {
128124
final Uri target = (assetMapping.key as KernelAssetAbsolutePath).uri;
129125
final List<File> sources = <File>[
130-
for (final CodeAsset source in assetMapping.value) fileSystem.file(source.file),
126+
for (final FlutterCodeAsset source in assetMapping.value)
127+
fileSystem.file(source.codeAsset.file),
131128
];
132129
final Uri targetUri = buildUri.resolveUri(target);
133130
final String name = targetUri.pathSegments.last;
@@ -201,7 +198,7 @@ Future<void> copyNativeCodeAssetsMacOS(
201198
/// Code signing is also done here.
202199
Future<void> copyNativeCodeAssetsMacOSFlutterTester(
203200
Uri buildUri,
204-
Map<KernelAssetPath, List<CodeAsset>> assetTargetLocations,
201+
Map<KernelAssetPath, List<FlutterCodeAsset>> assetTargetLocations,
205202
String? codesignIdentity,
206203
BuildMode buildMode,
207204
FileSystem fileSystem,
@@ -211,11 +208,12 @@ Future<void> copyNativeCodeAssetsMacOSFlutterTester(
211208
final Map<String, String> oldToNewInstallNames = <String, String>{};
212209
final List<(File, String)> dylibs = <(File, String)>[];
213210

214-
for (final MapEntry<KernelAssetPath, List<CodeAsset>> assetMapping
211+
for (final MapEntry<KernelAssetPath, List<FlutterCodeAsset>> assetMapping
215212
in assetTargetLocations.entries) {
216213
final Uri target = (assetMapping.key as KernelAssetAbsolutePath).uri;
217214
final List<File> sources = <File>[
218-
for (final CodeAsset source in assetMapping.value) fileSystem.file(source.file),
215+
for (final FlutterCodeAsset source in assetMapping.value)
216+
fileSystem.file(source.codeAsset.file),
219217
];
220218
final Uri targetUri = buildUri.resolveUri(target);
221219
final File dylibFile = fileSystem.file(targetUri);

0 commit comments

Comments
 (0)