forked from firka/flutter
[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 (https://github.com/dart-lang/native/issues/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 https://github.com/flutter/flutter/pull/164094 already refactoring this code.)
This commit is contained in:
@@ -10,6 +10,7 @@ import '../../../android/gradle_utils.dart';
|
||||
import '../../../base/common.dart';
|
||||
import '../../../base/file_system.dart';
|
||||
import '../../../build_info.dart';
|
||||
import '../native_assets.dart';
|
||||
|
||||
int targetAndroidNdkApi(Map<String, String> environmentDefines) {
|
||||
return int.parse(environmentDefines[kMinSdkVersion] ?? minSdkVersion);
|
||||
@@ -17,7 +18,7 @@ int targetAndroidNdkApi(Map<String, String> environmentDefines) {
|
||||
|
||||
Future<void> copyNativeCodeAssetsAndroid(
|
||||
Uri buildUri,
|
||||
Map<CodeAsset, KernelAsset> assetTargetLocations,
|
||||
Map<FlutterCodeAsset, KernelAsset> assetTargetLocations,
|
||||
FileSystem fileSystem,
|
||||
) async {
|
||||
assert(assetTargetLocations.isNotEmpty);
|
||||
@@ -28,8 +29,8 @@ Future<void> copyNativeCodeAssetsAndroid(
|
||||
final Uri archUri = buildUri.resolve('jniLibs/lib/$jniArchDir/');
|
||||
await fileSystem.directory(archUri).create(recursive: true);
|
||||
}
|
||||
for (final MapEntry<CodeAsset, KernelAsset> assetMapping in assetTargetLocations.entries) {
|
||||
final Uri source = assetMapping.key.file!;
|
||||
for (final MapEntry<FlutterCodeAsset, KernelAsset> assetMapping in assetTargetLocations.entries) {
|
||||
final Uri source = assetMapping.key.codeAsset.file!;
|
||||
final Uri target = (assetMapping.value.path as KernelAssetAbsolutePath).uri;
|
||||
final AndroidArch androidArch = _getAndroidArch(assetMapping.value.target.architecture);
|
||||
final String jniArchDir = androidArch.archName;
|
||||
@@ -62,16 +63,18 @@ AndroidArch _getAndroidArch(Architecture architecture) {
|
||||
};
|
||||
}
|
||||
|
||||
Map<CodeAsset, KernelAsset> assetTargetLocationsAndroid(List<CodeAsset> nativeAssets) {
|
||||
return <CodeAsset, KernelAsset>{
|
||||
for (final CodeAsset asset in nativeAssets) asset: _targetLocationAndroid(asset),
|
||||
Map<FlutterCodeAsset, KernelAsset> assetTargetLocationsAndroid(
|
||||
List<FlutterCodeAsset> nativeAssets,
|
||||
) {
|
||||
return <FlutterCodeAsset, KernelAsset>{
|
||||
for (final FlutterCodeAsset asset in nativeAssets) asset: _targetLocationAndroid(asset),
|
||||
};
|
||||
}
|
||||
|
||||
/// Converts the `path` of [asset] as output from a `build.dart` invocation to
|
||||
/// the path used inside the Flutter app bundle.
|
||||
KernelAsset _targetLocationAndroid(CodeAsset asset) {
|
||||
final LinkMode linkMode = asset.linkMode;
|
||||
KernelAsset _targetLocationAndroid(FlutterCodeAsset asset) {
|
||||
final LinkMode linkMode = asset.codeAsset.linkMode;
|
||||
final KernelAssetPath kernelAssetPath;
|
||||
switch (linkMode) {
|
||||
case DynamicLoadingSystem _:
|
||||
@@ -81,16 +84,12 @@ KernelAsset _targetLocationAndroid(CodeAsset asset) {
|
||||
case LookupInProcess _:
|
||||
kernelAssetPath = KernelAssetInProcess();
|
||||
case DynamicLoadingBundled _:
|
||||
final String fileName = asset.file!.pathSegments.last;
|
||||
final String fileName = asset.codeAsset.file!.pathSegments.last;
|
||||
kernelAssetPath = KernelAssetAbsolutePath(Uri(path: fileName));
|
||||
default:
|
||||
throw Exception('Unsupported asset link mode $linkMode in asset $asset');
|
||||
}
|
||||
return KernelAsset(
|
||||
id: asset.id,
|
||||
target: Target.fromArchitectureAndOS(asset.architecture, asset.os),
|
||||
path: kernelAssetPath,
|
||||
);
|
||||
return KernelAsset(id: asset.codeAsset.id, target: asset.target, path: kernelAssetPath);
|
||||
}
|
||||
|
||||
/// Looks the NDK clang compiler tools.
|
||||
|
||||
@@ -8,6 +8,7 @@ import 'package:native_assets_cli/code_assets_builder.dart';
|
||||
import '../../../base/file_system.dart';
|
||||
import '../../../build_info.dart';
|
||||
import '../macos/native_assets_host.dart';
|
||||
import '../native_assets.dart';
|
||||
|
||||
// TODO(dcharkes): Fetch minimum iOS version from somewhere. https://github.com/flutter/flutter/issues/145104
|
||||
const int targetIOSVersion = 12;
|
||||
@@ -28,40 +29,41 @@ Architecture getNativeIOSArchitecture(DarwinArch darwinArch) {
|
||||
};
|
||||
}
|
||||
|
||||
Map<KernelAssetPath, List<CodeAsset>> fatAssetTargetLocationsIOS(List<CodeAsset> nativeAssets) {
|
||||
Map<KernelAssetPath, List<FlutterCodeAsset>> fatAssetTargetLocationsIOS(
|
||||
List<FlutterCodeAsset> nativeAssets,
|
||||
) {
|
||||
final Set<String> alreadyTakenNames = <String>{};
|
||||
final Map<KernelAssetPath, List<CodeAsset>> result = <KernelAssetPath, List<CodeAsset>>{};
|
||||
final Map<KernelAssetPath, List<FlutterCodeAsset>> result =
|
||||
<KernelAssetPath, List<FlutterCodeAsset>>{};
|
||||
final Map<String, KernelAssetPath> idToPath = <String, KernelAssetPath>{};
|
||||
for (final CodeAsset asset in nativeAssets) {
|
||||
for (final FlutterCodeAsset asset in nativeAssets) {
|
||||
// Use same target path for all assets with the same id.
|
||||
final String assetId = asset.codeAsset.id;
|
||||
final KernelAssetPath path =
|
||||
idToPath[asset.id] ?? _targetLocationIOS(asset, alreadyTakenNames).path;
|
||||
idToPath[asset.id] = path;
|
||||
result[path] ??= <CodeAsset>[];
|
||||
idToPath[assetId] ?? _targetLocationIOS(asset, alreadyTakenNames).path;
|
||||
idToPath[assetId] = path;
|
||||
result[path] ??= <FlutterCodeAsset>[];
|
||||
result[path]!.add(asset);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Map<CodeAsset, KernelAsset> assetTargetLocationsIOS(List<CodeAsset> nativeAssets) {
|
||||
Map<FlutterCodeAsset, KernelAsset> assetTargetLocationsIOS(List<FlutterCodeAsset> nativeAssets) {
|
||||
final Set<String> alreadyTakenNames = <String>{};
|
||||
final Map<String, KernelAssetPath> idToPath = <String, KernelAssetPath>{};
|
||||
final Map<CodeAsset, KernelAsset> result = <CodeAsset, KernelAsset>{};
|
||||
for (final CodeAsset asset in nativeAssets) {
|
||||
final Map<FlutterCodeAsset, KernelAsset> result = <FlutterCodeAsset, KernelAsset>{};
|
||||
for (final FlutterCodeAsset asset in nativeAssets) {
|
||||
final String assetId = asset.codeAsset.id;
|
||||
final KernelAssetPath path =
|
||||
idToPath[asset.id] ?? _targetLocationIOS(asset, alreadyTakenNames).path;
|
||||
idToPath[asset.id] = path;
|
||||
result[asset] = KernelAsset(
|
||||
id: asset.id,
|
||||
target: Target.fromArchitectureAndOS(asset.architecture, asset.os),
|
||||
path: path,
|
||||
);
|
||||
idToPath[assetId] ?? _targetLocationIOS(asset, alreadyTakenNames).path;
|
||||
idToPath[assetId] = path;
|
||||
result[asset] = KernelAsset(id: assetId, target: asset.target, path: path);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
KernelAsset _targetLocationIOS(CodeAsset asset, Set<String> alreadyTakenNames) {
|
||||
final LinkMode linkMode = asset.linkMode;
|
||||
KernelAsset _targetLocationIOS(FlutterCodeAsset asset, Set<String> alreadyTakenNames) {
|
||||
final LinkMode linkMode = asset.codeAsset.linkMode;
|
||||
final KernelAssetPath kernelAssetPath;
|
||||
switch (linkMode) {
|
||||
case DynamicLoadingSystem _:
|
||||
@@ -71,16 +73,12 @@ KernelAsset _targetLocationIOS(CodeAsset asset, Set<String> alreadyTakenNames) {
|
||||
case LookupInProcess _:
|
||||
kernelAssetPath = KernelAssetInProcess();
|
||||
case DynamicLoadingBundled _:
|
||||
final String fileName = asset.file!.pathSegments.last;
|
||||
final String fileName = asset.codeAsset.file!.pathSegments.last;
|
||||
kernelAssetPath = KernelAssetAbsolutePath(frameworkUri(fileName, alreadyTakenNames));
|
||||
default:
|
||||
throw Exception('Unsupported asset link mode $linkMode in asset $asset');
|
||||
}
|
||||
return KernelAsset(
|
||||
id: asset.id,
|
||||
target: Target.fromArchitectureAndOS(asset.architecture, asset.os),
|
||||
path: kernelAssetPath,
|
||||
);
|
||||
return KernelAsset(id: asset.codeAsset.id, target: asset.target, path: kernelAssetPath);
|
||||
}
|
||||
|
||||
/// Copies native assets into a framework per dynamic library.
|
||||
@@ -97,7 +95,7 @@ KernelAsset _targetLocationIOS(CodeAsset asset, Set<String> alreadyTakenNames) {
|
||||
/// in xcode_backend.dart.
|
||||
Future<void> copyNativeCodeAssetsIOS(
|
||||
Uri buildUri,
|
||||
Map<KernelAssetPath, List<CodeAsset>> assetTargetLocations,
|
||||
Map<KernelAssetPath, List<FlutterCodeAsset>> assetTargetLocations,
|
||||
String? codesignIdentity,
|
||||
BuildMode buildMode,
|
||||
FileSystem fileSystem,
|
||||
@@ -106,11 +104,12 @@ Future<void> copyNativeCodeAssetsIOS(
|
||||
final Map<String, String> oldToNewInstallNames = <String, String>{};
|
||||
final List<(File, String, Directory)> dylibs = <(File, String, Directory)>[];
|
||||
|
||||
for (final MapEntry<KernelAssetPath, List<CodeAsset>> assetMapping
|
||||
for (final MapEntry<KernelAssetPath, List<FlutterCodeAsset>> assetMapping
|
||||
in assetTargetLocations.entries) {
|
||||
final Uri target = (assetMapping.key as KernelAssetAbsolutePath).uri;
|
||||
final List<File> sources = <File>[
|
||||
for (final CodeAsset source in assetMapping.value) fileSystem.file(source.file),
|
||||
for (final FlutterCodeAsset source in assetMapping.value)
|
||||
fileSystem.file(source.codeAsset.file),
|
||||
];
|
||||
final Uri targetUri = buildUri.resolveUri(target);
|
||||
final File dylibFile = fileSystem.file(targetUri);
|
||||
|
||||
@@ -7,6 +7,7 @@ import 'package:native_assets_cli/code_assets_builder.dart';
|
||||
|
||||
import '../../../base/file_system.dart';
|
||||
import '../../../build_info.dart';
|
||||
import '../native_assets.dart';
|
||||
import 'native_assets_host.dart';
|
||||
|
||||
// TODO(dcharkes): Fetch minimum MacOS version from somewhere. https://github.com/flutter/flutter/issues/145104
|
||||
@@ -21,50 +22,49 @@ Architecture getNativeMacOSArchitecture(DarwinArch darwinArch) {
|
||||
};
|
||||
}
|
||||
|
||||
Map<KernelAssetPath, List<CodeAsset>> fatAssetTargetLocationsMacOS(
|
||||
List<CodeAsset> nativeAssets,
|
||||
Map<KernelAssetPath, List<FlutterCodeAsset>> fatAssetTargetLocationsMacOS(
|
||||
List<FlutterCodeAsset> nativeAssets,
|
||||
Uri? absolutePath,
|
||||
) {
|
||||
final Set<String> alreadyTakenNames = <String>{};
|
||||
final Map<KernelAssetPath, List<CodeAsset>> result = <KernelAssetPath, List<CodeAsset>>{};
|
||||
final Map<KernelAssetPath, List<FlutterCodeAsset>> result =
|
||||
<KernelAssetPath, List<FlutterCodeAsset>>{};
|
||||
final Map<String, KernelAssetPath> idToPath = <String, KernelAssetPath>{};
|
||||
for (final CodeAsset asset in nativeAssets) {
|
||||
for (final FlutterCodeAsset asset in nativeAssets) {
|
||||
// Use same target path for all assets with the same id.
|
||||
final String assetId = asset.codeAsset.id;
|
||||
final KernelAssetPath path =
|
||||
idToPath[asset.id] ?? _targetLocationMacOS(asset, absolutePath, alreadyTakenNames).path;
|
||||
idToPath[asset.id] = path;
|
||||
result[path] ??= <CodeAsset>[];
|
||||
idToPath[assetId] ?? _targetLocationMacOS(asset, absolutePath, alreadyTakenNames).path;
|
||||
idToPath[assetId] = path;
|
||||
result[path] ??= <FlutterCodeAsset>[];
|
||||
result[path]!.add(asset);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Map<CodeAsset, KernelAsset> assetTargetLocationsMacOS(
|
||||
List<CodeAsset> nativeAssets,
|
||||
Map<FlutterCodeAsset, KernelAsset> assetTargetLocationsMacOS(
|
||||
List<FlutterCodeAsset> nativeAssets,
|
||||
Uri? absolutePath,
|
||||
) {
|
||||
final Set<String> alreadyTakenNames = <String>{};
|
||||
final Map<String, KernelAssetPath> idToPath = <String, KernelAssetPath>{};
|
||||
final Map<CodeAsset, KernelAsset> result = <CodeAsset, KernelAsset>{};
|
||||
for (final CodeAsset asset in nativeAssets) {
|
||||
final Map<FlutterCodeAsset, KernelAsset> result = <FlutterCodeAsset, KernelAsset>{};
|
||||
for (final FlutterCodeAsset asset in nativeAssets) {
|
||||
final String assetId = asset.codeAsset.id;
|
||||
final KernelAssetPath path =
|
||||
idToPath[asset.id] ?? _targetLocationMacOS(asset, absolutePath, alreadyTakenNames).path;
|
||||
idToPath[asset.id] = path;
|
||||
result[asset] = KernelAsset(
|
||||
id: asset.id,
|
||||
target: Target.fromArchitectureAndOS(asset.architecture, asset.os),
|
||||
path: path,
|
||||
);
|
||||
idToPath[assetId] ?? _targetLocationMacOS(asset, absolutePath, alreadyTakenNames).path;
|
||||
idToPath[assetId] = path;
|
||||
result[asset] = KernelAsset(id: assetId, target: asset.target, path: path);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
KernelAsset _targetLocationMacOS(
|
||||
CodeAsset asset,
|
||||
FlutterCodeAsset asset,
|
||||
Uri? absolutePath,
|
||||
Set<String> alreadyTakenNames,
|
||||
) {
|
||||
final LinkMode linkMode = asset.linkMode;
|
||||
final LinkMode linkMode = asset.codeAsset.linkMode;
|
||||
final KernelAssetPath kernelAssetPath;
|
||||
switch (linkMode) {
|
||||
case DynamicLoadingSystem _:
|
||||
@@ -74,7 +74,7 @@ KernelAsset _targetLocationMacOS(
|
||||
case LookupInProcess _:
|
||||
kernelAssetPath = KernelAssetInProcess();
|
||||
case DynamicLoadingBundled _:
|
||||
final String fileName = asset.file!.pathSegments.last;
|
||||
final String fileName = asset.codeAsset.file!.pathSegments.last;
|
||||
Uri uri;
|
||||
if (absolutePath != null) {
|
||||
// Flutter tester needs full host paths.
|
||||
@@ -89,11 +89,7 @@ KernelAsset _targetLocationMacOS(
|
||||
default:
|
||||
throw Exception('Unsupported asset link mode $linkMode in asset $asset');
|
||||
}
|
||||
return KernelAsset(
|
||||
id: asset.id,
|
||||
target: Target.fromArchitectureAndOS(asset.architecture, asset.os),
|
||||
path: kernelAssetPath,
|
||||
);
|
||||
return KernelAsset(id: asset.codeAsset.id, target: asset.target, path: kernelAssetPath);
|
||||
}
|
||||
|
||||
/// Copies native assets into a framework per dynamic library.
|
||||
@@ -113,7 +109,7 @@ KernelAsset _targetLocationMacOS(
|
||||
/// in macos_assemble.sh.
|
||||
Future<void> copyNativeCodeAssetsMacOS(
|
||||
Uri buildUri,
|
||||
Map<KernelAssetPath, List<CodeAsset>> assetTargetLocations,
|
||||
Map<KernelAssetPath, List<FlutterCodeAsset>> assetTargetLocations,
|
||||
String? codesignIdentity,
|
||||
BuildMode buildMode,
|
||||
FileSystem fileSystem,
|
||||
@@ -123,11 +119,12 @@ Future<void> copyNativeCodeAssetsMacOS(
|
||||
final Map<String, String> oldToNewInstallNames = <String, String>{};
|
||||
final List<(File, String, Directory)> dylibs = <(File, String, Directory)>[];
|
||||
|
||||
for (final MapEntry<KernelAssetPath, List<CodeAsset>> assetMapping
|
||||
for (final MapEntry<KernelAssetPath, List<FlutterCodeAsset>> assetMapping
|
||||
in assetTargetLocations.entries) {
|
||||
final Uri target = (assetMapping.key as KernelAssetAbsolutePath).uri;
|
||||
final List<File> sources = <File>[
|
||||
for (final CodeAsset source in assetMapping.value) fileSystem.file(source.file),
|
||||
for (final FlutterCodeAsset source in assetMapping.value)
|
||||
fileSystem.file(source.codeAsset.file),
|
||||
];
|
||||
final Uri targetUri = buildUri.resolveUri(target);
|
||||
final String name = targetUri.pathSegments.last;
|
||||
@@ -201,7 +198,7 @@ Future<void> copyNativeCodeAssetsMacOS(
|
||||
/// Code signing is also done here.
|
||||
Future<void> copyNativeCodeAssetsMacOSFlutterTester(
|
||||
Uri buildUri,
|
||||
Map<KernelAssetPath, List<CodeAsset>> assetTargetLocations,
|
||||
Map<KernelAssetPath, List<FlutterCodeAsset>> assetTargetLocations,
|
||||
String? codesignIdentity,
|
||||
BuildMode buildMode,
|
||||
FileSystem fileSystem,
|
||||
@@ -211,11 +208,12 @@ Future<void> copyNativeCodeAssetsMacOSFlutterTester(
|
||||
final Map<String, String> oldToNewInstallNames = <String, String>{};
|
||||
final List<(File, String)> dylibs = <(File, String)>[];
|
||||
|
||||
for (final MapEntry<KernelAssetPath, List<CodeAsset>> assetMapping
|
||||
for (final MapEntry<KernelAssetPath, List<FlutterCodeAsset>> assetMapping
|
||||
in assetTargetLocations.entries) {
|
||||
final Uri target = (assetMapping.key as KernelAssetAbsolutePath).uri;
|
||||
final List<File> sources = <File>[
|
||||
for (final CodeAsset source in assetMapping.value) fileSystem.file(source.file),
|
||||
for (final FlutterCodeAsset source in assetMapping.value)
|
||||
fileSystem.file(source.codeAsset.file),
|
||||
];
|
||||
final Uri targetUri = buildUri.resolveUri(target);
|
||||
final File dylibFile = fileSystem.file(targetUri);
|
||||
|
||||
@@ -34,35 +34,63 @@ import 'windows/native_assets.dart';
|
||||
final class DartBuildResult {
|
||||
const DartBuildResult(this.codeAssets, this.dependencies);
|
||||
|
||||
const DartBuildResult.empty() : codeAssets = const <CodeAsset>[], dependencies = const <Uri>[];
|
||||
const DartBuildResult.empty()
|
||||
: codeAssets = const <FlutterCodeAsset>[],
|
||||
dependencies = const <Uri>[];
|
||||
|
||||
factory DartBuildResult.fromJson(Map<String, Object?> json) {
|
||||
final List<Uri> dependencies = <Uri>[
|
||||
for (final Object? encodedUri in json['dependencies']! as List<Object?>)
|
||||
Uri.parse(encodedUri! as String),
|
||||
];
|
||||
final List<CodeAsset> codeAssets = <CodeAsset>[
|
||||
final List<FlutterCodeAsset> codeAssets = <FlutterCodeAsset>[
|
||||
for (final Object? json in json['code_assets']! as List<Object?>)
|
||||
CodeAsset.fromEncoded(EncodedAsset.fromJson(json! as Map<String, Object?>)),
|
||||
FlutterCodeAsset(
|
||||
codeAsset: CodeAsset.fromEncoded(
|
||||
EncodedAsset.fromJson(
|
||||
(json! as Map<String, Object?>)['asset']! as Map<String, Object?>,
|
||||
),
|
||||
),
|
||||
target: Target.fromString((json as Map<String, Object?>)['target']! as String),
|
||||
),
|
||||
];
|
||||
return DartBuildResult(codeAssets, dependencies);
|
||||
}
|
||||
|
||||
final List<CodeAsset> codeAssets;
|
||||
final List<FlutterCodeAsset> codeAssets;
|
||||
final List<Uri> dependencies;
|
||||
|
||||
Map<String, Object?> toJson() => <String, Object?>{
|
||||
'dependencies': <Object?>[for (final Uri dep in dependencies) dep.toString()],
|
||||
'code_assets': <Object?>[for (final CodeAsset code in codeAssets) code.encode().toJson()],
|
||||
'code_assets': <Object?>[
|
||||
for (final FlutterCodeAsset code in codeAssets)
|
||||
<String, Object>{
|
||||
'asset': code.codeAsset.encode().toJson(),
|
||||
'target': code.target.toString(),
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
/// The files that eventually should be bundled with the app.
|
||||
List<Uri> get filesToBeBundled => <Uri>[
|
||||
for (final CodeAsset code in codeAssets)
|
||||
if (code.linkMode is DynamicLoadingBundled) code.file!,
|
||||
for (final FlutterCodeAsset code in codeAssets)
|
||||
if (code.codeAsset.linkMode is DynamicLoadingBundled) code.codeAsset.file!,
|
||||
];
|
||||
}
|
||||
|
||||
/// A [CodeAsset] for a specific [target].
|
||||
///
|
||||
/// Flutter builds [CodeAsset]s for multiple architectures (on MacOS and iOS).
|
||||
/// This class distinguishes the (otherwise identical) [codeAsset]s on different
|
||||
/// [target]s. These are then later combined into a single [KernelAsset] before
|
||||
/// being added to the native assets manifest.
|
||||
class FlutterCodeAsset {
|
||||
FlutterCodeAsset({required this.codeAsset, required this.target});
|
||||
|
||||
final CodeAsset codeAsset;
|
||||
final Target target;
|
||||
}
|
||||
|
||||
/// Invokes the build of all transitive Dart packages and prepares code assets
|
||||
/// to be included in the native build.
|
||||
Future<DartBuildResult> runFlutterSpecificDartBuild({
|
||||
@@ -122,7 +150,7 @@ Future<void> installCodeAssets({
|
||||
final BuildMode buildMode = _getBuildMode(environmentDefines, flutterTester);
|
||||
|
||||
final String? codesignIdentity = environmentDefines[kCodesignIdentity];
|
||||
final Map<CodeAsset, KernelAsset> assetTargetLocations = assetTargetLocationsForOS(
|
||||
final Map<FlutterCodeAsset, KernelAsset> assetTargetLocations = assetTargetLocationsForOS(
|
||||
targetOS,
|
||||
dartBuildResult.codeAssets,
|
||||
flutterTester,
|
||||
@@ -379,18 +407,18 @@ Uri nativeAssetsBuildUri(Uri projectUri, OS os) {
|
||||
return projectUri.resolve('$buildDir/native_assets/$os/');
|
||||
}
|
||||
|
||||
Map<CodeAsset, KernelAsset> _assetTargetLocationsWindowsLinux(
|
||||
List<CodeAsset> assets,
|
||||
Map<FlutterCodeAsset, KernelAsset> _assetTargetLocationsWindowsLinux(
|
||||
List<FlutterCodeAsset> assets,
|
||||
Uri? absolutePath,
|
||||
) {
|
||||
return <CodeAsset, KernelAsset>{
|
||||
for (final CodeAsset asset in assets)
|
||||
return <FlutterCodeAsset, KernelAsset>{
|
||||
for (final FlutterCodeAsset asset in assets)
|
||||
asset: _targetLocationSingleArchitecture(asset, absolutePath),
|
||||
};
|
||||
}
|
||||
|
||||
KernelAsset _targetLocationSingleArchitecture(CodeAsset asset, Uri? absolutePath) {
|
||||
final LinkMode linkMode = asset.linkMode;
|
||||
KernelAsset _targetLocationSingleArchitecture(FlutterCodeAsset asset, Uri? absolutePath) {
|
||||
final LinkMode linkMode = asset.codeAsset.linkMode;
|
||||
final KernelAssetPath kernelAssetPath;
|
||||
switch (linkMode) {
|
||||
case DynamicLoadingSystem _:
|
||||
@@ -400,7 +428,7 @@ KernelAsset _targetLocationSingleArchitecture(CodeAsset asset, Uri? absolutePath
|
||||
case LookupInProcess _:
|
||||
kernelAssetPath = KernelAssetInProcess();
|
||||
case DynamicLoadingBundled _:
|
||||
final String fileName = asset.file!.pathSegments.last;
|
||||
final String fileName = asset.codeAsset.file!.pathSegments.last;
|
||||
Uri uri;
|
||||
if (absolutePath != null) {
|
||||
// Flutter tester needs full host paths.
|
||||
@@ -415,16 +443,12 @@ KernelAsset _targetLocationSingleArchitecture(CodeAsset asset, Uri? absolutePath
|
||||
default:
|
||||
throw Exception('Unsupported asset link mode ${linkMode.runtimeType} in asset $asset');
|
||||
}
|
||||
return KernelAsset(
|
||||
id: asset.id,
|
||||
target: Target.fromArchitectureAndOS(asset.architecture, asset.os),
|
||||
path: kernelAssetPath,
|
||||
);
|
||||
return KernelAsset(id: asset.codeAsset.id, target: asset.target, path: kernelAssetPath);
|
||||
}
|
||||
|
||||
Map<CodeAsset, KernelAsset> assetTargetLocationsForOS(
|
||||
Map<FlutterCodeAsset, KernelAsset> assetTargetLocationsForOS(
|
||||
OS targetOS,
|
||||
List<CodeAsset> codeAssets,
|
||||
List<FlutterCodeAsset> codeAssets,
|
||||
bool flutterTester,
|
||||
Uri buildUri,
|
||||
) {
|
||||
@@ -450,7 +474,7 @@ Future<void> _copyNativeCodeAssetsForOS(
|
||||
Uri buildUri,
|
||||
BuildMode buildMode,
|
||||
FileSystem fileSystem,
|
||||
Map<CodeAsset, KernelAsset> assetTargetLocations,
|
||||
Map<FlutterCodeAsset, KernelAsset> assetTargetLocations,
|
||||
String? codesignIdentity,
|
||||
bool flutterTester,
|
||||
) async {
|
||||
@@ -458,9 +482,10 @@ Future<void> _copyNativeCodeAssetsForOS(
|
||||
// If a code asset that use a linking mode of [LookupInProcess],
|
||||
// [LookupInExecutable] or [DynamicLoadingSystem] do not have anything to
|
||||
// bundle as part of the app.
|
||||
assetTargetLocations = <CodeAsset, KernelAsset>{
|
||||
for (final CodeAsset codeAsset in assetTargetLocations.keys)
|
||||
if (codeAsset.linkMode is DynamicLoadingBundled) codeAsset: assetTargetLocations[codeAsset]!,
|
||||
assetTargetLocations = <FlutterCodeAsset, KernelAsset>{
|
||||
for (final FlutterCodeAsset codeAsset in assetTargetLocations.keys)
|
||||
if (codeAsset.codeAsset.linkMode is DynamicLoadingBundled)
|
||||
codeAsset: assetTargetLocations[codeAsset]!,
|
||||
};
|
||||
|
||||
if (assetTargetLocations.isEmpty) {
|
||||
@@ -468,7 +493,7 @@ Future<void> _copyNativeCodeAssetsForOS(
|
||||
}
|
||||
|
||||
globals.logger.printTrace('Copying native assets to ${buildUri.toFilePath()}.');
|
||||
final List<CodeAsset> codeAssets = assetTargetLocations.keys.toList();
|
||||
final List<FlutterCodeAsset> codeAssets = assetTargetLocations.keys.toList();
|
||||
switch (targetOS) {
|
||||
case OS.windows:
|
||||
case OS.linux:
|
||||
@@ -533,7 +558,7 @@ Future<DartBuildResult> _runDartBuild({
|
||||
: architectures.toList().toString();
|
||||
|
||||
globals.logger.printTrace('Building native assets for $targetOS $architectureString.');
|
||||
final List<EncodedAsset> assets = <EncodedAsset>[];
|
||||
final List<FlutterCodeAsset> codeAssets = <FlutterCodeAsset>[];
|
||||
final Set<Uri> dependencies = <Uri>{};
|
||||
|
||||
final EnvironmentType? environmentType;
|
||||
@@ -566,13 +591,14 @@ Future<DartBuildResult> _runDartBuild({
|
||||
final MacOSCodeConfig? macOSConfig =
|
||||
targetOS == OS.macOS ? MacOSCodeConfig(targetVersion: targetMacOSVersion) : null;
|
||||
for (final Architecture architecture in architectures) {
|
||||
final Target target = Target.fromArchitectureAndOS(architecture, targetOS!);
|
||||
final BuildResult? buildResult = await buildRunner.build(
|
||||
extensions: <ProtocolExtension>[
|
||||
CodeAssetExtension(
|
||||
targetArchitecture: architecture,
|
||||
linkModePreference: LinkModePreference.dynamic,
|
||||
cCompiler: cCompilerConfig,
|
||||
targetOS: targetOS!,
|
||||
targetOS: targetOS,
|
||||
android: androidConfig,
|
||||
iOS: iosConfig,
|
||||
macOS: macOSConfig,
|
||||
@@ -585,7 +611,7 @@ Future<DartBuildResult> _runDartBuild({
|
||||
}
|
||||
dependencies.addAll(buildResult.dependencies);
|
||||
if (!linkingEnabled) {
|
||||
assets.addAll(buildResult.encodedAssets);
|
||||
codeAssets.addAll(_filterCodeAssets(buildResult.encodedAssets, target));
|
||||
} else {
|
||||
final LinkResult? linkResult = await buildRunner.link(
|
||||
extensions: <ProtocolExtension>[
|
||||
@@ -604,20 +630,24 @@ Future<DartBuildResult> _runDartBuild({
|
||||
if (linkResult == null) {
|
||||
_throwNativeAssetsLinkFailed();
|
||||
}
|
||||
assets.addAll(linkResult.encodedAssets);
|
||||
codeAssets.addAll(_filterCodeAssets(linkResult.encodedAssets, target));
|
||||
dependencies.addAll(linkResult.dependencies);
|
||||
}
|
||||
}
|
||||
|
||||
final List<CodeAsset> codeAssets =
|
||||
assets
|
||||
.where((EncodedAsset asset) => asset.type == CodeAsset.type)
|
||||
.map<CodeAsset>(CodeAsset.fromEncoded)
|
||||
.toList();
|
||||
globals.logger.printTrace('Building native assets for $targetOS $architectureString done.');
|
||||
return DartBuildResult(codeAssets, dependencies.toList());
|
||||
}
|
||||
|
||||
List<FlutterCodeAsset> _filterCodeAssets(List<EncodedAsset> assets, Target target) =>
|
||||
assets
|
||||
.where((EncodedAsset asset) => asset.isCodeAsset)
|
||||
.map<FlutterCodeAsset>(
|
||||
(EncodedAsset encodedAsset) =>
|
||||
FlutterCodeAsset(codeAsset: encodedAsset.asCodeAsset, target: target),
|
||||
)
|
||||
.toList();
|
||||
|
||||
List<Architecture> _architecturesForOS(
|
||||
TargetPlatform targetPlatform,
|
||||
OS targetOS,
|
||||
@@ -676,7 +706,7 @@ Architecture _getNativeArchitecture(TargetPlatform targetPlatform) {
|
||||
|
||||
Future<void> _copyNativeCodeAssetsToBundleOnWindowsLinux(
|
||||
Uri buildUri,
|
||||
Map<CodeAsset, KernelAsset> assetTargetLocations,
|
||||
Map<FlutterCodeAsset, KernelAsset> assetTargetLocations,
|
||||
BuildMode buildMode,
|
||||
FileSystem fileSystem,
|
||||
) async {
|
||||
@@ -686,8 +716,8 @@ Future<void> _copyNativeCodeAssetsToBundleOnWindowsLinux(
|
||||
if (!buildDir.existsSync()) {
|
||||
buildDir.createSync(recursive: true);
|
||||
}
|
||||
for (final MapEntry<CodeAsset, KernelAsset> assetMapping in assetTargetLocations.entries) {
|
||||
final Uri source = assetMapping.key.file!;
|
||||
for (final MapEntry<FlutterCodeAsset, KernelAsset> assetMapping in assetTargetLocations.entries) {
|
||||
final Uri source = assetMapping.key.codeAsset.file!;
|
||||
final Uri target = (assetMapping.value.path as KernelAssetAbsolutePath).uri;
|
||||
final Uri targetUri = buildUri.resolveUri(target);
|
||||
final String targetFullPath = targetUri.toFilePath();
|
||||
|
||||
@@ -25,9 +25,9 @@ const Map<String, String> kManuallyPinnedDependencies = <String, String>{
|
||||
'flutter_template_images': '5.0.0', // Must always exactly match flutter_tools template.
|
||||
'google_mobile_ads': '5.1.0', // https://github.com/flutter/flutter/issues/156912
|
||||
'native_assets_builder':
|
||||
'0.12.0', // Under active development with breaking changes until 1.0.0. Manually rolled by @dcharkes.
|
||||
'0.13.0', // Under active development with breaking changes until 1.0.0. Manually rolled by @dcharkes.
|
||||
'native_assets_cli':
|
||||
'0.12.0', // Under active development with breaking changes until 1.0.0. Manually rolled by @dcharkes.
|
||||
'0.13.0', // Under active development with breaking changes until 1.0.0. Manually rolled by @dcharkes.
|
||||
'material_color_utilities': '0.11.1', // Keep pinned to latest until 1.0.0.
|
||||
'leak_tracker': '10.0.9', // https://github.com/flutter/devtools/issues/3951
|
||||
'leak_tracker_testing': '3.0.1', // https://github.com/flutter/devtools/issues/3951
|
||||
|
||||
@@ -55,8 +55,8 @@ dependencies:
|
||||
unified_analytics: 7.0.1
|
||||
|
||||
graphs: 2.3.2
|
||||
native_assets_builder: 0.12.0
|
||||
native_assets_cli: 0.12.0
|
||||
native_assets_builder: 0.13.0
|
||||
native_assets_cli: 0.13.0
|
||||
|
||||
# We depend on very specific internal implementation details of the
|
||||
# 'test' package, which change between versions, so when upgrading
|
||||
@@ -122,4 +122,4 @@ dartdoc:
|
||||
# Exclude this package from the hosted API docs.
|
||||
nodoc: true
|
||||
|
||||
# PUBSPEC CHECKSUM: 2b6e
|
||||
# PUBSPEC CHECKSUM: 5070
|
||||
|
||||
@@ -8,8 +8,8 @@ environment:
|
||||
|
||||
dependencies:
|
||||
logging: ^1.2.0
|
||||
native_assets_cli: ^0.12.0
|
||||
native_toolchain_c: ^0.9.0
|
||||
native_assets_cli: ^0.13.0
|
||||
native_toolchain_c: ^0.10.0
|
||||
|
||||
dev_dependencies:
|
||||
ffi: ^2.1.3
|
||||
|
||||
@@ -254,10 +254,11 @@ void main() {
|
||||
),
|
||||
),
|
||||
);
|
||||
expect(result.codeAssets.map((CodeAsset c) => c.file!.toString()).toList()..sort(), <String>[
|
||||
directSoFile.uri.toString(),
|
||||
linkedSoFile.uri.toString(),
|
||||
]);
|
||||
expect(
|
||||
result.codeAssets.map((FlutterCodeAsset c) => c.codeAsset.file!.toString()).toList()
|
||||
..sort(),
|
||||
<String>[directSoFile.uri.toString(), linkedSoFile.uri.toString()],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@@ -189,7 +189,7 @@ void main(List<String> args) async {
|
||||
await build(args, (input, output) async {
|
||||
final packageName = input.packageName;
|
||||
|
||||
if (!input.config.buildAssetTypes.contains(CodeAsset.type)) {
|
||||
if (!input.config.buildCodeAssets) {
|
||||
return;
|
||||
}
|
||||
final builders = [
|
||||
|
||||
Reference in New Issue
Block a user