diff --git a/packages/flutter_tools/lib/src/build_system/targets/native_assets.dart b/packages/flutter_tools/lib/src/build_system/targets/native_assets.dart index 967546e14a9..10d1cd09ecf 100644 --- a/packages/flutter_tools/lib/src/build_system/targets/native_assets.dart +++ b/packages/flutter_tools/lib/src/build_system/targets/native_assets.dart @@ -3,7 +3,7 @@ // found in the LICENSE file. import 'package:meta/meta.dart'; -import 'package:native_assets_cli/native_assets_cli_internal.dart' show Asset; +import 'package:native_assets_builder/native_assets_builder.dart' hide NativeAssetsBuildRunner; import 'package:package_config/package_config_types.dart'; import '../../android/gradle_utils.dart'; @@ -56,7 +56,7 @@ class NativeAssets extends Target { final File nativeAssetsFile = environment.buildDir.childFile('native_assets.yaml'); if (nativeAssetsEnvironment == 'false') { dependencies = []; - await writeNativeAssetsYaml([], environment.buildDir.uri, fileSystem); + await writeNativeAssetsYaml(KernelAssets(), environment.buildDir.uri, fileSystem); } else { final String? targetPlatformEnvironment = environment.defines[kTargetPlatform]; if (targetPlatformEnvironment == null) { @@ -145,7 +145,7 @@ class NativeAssets extends Target { } else { // TODO(dacoharkes): Implement other OSes. https://github.com/flutter/flutter/issues/129757 // Write the file we claim to have in the [outputs]. - await writeNativeAssetsYaml([], environment.buildDir.uri, fileSystem); + await writeNativeAssetsYaml(KernelAssets(), environment.buildDir.uri, fileSystem); dependencies = []; } case TargetPlatform.android_arm: @@ -165,7 +165,7 @@ class NativeAssets extends Target { case TargetPlatform.web_javascript: // TODO(dacoharkes): Implement other OSes. https://github.com/flutter/flutter/issues/129757 // Write the file we claim to have in the [outputs]. - await writeNativeAssetsYaml([], environment.buildDir.uri, fileSystem); + await writeNativeAssetsYaml(KernelAssets(), environment.buildDir.uri, fileSystem); dependencies = []; } } diff --git a/packages/flutter_tools/lib/src/isolated/native_assets/android/native_assets.dart b/packages/flutter_tools/lib/src/isolated/native_assets/android/native_assets.dart index c2b40011c74..3bd69500352 100644 --- a/packages/flutter_tools/lib/src/isolated/native_assets/android/native_assets.dart +++ b/packages/flutter_tools/lib/src/isolated/native_assets/android/native_assets.dart @@ -3,7 +3,7 @@ // found in the LICENSE file. import 'package:native_assets_builder/native_assets_builder.dart' - show BuildResult, DryRunResult; + hide NativeAssetsBuildRunner; import 'package:native_assets_cli/native_assets_cli_internal.dart' as native_assets_cli; import 'package:native_assets_cli/native_assets_cli_internal.dart' @@ -31,21 +31,21 @@ Future dryRunNativeAssetsAndroid({ } final Uri buildUri_ = nativeAssetsBuildUri(projectUri, OS.android); - final Iterable nativeAssetPaths = + final Iterable nativeAssetPaths = await dryRunNativeAssetsAndroidInternal( fileSystem, projectUri, buildRunner, ); final Uri nativeAssetsUri = await writeNativeAssetsYaml( - nativeAssetPaths, + KernelAssets(nativeAssetPaths), buildUri_, fileSystem, ); return nativeAssetsUri; } -Future> dryRunNativeAssetsAndroidInternal( +Future> dryRunNativeAssetsAndroidInternal( FileSystem fileSystem, Uri projectUri, NativeAssetsBuildRunner buildRunner, @@ -63,10 +63,9 @@ Future> dryRunNativeAssetsAndroidInternal( final List nativeAssets = dryRunResult.assets; ensureNoLinkModeStatic(nativeAssets); globals.logger.printTrace('Dry running native assets for $targetOS done.'); - final Map assetTargetLocations = + final Map assetTargetLocations = _assetTargetLocations(nativeAssets); - final Iterable nativeAssetPaths = assetTargetLocations.values; - return nativeAssetPaths; + return assetTargetLocations.values; } /// Builds native assets. @@ -85,7 +84,7 @@ Future<(Uri? nativeAssetsYaml, List dependencies)> final Uri buildUri_ = nativeAssetsBuildUri(projectUri, targetOS); if (!await nativeBuildRequired(buildRunner)) { final Uri nativeAssetsYaml = await writeNativeAssetsYaml( - [], + KernelAssets(), yamlParentDirectory ?? buildUri_, fileSystem, ); @@ -116,11 +115,11 @@ Future<(Uri? nativeAssetsYaml, List dependencies)> } ensureNoLinkModeStatic(nativeAssets); globals.logger.printTrace('Building native assets for $targets done.'); - final Map assetTargetLocations = + final Map assetTargetLocations = _assetTargetLocations(nativeAssets); await _copyNativeAssetsAndroid(buildUri_, assetTargetLocations, fileSystem); final Uri nativeAssetsUri = await writeNativeAssetsYaml( - assetTargetLocations.values, + KernelAssets(assetTargetLocations.values), yamlParentDirectory ?? buildUri_, fileSystem); return (nativeAssetsUri, dependencies.toList()); @@ -128,7 +127,7 @@ Future<(Uri? nativeAssetsYaml, List dependencies)> Future _copyNativeAssetsAndroid( Uri buildUri, - Map assetTargetLocations, + Map assetTargetLocations, FileSystem fileSystem, ) async { if (assetTargetLocations.isNotEmpty) { @@ -142,10 +141,10 @@ Future _copyNativeAssetsAndroid( final Uri archUri = buildUri.resolve('jniLibs/lib/$jniArchDir/'); await fileSystem.directory(archUri).create(recursive: true); } - for (final MapEntry assetMapping + for (final MapEntry assetMapping in assetTargetLocations.entries) { final Uri source = (assetMapping.key.path as AssetAbsolutePath).uri; - final Uri target = (assetMapping.value.path as AssetAbsolutePath).uri; + final Uri target = (assetMapping.value.path as KernelAssetAbsolutePath).uri; final AndroidArch androidArch = _getAndroidArch(assetMapping.value.target); final String jniArchDir = androidArch.archName; @@ -190,8 +189,8 @@ AndroidArch _getAndroidArch(Target target) { } } -Map _assetTargetLocations(List nativeAssets) { - return { +Map _assetTargetLocations(List nativeAssets) { + return { for (final Asset asset in nativeAssets) asset: _targetLocationAndroid(asset), }; @@ -199,19 +198,28 @@ Map _assetTargetLocations(List nativeAssets) { /// Converts the `path` of [asset] as output from a `build.dart` invocation to /// the path used inside the Flutter app bundle. -Asset _targetLocationAndroid(Asset asset) { +KernelAsset _targetLocationAndroid(Asset asset) { final AssetPath path = asset.path; + final KernelAssetPath kernelAssetPath; switch (path) { case AssetSystemPath _: + kernelAssetPath = KernelAssetSystemPath(path.uri); case AssetInExecutable _: + kernelAssetPath = KernelAssetInExecutable(); case AssetInProcess _: - return asset; + kernelAssetPath = KernelAssetInProcess(); case AssetAbsolutePath _: final String fileName = path.uri.pathSegments.last; - return asset.copyWith(path: AssetAbsolutePath(Uri(path: fileName))); + kernelAssetPath = KernelAssetAbsolutePath(Uri(path: fileName)); + default: + throw Exception( + 'Unsupported asset path type ${path.runtimeType} in asset $asset', + ); } - throw Exception( - 'Unsupported asset path type ${path.runtimeType} in asset $asset', + return KernelAsset( + id: asset.id, + target: asset.target, + path: kernelAssetPath, ); } diff --git a/packages/flutter_tools/lib/src/isolated/native_assets/ios/native_assets.dart b/packages/flutter_tools/lib/src/isolated/native_assets/ios/native_assets.dart index 24e1beb78d9..1c6a0c94d54 100644 --- a/packages/flutter_tools/lib/src/isolated/native_assets/ios/native_assets.dart +++ b/packages/flutter_tools/lib/src/isolated/native_assets/ios/native_assets.dart @@ -3,7 +3,7 @@ // found in the LICENSE file. import 'package:native_assets_builder/native_assets_builder.dart' - show BuildResult, DryRunResult; + hide NativeAssetsBuildRunner; import 'package:native_assets_cli/native_assets_cli_internal.dart' hide BuildMode; import 'package:native_assets_cli/native_assets_cli_internal.dart' @@ -31,20 +31,20 @@ Future dryRunNativeAssetsIOS({ } final Uri buildUri = nativeAssetsBuildUri(projectUri, OS.iOS); - final Iterable assetTargetLocations = await dryRunNativeAssetsIOSInternal( + final Iterable assetTargetLocations = await dryRunNativeAssetsIOSInternal( fileSystem, projectUri, buildRunner, ); final Uri nativeAssetsUri = await writeNativeAssetsYaml( - assetTargetLocations, + KernelAssets(assetTargetLocations), buildUri, fileSystem, ); return nativeAssetsUri; } -Future> dryRunNativeAssetsIOSInternal( +Future> dryRunNativeAssetsIOSInternal( FileSystem fileSystem, Uri projectUri, NativeAssetsBuildRunner buildRunner, @@ -61,8 +61,7 @@ Future> dryRunNativeAssetsIOSInternal( final List nativeAssets = dryRunResult.assets; ensureNoLinkModeStatic(nativeAssets); globals.logger.printTrace('Dry running native assets for $targetOS done.'); - final Iterable assetTargetLocations = _assetTargetLocations(nativeAssets).values; - return assetTargetLocations; + return _assetTargetLocations(nativeAssets).values; } /// Builds native assets. @@ -77,7 +76,7 @@ Future> buildNativeAssetsIOS({ required FileSystem fileSystem, }) async { if (!await nativeBuildRequired(buildRunner)) { - await writeNativeAssetsYaml([], yamlParentDirectory, fileSystem); + await writeNativeAssetsYaml(KernelAssets(), yamlParentDirectory, fileSystem); return []; } @@ -107,7 +106,7 @@ Future> buildNativeAssetsIOS({ } ensureNoLinkModeStatic(nativeAssets); globals.logger.printTrace('Building native assets for $targets done.'); - final Map> fatAssetTargetLocations = _fatAssetTargetLocations(nativeAssets); + final Map> fatAssetTargetLocations = _fatAssetTargetLocations(nativeAssets); await _copyNativeAssetsIOS( buildUri, fatAssetTargetLocations, @@ -116,9 +115,9 @@ Future> buildNativeAssetsIOS({ fileSystem, ); - final Map assetTargetLocations = _assetTargetLocations(nativeAssets); + final Map assetTargetLocations = _assetTargetLocations(nativeAssets); await writeNativeAssetsYaml( - assetTargetLocations.values, + KernelAssets(assetTargetLocations.values), yamlParentDirectory, fileSystem, ); @@ -146,40 +145,51 @@ Target _getNativeTarget(DarwinArch darwinArch) { } } -Map> _fatAssetTargetLocations(List nativeAssets) { +Map> _fatAssetTargetLocations(List nativeAssets) { final Set alreadyTakenNames = {}; - final Map> result = >{}; + final Map> result = >{}; for (final Asset asset in nativeAssets) { - final AssetPath path = _targetLocationIOS(asset, alreadyTakenNames).path; + final KernelAssetPath path = _targetLocationIOS(asset, alreadyTakenNames).path; result[path] ??= []; result[path]!.add(asset); } return result; } -Map _assetTargetLocations(List nativeAssets) { +Map _assetTargetLocations(List nativeAssets) { final Set alreadyTakenNames = {}; - return { + return { for (final Asset asset in nativeAssets) asset: _targetLocationIOS(asset, alreadyTakenNames), }; } -Asset _targetLocationIOS(Asset asset, Set alreadyTakenNames) { +KernelAsset _targetLocationIOS(Asset asset, Set alreadyTakenNames) { final AssetPath path = asset.path; +final KernelAssetPath kernelAssetPath; switch (path) { case AssetSystemPath _: + kernelAssetPath = KernelAssetSystemPath(path.uri); case AssetInExecutable _: + kernelAssetPath = KernelAssetInExecutable(); case AssetInProcess _: - return asset; + kernelAssetPath = KernelAssetInProcess(); case AssetAbsolutePath _: final String fileName = path.uri.pathSegments.last; - return asset.copyWith( - path: AssetAbsolutePath(frameworkUri(fileName, alreadyTakenNames)), + kernelAssetPath = KernelAssetAbsolutePath(frameworkUri( + fileName, + alreadyTakenNames, + )); + default: + throw Exception( + 'Unsupported asset path type ${path.runtimeType} in asset $asset', ); } - throw Exception( - 'Unsupported asset path type ${path.runtimeType} in asset $asset'); + return KernelAsset( + id: asset.id, + target: asset.target, + path: kernelAssetPath, + ); } /// Copies native assets into a framework per dynamic library. @@ -194,7 +204,7 @@ Asset _targetLocationIOS(Asset asset, Set alreadyTakenNames) { /// in xcode_backend.dart. Future _copyNativeAssetsIOS( Uri buildUri, - Map> assetTargetLocations, + Map> assetTargetLocations, String? codesignIdentity, BuildMode buildMode, FileSystem fileSystem, @@ -202,9 +212,9 @@ Future _copyNativeAssetsIOS( if (assetTargetLocations.isNotEmpty) { globals.logger .printTrace('Copying native assets to ${buildUri.toFilePath()}.'); - for (final MapEntry> assetMapping + for (final MapEntry> assetMapping in assetTargetLocations.entries) { - final Uri target = (assetMapping.key as AssetAbsolutePath).uri; + final Uri target = (assetMapping.key as KernelAssetAbsolutePath).uri; final List sources = [ for (final Asset source in assetMapping.value) (source.path as AssetAbsolutePath).uri diff --git a/packages/flutter_tools/lib/src/isolated/native_assets/linux/native_assets.dart b/packages/flutter_tools/lib/src/isolated/native_assets/linux/native_assets.dart index 47c6d57216f..c0646b3cbe6 100644 --- a/packages/flutter_tools/lib/src/isolated/native_assets/linux/native_assets.dart +++ b/packages/flutter_tools/lib/src/isolated/native_assets/linux/native_assets.dart @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +import 'package:native_assets_builder/native_assets_builder.dart' + hide NativeAssetsBuildRunner; import 'package:native_assets_cli/native_assets_cli_internal.dart' hide BuildMode; @@ -31,7 +33,7 @@ Future dryRunNativeAssetsLinux({ ); } -Future> dryRunNativeAssetsLinuxInternal( +Future> dryRunNativeAssetsLinuxInternal( FileSystem fileSystem, Uri projectUri, bool flutterTester, diff --git a/packages/flutter_tools/lib/src/isolated/native_assets/macos/native_assets.dart b/packages/flutter_tools/lib/src/isolated/native_assets/macos/native_assets.dart index c68a8f8d2ab..45d4fd00f80 100644 --- a/packages/flutter_tools/lib/src/isolated/native_assets/macos/native_assets.dart +++ b/packages/flutter_tools/lib/src/isolated/native_assets/macos/native_assets.dart @@ -3,7 +3,7 @@ // found in the LICENSE file. import 'package:native_assets_builder/native_assets_builder.dart' - show BuildResult, DryRunResult; + hide NativeAssetsBuildRunner; import 'package:native_assets_cli/native_assets_cli_internal.dart' hide BuildMode; import 'package:native_assets_cli/native_assets_cli_internal.dart' @@ -31,12 +31,21 @@ Future dryRunNativeAssetsMacOS({ } final Uri buildUri = nativeAssetsBuildUri(projectUri, OS.macOS); - final Iterable nativeAssetPaths = await dryRunNativeAssetsMacOSInternal(fileSystem, projectUri, flutterTester, buildRunner); - final Uri nativeAssetsUri = await writeNativeAssetsYaml(nativeAssetPaths, buildUri, fileSystem); + final Iterable nativeAssetPaths = await dryRunNativeAssetsMacOSInternal( + fileSystem, + projectUri, + flutterTester, + buildRunner, + ); + final Uri nativeAssetsUri = await writeNativeAssetsYaml( + KernelAssets(nativeAssetPaths), + buildUri, + fileSystem, + ); return nativeAssetsUri; } -Future> dryRunNativeAssetsMacOSInternal( +Future> dryRunNativeAssetsMacOSInternal( FileSystem fileSystem, Uri projectUri, bool flutterTester, @@ -57,9 +66,11 @@ Future> dryRunNativeAssetsMacOSInternal( ensureNoLinkModeStatic(nativeAssets); globals.logger.printTrace('Dry running native assets for $targetOS done.'); final Uri? absolutePath = flutterTester ? buildUri : null; - final Map assetTargetLocations = _assetTargetLocations(nativeAssets, absolutePath); - final Iterable nativeAssetPaths = assetTargetLocations.values; - return nativeAssetPaths; + final Map assetTargetLocations = _assetTargetLocations( + nativeAssets, + absolutePath, + ); + return assetTargetLocations.values; } /// Builds native assets. @@ -82,14 +93,22 @@ Future<(Uri? nativeAssetsYaml, List dependencies)> buildNativeAssetsMacOS({ const OS targetOS = OS.macOS; final Uri buildUri = nativeAssetsBuildUri(projectUri, targetOS); if (!await nativeBuildRequired(buildRunner)) { - final Uri nativeAssetsYaml = await writeNativeAssetsYaml([], yamlParentDirectory ?? buildUri, fileSystem); + final Uri nativeAssetsYaml = await writeNativeAssetsYaml( + KernelAssets(), + yamlParentDirectory ?? buildUri, + fileSystem, + ); return (nativeAssetsYaml, []); } - final List targets = darwinArchs != null ? darwinArchs.map(_getNativeTarget).toList() : [Target.current]; - final native_assets_cli.BuildMode buildModeCli = nativeAssetsBuildMode(buildMode); + final List targets = darwinArchs != null + ? darwinArchs.map(_getNativeTarget).toList() + : [Target.current]; + final native_assets_cli.BuildMode buildModeCli = + nativeAssetsBuildMode(buildMode); - globals.logger.printTrace('Building native assets for $targets $buildModeCli.'); + globals.logger + .printTrace('Building native assets for $targets $buildModeCli.'); final List nativeAssets = []; final Set dependencies = {}; for (final Target target in targets) { @@ -108,8 +127,10 @@ Future<(Uri? nativeAssetsYaml, List dependencies)> buildNativeAssetsMacOS({ ensureNoLinkModeStatic(nativeAssets); globals.logger.printTrace('Building native assets for $targets done.'); final Uri? absolutePath = flutterTester ? buildUri : null; - final Map assetTargetLocations = _assetTargetLocations(nativeAssets, absolutePath); - final Map> fatAssetTargetLocations = _fatAssetTargetLocations(nativeAssets, absolutePath); + final Map assetTargetLocations = + _assetTargetLocations(nativeAssets, absolutePath); + final Map> fatAssetTargetLocations = + _fatAssetTargetLocations(nativeAssets, absolutePath); if (flutterTester) { await _copyNativeAssetsMacOSFlutterTester( buildUri, @@ -127,7 +148,11 @@ Future<(Uri? nativeAssetsYaml, List dependencies)> buildNativeAssetsMacOS({ fileSystem, ); } - final Uri nativeAssetsUri = await writeNativeAssetsYaml(assetTargetLocations.values, yamlParentDirectory ?? buildUri, fileSystem); + final Uri nativeAssetsUri = await writeNativeAssetsYaml( + KernelAssets(assetTargetLocations.values), + yamlParentDirectory ?? buildUri, + fileSystem, + ); return (nativeAssetsUri, dependencies.toList()); } @@ -143,14 +168,15 @@ Target _getNativeTarget(DarwinArch darwinArch) { } } -Map> _fatAssetTargetLocations( +Map> _fatAssetTargetLocations( List nativeAssets, Uri? absolutePath, ) { final Set alreadyTakenNames = {}; - final Map> result = >{}; + final Map> result = + >{}; for (final Asset asset in nativeAssets) { - final AssetPath path = _targetLocationMacOS( + final KernelAssetPath path = _targetLocationMacOS( asset, absolutePath, alreadyTakenNames, @@ -161,28 +187,31 @@ Map> _fatAssetTargetLocations( return result; } -Map _assetTargetLocations( +Map _assetTargetLocations( List nativeAssets, Uri? absolutePath, ) { final Set alreadyTakenNames = {}; - return { + return { for (final Asset asset in nativeAssets) asset: _targetLocationMacOS(asset, absolutePath, alreadyTakenNames), }; } -Asset _targetLocationMacOS( +KernelAsset _targetLocationMacOS( Asset asset, Uri? absolutePath, Set alreadyTakenNames, ) { final AssetPath path = asset.path; + final KernelAssetPath kernelAssetPath; switch (path) { case AssetSystemPath _: + kernelAssetPath = KernelAssetSystemPath(path.uri); case AssetInExecutable _: + kernelAssetPath = KernelAssetInExecutable(); case AssetInProcess _: - return asset; + kernelAssetPath = KernelAssetInProcess(); case AssetAbsolutePath _: final String fileName = path.uri.pathSegments.last; Uri uri; @@ -194,11 +223,18 @@ Asset _targetLocationMacOS( // "relative" in the context of native assets would be relative to the // kernel or aot snapshot. uri = frameworkUri(fileName, alreadyTakenNames); - } - return asset.copyWith(path: AssetAbsolutePath(uri)); + kernelAssetPath = KernelAssetAbsolutePath(uri); + default: + throw Exception( + 'Unsupported asset path type ${path.runtimeType} in asset $asset', + ); } - throw Exception('Unsupported asset path type ${path.runtimeType} in asset $asset'); + return KernelAsset( + id: asset.id, + target: asset.target, + path: kernelAssetPath, + ); } /// Copies native assets into a framework per dynamic library. @@ -216,15 +252,18 @@ Asset _targetLocationMacOS( /// in macos_assemble.sh. Future _copyNativeAssetsMacOS( Uri buildUri, - Map> assetTargetLocations, + Map> assetTargetLocations, String? codesignIdentity, BuildMode buildMode, FileSystem fileSystem, ) async { if (assetTargetLocations.isNotEmpty) { - globals.logger.printTrace('Copying native assets to ${buildUri.toFilePath()}.'); - for (final MapEntry> assetMapping in assetTargetLocations.entries) { - final Uri target = (assetMapping.key as AssetAbsolutePath).uri; + globals.logger.printTrace( + 'Copying native assets to ${buildUri.toFilePath()}.', + ); + for (final MapEntry> assetMapping + in assetTargetLocations.entries) { + final Uri target = (assetMapping.key as KernelAssetAbsolutePath).uri; final List sources = [ for (final Asset source in assetMapping.value) (source.path as AssetAbsolutePath).uri, @@ -273,7 +312,6 @@ Future _copyNativeAssetsMacOS( } } - /// Copies native assets for flutter tester. /// /// For `flutter run -release` a multi-architecture solution is needed. So, @@ -284,15 +322,18 @@ Future _copyNativeAssetsMacOS( /// Code signing is also done here. Future _copyNativeAssetsMacOSFlutterTester( Uri buildUri, - Map> assetTargetLocations, + Map> assetTargetLocations, String? codesignIdentity, BuildMode buildMode, FileSystem fileSystem, ) async { if (assetTargetLocations.isNotEmpty) { - globals.logger.printTrace('Copying native assets to ${buildUri.toFilePath()}.'); - for (final MapEntry> assetMapping in assetTargetLocations.entries) { - final Uri target = (assetMapping.key as AssetAbsolutePath).uri; + globals.logger.printTrace( + 'Copying native assets to ${buildUri.toFilePath()}.', + ); + for (final MapEntry> assetMapping + in assetTargetLocations.entries) { + final Uri target = (assetMapping.key as KernelAssetAbsolutePath).uri; final List sources = [ for (final Asset source in assetMapping.value) (source.path as AssetAbsolutePath).uri, diff --git a/packages/flutter_tools/lib/src/isolated/native_assets/native_assets.dart b/packages/flutter_tools/lib/src/isolated/native_assets/native_assets.dart index 99dc6f6780c..a39fd699d0b 100644 --- a/packages/flutter_tools/lib/src/isolated/native_assets/native_assets.dart +++ b/packages/flutter_tools/lib/src/isolated/native_assets/native_assets.dart @@ -195,7 +195,7 @@ class NativeAssetsBuildRunnerImpl implements NativeAssetsBuildRunner { /// Write [assets] to `native_assets.yaml` in [yamlParentDirectory]. Future writeNativeAssetsYaml( - Iterable assets, + KernelAssets assets, Uri yamlParentDirectory, FileSystem fileSystem, ) async { @@ -295,7 +295,7 @@ Future ensureNoNativeAssetsOrOsIsSupported( /// /// Therefore, ensure all `build.dart` scripts return only dynamic libraries. void ensureNoLinkModeStatic(List nativeAssets) { - final Iterable staticAssets = nativeAssets.whereLinkMode(LinkMode.static); + final Iterable staticAssets = nativeAssets.where((Asset e) => e.linkMode == LinkMode.static); if (staticAssets.isNotEmpty) { final String assetIds = staticAssets.map((Asset a) => a.id).toSet().join(', '); throwToolExit( @@ -453,7 +453,7 @@ Future dryRunNativeAssetsMultipleOSes({ } final Uri buildUri = buildUriMultiple(projectUri); - final Iterable nativeAssetPaths = [ + final Iterable nativeAssetPaths = [ if (targetPlatforms.contains(build_info.TargetPlatform.darwin) || (targetPlatforms.contains(build_info.TargetPlatform.tester) && OS.current == OS.macOS)) ...await dryRunNativeAssetsMacOSInternal( @@ -497,7 +497,11 @@ Future dryRunNativeAssetsMultipleOSes({ buildRunner, ), ]; - final Uri nativeAssetsUri = await writeNativeAssetsYaml(nativeAssetPaths, buildUri, fileSystem); + final Uri nativeAssetsUri = await writeNativeAssetsYaml( + KernelAssets(nativeAssetPaths), + buildUri, + fileSystem, + ); return nativeAssetsUri; } @@ -524,7 +528,7 @@ Future dryRunNativeAssetsSingleArchitecture({ } final Uri buildUri = nativeAssetsBuildUri(projectUri, os); - final Iterable nativeAssetPaths = await dryRunNativeAssetsSingleArchitectureInternal( + final Iterable nativeAssetPaths = await dryRunNativeAssetsSingleArchitectureInternal( fileSystem, projectUri, flutterTester, @@ -532,14 +536,14 @@ Future dryRunNativeAssetsSingleArchitecture({ os, ); final Uri nativeAssetsUri = await writeNativeAssetsYaml( - nativeAssetPaths, + KernelAssets(nativeAssetPaths.toList()), buildUri, fileSystem, ); return nativeAssetsUri; } -Future> dryRunNativeAssetsSingleArchitectureInternal( +Future> dryRunNativeAssetsSingleArchitectureInternal( FileSystem fileSystem, Uri projectUri, bool flutterTester, @@ -561,12 +565,11 @@ Future> dryRunNativeAssetsSingleArchitectureInternal( ensureNoLinkModeStatic(nativeAssets); globals.logger.printTrace('Dry running native assets for $targetOS done.'); final Uri? absolutePath = flutterTester ? buildUri : null; - final Map assetTargetLocations = _assetTargetLocationsSingleArchitecture( + final Map assetTargetLocations = _assetTargetLocationsSingleArchitecture( nativeAssets, absolutePath, ); - final Iterable nativeAssetPaths = assetTargetLocations.values; - return nativeAssetPaths; + return assetTargetLocations.values; } /// Builds native assets. @@ -595,7 +598,7 @@ Future<(Uri? nativeAssetsYaml, List dependencies)> buildNativeAssetsSingleA } if (!await nativeBuildRequired(buildRunner)) { final Uri nativeAssetsYaml = await writeNativeAssetsYaml( - [], + KernelAssets(), yamlParentDirectory ?? buildUri, fileSystem, ); @@ -619,7 +622,7 @@ Future<(Uri? nativeAssetsYaml, List dependencies)> buildNativeAssetsSingleA ensureNoLinkModeStatic(nativeAssets); globals.logger.printTrace('Building native assets for $target done.'); final Uri? absolutePath = flutterTester ? buildUri : null; - final Map assetTargetLocations = _assetTargetLocationsSingleArchitecture(nativeAssets, absolutePath); + final Map assetTargetLocations = _assetTargetLocationsSingleArchitecture(nativeAssets, absolutePath); await _copyNativeAssetsSingleArchitecture( buildUri, assetTargetLocations, @@ -627,18 +630,18 @@ Future<(Uri? nativeAssetsYaml, List dependencies)> buildNativeAssetsSingleA fileSystem, ); final Uri nativeAssetsUri = await writeNativeAssetsYaml( - assetTargetLocations.values, + KernelAssets(assetTargetLocations.values.toList()), yamlParentDirectory ?? buildUri, fileSystem, ); return (nativeAssetsUri, dependencies.toList()); } -Map _assetTargetLocationsSingleArchitecture( +Map _assetTargetLocationsSingleArchitecture( List nativeAssets, Uri? absolutePath, ) { - return { + return { for (final Asset asset in nativeAssets) asset: _targetLocationSingleArchitecture( asset, @@ -647,13 +650,16 @@ Map _assetTargetLocationsSingleArchitecture( }; } -Asset _targetLocationSingleArchitecture(Asset asset, Uri? absolutePath) { +KernelAsset _targetLocationSingleArchitecture(Asset asset, Uri? absolutePath) { final AssetPath path = asset.path; + final KernelAssetPath kernelAssetPath; switch (path) { case AssetSystemPath _: + kernelAssetPath = KernelAssetSystemPath(path.uri); case AssetInExecutable _: + kernelAssetPath = KernelAssetInExecutable(); case AssetInProcess _: - return asset; + kernelAssetPath = KernelAssetInProcess(); case AssetAbsolutePath _: final String fileName = path.uri.pathSegments.last; Uri uri; @@ -666,9 +672,17 @@ Asset _targetLocationSingleArchitecture(Asset asset, Uri? absolutePath) { // kernel or aot snapshot. uri = Uri(path: fileName); } - return asset.copyWith(path: AssetAbsolutePath(uri)); + kernelAssetPath = KernelAssetAbsolutePath(uri); + default: + throw Exception( + 'Unsupported asset path type ${path.runtimeType} in asset $asset', + ); } - throw Exception('Unsupported asset path type ${path.runtimeType} in asset $asset'); + return KernelAsset( + id: asset.id, + target: asset.target, + path: kernelAssetPath, + ); } /// Extract the [Target] from a [TargetPlatform]. @@ -702,7 +716,7 @@ Target _getNativeTarget(build_info.TargetPlatform targetPlatform) { Future _copyNativeAssetsSingleArchitecture( Uri buildUri, - Map assetTargetLocations, + Map assetTargetLocations, build_info.BuildMode buildMode, FileSystem fileSystem, ) async { @@ -712,9 +726,9 @@ Future _copyNativeAssetsSingleArchitecture( if (!buildDir.existsSync()) { buildDir.createSync(recursive: true); } - for (final MapEntry assetMapping in assetTargetLocations.entries) { + for (final MapEntry assetMapping in assetTargetLocations.entries) { final Uri source = (assetMapping.key.path as AssetAbsolutePath).uri; - final Uri target = (assetMapping.value.path as AssetAbsolutePath).uri; + final Uri target = (assetMapping.value.path as KernelAssetAbsolutePath).uri; final Uri targetUri = buildUri.resolveUri(target); final String targetFullPath = targetUri.toFilePath(); await fileSystem.file(source).copy(targetFullPath); diff --git a/packages/flutter_tools/lib/src/isolated/native_assets/windows/native_assets.dart b/packages/flutter_tools/lib/src/isolated/native_assets/windows/native_assets.dart index 77e8b5350b5..98fd21ab0f0 100644 --- a/packages/flutter_tools/lib/src/isolated/native_assets/windows/native_assets.dart +++ b/packages/flutter_tools/lib/src/isolated/native_assets/windows/native_assets.dart @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +import 'package:native_assets_builder/native_assets_builder.dart' + hide NativeAssetsBuildRunner; import 'package:native_assets_cli/native_assets_cli_internal.dart' hide BuildMode; @@ -30,7 +32,7 @@ Future dryRunNativeAssetsWindows({ ); } -Future> dryRunNativeAssetsWindowsInternal( +Future> dryRunNativeAssetsWindowsInternal( FileSystem fileSystem, Uri projectUri, bool flutterTester, diff --git a/packages/flutter_tools/pubspec.yaml b/packages/flutter_tools/pubspec.yaml index 99b7dfde28e..5ea51ac8394 100644 --- a/packages/flutter_tools/pubspec.yaml +++ b/packages/flutter_tools/pubspec.yaml @@ -55,7 +55,7 @@ dependencies: cli_config: 0.1.2 graphs: 2.3.1 - native_assets_builder: 0.3.2 + native_assets_builder: 0.5.0 native_assets_cli: 0.4.2 # We depend on very specific internal implementation details of the @@ -118,4 +118,4 @@ dartdoc: # Exclude this package from the hosted API docs. nodoc: true -# PUBSPEC CHECKSUM: 980d +# PUBSPEC CHECKSUM: a00d