mirror of
https://github.com/flutter/flutter
synced 2024-08-25 02:46:31 +00:00
[deps] Bump native assets dependencies (#145612)
Roll of a bunch of breaking changes from the native_assets_builder and native_assets_cli upstream. Most notably: * https://github.com/dart-lang/native/pull/946 * https://github.com/dart-lang/native/pull/1018 * https://github.com/dart-lang/native/pull/1019 This PR also updates the template in `flutter create --template=package_ffi` to use the rewritten API. This PR does not change any functionality in Flutter. For reference, the same roll in the Dart SDK: * https://dart-review.googlesource.com/c/sdk/+/357605 * https://dart-review.googlesource.com/c/sdk/+/357623 ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] All existing and new tests are passing. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/wiki/Tree-hygiene#overview [Tree Hygiene]: https://github.com/flutter/flutter/wiki/Tree-hygiene [test-exempt]: https://github.com/flutter/flutter/wiki/Tree-hygiene#tests [Flutter Style Guide]: https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo [Features we expect every widget to implement]: https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/wiki/Tree-hygiene#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/wiki/Chat
This commit is contained in:
parent
280037f6b1
commit
baa54fdd76
|
@ -4,10 +4,7 @@
|
||||||
|
|
||||||
import 'package:native_assets_builder/native_assets_builder.dart'
|
import 'package:native_assets_builder/native_assets_builder.dart'
|
||||||
hide NativeAssetsBuildRunner;
|
hide NativeAssetsBuildRunner;
|
||||||
import 'package:native_assets_cli/native_assets_cli_internal.dart'
|
import 'package:native_assets_cli/native_assets_cli_internal.dart';
|
||||||
as native_assets_cli;
|
|
||||||
import 'package:native_assets_cli/native_assets_cli_internal.dart'
|
|
||||||
hide BuildMode;
|
|
||||||
|
|
||||||
import '../../../android/android_sdk.dart';
|
import '../../../android/android_sdk.dart';
|
||||||
import '../../../base/common.dart';
|
import '../../../base/common.dart';
|
||||||
|
@ -30,7 +27,7 @@ Future<Uri?> dryRunNativeAssetsAndroid({
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
final Uri buildUri_ = nativeAssetsBuildUri(projectUri, OS.android);
|
final Uri buildUri_ = nativeAssetsBuildUri(projectUri, OSImpl.android);
|
||||||
final Iterable<KernelAsset> nativeAssetPaths =
|
final Iterable<KernelAsset> nativeAssetPaths =
|
||||||
await dryRunNativeAssetsAndroidInternal(
|
await dryRunNativeAssetsAndroidInternal(
|
||||||
fileSystem,
|
fileSystem,
|
||||||
|
@ -50,20 +47,20 @@ Future<Iterable<KernelAsset>> dryRunNativeAssetsAndroidInternal(
|
||||||
Uri projectUri,
|
Uri projectUri,
|
||||||
NativeAssetsBuildRunner buildRunner,
|
NativeAssetsBuildRunner buildRunner,
|
||||||
) async {
|
) async {
|
||||||
const OS targetOS = OS.android;
|
const OSImpl targetOS = OSImpl.android;
|
||||||
|
|
||||||
globals.logger.printTrace('Dry running native assets for $targetOS.');
|
globals.logger.printTrace('Dry running native assets for $targetOS.');
|
||||||
final DryRunResult dryRunResult = await buildRunner.dryRun(
|
final DryRunResult dryRunResult = await buildRunner.dryRun(
|
||||||
linkModePreference: LinkModePreference.dynamic,
|
linkModePreference: LinkModePreferenceImpl.dynamic,
|
||||||
targetOS: targetOS,
|
targetOS: targetOS,
|
||||||
workingDirectory: projectUri,
|
workingDirectory: projectUri,
|
||||||
includeParentEnvironment: true,
|
includeParentEnvironment: true,
|
||||||
);
|
);
|
||||||
ensureNativeAssetsBuildSucceed(dryRunResult);
|
ensureNativeAssetsBuildSucceed(dryRunResult);
|
||||||
final List<Asset> nativeAssets = dryRunResult.assets;
|
final List<AssetImpl> nativeAssets = dryRunResult.assets;
|
||||||
ensureNoLinkModeStatic(nativeAssets);
|
ensureNoLinkModeStatic(nativeAssets);
|
||||||
globals.logger.printTrace('Dry running native assets for $targetOS done.');
|
globals.logger.printTrace('Dry running native assets for $targetOS done.');
|
||||||
final Map<Asset, KernelAsset> assetTargetLocations =
|
final Map<AssetImpl, KernelAsset> assetTargetLocations =
|
||||||
_assetTargetLocations(nativeAssets);
|
_assetTargetLocations(nativeAssets);
|
||||||
return assetTargetLocations.values;
|
return assetTargetLocations.values;
|
||||||
}
|
}
|
||||||
|
@ -80,7 +77,7 @@ Future<(Uri? nativeAssetsYaml, List<Uri> dependencies)>
|
||||||
required FileSystem fileSystem,
|
required FileSystem fileSystem,
|
||||||
required int targetAndroidNdkApi,
|
required int targetAndroidNdkApi,
|
||||||
}) async {
|
}) async {
|
||||||
const OS targetOS = OS.android;
|
const OSImpl targetOS = OSImpl.android;
|
||||||
final Uri buildUri_ = nativeAssetsBuildUri(projectUri, targetOS);
|
final Uri buildUri_ = nativeAssetsBuildUri(projectUri, targetOS);
|
||||||
if (!await nativeBuildRequired(buildRunner)) {
|
if (!await nativeBuildRequired(buildRunner)) {
|
||||||
final Uri nativeAssetsYaml = await writeNativeAssetsYaml(
|
final Uri nativeAssetsYaml = await writeNativeAssetsYaml(
|
||||||
|
@ -92,21 +89,21 @@ Future<(Uri? nativeAssetsYaml, List<Uri> dependencies)>
|
||||||
}
|
}
|
||||||
|
|
||||||
final List<Target> targets = androidArchs.map(_getNativeTarget).toList();
|
final List<Target> targets = androidArchs.map(_getNativeTarget).toList();
|
||||||
final native_assets_cli.BuildMode buildModeCli =
|
final BuildModeImpl buildModeCli =
|
||||||
nativeAssetsBuildMode(buildMode);
|
nativeAssetsBuildMode(buildMode);
|
||||||
|
|
||||||
globals.logger
|
globals.logger
|
||||||
.printTrace('Building native assets for $targets $buildModeCli.');
|
.printTrace('Building native assets for $targets $buildModeCli.');
|
||||||
final List<Asset> nativeAssets = <Asset>[];
|
final List<AssetImpl> nativeAssets = <AssetImpl>[];
|
||||||
final Set<Uri> dependencies = <Uri>{};
|
final Set<Uri> dependencies = <Uri>{};
|
||||||
for (final Target target in targets) {
|
for (final Target target in targets) {
|
||||||
final BuildResult result = await buildRunner.build(
|
final BuildResult result = await buildRunner.build(
|
||||||
linkModePreference: LinkModePreference.dynamic,
|
linkModePreference: LinkModePreferenceImpl.dynamic,
|
||||||
target: target,
|
target: target,
|
||||||
buildMode: buildModeCli,
|
buildMode: buildModeCli,
|
||||||
workingDirectory: projectUri,
|
workingDirectory: projectUri,
|
||||||
includeParentEnvironment: true,
|
includeParentEnvironment: true,
|
||||||
cCompilerConfig: await buildRunner.ndkCCompilerConfig,
|
cCompilerConfig: await buildRunner.ndkCCompilerConfigImpl,
|
||||||
targetAndroidNdkApi: targetAndroidNdkApi,
|
targetAndroidNdkApi: targetAndroidNdkApi,
|
||||||
);
|
);
|
||||||
ensureNativeAssetsBuildSucceed(result);
|
ensureNativeAssetsBuildSucceed(result);
|
||||||
|
@ -115,7 +112,7 @@ Future<(Uri? nativeAssetsYaml, List<Uri> dependencies)>
|
||||||
}
|
}
|
||||||
ensureNoLinkModeStatic(nativeAssets);
|
ensureNoLinkModeStatic(nativeAssets);
|
||||||
globals.logger.printTrace('Building native assets for $targets done.');
|
globals.logger.printTrace('Building native assets for $targets done.');
|
||||||
final Map<Asset, KernelAsset> assetTargetLocations =
|
final Map<AssetImpl, KernelAsset> assetTargetLocations =
|
||||||
_assetTargetLocations(nativeAssets);
|
_assetTargetLocations(nativeAssets);
|
||||||
await _copyNativeAssetsAndroid(buildUri_, assetTargetLocations, fileSystem);
|
await _copyNativeAssetsAndroid(buildUri_, assetTargetLocations, fileSystem);
|
||||||
final Uri nativeAssetsUri = await writeNativeAssetsYaml(
|
final Uri nativeAssetsUri = await writeNativeAssetsYaml(
|
||||||
|
@ -127,7 +124,7 @@ Future<(Uri? nativeAssetsYaml, List<Uri> dependencies)>
|
||||||
|
|
||||||
Future<void> _copyNativeAssetsAndroid(
|
Future<void> _copyNativeAssetsAndroid(
|
||||||
Uri buildUri,
|
Uri buildUri,
|
||||||
Map<Asset, KernelAsset> assetTargetLocations,
|
Map<AssetImpl, KernelAsset> assetTargetLocations,
|
||||||
FileSystem fileSystem,
|
FileSystem fileSystem,
|
||||||
) async {
|
) async {
|
||||||
if (assetTargetLocations.isNotEmpty) {
|
if (assetTargetLocations.isNotEmpty) {
|
||||||
|
@ -141,9 +138,9 @@ Future<void> _copyNativeAssetsAndroid(
|
||||||
final Uri archUri = buildUri.resolve('jniLibs/lib/$jniArchDir/');
|
final Uri archUri = buildUri.resolve('jniLibs/lib/$jniArchDir/');
|
||||||
await fileSystem.directory(archUri).create(recursive: true);
|
await fileSystem.directory(archUri).create(recursive: true);
|
||||||
}
|
}
|
||||||
for (final MapEntry<Asset, KernelAsset> assetMapping
|
for (final MapEntry<AssetImpl, KernelAsset> assetMapping
|
||||||
in assetTargetLocations.entries) {
|
in assetTargetLocations.entries) {
|
||||||
final Uri source = (assetMapping.key.path as AssetAbsolutePath).uri;
|
final Uri source = assetMapping.key.file!;
|
||||||
final Uri target = (assetMapping.value.path as KernelAssetAbsolutePath).uri;
|
final Uri target = (assetMapping.value.path as KernelAssetAbsolutePath).uri;
|
||||||
final AndroidArch androidArch =
|
final AndroidArch androidArch =
|
||||||
_getAndroidArch(assetMapping.value.target);
|
_getAndroidArch(assetMapping.value.target);
|
||||||
|
@ -189,36 +186,37 @@ AndroidArch _getAndroidArch(Target target) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<Asset, KernelAsset> _assetTargetLocations(List<Asset> nativeAssets) {
|
Map<AssetImpl, KernelAsset> _assetTargetLocations(
|
||||||
return <Asset, KernelAsset>{
|
List<AssetImpl> nativeAssets) {
|
||||||
for (final Asset asset in nativeAssets)
|
return <AssetImpl, KernelAsset>{
|
||||||
|
for (final AssetImpl asset in nativeAssets)
|
||||||
asset: _targetLocationAndroid(asset),
|
asset: _targetLocationAndroid(asset),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Converts the `path` of [asset] as output from a `build.dart` invocation to
|
/// Converts the `path` of [asset] as output from a `build.dart` invocation to
|
||||||
/// the path used inside the Flutter app bundle.
|
/// the path used inside the Flutter app bundle.
|
||||||
KernelAsset _targetLocationAndroid(Asset asset) {
|
KernelAsset _targetLocationAndroid(AssetImpl asset) {
|
||||||
final AssetPath path = asset.path;
|
final LinkModeImpl linkMode = (asset as NativeCodeAssetImpl).linkMode;
|
||||||
final KernelAssetPath kernelAssetPath;
|
final KernelAssetPath kernelAssetPath;
|
||||||
switch (path) {
|
switch (linkMode) {
|
||||||
case AssetSystemPath _:
|
case DynamicLoadingSystemImpl _:
|
||||||
kernelAssetPath = KernelAssetSystemPath(path.uri);
|
kernelAssetPath = KernelAssetSystemPath(linkMode.uri);
|
||||||
case AssetInExecutable _:
|
case LookupInExecutableImpl _:
|
||||||
kernelAssetPath = KernelAssetInExecutable();
|
kernelAssetPath = KernelAssetInExecutable();
|
||||||
case AssetInProcess _:
|
case LookupInProcessImpl _:
|
||||||
kernelAssetPath = KernelAssetInProcess();
|
kernelAssetPath = KernelAssetInProcess();
|
||||||
case AssetAbsolutePath _:
|
case DynamicLoadingBundledImpl _:
|
||||||
final String fileName = path.uri.pathSegments.last;
|
final String fileName = asset.file!.pathSegments.last;
|
||||||
kernelAssetPath = KernelAssetAbsolutePath(Uri(path: fileName));
|
kernelAssetPath = KernelAssetAbsolutePath(Uri(path: fileName));
|
||||||
default:
|
default:
|
||||||
throw Exception(
|
throw Exception(
|
||||||
'Unsupported asset path type ${path.runtimeType} in asset $asset',
|
'Unsupported asset link mode $linkMode in asset $asset',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return KernelAsset(
|
return KernelAsset(
|
||||||
id: asset.id,
|
id: asset.id,
|
||||||
target: asset.target,
|
target: Target.fromArchitectureAndOS(asset.architecture!, asset.os),
|
||||||
path: kernelAssetPath,
|
path: kernelAssetPath,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -231,17 +229,19 @@ KernelAsset _targetLocationAndroid(Asset asset) {
|
||||||
/// assets feature is disabled, or none of the packages have native assets, a
|
/// assets feature is disabled, or none of the packages have native assets, a
|
||||||
/// missing NDK is okay.
|
/// missing NDK is okay.
|
||||||
@override
|
@override
|
||||||
Future<CCompilerConfig> cCompilerConfigAndroid() async {
|
Future<CCompilerConfigImpl> cCompilerConfigAndroid() async {
|
||||||
final AndroidSdk? androidSdk = AndroidSdk.locateAndroidSdk();
|
final AndroidSdk? androidSdk = AndroidSdk.locateAndroidSdk();
|
||||||
if (androidSdk == null) {
|
if (androidSdk == null) {
|
||||||
throwToolExit('Android SDK could not be found.');
|
throwToolExit('Android SDK could not be found.');
|
||||||
}
|
}
|
||||||
final CCompilerConfig result = CCompilerConfig(
|
final CCompilerConfigImpl result = CCompilerConfigImpl(
|
||||||
cc: _toOptionalFileUri(androidSdk.getNdkClangPath()),
|
compiler: _toOptionalFileUri(androidSdk.getNdkClangPath()),
|
||||||
ar: _toOptionalFileUri(androidSdk.getNdkArPath()),
|
archiver: _toOptionalFileUri(androidSdk.getNdkArPath()),
|
||||||
ld: _toOptionalFileUri(androidSdk.getNdkLdPath()),
|
linker: _toOptionalFileUri(androidSdk.getNdkLdPath()),
|
||||||
);
|
);
|
||||||
if (result.cc == null || result.ar == null || result.ld == null) {
|
if (result.compiler == null ||
|
||||||
|
result.archiver == null ||
|
||||||
|
result.linker == null) {
|
||||||
throwToolExit('Android NDK Clang could not be found.');
|
throwToolExit('Android NDK Clang could not be found.');
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
|
|
@ -4,10 +4,7 @@
|
||||||
|
|
||||||
import 'package:native_assets_builder/native_assets_builder.dart'
|
import 'package:native_assets_builder/native_assets_builder.dart'
|
||||||
hide NativeAssetsBuildRunner;
|
hide NativeAssetsBuildRunner;
|
||||||
import 'package:native_assets_cli/native_assets_cli_internal.dart'
|
import 'package:native_assets_cli/native_assets_cli_internal.dart';
|
||||||
hide BuildMode;
|
|
||||||
import 'package:native_assets_cli/native_assets_cli_internal.dart'
|
|
||||||
as native_assets_cli;
|
|
||||||
|
|
||||||
import '../../../base/file_system.dart';
|
import '../../../base/file_system.dart';
|
||||||
import '../../../build_info.dart';
|
import '../../../build_info.dart';
|
||||||
|
@ -30,7 +27,7 @@ Future<Uri?> dryRunNativeAssetsIOS({
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
final Uri buildUri = nativeAssetsBuildUri(projectUri, OS.iOS);
|
final Uri buildUri = nativeAssetsBuildUri(projectUri, OSImpl.iOS);
|
||||||
final Iterable<KernelAsset> assetTargetLocations = await dryRunNativeAssetsIOSInternal(
|
final Iterable<KernelAsset> assetTargetLocations = await dryRunNativeAssetsIOSInternal(
|
||||||
fileSystem,
|
fileSystem,
|
||||||
projectUri,
|
projectUri,
|
||||||
|
@ -49,16 +46,16 @@ Future<Iterable<KernelAsset>> dryRunNativeAssetsIOSInternal(
|
||||||
Uri projectUri,
|
Uri projectUri,
|
||||||
NativeAssetsBuildRunner buildRunner,
|
NativeAssetsBuildRunner buildRunner,
|
||||||
) async {
|
) async {
|
||||||
const OS targetOS = OS.iOS;
|
const OSImpl targetOS = OSImpl.iOS;
|
||||||
globals.logger.printTrace('Dry running native assets for $targetOS.');
|
globals.logger.printTrace('Dry running native assets for $targetOS.');
|
||||||
final DryRunResult dryRunResult = await buildRunner.dryRun(
|
final DryRunResult dryRunResult = await buildRunner.dryRun(
|
||||||
linkModePreference: LinkModePreference.dynamic,
|
linkModePreference: LinkModePreferenceImpl.dynamic,
|
||||||
targetOS: targetOS,
|
targetOS: targetOS,
|
||||||
workingDirectory: projectUri,
|
workingDirectory: projectUri,
|
||||||
includeParentEnvironment: true,
|
includeParentEnvironment: true,
|
||||||
);
|
);
|
||||||
ensureNativeAssetsBuildSucceed(dryRunResult);
|
ensureNativeAssetsBuildSucceed(dryRunResult);
|
||||||
final List<Asset> nativeAssets = dryRunResult.assets;
|
final List<AssetImpl> nativeAssets = dryRunResult.assets;
|
||||||
ensureNoLinkModeStatic(nativeAssets);
|
ensureNoLinkModeStatic(nativeAssets);
|
||||||
globals.logger.printTrace('Dry running native assets for $targetOS done.');
|
globals.logger.printTrace('Dry running native assets for $targetOS done.');
|
||||||
return _assetTargetLocations(nativeAssets).values;
|
return _assetTargetLocations(nativeAssets).values;
|
||||||
|
@ -81,20 +78,20 @@ Future<List<Uri>> buildNativeAssetsIOS({
|
||||||
}
|
}
|
||||||
|
|
||||||
final List<Target> targets = darwinArchs.map(_getNativeTarget).toList();
|
final List<Target> targets = darwinArchs.map(_getNativeTarget).toList();
|
||||||
final native_assets_cli.BuildMode buildModeCli = nativeAssetsBuildMode(buildMode);
|
final BuildModeImpl buildModeCli = nativeAssetsBuildMode(buildMode);
|
||||||
|
|
||||||
const OS targetOS = OS.iOS;
|
const OSImpl targetOS = OSImpl.iOS;
|
||||||
final Uri buildUri = nativeAssetsBuildUri(projectUri, targetOS);
|
final Uri buildUri = nativeAssetsBuildUri(projectUri, targetOS);
|
||||||
final IOSSdk iosSdk = _getIOSSdk(environmentType);
|
final IOSSdkImpl iosSdk = _getIOSSdkImpl(environmentType);
|
||||||
|
|
||||||
globals.logger.printTrace('Building native assets for $targets $buildModeCli.');
|
globals.logger.printTrace('Building native assets for $targets $buildModeCli.');
|
||||||
final List<Asset> nativeAssets = <Asset>[];
|
final List<AssetImpl> nativeAssets = <AssetImpl>[];
|
||||||
final Set<Uri> dependencies = <Uri>{};
|
final Set<Uri> dependencies = <Uri>{};
|
||||||
for (final Target target in targets) {
|
for (final Target target in targets) {
|
||||||
final BuildResult result = await buildRunner.build(
|
final BuildResult result = await buildRunner.build(
|
||||||
linkModePreference: LinkModePreference.dynamic,
|
linkModePreference: LinkModePreferenceImpl.dynamic,
|
||||||
target: target,
|
target: target,
|
||||||
targetIOSSdk: iosSdk,
|
targetIOSSdkImpl: iosSdk,
|
||||||
buildMode: buildModeCli,
|
buildMode: buildModeCli,
|
||||||
workingDirectory: projectUri,
|
workingDirectory: projectUri,
|
||||||
includeParentEnvironment: true,
|
includeParentEnvironment: true,
|
||||||
|
@ -106,7 +103,8 @@ Future<List<Uri>> buildNativeAssetsIOS({
|
||||||
}
|
}
|
||||||
ensureNoLinkModeStatic(nativeAssets);
|
ensureNoLinkModeStatic(nativeAssets);
|
||||||
globals.logger.printTrace('Building native assets for $targets done.');
|
globals.logger.printTrace('Building native assets for $targets done.');
|
||||||
final Map<KernelAssetPath, List<Asset>> fatAssetTargetLocations = _fatAssetTargetLocations(nativeAssets);
|
final Map<KernelAssetPath, List<AssetImpl>> fatAssetTargetLocations =
|
||||||
|
_fatAssetTargetLocations(nativeAssets);
|
||||||
await _copyNativeAssetsIOS(
|
await _copyNativeAssetsIOS(
|
||||||
buildUri,
|
buildUri,
|
||||||
fatAssetTargetLocations,
|
fatAssetTargetLocations,
|
||||||
|
@ -115,7 +113,8 @@ Future<List<Uri>> buildNativeAssetsIOS({
|
||||||
fileSystem,
|
fileSystem,
|
||||||
);
|
);
|
||||||
|
|
||||||
final Map<Asset, KernelAsset> assetTargetLocations = _assetTargetLocations(nativeAssets);
|
final Map<AssetImpl, KernelAsset> assetTargetLocations =
|
||||||
|
_assetTargetLocations(nativeAssets);
|
||||||
await writeNativeAssetsYaml(
|
await writeNativeAssetsYaml(
|
||||||
KernelAssets(assetTargetLocations.values),
|
KernelAssets(assetTargetLocations.values),
|
||||||
yamlParentDirectory,
|
yamlParentDirectory,
|
||||||
|
@ -124,12 +123,12 @@ Future<List<Uri>> buildNativeAssetsIOS({
|
||||||
return dependencies.toList();
|
return dependencies.toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
IOSSdk _getIOSSdk(EnvironmentType environmentType) {
|
IOSSdkImpl _getIOSSdkImpl(EnvironmentType environmentType) {
|
||||||
switch (environmentType) {
|
switch (environmentType) {
|
||||||
case EnvironmentType.physical:
|
case EnvironmentType.physical:
|
||||||
return IOSSdk.iPhoneOs;
|
return IOSSdkImpl.iPhoneOS;
|
||||||
case EnvironmentType.simulator:
|
case EnvironmentType.simulator:
|
||||||
return IOSSdk.iPhoneSimulator;
|
return IOSSdkImpl.iPhoneSimulator;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -145,11 +144,13 @@ Target _getNativeTarget(DarwinArch darwinArch) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<KernelAssetPath, List<Asset>> _fatAssetTargetLocations(List<Asset> nativeAssets) {
|
Map<KernelAssetPath, List<AssetImpl>> _fatAssetTargetLocations(
|
||||||
|
List<AssetImpl> nativeAssets) {
|
||||||
final Set<String> alreadyTakenNames = <String>{};
|
final Set<String> alreadyTakenNames = <String>{};
|
||||||
final Map<KernelAssetPath, List<Asset>> result = <KernelAssetPath, List<Asset>>{};
|
final Map<KernelAssetPath, List<AssetImpl>> result =
|
||||||
|
<KernelAssetPath, List<AssetImpl>>{};
|
||||||
final Map<String, KernelAssetPath> idToPath = <String, KernelAssetPath>{};
|
final Map<String, KernelAssetPath> idToPath = <String, KernelAssetPath>{};
|
||||||
for (final Asset asset in nativeAssets) {
|
for (final AssetImpl asset in nativeAssets) {
|
||||||
// Use same target path for all assets with the same id.
|
// Use same target path for all assets with the same id.
|
||||||
final KernelAssetPath path = idToPath[asset.id] ??
|
final KernelAssetPath path = idToPath[asset.id] ??
|
||||||
_targetLocationIOS(
|
_targetLocationIOS(
|
||||||
|
@ -157,44 +158,45 @@ Map<KernelAssetPath, List<Asset>> _fatAssetTargetLocations(List<Asset> nativeAss
|
||||||
alreadyTakenNames,
|
alreadyTakenNames,
|
||||||
).path;
|
).path;
|
||||||
idToPath[asset.id] = path;
|
idToPath[asset.id] = path;
|
||||||
result[path] ??= <Asset>[];
|
result[path] ??= <AssetImpl>[];
|
||||||
result[path]!.add(asset);
|
result[path]!.add(asset);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<Asset, KernelAsset> _assetTargetLocations(List<Asset> nativeAssets) {
|
Map<AssetImpl, KernelAsset> _assetTargetLocations(
|
||||||
|
List<AssetImpl> nativeAssets) {
|
||||||
final Set<String> alreadyTakenNames = <String>{};
|
final Set<String> alreadyTakenNames = <String>{};
|
||||||
return <Asset, KernelAsset>{
|
return <AssetImpl, KernelAsset>{
|
||||||
for (final Asset asset in nativeAssets)
|
for (final AssetImpl asset in nativeAssets)
|
||||||
asset: _targetLocationIOS(asset, alreadyTakenNames),
|
asset: _targetLocationIOS(asset, alreadyTakenNames),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
KernelAsset _targetLocationIOS(Asset asset, Set<String> alreadyTakenNames) {
|
KernelAsset _targetLocationIOS(AssetImpl asset, Set<String> alreadyTakenNames) {
|
||||||
final AssetPath path = asset.path;
|
final LinkModeImpl linkMode = (asset as NativeCodeAssetImpl).linkMode;
|
||||||
final KernelAssetPath kernelAssetPath;
|
final KernelAssetPath kernelAssetPath;
|
||||||
switch (path) {
|
switch (linkMode) {
|
||||||
case AssetSystemPath _:
|
case DynamicLoadingSystemImpl _:
|
||||||
kernelAssetPath = KernelAssetSystemPath(path.uri);
|
kernelAssetPath = KernelAssetSystemPath(linkMode.uri);
|
||||||
case AssetInExecutable _:
|
case LookupInExecutableImpl _:
|
||||||
kernelAssetPath = KernelAssetInExecutable();
|
kernelAssetPath = KernelAssetInExecutable();
|
||||||
case AssetInProcess _:
|
case LookupInProcessImpl _:
|
||||||
kernelAssetPath = KernelAssetInProcess();
|
kernelAssetPath = KernelAssetInProcess();
|
||||||
case AssetAbsolutePath _:
|
case DynamicLoadingBundledImpl _:
|
||||||
final String fileName = path.uri.pathSegments.last;
|
final String fileName = asset.file!.pathSegments.last;
|
||||||
kernelAssetPath = KernelAssetAbsolutePath(frameworkUri(
|
kernelAssetPath = KernelAssetAbsolutePath(frameworkUri(
|
||||||
fileName,
|
fileName,
|
||||||
alreadyTakenNames,
|
alreadyTakenNames,
|
||||||
));
|
));
|
||||||
default:
|
default:
|
||||||
throw Exception(
|
throw Exception(
|
||||||
'Unsupported asset path type ${path.runtimeType} in asset $asset',
|
'Unsupported asset link mode $linkMode in asset $asset',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return KernelAsset(
|
return KernelAsset(
|
||||||
id: asset.id,
|
id: asset.id,
|
||||||
target: asset.target,
|
target: Target.fromArchitectureAndOS(asset.architecture!, asset.os),
|
||||||
path: kernelAssetPath,
|
path: kernelAssetPath,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -211,7 +213,7 @@ final KernelAssetPath kernelAssetPath;
|
||||||
/// in xcode_backend.dart.
|
/// in xcode_backend.dart.
|
||||||
Future<void> _copyNativeAssetsIOS(
|
Future<void> _copyNativeAssetsIOS(
|
||||||
Uri buildUri,
|
Uri buildUri,
|
||||||
Map<KernelAssetPath, List<Asset>> assetTargetLocations,
|
Map<KernelAssetPath, List<AssetImpl>> assetTargetLocations,
|
||||||
String? codesignIdentity,
|
String? codesignIdentity,
|
||||||
BuildMode buildMode,
|
BuildMode buildMode,
|
||||||
FileSystem fileSystem,
|
FileSystem fileSystem,
|
||||||
|
@ -219,12 +221,11 @@ Future<void> _copyNativeAssetsIOS(
|
||||||
if (assetTargetLocations.isNotEmpty) {
|
if (assetTargetLocations.isNotEmpty) {
|
||||||
globals.logger
|
globals.logger
|
||||||
.printTrace('Copying native assets to ${buildUri.toFilePath()}.');
|
.printTrace('Copying native assets to ${buildUri.toFilePath()}.');
|
||||||
for (final MapEntry<KernelAssetPath, List<Asset>> assetMapping
|
for (final MapEntry<KernelAssetPath, List<AssetImpl>> assetMapping
|
||||||
in assetTargetLocations.entries) {
|
in assetTargetLocations.entries) {
|
||||||
final Uri target = (assetMapping.key as KernelAssetAbsolutePath).uri;
|
final Uri target = (assetMapping.key as KernelAssetAbsolutePath).uri;
|
||||||
final List<Uri> sources = <Uri>[
|
final List<Uri> sources = <Uri>[
|
||||||
for (final Asset source in assetMapping.value)
|
for (final AssetImpl source in assetMapping.value) source.file!
|
||||||
(source.path as AssetAbsolutePath).uri
|
|
||||||
];
|
];
|
||||||
final Uri targetUri = buildUri.resolveUri(target);
|
final Uri targetUri = buildUri.resolveUri(target);
|
||||||
final File dylibFile = fileSystem.file(targetUri);
|
final File dylibFile = fileSystem.file(targetUri);
|
||||||
|
|
|
@ -4,8 +4,7 @@
|
||||||
|
|
||||||
import 'package:native_assets_builder/native_assets_builder.dart'
|
import 'package:native_assets_builder/native_assets_builder.dart'
|
||||||
hide NativeAssetsBuildRunner;
|
hide NativeAssetsBuildRunner;
|
||||||
import 'package:native_assets_cli/native_assets_cli_internal.dart'
|
import 'package:native_assets_cli/native_assets_cli_internal.dart';
|
||||||
hide BuildMode;
|
|
||||||
|
|
||||||
import '../../../base/common.dart';
|
import '../../../base/common.dart';
|
||||||
import '../../../base/file_system.dart';
|
import '../../../base/file_system.dart';
|
||||||
|
@ -29,7 +28,7 @@ Future<Uri?> dryRunNativeAssetsLinux({
|
||||||
projectUri: projectUri,
|
projectUri: projectUri,
|
||||||
flutterTester: flutterTester,
|
flutterTester: flutterTester,
|
||||||
fileSystem: fileSystem,
|
fileSystem: fileSystem,
|
||||||
os: OS.linux,
|
os: OSImpl.linux,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,7 +43,7 @@ Future<Iterable<KernelAsset>> dryRunNativeAssetsLinuxInternal(
|
||||||
projectUri,
|
projectUri,
|
||||||
flutterTester,
|
flutterTester,
|
||||||
buildRunner,
|
buildRunner,
|
||||||
OS.linux,
|
OSImpl.linux,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,7 +70,7 @@ Future<(Uri? nativeAssetsYaml, List<Uri> dependencies)> buildNativeAssetsLinux({
|
||||||
/// Flutter expects `clang++` to be on the path on Linux hosts.
|
/// Flutter expects `clang++` to be on the path on Linux hosts.
|
||||||
///
|
///
|
||||||
/// Search for the accompanying `clang`, `ar`, and `ld`.
|
/// Search for the accompanying `clang`, `ar`, and `ld`.
|
||||||
Future<CCompilerConfig> cCompilerConfigLinux() async {
|
Future<CCompilerConfigImpl> cCompilerConfigLinux() async {
|
||||||
const String kClangPlusPlusBinary = 'clang++';
|
const String kClangPlusPlusBinary = 'clang++';
|
||||||
const String kClangBinary = 'clang';
|
const String kClangBinary = 'clang';
|
||||||
const String kArBinary = 'llvm-ar';
|
const String kArBinary = 'llvm-ar';
|
||||||
|
@ -93,9 +92,9 @@ Future<CCompilerConfig> cCompilerConfigLinux() async {
|
||||||
}
|
}
|
||||||
binaryPaths[binary] = binaryFile.uri;
|
binaryPaths[binary] = binaryFile.uri;
|
||||||
}
|
}
|
||||||
return CCompilerConfig(
|
return CCompilerConfigImpl(
|
||||||
ar: binaryPaths[kArBinary],
|
archiver: binaryPaths[kArBinary],
|
||||||
cc: binaryPaths[kClangBinary],
|
compiler: binaryPaths[kClangBinary],
|
||||||
ld: binaryPaths[kLdBinary],
|
linker: binaryPaths[kLdBinary],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,10 +4,7 @@
|
||||||
|
|
||||||
import 'package:native_assets_builder/native_assets_builder.dart'
|
import 'package:native_assets_builder/native_assets_builder.dart'
|
||||||
hide NativeAssetsBuildRunner;
|
hide NativeAssetsBuildRunner;
|
||||||
import 'package:native_assets_cli/native_assets_cli_internal.dart'
|
import 'package:native_assets_cli/native_assets_cli_internal.dart';
|
||||||
hide BuildMode;
|
|
||||||
import 'package:native_assets_cli/native_assets_cli_internal.dart'
|
|
||||||
as native_assets_cli;
|
|
||||||
|
|
||||||
import '../../../base/file_system.dart';
|
import '../../../base/file_system.dart';
|
||||||
import '../../../build_info.dart';
|
import '../../../build_info.dart';
|
||||||
|
@ -30,7 +27,7 @@ Future<Uri?> dryRunNativeAssetsMacOS({
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
final Uri buildUri = nativeAssetsBuildUri(projectUri, OS.macOS);
|
final Uri buildUri = nativeAssetsBuildUri(projectUri, OSImpl.macOS);
|
||||||
final Iterable<KernelAsset> nativeAssetPaths = await dryRunNativeAssetsMacOSInternal(
|
final Iterable<KernelAsset> nativeAssetPaths = await dryRunNativeAssetsMacOSInternal(
|
||||||
fileSystem,
|
fileSystem,
|
||||||
projectUri,
|
projectUri,
|
||||||
|
@ -51,22 +48,23 @@ Future<Iterable<KernelAsset>> dryRunNativeAssetsMacOSInternal(
|
||||||
bool flutterTester,
|
bool flutterTester,
|
||||||
NativeAssetsBuildRunner buildRunner,
|
NativeAssetsBuildRunner buildRunner,
|
||||||
) async {
|
) async {
|
||||||
const OS targetOS = OS.macOS;
|
const OSImpl targetOS = OSImpl.macOS;
|
||||||
final Uri buildUri = nativeAssetsBuildUri(projectUri, targetOS);
|
final Uri buildUri = nativeAssetsBuildUri(projectUri, targetOS);
|
||||||
|
|
||||||
globals.logger.printTrace('Dry running native assets for $targetOS.');
|
globals.logger.printTrace('Dry running native assets for $targetOS.');
|
||||||
final DryRunResult dryRunResult = await buildRunner.dryRun(
|
final DryRunResult dryRunResult = await buildRunner.dryRun(
|
||||||
linkModePreference: LinkModePreference.dynamic,
|
linkModePreference: LinkModePreferenceImpl.dynamic,
|
||||||
targetOS: targetOS,
|
targetOS: targetOS,
|
||||||
workingDirectory: projectUri,
|
workingDirectory: projectUri,
|
||||||
includeParentEnvironment: true,
|
includeParentEnvironment: true,
|
||||||
);
|
);
|
||||||
ensureNativeAssetsBuildSucceed(dryRunResult);
|
ensureNativeAssetsBuildSucceed(dryRunResult);
|
||||||
final List<Asset> nativeAssets = dryRunResult.assets;
|
final List<AssetImpl> nativeAssets = dryRunResult.assets;
|
||||||
ensureNoLinkModeStatic(nativeAssets);
|
ensureNoLinkModeStatic(nativeAssets);
|
||||||
globals.logger.printTrace('Dry running native assets for $targetOS done.');
|
globals.logger.printTrace('Dry running native assets for $targetOS done.');
|
||||||
final Uri? absolutePath = flutterTester ? buildUri : null;
|
final Uri? absolutePath = flutterTester ? buildUri : null;
|
||||||
final Map<Asset, KernelAsset> assetTargetLocations = _assetTargetLocations(
|
final Map<AssetImpl, KernelAsset> assetTargetLocations =
|
||||||
|
_assetTargetLocations(
|
||||||
nativeAssets,
|
nativeAssets,
|
||||||
absolutePath,
|
absolutePath,
|
||||||
);
|
);
|
||||||
|
@ -90,7 +88,7 @@ Future<(Uri? nativeAssetsYaml, List<Uri> dependencies)> buildNativeAssetsMacOS({
|
||||||
Uri? yamlParentDirectory,
|
Uri? yamlParentDirectory,
|
||||||
required FileSystem fileSystem,
|
required FileSystem fileSystem,
|
||||||
}) async {
|
}) async {
|
||||||
const OS targetOS = OS.macOS;
|
const OSImpl targetOS = OSImpl.macOS;
|
||||||
final Uri buildUri = nativeAssetsBuildUri(projectUri, targetOS);
|
final Uri buildUri = nativeAssetsBuildUri(projectUri, targetOS);
|
||||||
if (!await nativeBuildRequired(buildRunner)) {
|
if (!await nativeBuildRequired(buildRunner)) {
|
||||||
final Uri nativeAssetsYaml = await writeNativeAssetsYaml(
|
final Uri nativeAssetsYaml = await writeNativeAssetsYaml(
|
||||||
|
@ -104,16 +102,16 @@ Future<(Uri? nativeAssetsYaml, List<Uri> dependencies)> buildNativeAssetsMacOS({
|
||||||
final List<Target> targets = darwinArchs != null
|
final List<Target> targets = darwinArchs != null
|
||||||
? darwinArchs.map(_getNativeTarget).toList()
|
? darwinArchs.map(_getNativeTarget).toList()
|
||||||
: <Target>[Target.current];
|
: <Target>[Target.current];
|
||||||
final native_assets_cli.BuildMode buildModeCli =
|
final BuildModeImpl buildModeCli =
|
||||||
nativeAssetsBuildMode(buildMode);
|
nativeAssetsBuildMode(buildMode);
|
||||||
|
|
||||||
globals.logger
|
globals.logger
|
||||||
.printTrace('Building native assets for $targets $buildModeCli.');
|
.printTrace('Building native assets for $targets $buildModeCli.');
|
||||||
final List<Asset> nativeAssets = <Asset>[];
|
final List<AssetImpl> nativeAssets = <AssetImpl>[];
|
||||||
final Set<Uri> dependencies = <Uri>{};
|
final Set<Uri> dependencies = <Uri>{};
|
||||||
for (final Target target in targets) {
|
for (final Target target in targets) {
|
||||||
final BuildResult result = await buildRunner.build(
|
final BuildResult result = await buildRunner.build(
|
||||||
linkModePreference: LinkModePreference.dynamic,
|
linkModePreference: LinkModePreferenceImpl.dynamic,
|
||||||
target: target,
|
target: target,
|
||||||
buildMode: buildModeCli,
|
buildMode: buildModeCli,
|
||||||
workingDirectory: projectUri,
|
workingDirectory: projectUri,
|
||||||
|
@ -127,9 +125,9 @@ Future<(Uri? nativeAssetsYaml, List<Uri> dependencies)> buildNativeAssetsMacOS({
|
||||||
ensureNoLinkModeStatic(nativeAssets);
|
ensureNoLinkModeStatic(nativeAssets);
|
||||||
globals.logger.printTrace('Building native assets for $targets done.');
|
globals.logger.printTrace('Building native assets for $targets done.');
|
||||||
final Uri? absolutePath = flutterTester ? buildUri : null;
|
final Uri? absolutePath = flutterTester ? buildUri : null;
|
||||||
final Map<Asset, KernelAsset> assetTargetLocations =
|
final Map<AssetImpl, KernelAsset> assetTargetLocations =
|
||||||
_assetTargetLocations(nativeAssets, absolutePath);
|
_assetTargetLocations(nativeAssets, absolutePath);
|
||||||
final Map<KernelAssetPath, List<Asset>> fatAssetTargetLocations =
|
final Map<KernelAssetPath, List<AssetImpl>> fatAssetTargetLocations =
|
||||||
_fatAssetTargetLocations(nativeAssets, absolutePath);
|
_fatAssetTargetLocations(nativeAssets, absolutePath);
|
||||||
if (flutterTester) {
|
if (flutterTester) {
|
||||||
await _copyNativeAssetsMacOSFlutterTester(
|
await _copyNativeAssetsMacOSFlutterTester(
|
||||||
|
@ -168,15 +166,15 @@ Target _getNativeTarget(DarwinArch darwinArch) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<KernelAssetPath, List<Asset>> _fatAssetTargetLocations(
|
Map<KernelAssetPath, List<AssetImpl>> _fatAssetTargetLocations(
|
||||||
List<Asset> nativeAssets,
|
List<AssetImpl> nativeAssets,
|
||||||
Uri? absolutePath,
|
Uri? absolutePath,
|
||||||
) {
|
) {
|
||||||
final Set<String> alreadyTakenNames = <String>{};
|
final Set<String> alreadyTakenNames = <String>{};
|
||||||
final Map<KernelAssetPath, List<Asset>> result =
|
final Map<KernelAssetPath, List<AssetImpl>> result =
|
||||||
<KernelAssetPath, List<Asset>>{};
|
<KernelAssetPath, List<AssetImpl>>{};
|
||||||
final Map<String, KernelAssetPath> idToPath = <String, KernelAssetPath>{};
|
final Map<String, KernelAssetPath> idToPath = <String, KernelAssetPath>{};
|
||||||
for (final Asset asset in nativeAssets) {
|
for (final AssetImpl asset in nativeAssets) {
|
||||||
// Use same target path for all assets with the same id.
|
// Use same target path for all assets with the same id.
|
||||||
final KernelAssetPath path = idToPath[asset.id] ??
|
final KernelAssetPath path = idToPath[asset.id] ??
|
||||||
_targetLocationMacOS(
|
_targetLocationMacOS(
|
||||||
|
@ -185,39 +183,39 @@ Map<KernelAssetPath, List<Asset>> _fatAssetTargetLocations(
|
||||||
alreadyTakenNames,
|
alreadyTakenNames,
|
||||||
).path;
|
).path;
|
||||||
idToPath[asset.id] = path;
|
idToPath[asset.id] = path;
|
||||||
result[path] ??= <Asset>[];
|
result[path] ??= <AssetImpl>[];
|
||||||
result[path]!.add(asset);
|
result[path]!.add(asset);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<Asset, KernelAsset> _assetTargetLocations(
|
Map<AssetImpl, KernelAsset> _assetTargetLocations(
|
||||||
List<Asset> nativeAssets,
|
List<AssetImpl> nativeAssets,
|
||||||
Uri? absolutePath,
|
Uri? absolutePath,
|
||||||
) {
|
) {
|
||||||
final Set<String> alreadyTakenNames = <String>{};
|
final Set<String> alreadyTakenNames = <String>{};
|
||||||
return <Asset, KernelAsset>{
|
return <AssetImpl, KernelAsset>{
|
||||||
for (final Asset asset in nativeAssets)
|
for (final AssetImpl asset in nativeAssets)
|
||||||
asset: _targetLocationMacOS(asset, absolutePath, alreadyTakenNames),
|
asset: _targetLocationMacOS(asset, absolutePath, alreadyTakenNames),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
KernelAsset _targetLocationMacOS(
|
KernelAsset _targetLocationMacOS(
|
||||||
Asset asset,
|
AssetImpl asset,
|
||||||
Uri? absolutePath,
|
Uri? absolutePath,
|
||||||
Set<String> alreadyTakenNames,
|
Set<String> alreadyTakenNames,
|
||||||
) {
|
) {
|
||||||
final AssetPath path = asset.path;
|
final LinkModeImpl linkMode = (asset as NativeCodeAssetImpl).linkMode;
|
||||||
final KernelAssetPath kernelAssetPath;
|
final KernelAssetPath kernelAssetPath;
|
||||||
switch (path) {
|
switch (linkMode) {
|
||||||
case AssetSystemPath _:
|
case DynamicLoadingSystemImpl _:
|
||||||
kernelAssetPath = KernelAssetSystemPath(path.uri);
|
kernelAssetPath = KernelAssetSystemPath(linkMode.uri);
|
||||||
case AssetInExecutable _:
|
case LookupInExecutableImpl _:
|
||||||
kernelAssetPath = KernelAssetInExecutable();
|
kernelAssetPath = KernelAssetInExecutable();
|
||||||
case AssetInProcess _:
|
case LookupInProcessImpl _:
|
||||||
kernelAssetPath = KernelAssetInProcess();
|
kernelAssetPath = KernelAssetInProcess();
|
||||||
case AssetAbsolutePath _:
|
case DynamicLoadingBundledImpl _:
|
||||||
final String fileName = path.uri.pathSegments.last;
|
final String fileName = asset.file!.pathSegments.last;
|
||||||
Uri uri;
|
Uri uri;
|
||||||
if (absolutePath != null) {
|
if (absolutePath != null) {
|
||||||
// Flutter tester needs full host paths.
|
// Flutter tester needs full host paths.
|
||||||
|
@ -231,12 +229,12 @@ KernelAsset _targetLocationMacOS(
|
||||||
kernelAssetPath = KernelAssetAbsolutePath(uri);
|
kernelAssetPath = KernelAssetAbsolutePath(uri);
|
||||||
default:
|
default:
|
||||||
throw Exception(
|
throw Exception(
|
||||||
'Unsupported asset path type ${path.runtimeType} in asset $asset',
|
'Unsupported asset link mode $linkMode in asset $asset',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return KernelAsset(
|
return KernelAsset(
|
||||||
id: asset.id,
|
id: asset.id,
|
||||||
target: asset.target,
|
target: Target.fromArchitectureAndOS(asset.architecture!, asset.os),
|
||||||
path: kernelAssetPath,
|
path: kernelAssetPath,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -256,7 +254,7 @@ KernelAsset _targetLocationMacOS(
|
||||||
/// in macos_assemble.sh.
|
/// in macos_assemble.sh.
|
||||||
Future<void> _copyNativeAssetsMacOS(
|
Future<void> _copyNativeAssetsMacOS(
|
||||||
Uri buildUri,
|
Uri buildUri,
|
||||||
Map<KernelAssetPath, List<Asset>> assetTargetLocations,
|
Map<KernelAssetPath, List<AssetImpl>> assetTargetLocations,
|
||||||
String? codesignIdentity,
|
String? codesignIdentity,
|
||||||
BuildMode buildMode,
|
BuildMode buildMode,
|
||||||
FileSystem fileSystem,
|
FileSystem fileSystem,
|
||||||
|
@ -265,12 +263,11 @@ Future<void> _copyNativeAssetsMacOS(
|
||||||
globals.logger.printTrace(
|
globals.logger.printTrace(
|
||||||
'Copying native assets to ${buildUri.toFilePath()}.',
|
'Copying native assets to ${buildUri.toFilePath()}.',
|
||||||
);
|
);
|
||||||
for (final MapEntry<KernelAssetPath, List<Asset>> assetMapping
|
for (final MapEntry<KernelAssetPath, List<AssetImpl>> assetMapping
|
||||||
in assetTargetLocations.entries) {
|
in assetTargetLocations.entries) {
|
||||||
final Uri target = (assetMapping.key as KernelAssetAbsolutePath).uri;
|
final Uri target = (assetMapping.key as KernelAssetAbsolutePath).uri;
|
||||||
final List<Uri> sources = <Uri>[
|
final List<Uri> sources = <Uri>[
|
||||||
for (final Asset source in assetMapping.value)
|
for (final AssetImpl source in assetMapping.value) source.file!,
|
||||||
(source.path as AssetAbsolutePath).uri,
|
|
||||||
];
|
];
|
||||||
final Uri targetUri = buildUri.resolveUri(target);
|
final Uri targetUri = buildUri.resolveUri(target);
|
||||||
final String name = targetUri.pathSegments.last;
|
final String name = targetUri.pathSegments.last;
|
||||||
|
@ -326,7 +323,7 @@ Future<void> _copyNativeAssetsMacOS(
|
||||||
/// Code signing is also done here.
|
/// Code signing is also done here.
|
||||||
Future<void> _copyNativeAssetsMacOSFlutterTester(
|
Future<void> _copyNativeAssetsMacOSFlutterTester(
|
||||||
Uri buildUri,
|
Uri buildUri,
|
||||||
Map<KernelAssetPath, List<Asset>> assetTargetLocations,
|
Map<KernelAssetPath, List<AssetImpl>> assetTargetLocations,
|
||||||
String? codesignIdentity,
|
String? codesignIdentity,
|
||||||
BuildMode buildMode,
|
BuildMode buildMode,
|
||||||
FileSystem fileSystem,
|
FileSystem fileSystem,
|
||||||
|
@ -335,12 +332,11 @@ Future<void> _copyNativeAssetsMacOSFlutterTester(
|
||||||
globals.logger.printTrace(
|
globals.logger.printTrace(
|
||||||
'Copying native assets to ${buildUri.toFilePath()}.',
|
'Copying native assets to ${buildUri.toFilePath()}.',
|
||||||
);
|
);
|
||||||
for (final MapEntry<KernelAssetPath, List<Asset>> assetMapping
|
for (final MapEntry<KernelAssetPath, List<AssetImpl>> assetMapping
|
||||||
in assetTargetLocations.entries) {
|
in assetTargetLocations.entries) {
|
||||||
final Uri target = (assetMapping.key as KernelAssetAbsolutePath).uri;
|
final Uri target = (assetMapping.key as KernelAssetAbsolutePath).uri;
|
||||||
final List<Uri> sources = <Uri>[
|
final List<Uri> sources = <Uri>[
|
||||||
for (final Asset source in assetMapping.value)
|
for (final AssetImpl source in assetMapping.value) source.file!,
|
||||||
(source.path as AssetAbsolutePath).uri,
|
|
||||||
];
|
];
|
||||||
final Uri targetUri = buildUri.resolveUri(target);
|
final Uri targetUri = buildUri.resolveUri(target);
|
||||||
final File dylibFile = fileSystem.file(targetUri);
|
final File dylibFile = fileSystem.file(targetUri);
|
||||||
|
|
|
@ -4,8 +4,7 @@
|
||||||
|
|
||||||
// Shared logic between iOS and macOS implementations of native assets.
|
// Shared logic between iOS and macOS implementations of native assets.
|
||||||
|
|
||||||
import 'package:native_assets_cli/native_assets_cli_internal.dart'
|
import 'package:native_assets_cli/native_assets_cli_internal.dart';
|
||||||
hide BuildMode;
|
|
||||||
|
|
||||||
import '../../../base/common.dart';
|
import '../../../base/common.dart';
|
||||||
import '../../../base/file_system.dart';
|
import '../../../base/file_system.dart';
|
||||||
|
@ -131,7 +130,7 @@ Future<void> codesignDylib(
|
||||||
/// Flutter expects `xcrun` to be on the path on macOS hosts.
|
/// Flutter expects `xcrun` to be on the path on macOS hosts.
|
||||||
///
|
///
|
||||||
/// Use the `clang`, `ar`, and `ld` that would be used if run with `xcrun`.
|
/// Use the `clang`, `ar`, and `ld` that would be used if run with `xcrun`.
|
||||||
Future<CCompilerConfig> cCompilerConfigMacOS() async {
|
Future<CCompilerConfigImpl> cCompilerConfigMacOS() async {
|
||||||
final ProcessResult xcrunResult = await globals.processManager.run(
|
final ProcessResult xcrunResult = await globals.processManager.run(
|
||||||
<String>['xcrun', 'clang', '--version'],
|
<String>['xcrun', 'clang', '--version'],
|
||||||
);
|
);
|
||||||
|
@ -142,10 +141,10 @@ Future<CCompilerConfig> cCompilerConfigMacOS() async {
|
||||||
.firstWhere((String s) => s.startsWith('InstalledDir: '))
|
.firstWhere((String s) => s.startsWith('InstalledDir: '))
|
||||||
.split(' ')
|
.split(' ')
|
||||||
.last;
|
.last;
|
||||||
return CCompilerConfig(
|
return CCompilerConfigImpl(
|
||||||
cc: Uri.file('$installPath/clang'),
|
compiler: Uri.file('$installPath/clang'),
|
||||||
ar: Uri.file('$installPath/ar'),
|
archiver: Uri.file('$installPath/ar'),
|
||||||
ld: Uri.file('$installPath/ld'),
|
linker: Uri.file('$installPath/ld'),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,7 @@ import 'package:native_assets_builder/native_assets_builder.dart'
|
||||||
as native_assets_builder show NativeAssetsBuildRunner;
|
as native_assets_builder show NativeAssetsBuildRunner;
|
||||||
import 'package:native_assets_builder/native_assets_builder.dart'
|
import 'package:native_assets_builder/native_assets_builder.dart'
|
||||||
hide NativeAssetsBuildRunner;
|
hide NativeAssetsBuildRunner;
|
||||||
|
import 'package:native_assets_cli/native_assets_cli.dart';
|
||||||
import 'package:native_assets_cli/native_assets_cli_internal.dart';
|
import 'package:native_assets_cli/native_assets_cli_internal.dart';
|
||||||
import 'package:package_config/package_config_types.dart';
|
import 'package:package_config/package_config_types.dart';
|
||||||
|
|
||||||
|
@ -46,28 +47,28 @@ abstract class NativeAssetsBuildRunner {
|
||||||
/// Runs all [packagesWithNativeAssets] `build.dart` in dry run.
|
/// Runs all [packagesWithNativeAssets] `build.dart` in dry run.
|
||||||
Future<DryRunResult> dryRun({
|
Future<DryRunResult> dryRun({
|
||||||
required bool includeParentEnvironment,
|
required bool includeParentEnvironment,
|
||||||
required LinkModePreference linkModePreference,
|
required LinkModePreferenceImpl linkModePreference,
|
||||||
required OS targetOS,
|
required OSImpl targetOS,
|
||||||
required Uri workingDirectory,
|
required Uri workingDirectory,
|
||||||
});
|
});
|
||||||
|
|
||||||
/// Runs all [packagesWithNativeAssets] `build.dart`.
|
/// Runs all [packagesWithNativeAssets] `build.dart`.
|
||||||
Future<BuildResult> build({
|
Future<BuildResult> build({
|
||||||
required bool includeParentEnvironment,
|
required bool includeParentEnvironment,
|
||||||
required BuildMode buildMode,
|
required BuildModeImpl buildMode,
|
||||||
required LinkModePreference linkModePreference,
|
required LinkModePreferenceImpl linkModePreference,
|
||||||
required Target target,
|
required Target target,
|
||||||
required Uri workingDirectory,
|
required Uri workingDirectory,
|
||||||
CCompilerConfig? cCompilerConfig,
|
CCompilerConfigImpl? cCompilerConfig,
|
||||||
int? targetAndroidNdkApi,
|
int? targetAndroidNdkApi,
|
||||||
IOSSdk? targetIOSSdk,
|
IOSSdkImpl? targetIOSSdkImpl,
|
||||||
});
|
});
|
||||||
|
|
||||||
/// The C compiler config to use for compilation.
|
/// The C compiler config to use for compilation.
|
||||||
Future<CCompilerConfig> get cCompilerConfig;
|
Future<CCompilerConfigImpl> get cCompilerConfig;
|
||||||
|
|
||||||
/// The NDK compiler to use to use for compilation for Android.
|
/// The NDK compiler to use to use for compilation for Android.
|
||||||
Future<CCompilerConfig> get ndkCCompilerConfig;
|
Future<CCompilerConfigImpl> get ndkCCompilerConfigImpl;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Uses `package:native_assets_builder` for its implementation.
|
/// Uses `package:native_assets_builder` for its implementation.
|
||||||
|
@ -125,8 +126,8 @@ class NativeAssetsBuildRunnerImpl implements NativeAssetsBuildRunner {
|
||||||
@override
|
@override
|
||||||
Future<DryRunResult> dryRun({
|
Future<DryRunResult> dryRun({
|
||||||
required bool includeParentEnvironment,
|
required bool includeParentEnvironment,
|
||||||
required LinkModePreference linkModePreference,
|
required LinkModePreferenceImpl linkModePreference,
|
||||||
required OS targetOS,
|
required OSImpl targetOS,
|
||||||
required Uri workingDirectory,
|
required Uri workingDirectory,
|
||||||
}) {
|
}) {
|
||||||
final PackageLayout packageLayout = PackageLayout.fromPackageConfig(
|
final PackageLayout packageLayout = PackageLayout.fromPackageConfig(
|
||||||
|
@ -136,7 +137,7 @@ class NativeAssetsBuildRunnerImpl implements NativeAssetsBuildRunner {
|
||||||
return _buildRunner.dryRun(
|
return _buildRunner.dryRun(
|
||||||
includeParentEnvironment: includeParentEnvironment,
|
includeParentEnvironment: includeParentEnvironment,
|
||||||
linkModePreference: linkModePreference,
|
linkModePreference: linkModePreference,
|
||||||
targetOs: targetOS,
|
targetOS: targetOS,
|
||||||
workingDirectory: workingDirectory,
|
workingDirectory: workingDirectory,
|
||||||
packageLayout: packageLayout,
|
packageLayout: packageLayout,
|
||||||
);
|
);
|
||||||
|
@ -145,13 +146,13 @@ class NativeAssetsBuildRunnerImpl implements NativeAssetsBuildRunner {
|
||||||
@override
|
@override
|
||||||
Future<BuildResult> build({
|
Future<BuildResult> build({
|
||||||
required bool includeParentEnvironment,
|
required bool includeParentEnvironment,
|
||||||
required BuildMode buildMode,
|
required BuildModeImpl buildMode,
|
||||||
required LinkModePreference linkModePreference,
|
required LinkModePreferenceImpl linkModePreference,
|
||||||
required Target target,
|
required Target target,
|
||||||
required Uri workingDirectory,
|
required Uri workingDirectory,
|
||||||
CCompilerConfig? cCompilerConfig,
|
CCompilerConfigImpl? cCompilerConfig,
|
||||||
int? targetAndroidNdkApi,
|
int? targetAndroidNdkApi,
|
||||||
IOSSdk? targetIOSSdk,
|
IOSSdkImpl? targetIOSSdkImpl,
|
||||||
}) {
|
}) {
|
||||||
final PackageLayout packageLayout = PackageLayout.fromPackageConfig(
|
final PackageLayout packageLayout = PackageLayout.fromPackageConfig(
|
||||||
packageConfig,
|
packageConfig,
|
||||||
|
@ -164,14 +165,14 @@ class NativeAssetsBuildRunnerImpl implements NativeAssetsBuildRunner {
|
||||||
linkModePreference: linkModePreference,
|
linkModePreference: linkModePreference,
|
||||||
target: target,
|
target: target,
|
||||||
targetAndroidNdkApi: targetAndroidNdkApi,
|
targetAndroidNdkApi: targetAndroidNdkApi,
|
||||||
targetIOSSdk: targetIOSSdk,
|
targetIOSSdk: targetIOSSdkImpl,
|
||||||
workingDirectory: workingDirectory,
|
workingDirectory: workingDirectory,
|
||||||
packageLayout: packageLayout,
|
packageLayout: packageLayout,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
late final Future<CCompilerConfig> cCompilerConfig = () {
|
late final Future<CCompilerConfigImpl> cCompilerConfig = () {
|
||||||
if (globals.platform.isMacOS || globals.platform.isIOS) {
|
if (globals.platform.isMacOS || globals.platform.isIOS) {
|
||||||
return cCompilerConfigMacOS();
|
return cCompilerConfigMacOS();
|
||||||
}
|
}
|
||||||
|
@ -182,13 +183,13 @@ class NativeAssetsBuildRunnerImpl implements NativeAssetsBuildRunner {
|
||||||
return cCompilerConfigWindows();
|
return cCompilerConfigWindows();
|
||||||
}
|
}
|
||||||
if (globals.platform.isAndroid) {
|
if (globals.platform.isAndroid) {
|
||||||
throwToolExit('Should use ndkCCompilerConfig for Android.');
|
throwToolExit('Should use ndkCCompilerConfigImpl for Android.');
|
||||||
}
|
}
|
||||||
throwToolExit('Unknown target OS.');
|
throwToolExit('Unknown target OS.');
|
||||||
}();
|
}();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
late final Future<CCompilerConfig> ndkCCompilerConfig = () {
|
late final Future<CCompilerConfigImpl> ndkCCompilerConfigImpl = () {
|
||||||
return cCompilerConfigAndroid();
|
return cCompilerConfigAndroid();
|
||||||
}();
|
}();
|
||||||
}
|
}
|
||||||
|
@ -212,14 +213,14 @@ Future<Uri> writeNativeAssetsYaml(
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Select the native asset build mode for a given Flutter build mode.
|
/// Select the native asset build mode for a given Flutter build mode.
|
||||||
BuildMode nativeAssetsBuildMode(build_info.BuildMode buildMode) {
|
BuildModeImpl nativeAssetsBuildMode(build_info.BuildMode buildMode) {
|
||||||
switch (buildMode) {
|
switch (buildMode) {
|
||||||
case build_info.BuildMode.debug:
|
case build_info.BuildMode.debug:
|
||||||
return BuildMode.debug;
|
return BuildModeImpl.debug;
|
||||||
case build_info.BuildMode.jitRelease:
|
case build_info.BuildMode.jitRelease:
|
||||||
case build_info.BuildMode.profile:
|
case build_info.BuildMode.profile:
|
||||||
case build_info.BuildMode.release:
|
case build_info.BuildMode.release:
|
||||||
return BuildMode.release;
|
return BuildModeImpl.release;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -294,10 +295,12 @@ Future<void> ensureNoNativeAssetsOrOsIsSupported(
|
||||||
/// https://github.com/dart-lang/sdk/issues/49418.
|
/// https://github.com/dart-lang/sdk/issues/49418.
|
||||||
///
|
///
|
||||||
/// Therefore, ensure all `build.dart` scripts return only dynamic libraries.
|
/// Therefore, ensure all `build.dart` scripts return only dynamic libraries.
|
||||||
void ensureNoLinkModeStatic(List<Asset> nativeAssets) {
|
void ensureNoLinkModeStatic(List<AssetImpl> nativeAssets) {
|
||||||
final Iterable<Asset> staticAssets = nativeAssets.where((Asset e) => e.linkMode == LinkMode.static);
|
final Iterable<AssetImpl> staticAssets = nativeAssets.where((AssetImpl e) =>
|
||||||
|
e is NativeCodeAssetImpl && e.linkMode == StaticLinkingImpl());
|
||||||
if (staticAssets.isNotEmpty) {
|
if (staticAssets.isNotEmpty) {
|
||||||
final String assetIds = staticAssets.map((Asset a) => a.id).toSet().join(', ');
|
final String assetIds =
|
||||||
|
staticAssets.map((AssetImpl a) => a.id).toSet().join(', ');
|
||||||
throwToolExit(
|
throwToolExit(
|
||||||
'Native asset(s) $assetIds have their link mode set to static, '
|
'Native asset(s) $assetIds have their link mode set to static, '
|
||||||
'but this is not yet supported. '
|
'but this is not yet supported. '
|
||||||
|
@ -308,7 +311,7 @@ void ensureNoLinkModeStatic(List<Asset> nativeAssets) {
|
||||||
|
|
||||||
/// This should be the same for different archs, debug/release, etc.
|
/// This should be the same for different archs, debug/release, etc.
|
||||||
/// It should work for all macOS.
|
/// It should work for all macOS.
|
||||||
Uri nativeAssetsBuildUri(Uri projectUri, OS os) {
|
Uri nativeAssetsBuildUri(Uri projectUri, OSImpl os) {
|
||||||
final String buildDir = build_info.getBuildDirectory();
|
final String buildDir = build_info.getBuildDirectory();
|
||||||
return projectUri.resolve('$buildDir/native_assets/$os/');
|
return projectUri.resolve('$buildDir/native_assets/$os/');
|
||||||
}
|
}
|
||||||
|
@ -455,7 +458,8 @@ Future<Uri?> dryRunNativeAssetsMultipleOSes({
|
||||||
final Uri buildUri = buildUriMultiple(projectUri);
|
final Uri buildUri = buildUriMultiple(projectUri);
|
||||||
final Iterable<KernelAsset> nativeAssetPaths = <KernelAsset>[
|
final Iterable<KernelAsset> nativeAssetPaths = <KernelAsset>[
|
||||||
if (targetPlatforms.contains(build_info.TargetPlatform.darwin) ||
|
if (targetPlatforms.contains(build_info.TargetPlatform.darwin) ||
|
||||||
(targetPlatforms.contains(build_info.TargetPlatform.tester) && OS.current == OS.macOS))
|
(targetPlatforms.contains(build_info.TargetPlatform.tester) &&
|
||||||
|
OSImpl.current == OSImpl.macOS))
|
||||||
...await dryRunNativeAssetsMacOSInternal(
|
...await dryRunNativeAssetsMacOSInternal(
|
||||||
fileSystem,
|
fileSystem,
|
||||||
projectUri,
|
projectUri,
|
||||||
|
@ -464,7 +468,8 @@ Future<Uri?> dryRunNativeAssetsMultipleOSes({
|
||||||
),
|
),
|
||||||
if (targetPlatforms.contains(build_info.TargetPlatform.linux_arm64) ||
|
if (targetPlatforms.contains(build_info.TargetPlatform.linux_arm64) ||
|
||||||
targetPlatforms.contains(build_info.TargetPlatform.linux_x64) ||
|
targetPlatforms.contains(build_info.TargetPlatform.linux_x64) ||
|
||||||
(targetPlatforms.contains(build_info.TargetPlatform.tester) && OS.current == OS.linux))
|
(targetPlatforms.contains(build_info.TargetPlatform.tester) &&
|
||||||
|
OSImpl.current == OSImpl.linux))
|
||||||
...await dryRunNativeAssetsLinuxInternal(
|
...await dryRunNativeAssetsLinuxInternal(
|
||||||
fileSystem,
|
fileSystem,
|
||||||
projectUri,
|
projectUri,
|
||||||
|
@ -473,7 +478,8 @@ Future<Uri?> dryRunNativeAssetsMultipleOSes({
|
||||||
),
|
),
|
||||||
if (targetPlatforms.contains(build_info.TargetPlatform.windows_arm64) ||
|
if (targetPlatforms.contains(build_info.TargetPlatform.windows_arm64) ||
|
||||||
targetPlatforms.contains(build_info.TargetPlatform.windows_x64) ||
|
targetPlatforms.contains(build_info.TargetPlatform.windows_x64) ||
|
||||||
(targetPlatforms.contains(build_info.TargetPlatform.tester) && OS.current == OS.windows))
|
(targetPlatforms.contains(build_info.TargetPlatform.tester) &&
|
||||||
|
OSImpl.current == OSImpl.windows))
|
||||||
...await dryRunNativeAssetsWindowsInternal(
|
...await dryRunNativeAssetsWindowsInternal(
|
||||||
fileSystem,
|
fileSystem,
|
||||||
projectUri,
|
projectUri,
|
||||||
|
@ -521,7 +527,7 @@ Future<Uri?> dryRunNativeAssetsSingleArchitecture({
|
||||||
required Uri projectUri,
|
required Uri projectUri,
|
||||||
bool flutterTester = false,
|
bool flutterTester = false,
|
||||||
required FileSystem fileSystem,
|
required FileSystem fileSystem,
|
||||||
required OS os,
|
required OSImpl os,
|
||||||
}) async {
|
}) async {
|
||||||
if (!await nativeBuildRequired(buildRunner)) {
|
if (!await nativeBuildRequired(buildRunner)) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -548,24 +554,25 @@ Future<Iterable<KernelAsset>> dryRunNativeAssetsSingleArchitectureInternal(
|
||||||
Uri projectUri,
|
Uri projectUri,
|
||||||
bool flutterTester,
|
bool flutterTester,
|
||||||
NativeAssetsBuildRunner buildRunner,
|
NativeAssetsBuildRunner buildRunner,
|
||||||
OS targetOS,
|
OSImpl targetOS,
|
||||||
) async {
|
) async {
|
||||||
final Uri buildUri = nativeAssetsBuildUri(projectUri, targetOS);
|
final Uri buildUri = nativeAssetsBuildUri(projectUri, targetOS);
|
||||||
|
|
||||||
globals.logger.printTrace('Dry running native assets for $targetOS.');
|
globals.logger.printTrace('Dry running native assets for $targetOS.');
|
||||||
|
|
||||||
final DryRunResult dryRunResult = await buildRunner.dryRun(
|
final DryRunResult dryRunResult = await buildRunner.dryRun(
|
||||||
linkModePreference: LinkModePreference.dynamic,
|
linkModePreference: LinkModePreferenceImpl.dynamic,
|
||||||
targetOS: targetOS,
|
targetOS: targetOS,
|
||||||
workingDirectory: projectUri,
|
workingDirectory: projectUri,
|
||||||
includeParentEnvironment: true,
|
includeParentEnvironment: true,
|
||||||
);
|
);
|
||||||
ensureNativeAssetsBuildSucceed(dryRunResult);
|
ensureNativeAssetsBuildSucceed(dryRunResult);
|
||||||
final List<Asset> nativeAssets = dryRunResult.assets;
|
final List<AssetImpl> nativeAssets = dryRunResult.assets;
|
||||||
ensureNoLinkModeStatic(nativeAssets);
|
ensureNoLinkModeStatic(nativeAssets);
|
||||||
globals.logger.printTrace('Dry running native assets for $targetOS done.');
|
globals.logger.printTrace('Dry running native assets for $targetOS done.');
|
||||||
final Uri? absolutePath = flutterTester ? buildUri : null;
|
final Uri? absolutePath = flutterTester ? buildUri : null;
|
||||||
final Map<Asset, KernelAsset> assetTargetLocations = _assetTargetLocationsSingleArchitecture(
|
final Map<AssetImpl, KernelAsset> assetTargetLocations =
|
||||||
|
_assetTargetLocationsSingleArchitecture(
|
||||||
nativeAssets,
|
nativeAssets,
|
||||||
absolutePath,
|
absolutePath,
|
||||||
);
|
);
|
||||||
|
@ -589,7 +596,7 @@ Future<(Uri? nativeAssetsYaml, List<Uri> dependencies)> buildNativeAssetsSingleA
|
||||||
required FileSystem fileSystem,
|
required FileSystem fileSystem,
|
||||||
}) async {
|
}) async {
|
||||||
final Target target = targetPlatform != null ? _getNativeTarget(targetPlatform) : Target.current;
|
final Target target = targetPlatform != null ? _getNativeTarget(targetPlatform) : Target.current;
|
||||||
final OS targetOS = target.os;
|
final OSImpl targetOS = target.os;
|
||||||
final Uri buildUri = nativeAssetsBuildUri(projectUri, targetOS);
|
final Uri buildUri = nativeAssetsBuildUri(projectUri, targetOS);
|
||||||
final Directory buildDir = fileSystem.directory(buildUri);
|
final Directory buildDir = fileSystem.directory(buildUri);
|
||||||
if (!await buildDir.exists()) {
|
if (!await buildDir.exists()) {
|
||||||
|
@ -605,11 +612,11 @@ Future<(Uri? nativeAssetsYaml, List<Uri> dependencies)> buildNativeAssetsSingleA
|
||||||
return (nativeAssetsYaml, <Uri>[]);
|
return (nativeAssetsYaml, <Uri>[]);
|
||||||
}
|
}
|
||||||
|
|
||||||
final BuildMode buildModeCli = nativeAssetsBuildMode(buildMode);
|
final BuildModeImpl buildModeCli = nativeAssetsBuildMode(buildMode);
|
||||||
|
|
||||||
globals.logger.printTrace('Building native assets for $target $buildModeCli.');
|
globals.logger.printTrace('Building native assets for $target $buildModeCli.');
|
||||||
final BuildResult result = await buildRunner.build(
|
final BuildResult result = await buildRunner.build(
|
||||||
linkModePreference: LinkModePreference.dynamic,
|
linkModePreference: LinkModePreferenceImpl.dynamic,
|
||||||
target: target,
|
target: target,
|
||||||
buildMode: buildModeCli,
|
buildMode: buildModeCli,
|
||||||
workingDirectory: projectUri,
|
workingDirectory: projectUri,
|
||||||
|
@ -617,12 +624,13 @@ Future<(Uri? nativeAssetsYaml, List<Uri> dependencies)> buildNativeAssetsSingleA
|
||||||
cCompilerConfig: await buildRunner.cCompilerConfig,
|
cCompilerConfig: await buildRunner.cCompilerConfig,
|
||||||
);
|
);
|
||||||
ensureNativeAssetsBuildSucceed(result);
|
ensureNativeAssetsBuildSucceed(result);
|
||||||
final List<Asset> nativeAssets = result.assets;
|
final List<AssetImpl> nativeAssets = result.assets;
|
||||||
final Set<Uri> dependencies = result.dependencies.toSet();
|
final Set<Uri> dependencies = result.dependencies.toSet();
|
||||||
ensureNoLinkModeStatic(nativeAssets);
|
ensureNoLinkModeStatic(nativeAssets);
|
||||||
globals.logger.printTrace('Building native assets for $target done.');
|
globals.logger.printTrace('Building native assets for $target done.');
|
||||||
final Uri? absolutePath = flutterTester ? buildUri : null;
|
final Uri? absolutePath = flutterTester ? buildUri : null;
|
||||||
final Map<Asset, KernelAsset> assetTargetLocations = _assetTargetLocationsSingleArchitecture(nativeAssets, absolutePath);
|
final Map<AssetImpl, KernelAsset> assetTargetLocations =
|
||||||
|
_assetTargetLocationsSingleArchitecture(nativeAssets, absolutePath);
|
||||||
await _copyNativeAssetsSingleArchitecture(
|
await _copyNativeAssetsSingleArchitecture(
|
||||||
buildUri,
|
buildUri,
|
||||||
assetTargetLocations,
|
assetTargetLocations,
|
||||||
|
@ -637,12 +645,12 @@ Future<(Uri? nativeAssetsYaml, List<Uri> dependencies)> buildNativeAssetsSingleA
|
||||||
return (nativeAssetsUri, dependencies.toList());
|
return (nativeAssetsUri, dependencies.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<Asset, KernelAsset> _assetTargetLocationsSingleArchitecture(
|
Map<AssetImpl, KernelAsset> _assetTargetLocationsSingleArchitecture(
|
||||||
List<Asset> nativeAssets,
|
List<AssetImpl> nativeAssets,
|
||||||
Uri? absolutePath,
|
Uri? absolutePath,
|
||||||
) {
|
) {
|
||||||
return <Asset, KernelAsset>{
|
return <AssetImpl, KernelAsset>{
|
||||||
for (final Asset asset in nativeAssets)
|
for (final AssetImpl asset in nativeAssets)
|
||||||
asset: _targetLocationSingleArchitecture(
|
asset: _targetLocationSingleArchitecture(
|
||||||
asset,
|
asset,
|
||||||
absolutePath,
|
absolutePath,
|
||||||
|
@ -650,18 +658,24 @@ Map<Asset, KernelAsset> _assetTargetLocationsSingleArchitecture(
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
KernelAsset _targetLocationSingleArchitecture(Asset asset, Uri? absolutePath) {
|
KernelAsset _targetLocationSingleArchitecture(
|
||||||
final AssetPath path = asset.path;
|
AssetImpl asset, Uri? absolutePath) {
|
||||||
|
if (asset is! NativeCodeAssetImpl) {
|
||||||
|
throw Exception(
|
||||||
|
'Unsupported asset type ${asset.runtimeType}',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
final LinkModeImpl linkMode = asset.linkMode;
|
||||||
final KernelAssetPath kernelAssetPath;
|
final KernelAssetPath kernelAssetPath;
|
||||||
switch (path) {
|
switch (linkMode) {
|
||||||
case AssetSystemPath _:
|
case DynamicLoadingSystemImpl _:
|
||||||
kernelAssetPath = KernelAssetSystemPath(path.uri);
|
kernelAssetPath = KernelAssetSystemPath(linkMode.uri);
|
||||||
case AssetInExecutable _:
|
case LookupInExecutableImpl _:
|
||||||
kernelAssetPath = KernelAssetInExecutable();
|
kernelAssetPath = KernelAssetInExecutable();
|
||||||
case AssetInProcess _:
|
case LookupInProcessImpl _:
|
||||||
kernelAssetPath = KernelAssetInProcess();
|
kernelAssetPath = KernelAssetInProcess();
|
||||||
case AssetAbsolutePath _:
|
case DynamicLoadingBundledImpl _:
|
||||||
final String fileName = path.uri.pathSegments.last;
|
final String fileName = asset.file!.pathSegments.last;
|
||||||
Uri uri;
|
Uri uri;
|
||||||
if (absolutePath != null) {
|
if (absolutePath != null) {
|
||||||
// Flutter tester needs full host paths.
|
// Flutter tester needs full host paths.
|
||||||
|
@ -675,12 +689,12 @@ KernelAsset _targetLocationSingleArchitecture(Asset asset, Uri? absolutePath) {
|
||||||
kernelAssetPath = KernelAssetAbsolutePath(uri);
|
kernelAssetPath = KernelAssetAbsolutePath(uri);
|
||||||
default:
|
default:
|
||||||
throw Exception(
|
throw Exception(
|
||||||
'Unsupported asset path type ${path.runtimeType} in asset $asset',
|
'Unsupported asset link mode ${linkMode.runtimeType} in asset $asset',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return KernelAsset(
|
return KernelAsset(
|
||||||
id: asset.id,
|
id: asset.id,
|
||||||
target: asset.target,
|
target: Target.fromArchitectureAndOS(asset.architecture!, asset.os),
|
||||||
path: kernelAssetPath,
|
path: kernelAssetPath,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -727,7 +741,7 @@ Future<void> _copyNativeAssetsSingleArchitecture(
|
||||||
buildDir.createSync(recursive: true);
|
buildDir.createSync(recursive: true);
|
||||||
}
|
}
|
||||||
for (final MapEntry<Asset, KernelAsset> assetMapping in assetTargetLocations.entries) {
|
for (final MapEntry<Asset, KernelAsset> assetMapping in assetTargetLocations.entries) {
|
||||||
final Uri source = (assetMapping.key.path as AssetAbsolutePath).uri;
|
final Uri source = assetMapping.key.file!;
|
||||||
final Uri target = (assetMapping.value.path as KernelAssetAbsolutePath).uri;
|
final Uri target = (assetMapping.value.path as KernelAssetAbsolutePath).uri;
|
||||||
final Uri targetUri = buildUri.resolveUri(target);
|
final Uri targetUri = buildUri.resolveUri(target);
|
||||||
final String targetFullPath = targetUri.toFilePath();
|
final String targetFullPath = targetUri.toFilePath();
|
||||||
|
|
|
@ -4,8 +4,7 @@
|
||||||
|
|
||||||
import 'package:native_assets_builder/native_assets_builder.dart'
|
import 'package:native_assets_builder/native_assets_builder.dart'
|
||||||
hide NativeAssetsBuildRunner;
|
hide NativeAssetsBuildRunner;
|
||||||
import 'package:native_assets_cli/native_assets_cli_internal.dart'
|
import 'package:native_assets_cli/native_assets_cli_internal.dart';
|
||||||
hide BuildMode;
|
|
||||||
|
|
||||||
import '../../../base/file_system.dart';
|
import '../../../base/file_system.dart';
|
||||||
import '../../../build_info.dart';
|
import '../../../build_info.dart';
|
||||||
|
@ -28,7 +27,7 @@ Future<Uri?> dryRunNativeAssetsWindows({
|
||||||
projectUri: projectUri,
|
projectUri: projectUri,
|
||||||
flutterTester: flutterTester,
|
flutterTester: flutterTester,
|
||||||
fileSystem: fileSystem,
|
fileSystem: fileSystem,
|
||||||
os: OS.windows,
|
os: OSImpl.windows,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,7 +42,7 @@ Future<Iterable<KernelAsset>> dryRunNativeAssetsWindowsInternal(
|
||||||
projectUri,
|
projectUri,
|
||||||
flutterTester,
|
flutterTester,
|
||||||
buildRunner,
|
buildRunner,
|
||||||
OS.windows,
|
OSImpl.windows,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,7 +67,7 @@ Future<(Uri? nativeAssetsYaml, List<Uri> dependencies)>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<CCompilerConfig> cCompilerConfigWindows() async {
|
Future<CCompilerConfigImpl> cCompilerConfigWindows() async {
|
||||||
final VisualStudio visualStudio = VisualStudio(
|
final VisualStudio visualStudio = VisualStudio(
|
||||||
fileSystem: globals.fs,
|
fileSystem: globals.fs,
|
||||||
platform: globals.platform,
|
platform: globals.platform,
|
||||||
|
@ -77,10 +76,10 @@ Future<CCompilerConfig> cCompilerConfigWindows() async {
|
||||||
osUtils: globals.os,
|
osUtils: globals.os,
|
||||||
);
|
);
|
||||||
|
|
||||||
return CCompilerConfig(
|
return CCompilerConfigImpl(
|
||||||
cc: _toOptionalFileUri(visualStudio.clPath),
|
compiler: _toOptionalFileUri(visualStudio.clPath),
|
||||||
ld: _toOptionalFileUri(visualStudio.linkPath),
|
linker: _toOptionalFileUri(visualStudio.linkPath),
|
||||||
ar: _toOptionalFileUri(visualStudio.libPath),
|
archiver: _toOptionalFileUri(visualStudio.libPath),
|
||||||
envScript: _toOptionalFileUri(visualStudio.vcvarsPath),
|
envScript: _toOptionalFileUri(visualStudio.vcvarsPath),
|
||||||
envScriptArgs: <String>[],
|
envScriptArgs: <String>[],
|
||||||
);
|
);
|
||||||
|
|
|
@ -54,10 +54,10 @@ dependencies:
|
||||||
async: 2.11.0
|
async: 2.11.0
|
||||||
unified_analytics: 5.8.8
|
unified_analytics: 5.8.8
|
||||||
|
|
||||||
cli_config: 0.1.2
|
cli_config: 0.2.0
|
||||||
graphs: 2.3.1
|
graphs: 2.3.1
|
||||||
native_assets_builder: 0.5.0
|
native_assets_builder: 0.6.1
|
||||||
native_assets_cli: 0.4.2
|
native_assets_cli: 0.5.3
|
||||||
|
|
||||||
# We depend on very specific internal implementation details of the
|
# We depend on very specific internal implementation details of the
|
||||||
# 'test' package, which change between versions, so when upgrading
|
# 'test' package, which change between versions, so when upgrading
|
||||||
|
@ -120,4 +120,4 @@ dartdoc:
|
||||||
# Exclude this package from the hosted API docs.
|
# Exclude this package from the hosted API docs.
|
||||||
nodoc: true
|
nodoc: true
|
||||||
|
|
||||||
# PUBSPEC CHECKSUM: df1d
|
# PUBSPEC CHECKSUM: ba20
|
||||||
|
|
|
@ -1,24 +0,0 @@
|
||||||
import 'package:native_toolchain_c/native_toolchain_c.dart';
|
|
||||||
import 'package:logging/logging.dart';
|
|
||||||
import 'package:native_assets_cli/native_assets_cli.dart';
|
|
||||||
|
|
||||||
const packageName = '{{projectName}}';
|
|
||||||
|
|
||||||
void main(List<String> args) async {
|
|
||||||
final buildConfig = await BuildConfig.fromArgs(args);
|
|
||||||
final buildOutput = BuildOutput();
|
|
||||||
final cbuilder = CBuilder.library(
|
|
||||||
name: packageName,
|
|
||||||
assetId:
|
|
||||||
'package:$packageName/${packageName}_bindings_generated.dart',
|
|
||||||
sources: [
|
|
||||||
'src/$packageName.c',
|
|
||||||
],
|
|
||||||
);
|
|
||||||
await cbuilder.run(
|
|
||||||
buildConfig: buildConfig,
|
|
||||||
buildOutput: buildOutput,
|
|
||||||
logger: Logger('')..onRecord.listen((record) => print(record.message)),
|
|
||||||
);
|
|
||||||
await buildOutput.writeToFile(outDir: buildConfig.outDir);
|
|
||||||
}
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
import 'package:native_toolchain_c/native_toolchain_c.dart';
|
||||||
|
import 'package:logging/logging.dart';
|
||||||
|
import 'package:native_assets_cli/native_assets_cli.dart';
|
||||||
|
|
||||||
|
const packageName = '{{projectName}}';
|
||||||
|
|
||||||
|
void main(List<String> args) async {
|
||||||
|
await build(args, (config, output) async {
|
||||||
|
final packageName = config.packageName;
|
||||||
|
final cbuilder = CBuilder.library(
|
||||||
|
name: packageName,
|
||||||
|
assetName: '${packageName}_bindings_generated.dart',
|
||||||
|
sources: [
|
||||||
|
'src/$packageName.c',
|
||||||
|
],
|
||||||
|
dartBuildFiles: ['hook/build.dart'],
|
||||||
|
);
|
||||||
|
await cbuilder.run(
|
||||||
|
buildConfig: config,
|
||||||
|
buildOutput: output,
|
||||||
|
logger: Logger('')
|
||||||
|
..level = Level.ALL
|
||||||
|
..onRecord.listen((record) => print(record.message)),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
|
@ -7,10 +7,10 @@ environment:
|
||||||
sdk: {{dartSdkVersionBounds}}
|
sdk: {{dartSdkVersionBounds}}
|
||||||
|
|
||||||
dependencies:
|
dependencies:
|
||||||
cli_config: ^0.1.2
|
cli_config: ^0.2.0
|
||||||
logging: ^1.2.0
|
logging: ^1.2.0
|
||||||
native_assets_cli: ^0.4.2
|
native_assets_cli: ^0.5.3
|
||||||
native_toolchain_c: ^0.3.4+1
|
native_toolchain_c: ^0.4.1
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
ffi: ^2.1.0
|
ffi: ^2.1.0
|
||||||
|
|
|
@ -252,9 +252,9 @@
|
||||||
"templates/package_ffi/.gitignore.tmpl",
|
"templates/package_ffi/.gitignore.tmpl",
|
||||||
"templates/package_ffi/.metadata.tmpl",
|
"templates/package_ffi/.metadata.tmpl",
|
||||||
"templates/package_ffi/analysis_options.yaml.tmpl",
|
"templates/package_ffi/analysis_options.yaml.tmpl",
|
||||||
"templates/package_ffi/build.dart.tmpl",
|
|
||||||
"templates/package_ffi/CHANGELOG.md.tmpl",
|
"templates/package_ffi/CHANGELOG.md.tmpl",
|
||||||
"templates/package_ffi/ffigen.yaml.tmpl",
|
"templates/package_ffi/ffigen.yaml.tmpl",
|
||||||
|
"templates/package_ffi/hook/build.dart.tmpl",
|
||||||
"templates/package_ffi/lib/projectName_bindings_generated.dart.tmpl",
|
"templates/package_ffi/lib/projectName_bindings_generated.dart.tmpl",
|
||||||
"templates/package_ffi/lib/projectName.dart.tmpl",
|
"templates/package_ffi/lib/projectName.dart.tmpl",
|
||||||
"templates/package_ffi/LICENSE.tmpl",
|
"templates/package_ffi/LICENSE.tmpl",
|
||||||
|
|
|
@ -15,10 +15,7 @@ import 'package:flutter_tools/src/build_system/build_system.dart';
|
||||||
import 'package:flutter_tools/src/features.dart';
|
import 'package:flutter_tools/src/features.dart';
|
||||||
import 'package:flutter_tools/src/globals.dart' as globals;
|
import 'package:flutter_tools/src/globals.dart' as globals;
|
||||||
import 'package:flutter_tools/src/isolated/native_assets/android/native_assets.dart';
|
import 'package:flutter_tools/src/isolated/native_assets/android/native_assets.dart';
|
||||||
import 'package:native_assets_cli/native_assets_cli_internal.dart'
|
import 'package:native_assets_cli/native_assets_cli_internal.dart';
|
||||||
as native_assets_cli;
|
|
||||||
import 'package:native_assets_cli/native_assets_cli_internal.dart'
|
|
||||||
hide BuildMode, Target;
|
|
||||||
import 'package:package_config/package_config_types.dart';
|
import 'package:package_config/package_config_types.dart';
|
||||||
|
|
||||||
import '../../../src/common.dart';
|
import '../../../src/common.dart';
|
||||||
|
@ -128,18 +125,20 @@ void main() {
|
||||||
Package('bar', projectUri),
|
Package('bar', projectUri),
|
||||||
],
|
],
|
||||||
dryRunResult: FakeNativeAssetsBuilderResult(
|
dryRunResult: FakeNativeAssetsBuilderResult(
|
||||||
assets: <Asset>[
|
assets: <AssetImpl>[
|
||||||
Asset(
|
NativeCodeAssetImpl(
|
||||||
id: 'package:bar/bar.dart',
|
id: 'package:bar/bar.dart',
|
||||||
linkMode: LinkMode.dynamic,
|
linkMode: DynamicLoadingBundledImpl(),
|
||||||
target: native_assets_cli.Target.macOSArm64,
|
os: OSImpl.macOS,
|
||||||
path: AssetAbsolutePath(Uri.file('libbar.so')),
|
architecture: ArchitectureImpl.arm64,
|
||||||
|
file: Uri.file('libbar.so'),
|
||||||
),
|
),
|
||||||
Asset(
|
NativeCodeAssetImpl(
|
||||||
id: 'package:bar/bar.dart',
|
id: 'package:bar/bar.dart',
|
||||||
linkMode: LinkMode.dynamic,
|
linkMode: DynamicLoadingBundledImpl(),
|
||||||
target: native_assets_cli.Target.macOSX64,
|
os: OSImpl.macOS,
|
||||||
path: AssetAbsolutePath(Uri.file('libbar.so')),
|
architecture: ArchitectureImpl.x64,
|
||||||
|
file: Uri.file('libbar.so'),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
@ -237,12 +236,13 @@ void main() {
|
||||||
Package('bar', projectUri),
|
Package('bar', projectUri),
|
||||||
],
|
],
|
||||||
buildResult: FakeNativeAssetsBuilderResult(
|
buildResult: FakeNativeAssetsBuilderResult(
|
||||||
assets: <Asset>[
|
assets: <AssetImpl>[
|
||||||
Asset(
|
NativeCodeAssetImpl(
|
||||||
id: 'package:bar/bar.dart',
|
id: 'package:bar/bar.dart',
|
||||||
linkMode: LinkMode.dynamic,
|
linkMode: DynamicLoadingBundledImpl(),
|
||||||
target: native_assets_cli.Target.androidArm64,
|
os: OSImpl.android,
|
||||||
path: AssetAbsolutePath(Uri.file('libbar.so')),
|
architecture: ArchitectureImpl.arm64,
|
||||||
|
file: Uri.file('libbar.so'),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
@ -382,6 +382,6 @@ class _BuildRunnerWithoutNdk extends FakeNativeAssetsBuildRunner {
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<CCompilerConfig> get ndkCCompilerConfig async =>
|
Future<CCompilerConfigImpl> get ndkCCompilerConfigImpl async =>
|
||||||
throwToolExit('Android NDK Clang could not be found.');
|
throwToolExit('Android NDK Clang could not be found.');
|
||||||
}
|
}
|
||||||
|
|
|
@ -130,18 +130,20 @@ void main() {
|
||||||
|
|
||||||
final NativeAssetsBuildRunner buildRunner = FakeNativeAssetsBuildRunner(
|
final NativeAssetsBuildRunner buildRunner = FakeNativeAssetsBuildRunner(
|
||||||
packagesWithNativeAssetsResult: <Package>[Package('foo', iosEnvironment.buildDir.uri)],
|
packagesWithNativeAssetsResult: <Package>[Package('foo', iosEnvironment.buildDir.uri)],
|
||||||
buildResult: FakeNativeAssetsBuilderResult(assets: <native_assets_cli.Asset>[
|
buildResult: FakeNativeAssetsBuilderResult(
|
||||||
native_assets_cli.Asset(
|
assets: <native_assets_cli.AssetImpl>[
|
||||||
id: 'package:foo/foo.dart',
|
native_assets_cli.NativeCodeAssetImpl(
|
||||||
linkMode: native_assets_cli.LinkMode.dynamic,
|
id: 'package:foo/foo.dart',
|
||||||
target: native_assets_cli.Target.iOSArm64,
|
linkMode: native_assets_cli.DynamicLoadingBundledImpl(),
|
||||||
path: native_assets_cli.AssetAbsolutePath(
|
os: native_assets_cli.OSImpl.iOS,
|
||||||
Uri.file('foo.framework/foo'),
|
architecture: native_assets_cli.ArchitectureImpl.arm64,
|
||||||
|
file: Uri.file('foo.framework/foo'),
|
||||||
),
|
),
|
||||||
)
|
],
|
||||||
], dependencies: <Uri>[
|
dependencies: <Uri>[
|
||||||
Uri.file('src/foo.c'),
|
Uri.file('src/foo.c'),
|
||||||
]),
|
],
|
||||||
|
),
|
||||||
);
|
);
|
||||||
await NativeAssets(buildRunner: buildRunner).build(iosEnvironment);
|
await NativeAssets(buildRunner: buildRunner).build(iosEnvironment);
|
||||||
|
|
||||||
|
@ -191,23 +193,27 @@ void main() {
|
||||||
packagesWithNativeAssetsResult: <Package>[
|
packagesWithNativeAssetsResult: <Package>[
|
||||||
Package('foo', androidEnvironment.buildDir.uri)
|
Package('foo', androidEnvironment.buildDir.uri)
|
||||||
],
|
],
|
||||||
buildResult:
|
buildResult: FakeNativeAssetsBuilderResult(
|
||||||
FakeNativeAssetsBuilderResult(assets: <native_assets_cli.Asset>[
|
assets: <native_assets_cli.AssetImpl>[
|
||||||
if (hasAssets)
|
if (hasAssets)
|
||||||
native_assets_cli.Asset(
|
native_assets_cli.NativeCodeAssetImpl(
|
||||||
id: 'package:foo/foo.dart',
|
id: 'package:foo/foo.dart',
|
||||||
linkMode: native_assets_cli.LinkMode.dynamic,
|
linkMode: native_assets_cli.DynamicLoadingBundledImpl(),
|
||||||
target: native_assets_cli.Target.androidArm64,
|
os: native_assets_cli.OSImpl.android,
|
||||||
path: native_assets_cli.AssetAbsolutePath(
|
architecture: native_assets_cli.ArchitectureImpl.arm64,
|
||||||
Uri.file('libfoo.so'),
|
file: Uri.file('libfoo.so'),
|
||||||
),
|
),
|
||||||
)
|
],
|
||||||
], dependencies: <Uri>[
|
dependencies: <Uri>[
|
||||||
Uri.file('src/foo.c'),
|
Uri.file('src/foo.c'),
|
||||||
]),
|
],
|
||||||
|
),
|
||||||
);
|
);
|
||||||
await NativeAssets(buildRunner: buildRunner).build(androidEnvironment);
|
await NativeAssets(buildRunner: buildRunner).build(androidEnvironment);
|
||||||
expect(buildRunner.lastBuildMode, native_assets_cli.BuildMode.release);
|
expect(
|
||||||
|
buildRunner.lastBuildMode,
|
||||||
|
native_assets_cli.BuildModeImpl.release,
|
||||||
|
);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,35 +21,36 @@ class FakeNativeAssetsBuildRunner implements NativeAssetsBuildRunner {
|
||||||
this.onBuild,
|
this.onBuild,
|
||||||
this.dryRunResult = const FakeNativeAssetsBuilderResult(),
|
this.dryRunResult = const FakeNativeAssetsBuilderResult(),
|
||||||
this.buildResult = const FakeNativeAssetsBuilderResult(),
|
this.buildResult = const FakeNativeAssetsBuilderResult(),
|
||||||
CCompilerConfig? cCompilerConfigResult,
|
CCompilerConfigImpl? cCompilerConfigResult,
|
||||||
CCompilerConfig? ndkCCompilerConfigResult,
|
CCompilerConfigImpl? ndkCCompilerConfigImplResult,
|
||||||
}) : cCompilerConfigResult = cCompilerConfigResult ?? CCompilerConfig(),
|
}) : cCompilerConfigResult = cCompilerConfigResult ?? CCompilerConfigImpl(),
|
||||||
ndkCCompilerConfigResult = ndkCCompilerConfigResult ?? CCompilerConfig();
|
ndkCCompilerConfigImplResult =
|
||||||
|
ndkCCompilerConfigImplResult ?? CCompilerConfigImpl();
|
||||||
|
|
||||||
final native_assets_builder.BuildResult Function(Target)? onBuild;
|
final native_assets_builder.BuildResult Function(Target)? onBuild;
|
||||||
final native_assets_builder.BuildResult buildResult;
|
final native_assets_builder.BuildResult buildResult;
|
||||||
final native_assets_builder.DryRunResult dryRunResult;
|
final native_assets_builder.DryRunResult dryRunResult;
|
||||||
final bool hasPackageConfigResult;
|
final bool hasPackageConfigResult;
|
||||||
final List<Package> packagesWithNativeAssetsResult;
|
final List<Package> packagesWithNativeAssetsResult;
|
||||||
final CCompilerConfig cCompilerConfigResult;
|
final CCompilerConfigImpl cCompilerConfigResult;
|
||||||
final CCompilerConfig ndkCCompilerConfigResult;
|
final CCompilerConfigImpl ndkCCompilerConfigImplResult;
|
||||||
|
|
||||||
int buildInvocations = 0;
|
int buildInvocations = 0;
|
||||||
int dryRunInvocations = 0;
|
int dryRunInvocations = 0;
|
||||||
int hasPackageConfigInvocations = 0;
|
int hasPackageConfigInvocations = 0;
|
||||||
int packagesWithNativeAssetsInvocations = 0;
|
int packagesWithNativeAssetsInvocations = 0;
|
||||||
BuildMode? lastBuildMode;
|
BuildModeImpl? lastBuildMode;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<native_assets_builder.BuildResult> build({
|
Future<native_assets_builder.BuildResult> build({
|
||||||
required bool includeParentEnvironment,
|
required bool includeParentEnvironment,
|
||||||
required BuildMode buildMode,
|
required BuildModeImpl buildMode,
|
||||||
required LinkModePreference linkModePreference,
|
required LinkModePreferenceImpl linkModePreference,
|
||||||
required Target target,
|
required Target target,
|
||||||
required Uri workingDirectory,
|
required Uri workingDirectory,
|
||||||
CCompilerConfig? cCompilerConfig,
|
CCompilerConfigImpl? cCompilerConfig,
|
||||||
int? targetAndroidNdkApi,
|
int? targetAndroidNdkApi,
|
||||||
IOSSdk? targetIOSSdk,
|
IOSSdkImpl? targetIOSSdkImpl,
|
||||||
}) async {
|
}) async {
|
||||||
buildInvocations++;
|
buildInvocations++;
|
||||||
lastBuildMode = buildMode;
|
lastBuildMode = buildMode;
|
||||||
|
@ -59,8 +60,8 @@ class FakeNativeAssetsBuildRunner implements NativeAssetsBuildRunner {
|
||||||
@override
|
@override
|
||||||
Future<native_assets_builder.DryRunResult> dryRun({
|
Future<native_assets_builder.DryRunResult> dryRun({
|
||||||
required bool includeParentEnvironment,
|
required bool includeParentEnvironment,
|
||||||
required LinkModePreference linkModePreference,
|
required LinkModePreferenceImpl linkModePreference,
|
||||||
required OS targetOS,
|
required OSImpl targetOS,
|
||||||
required Uri workingDirectory,
|
required Uri workingDirectory,
|
||||||
}) async {
|
}) async {
|
||||||
dryRunInvocations++;
|
dryRunInvocations++;
|
||||||
|
@ -80,22 +81,24 @@ class FakeNativeAssetsBuildRunner implements NativeAssetsBuildRunner {
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<CCompilerConfig> get cCompilerConfig async => cCompilerConfigResult;
|
Future<CCompilerConfigImpl> get cCompilerConfig async =>
|
||||||
|
cCompilerConfigResult;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<CCompilerConfig> get ndkCCompilerConfig async => cCompilerConfigResult;
|
Future<CCompilerConfigImpl> get ndkCCompilerConfigImpl async =>
|
||||||
|
cCompilerConfigResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
final class FakeNativeAssetsBuilderResult
|
final class FakeNativeAssetsBuilderResult
|
||||||
implements native_assets_builder.BuildResult {
|
implements native_assets_builder.BuildResult {
|
||||||
const FakeNativeAssetsBuilderResult({
|
const FakeNativeAssetsBuilderResult({
|
||||||
this.assets = const <Asset>[],
|
this.assets = const <AssetImpl>[],
|
||||||
this.dependencies = const <Uri>[],
|
this.dependencies = const <Uri>[],
|
||||||
this.success = true,
|
this.success = true,
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
final List<Asset> assets;
|
final List<AssetImpl> assets;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
final List<Uri> dependencies;
|
final List<Uri> dependencies;
|
||||||
|
|
|
@ -14,9 +14,7 @@ import 'package:flutter_tools/src/resident_devtools_handler.dart';
|
||||||
import 'package:flutter_tools/src/resident_runner.dart';
|
import 'package:flutter_tools/src/resident_runner.dart';
|
||||||
import 'package:flutter_tools/src/run_hot.dart';
|
import 'package:flutter_tools/src/run_hot.dart';
|
||||||
import 'package:native_assets_cli/native_assets_cli_internal.dart'
|
import 'package:native_assets_cli/native_assets_cli_internal.dart'
|
||||||
hide BuildMode, Target;
|
hide Target;
|
||||||
import 'package:native_assets_cli/native_assets_cli_internal.dart'
|
|
||||||
as native_assets_cli;
|
|
||||||
import 'package:package_config/package_config.dart';
|
import 'package:package_config/package_config.dart';
|
||||||
import 'package:unified_analytics/unified_analytics.dart';
|
import 'package:unified_analytics/unified_analytics.dart';
|
||||||
|
|
||||||
|
@ -65,12 +63,20 @@ void main() {
|
||||||
Package('bar', fileSystem.currentDirectory.uri),
|
Package('bar', fileSystem.currentDirectory.uri),
|
||||||
],
|
],
|
||||||
dryRunResult: FakeNativeAssetsBuilderResult(
|
dryRunResult: FakeNativeAssetsBuilderResult(
|
||||||
assets: <Asset>[
|
assets: <AssetImpl>[
|
||||||
Asset(
|
NativeCodeAssetImpl(
|
||||||
id: 'package:bar/bar.dart',
|
id: 'package:bar/bar.dart',
|
||||||
linkMode: LinkMode.dynamic,
|
linkMode: DynamicLoadingBundledImpl(),
|
||||||
target: native_assets_cli.Target.macOSArm64,
|
os: OSImpl.macOS,
|
||||||
path: AssetAbsolutePath(Uri.file('bar.dylib')),
|
architecture: ArchitectureImpl.arm64,
|
||||||
|
file: Uri.file('bar.dylib'),
|
||||||
|
),
|
||||||
|
NativeCodeAssetImpl(
|
||||||
|
id: 'package:bar/bar.dart',
|
||||||
|
linkMode: DynamicLoadingBundledImpl(),
|
||||||
|
os: OSImpl.macOS,
|
||||||
|
architecture: ArchitectureImpl.x64,
|
||||||
|
file: Uri.file('bar.dylib'),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
@ -124,12 +130,20 @@ void main() {
|
||||||
Package('bar', fileSystem.currentDirectory.uri),
|
Package('bar', fileSystem.currentDirectory.uri),
|
||||||
],
|
],
|
||||||
dryRunResult: FakeNativeAssetsBuilderResult(
|
dryRunResult: FakeNativeAssetsBuilderResult(
|
||||||
assets: <Asset>[
|
assets: <AssetImpl>[
|
||||||
Asset(
|
NativeCodeAssetImpl(
|
||||||
id: 'package:bar/bar.dart',
|
id: 'package:bar/bar.dart',
|
||||||
linkMode: LinkMode.dynamic,
|
linkMode: DynamicLoadingBundledImpl(),
|
||||||
target: native_assets_cli.Target.macOSArm64,
|
os: OSImpl.macOS,
|
||||||
path: AssetAbsolutePath(Uri.file('bar.dylib')),
|
architecture: ArchitectureImpl.arm64,
|
||||||
|
file: Uri.file('bar.dylib'),
|
||||||
|
),
|
||||||
|
NativeCodeAssetImpl(
|
||||||
|
id: 'package:bar/bar.dart',
|
||||||
|
linkMode: DynamicLoadingBundledImpl(),
|
||||||
|
os: OSImpl.macOS,
|
||||||
|
architecture: ArchitectureImpl.x64,
|
||||||
|
file: Uri.file('bar.dylib'),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|
|
@ -15,7 +15,7 @@ import 'package:flutter_tools/src/features.dart';
|
||||||
import 'package:flutter_tools/src/globals.dart' as globals;
|
import 'package:flutter_tools/src/globals.dart' as globals;
|
||||||
import 'package:flutter_tools/src/isolated/native_assets/ios/native_assets.dart';
|
import 'package:flutter_tools/src/isolated/native_assets/ios/native_assets.dart';
|
||||||
import 'package:native_assets_cli/native_assets_cli_internal.dart'
|
import 'package:native_assets_cli/native_assets_cli_internal.dart'
|
||||||
hide BuildMode, Target;
|
hide Target;
|
||||||
import 'package:native_assets_cli/native_assets_cli_internal.dart'
|
import 'package:native_assets_cli/native_assets_cli_internal.dart'
|
||||||
as native_assets_cli;
|
as native_assets_cli;
|
||||||
import 'package:package_config/package_config_types.dart';
|
import 'package:package_config/package_config_types.dart';
|
||||||
|
@ -127,18 +127,20 @@ void main() {
|
||||||
Package('bar', projectUri),
|
Package('bar', projectUri),
|
||||||
],
|
],
|
||||||
dryRunResult: FakeNativeAssetsBuilderResult(
|
dryRunResult: FakeNativeAssetsBuilderResult(
|
||||||
assets: <Asset>[
|
assets: <AssetImpl>[
|
||||||
Asset(
|
NativeCodeAssetImpl(
|
||||||
id: 'package:bar/bar.dart',
|
id: 'package:bar/bar.dart',
|
||||||
linkMode: LinkMode.dynamic,
|
linkMode: DynamicLoadingBundledImpl(),
|
||||||
target: native_assets_cli.Target.macOSArm64,
|
os: OSImpl.macOS,
|
||||||
path: AssetAbsolutePath(Uri.file('libbar.dylib')),
|
architecture: ArchitectureImpl.arm64,
|
||||||
|
file: Uri.file('libbar.dylib'),
|
||||||
),
|
),
|
||||||
Asset(
|
NativeCodeAssetImpl(
|
||||||
id: 'package:bar/bar.dart',
|
id: 'package:bar/bar.dart',
|
||||||
linkMode: LinkMode.dynamic,
|
linkMode: DynamicLoadingBundledImpl(),
|
||||||
target: native_assets_cli.Target.macOSX64,
|
os: OSImpl.macOS,
|
||||||
path: AssetAbsolutePath(Uri.file('libbar.dylib')),
|
architecture: ArchitectureImpl.x64,
|
||||||
|
file: Uri.file('libbar.dylib'),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
@ -265,12 +267,13 @@ void main() {
|
||||||
Package('bar', projectUri),
|
Package('bar', projectUri),
|
||||||
],
|
],
|
||||||
onBuild: (native_assets_cli.Target target) => FakeNativeAssetsBuilderResult(
|
onBuild: (native_assets_cli.Target target) => FakeNativeAssetsBuilderResult(
|
||||||
assets: <Asset>[
|
assets: <AssetImpl>[
|
||||||
Asset(
|
NativeCodeAssetImpl(
|
||||||
id: 'package:bar/bar.dart',
|
id: 'package:bar/bar.dart',
|
||||||
linkMode: LinkMode.dynamic,
|
linkMode: DynamicLoadingBundledImpl(),
|
||||||
target: target,
|
os: target.os,
|
||||||
path: AssetAbsolutePath(Uri.file('${target.architecture}/libbar.dylib')),
|
architecture: target.architecture,
|
||||||
|
file: Uri.file('${target.architecture}/libbar.dylib'),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|
|
@ -18,9 +18,7 @@ import 'package:flutter_tools/src/globals.dart' as globals;
|
||||||
import 'package:flutter_tools/src/isolated/native_assets/linux/native_assets.dart';
|
import 'package:flutter_tools/src/isolated/native_assets/linux/native_assets.dart';
|
||||||
import 'package:flutter_tools/src/isolated/native_assets/native_assets.dart';
|
import 'package:flutter_tools/src/isolated/native_assets/native_assets.dart';
|
||||||
import 'package:native_assets_cli/native_assets_cli_internal.dart'
|
import 'package:native_assets_cli/native_assets_cli_internal.dart'
|
||||||
hide BuildMode, Target;
|
hide Target;
|
||||||
import 'package:native_assets_cli/native_assets_cli_internal.dart'
|
|
||||||
as native_assets_cli;
|
|
||||||
import 'package:package_config/package_config_types.dart';
|
import 'package:package_config/package_config_types.dart';
|
||||||
|
|
||||||
import '../../../src/common.dart';
|
import '../../../src/common.dart';
|
||||||
|
@ -165,18 +163,20 @@ void main() {
|
||||||
Package('bar', projectUri),
|
Package('bar', projectUri),
|
||||||
],
|
],
|
||||||
dryRunResult: FakeNativeAssetsBuilderResult(
|
dryRunResult: FakeNativeAssetsBuilderResult(
|
||||||
assets: <Asset>[
|
assets: <AssetImpl>[
|
||||||
Asset(
|
NativeCodeAssetImpl(
|
||||||
id: 'package:bar/bar.dart',
|
id: 'package:bar/bar.dart',
|
||||||
linkMode: LinkMode.dynamic,
|
linkMode: DynamicLoadingBundledImpl(),
|
||||||
target: native_assets_cli.Target.linuxX64,
|
os: OSImpl.linux,
|
||||||
path: AssetAbsolutePath(Uri.file('libbar.so')),
|
architecture: ArchitectureImpl.x64,
|
||||||
|
file: Uri.file('libbar.so'),
|
||||||
),
|
),
|
||||||
Asset(
|
NativeCodeAssetImpl(
|
||||||
id: 'package:bar/bar.dart',
|
id: 'package:bar/bar.dart',
|
||||||
linkMode: LinkMode.dynamic,
|
linkMode: DynamicLoadingBundledImpl(),
|
||||||
target: native_assets_cli.Target.linuxArm64,
|
os: OSImpl.linux,
|
||||||
path: AssetAbsolutePath(Uri.file('libbar.so')),
|
architecture: ArchitectureImpl.arm64,
|
||||||
|
file: Uri.file('libbar.so'),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
@ -284,12 +284,13 @@ void main() {
|
||||||
Package('bar', projectUri),
|
Package('bar', projectUri),
|
||||||
],
|
],
|
||||||
buildResult: FakeNativeAssetsBuilderResult(
|
buildResult: FakeNativeAssetsBuilderResult(
|
||||||
assets: <Asset>[
|
assets: <AssetImpl>[
|
||||||
Asset(
|
NativeCodeAssetImpl(
|
||||||
id: 'package:bar/bar.dart',
|
id: 'package:bar/bar.dart',
|
||||||
linkMode: LinkMode.dynamic,
|
linkMode: DynamicLoadingBundledImpl(),
|
||||||
target: native_assets_cli.Target.linuxX64,
|
os: OSImpl.linux,
|
||||||
path: AssetAbsolutePath(dylibAfterCompiling.uri),
|
architecture: ArchitectureImpl.x64,
|
||||||
|
file: dylibAfterCompiling.uri,
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
@ -337,18 +338,20 @@ void main() {
|
||||||
Package('bar', projectUri),
|
Package('bar', projectUri),
|
||||||
],
|
],
|
||||||
dryRunResult: FakeNativeAssetsBuilderResult(
|
dryRunResult: FakeNativeAssetsBuilderResult(
|
||||||
assets: <Asset>[
|
assets: <AssetImpl>[
|
||||||
Asset(
|
NativeCodeAssetImpl(
|
||||||
id: 'package:bar/bar.dart',
|
id: 'package:bar/bar.dart',
|
||||||
linkMode: LinkMode.static,
|
linkMode: StaticLinkingImpl(),
|
||||||
target: native_assets_cli.Target.macOSArm64,
|
os: OSImpl.macOS,
|
||||||
path: AssetAbsolutePath(Uri.file('bar.a')),
|
architecture: ArchitectureImpl.arm64,
|
||||||
|
file: Uri.file('bar.a'),
|
||||||
),
|
),
|
||||||
Asset(
|
NativeCodeAssetImpl(
|
||||||
id: 'package:bar/bar.dart',
|
id: 'package:bar/bar.dart',
|
||||||
linkMode: LinkMode.static,
|
linkMode: StaticLinkingImpl(),
|
||||||
target: native_assets_cli.Target.macOSX64,
|
os: OSImpl.macOS,
|
||||||
path: AssetAbsolutePath(Uri.file('bar.a')),
|
architecture: ArchitectureImpl.x64,
|
||||||
|
file: Uri.file('bar.a'),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
@ -460,12 +463,13 @@ void main() {
|
||||||
);
|
);
|
||||||
final NativeAssetsBuildRunner runner =
|
final NativeAssetsBuildRunner runner =
|
||||||
NativeAssetsBuildRunnerImpl(projectUri, packageConfig, fileSystem, logger);
|
NativeAssetsBuildRunnerImpl(projectUri, packageConfig, fileSystem, logger);
|
||||||
final CCompilerConfig result = await runner.cCompilerConfig;
|
final CCompilerConfigImpl result = await runner.cCompilerConfig;
|
||||||
expect(result.cc, Uri.file('/some/path/to/clang'));
|
expect(result.compiler, Uri.file('/some/path/to/clang'));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
class _BuildRunnerWithoutClang extends FakeNativeAssetsBuildRunner {
|
class _BuildRunnerWithoutClang extends FakeNativeAssetsBuildRunner {
|
||||||
@override
|
@override
|
||||||
Future<CCompilerConfig> get cCompilerConfig async => throwToolExit('Failed to find clang++ on the PATH.');
|
Future<CCompilerConfigImpl> get cCompilerConfig async =>
|
||||||
|
throwToolExit('Failed to find clang++ on the PATH.');
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,7 @@ import 'package:flutter_tools/src/globals.dart' as globals;
|
||||||
import 'package:flutter_tools/src/isolated/native_assets/macos/native_assets.dart';
|
import 'package:flutter_tools/src/isolated/native_assets/macos/native_assets.dart';
|
||||||
import 'package:flutter_tools/src/isolated/native_assets/native_assets.dart';
|
import 'package:flutter_tools/src/isolated/native_assets/native_assets.dart';
|
||||||
import 'package:native_assets_cli/native_assets_cli_internal.dart'
|
import 'package:native_assets_cli/native_assets_cli_internal.dart'
|
||||||
hide BuildMode, Target;
|
hide Target;
|
||||||
import 'package:native_assets_cli/native_assets_cli_internal.dart'
|
import 'package:native_assets_cli/native_assets_cli_internal.dart'
|
||||||
as native_assets_cli;
|
as native_assets_cli;
|
||||||
import 'package:package_config/package_config_types.dart';
|
import 'package:package_config/package_config_types.dart';
|
||||||
|
@ -146,18 +146,20 @@ void main() {
|
||||||
Package('bar', projectUri),
|
Package('bar', projectUri),
|
||||||
],
|
],
|
||||||
dryRunResult: FakeNativeAssetsBuilderResult(
|
dryRunResult: FakeNativeAssetsBuilderResult(
|
||||||
assets: <Asset>[
|
assets: <AssetImpl>[
|
||||||
Asset(
|
NativeCodeAssetImpl(
|
||||||
id: 'package:bar/bar.dart',
|
id: 'package:bar/bar.dart',
|
||||||
linkMode: LinkMode.dynamic,
|
linkMode: DynamicLoadingBundledImpl(),
|
||||||
target: native_assets_cli.Target.macOSArm64,
|
os: OSImpl.macOS,
|
||||||
path: AssetAbsolutePath(Uri.file('libbar.dylib')),
|
architecture: ArchitectureImpl.arm64,
|
||||||
|
file: Uri.file('libbar.dylib'),
|
||||||
),
|
),
|
||||||
Asset(
|
NativeCodeAssetImpl(
|
||||||
id: 'package:bar/bar.dart',
|
id: 'package:bar/bar.dart',
|
||||||
linkMode: LinkMode.dynamic,
|
linkMode: DynamicLoadingBundledImpl(),
|
||||||
target: native_assets_cli.Target.macOSX64,
|
os: OSImpl.macOS,
|
||||||
path: AssetAbsolutePath(Uri.file('libbar.dylib')),
|
architecture: ArchitectureImpl.x64,
|
||||||
|
file: Uri.file('libbar.dylib'),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
@ -302,12 +304,13 @@ void main() {
|
||||||
Package('bar', projectUri),
|
Package('bar', projectUri),
|
||||||
],
|
],
|
||||||
onBuild: (native_assets_cli.Target target) => FakeNativeAssetsBuilderResult(
|
onBuild: (native_assets_cli.Target target) => FakeNativeAssetsBuilderResult(
|
||||||
assets: <Asset>[
|
assets: <AssetImpl>[
|
||||||
Asset(
|
NativeCodeAssetImpl(
|
||||||
id: 'package:bar/bar.dart',
|
id: 'package:bar/bar.dart',
|
||||||
linkMode: LinkMode.dynamic,
|
linkMode: DynamicLoadingBundledImpl(),
|
||||||
target: target,
|
os: target.os,
|
||||||
path: AssetAbsolutePath(Uri.file('${target.architecture}/libbar.dylib')),
|
architecture: target.architecture,
|
||||||
|
file: Uri.file('${target.architecture}/libbar.dylib'),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
@ -355,18 +358,20 @@ void main() {
|
||||||
Package('bar', projectUri),
|
Package('bar', projectUri),
|
||||||
],
|
],
|
||||||
dryRunResult: FakeNativeAssetsBuilderResult(
|
dryRunResult: FakeNativeAssetsBuilderResult(
|
||||||
assets: <Asset>[
|
assets: <AssetImpl>[
|
||||||
Asset(
|
NativeCodeAssetImpl(
|
||||||
id: 'package:bar/bar.dart',
|
id: 'package:bar/bar.dart',
|
||||||
linkMode: LinkMode.static,
|
linkMode: StaticLinkingImpl(),
|
||||||
target: native_assets_cli.Target.macOSArm64,
|
os: OSImpl.macOS,
|
||||||
path: AssetAbsolutePath(Uri.file('bar.a')),
|
architecture: ArchitectureImpl.arm64,
|
||||||
|
file: Uri.file('bar.a'),
|
||||||
),
|
),
|
||||||
Asset(
|
NativeCodeAssetImpl(
|
||||||
id: 'package:bar/bar.dart',
|
id: 'package:bar/bar.dart',
|
||||||
linkMode: LinkMode.static,
|
linkMode: StaticLinkingImpl(),
|
||||||
target: native_assets_cli.Target.macOSX64,
|
os: OSImpl.macOS,
|
||||||
path: AssetAbsolutePath(Uri.file('bar.a')),
|
architecture: ArchitectureImpl.x64,
|
||||||
|
file: Uri.file('bar.a'),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
@ -479,9 +484,9 @@ InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault
|
||||||
fileSystem,
|
fileSystem,
|
||||||
logger,
|
logger,
|
||||||
);
|
);
|
||||||
final CCompilerConfig result = await runner.cCompilerConfig;
|
final CCompilerConfigImpl result = await runner.cCompilerConfig;
|
||||||
expect(
|
expect(
|
||||||
result.cc,
|
result.compiler,
|
||||||
Uri.file(
|
Uri.file(
|
||||||
'/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang',
|
'/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang',
|
||||||
),
|
),
|
||||||
|
|
|
@ -17,9 +17,7 @@ import 'package:flutter_tools/src/globals.dart' as globals;
|
||||||
import 'package:flutter_tools/src/isolated/native_assets/native_assets.dart';
|
import 'package:flutter_tools/src/isolated/native_assets/native_assets.dart';
|
||||||
import 'package:flutter_tools/src/isolated/native_assets/windows/native_assets.dart';
|
import 'package:flutter_tools/src/isolated/native_assets/windows/native_assets.dart';
|
||||||
import 'package:native_assets_cli/native_assets_cli_internal.dart'
|
import 'package:native_assets_cli/native_assets_cli_internal.dart'
|
||||||
hide BuildMode, Target;
|
hide Target;
|
||||||
import 'package:native_assets_cli/native_assets_cli_internal.dart'
|
|
||||||
as native_assets_cli;
|
|
||||||
import 'package:package_config/package_config_types.dart';
|
import 'package:package_config/package_config_types.dart';
|
||||||
|
|
||||||
import '../../../src/common.dart';
|
import '../../../src/common.dart';
|
||||||
|
@ -145,12 +143,13 @@ void main() {
|
||||||
Package('bar', projectUri),
|
Package('bar', projectUri),
|
||||||
],
|
],
|
||||||
dryRunResult: FakeNativeAssetsBuilderResult(
|
dryRunResult: FakeNativeAssetsBuilderResult(
|
||||||
assets: <Asset>[
|
assets: <AssetImpl>[
|
||||||
Asset(
|
NativeCodeAssetImpl(
|
||||||
id: 'package:bar/bar.dart',
|
id: 'package:bar/bar.dart',
|
||||||
linkMode: LinkMode.dynamic,
|
linkMode: DynamicLoadingBundledImpl(),
|
||||||
target: native_assets_cli.Target.windowsX64,
|
os: OSImpl.windows,
|
||||||
path: AssetAbsolutePath(Uri.file('bar.dll')),
|
architecture: ArchitectureImpl.x64,
|
||||||
|
file: Uri.file('bar.dll'),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
@ -255,12 +254,13 @@ void main() {
|
||||||
Package('bar', projectUri),
|
Package('bar', projectUri),
|
||||||
],
|
],
|
||||||
buildResult: FakeNativeAssetsBuilderResult(
|
buildResult: FakeNativeAssetsBuilderResult(
|
||||||
assets: <Asset>[
|
assets: <AssetImpl>[
|
||||||
Asset(
|
NativeCodeAssetImpl(
|
||||||
id: 'package:bar/bar.dart',
|
id: 'package:bar/bar.dart',
|
||||||
linkMode: LinkMode.dynamic,
|
linkMode: DynamicLoadingBundledImpl(),
|
||||||
target: native_assets_cli.Target.windowsX64,
|
os: OSImpl.windows,
|
||||||
path: AssetAbsolutePath(dylibAfterCompiling.uri),
|
architecture: ArchitectureImpl.x64,
|
||||||
|
file: dylibAfterCompiling.uri,
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
@ -308,12 +308,13 @@ void main() {
|
||||||
Package('bar', projectUri),
|
Package('bar', projectUri),
|
||||||
],
|
],
|
||||||
dryRunResult: FakeNativeAssetsBuilderResult(
|
dryRunResult: FakeNativeAssetsBuilderResult(
|
||||||
assets: <Asset>[
|
assets: <AssetImpl>[
|
||||||
Asset(
|
NativeCodeAssetImpl(
|
||||||
id: 'package:bar/bar.dart',
|
id: 'package:bar/bar.dart',
|
||||||
linkMode: LinkMode.static,
|
linkMode: StaticLinkingImpl(),
|
||||||
target: native_assets_cli.Target.windowsX64,
|
os: OSImpl.windows,
|
||||||
path: AssetAbsolutePath(Uri.file(OS.windows.staticlibFileName('bar'))),
|
architecture: ArchitectureImpl.x64,
|
||||||
|
file: Uri.file(OSImpl.windows.staticlibFileName('bar')),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
@ -492,10 +493,19 @@ void main() {
|
||||||
fileSystem,
|
fileSystem,
|
||||||
logger,
|
logger,
|
||||||
);
|
);
|
||||||
final CCompilerConfig result = await runner.cCompilerConfig;
|
final CCompilerConfigImpl result = await runner.cCompilerConfig;
|
||||||
expect(result.cc?.toFilePath(), msvcBinDir.childFile('cl.exe').uri.toFilePath());
|
expect(
|
||||||
expect(result.ar?.toFilePath(), msvcBinDir.childFile('lib.exe').uri.toFilePath());
|
result.compiler?.toFilePath(),
|
||||||
expect(result.ld?.toFilePath(), msvcBinDir.childFile('link.exe').uri.toFilePath());
|
msvcBinDir.childFile('cl.exe').uri.toFilePath(),
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
result.archiver?.toFilePath(),
|
||||||
|
msvcBinDir.childFile('lib.exe').uri.toFilePath(),
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
result.linker?.toFilePath(),
|
||||||
|
msvcBinDir.childFile('link.exe').uri.toFilePath(),
|
||||||
|
);
|
||||||
expect(result.envScript, isNotNull);
|
expect(result.envScript, isNotNull);
|
||||||
expect(result.envScriptArgs, isNotNull);
|
expect(result.envScriptArgs, isNotNull);
|
||||||
});
|
});
|
||||||
|
|
|
@ -227,16 +227,17 @@ void main() {
|
||||||
testWithoutContext('flutter build $buildSubcommand error on static libraries', () async {
|
testWithoutContext('flutter build $buildSubcommand error on static libraries', () async {
|
||||||
await inTempDir((Directory tempDirectory) async {
|
await inTempDir((Directory tempDirectory) async {
|
||||||
final Directory packageDirectory = await createTestProject(packageName, tempDirectory);
|
final Directory packageDirectory = await createTestProject(packageName, tempDirectory);
|
||||||
final File buildDotDart = packageDirectory.childFile('build.dart');
|
final File buildDotDart =
|
||||||
|
packageDirectory.childDirectory('hook').childFile('build.dart');
|
||||||
final String buildDotDartContents = await buildDotDart.readAsString();
|
final String buildDotDartContents = await buildDotDart.readAsString();
|
||||||
// Overrides the build to output static libraries.
|
// Overrides the build to output static libraries.
|
||||||
final String buildDotDartContentsNew = buildDotDartContents.replaceFirst(
|
final String buildDotDartContentsNew = buildDotDartContents.replaceFirst(
|
||||||
'final buildConfig = await BuildConfig.fromArgs(args);',
|
'await build(args, (config, output) async {',
|
||||||
'''
|
'''
|
||||||
final buildConfig = await BuildConfig.fromArgs([
|
await build([
|
||||||
'-D${LinkModePreference.configKey}=${LinkModePreference.static}',
|
'-D${LinkModePreferenceImpl.configKey}=${LinkModePreferenceImpl.static}',
|
||||||
...args,
|
...args,
|
||||||
]);
|
], (config, output) async {
|
||||||
''',
|
''',
|
||||||
);
|
);
|
||||||
expect(buildDotDartContentsNew, isNot(buildDotDartContents));
|
expect(buildDotDartContentsNew, isNot(buildDotDartContents));
|
||||||
|
@ -344,7 +345,7 @@ void expectDylibIsBundledIos(Directory appDirectory, String buildMode) {
|
||||||
/// Sample path: build/linux/x64/release/bundle/lib/libmy_package.so
|
/// Sample path: build/linux/x64/release/bundle/lib/libmy_package.so
|
||||||
void expectDylibIsBundledLinux(Directory appDirectory, String buildMode) {
|
void expectDylibIsBundledLinux(Directory appDirectory, String buildMode) {
|
||||||
// Linux does not support cross compilation, so always only check current architecture.
|
// Linux does not support cross compilation, so always only check current architecture.
|
||||||
final String architecture = Architecture.current.dartPlatform;
|
final String architecture = ArchitectureImpl.current.dartPlatform;
|
||||||
final Directory appBundle = appDirectory
|
final Directory appBundle = appDirectory
|
||||||
.childDirectory('build')
|
.childDirectory('build')
|
||||||
.childDirectory(hostOs)
|
.childDirectory(hostOs)
|
||||||
|
@ -354,7 +355,8 @@ void expectDylibIsBundledLinux(Directory appDirectory, String buildMode) {
|
||||||
expect(appBundle, exists);
|
expect(appBundle, exists);
|
||||||
final Directory dylibsFolder = appBundle.childDirectory('lib');
|
final Directory dylibsFolder = appBundle.childDirectory('lib');
|
||||||
expect(dylibsFolder, exists);
|
expect(dylibsFolder, exists);
|
||||||
final File dylib = dylibsFolder.childFile(OS.linux.dylibFileName(packageName));
|
final File dylib =
|
||||||
|
dylibsFolder.childFile(OSImpl.linux.dylibFileName(packageName));
|
||||||
expect(dylib, exists);
|
expect(dylib, exists);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -363,7 +365,7 @@ void expectDylibIsBundledLinux(Directory appDirectory, String buildMode) {
|
||||||
/// Sample path: build\windows\x64\runner\Debug\my_package_example.exe
|
/// Sample path: build\windows\x64\runner\Debug\my_package_example.exe
|
||||||
void expectDylibIsBundledWindows(Directory appDirectory, String buildMode) {
|
void expectDylibIsBundledWindows(Directory appDirectory, String buildMode) {
|
||||||
// Linux does not support cross compilation, so always only check current architecture.
|
// Linux does not support cross compilation, so always only check current architecture.
|
||||||
final String architecture = Architecture.current.dartPlatform;
|
final String architecture = ArchitectureImpl.current.dartPlatform;
|
||||||
final Directory appBundle = appDirectory
|
final Directory appBundle = appDirectory
|
||||||
.childDirectory('build')
|
.childDirectory('build')
|
||||||
.childDirectory(hostOs)
|
.childDirectory(hostOs)
|
||||||
|
@ -371,7 +373,8 @@ void expectDylibIsBundledWindows(Directory appDirectory, String buildMode) {
|
||||||
.childDirectory('runner')
|
.childDirectory('runner')
|
||||||
.childDirectory(buildMode.upperCaseFirst());
|
.childDirectory(buildMode.upperCaseFirst());
|
||||||
expect(appBundle, exists);
|
expect(appBundle, exists);
|
||||||
final File dylib = appBundle.childFile(OS.windows.dylibFileName(packageName));
|
final File dylib =
|
||||||
|
appBundle.childFile(OSImpl.windows.dylibFileName(packageName));
|
||||||
expect(dylib, exists);
|
expect(dylib, exists);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -401,7 +404,8 @@ void expectDylibIsBundledAndroid(Directory appDirectory, String buildMode) {
|
||||||
if (buildMode != 'debug') {
|
if (buildMode != 'debug') {
|
||||||
expect(archDir.childFile('libapp.so'), exists);
|
expect(archDir.childFile('libapp.so'), exists);
|
||||||
}
|
}
|
||||||
final File dylib = archDir.childFile(OS.android.dylibFileName(packageName));
|
final File dylib =
|
||||||
|
archDir.childFile(OSImpl.android.dylibFileName(packageName));
|
||||||
expect(dylib, exists);
|
expect(dylib, exists);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -424,14 +428,14 @@ void expectDylibIsBundledWithFrameworks(Directory appDirectory, String buildMode
|
||||||
void expectCCompilerIsConfigured(Directory appDirectory) {
|
void expectCCompilerIsConfigured(Directory appDirectory) {
|
||||||
final Directory nativeAssetsBuilderDir = appDirectory.childDirectory('.dart_tool/native_assets_builder/');
|
final Directory nativeAssetsBuilderDir = appDirectory.childDirectory('.dart_tool/native_assets_builder/');
|
||||||
for (final Directory subDir in nativeAssetsBuilderDir.listSync().whereType<Directory>()) {
|
for (final Directory subDir in nativeAssetsBuilderDir.listSync().whereType<Directory>()) {
|
||||||
final File config = subDir.childFile('config.yaml');
|
final File config = subDir.childFile('config.json');
|
||||||
expect(config, exists);
|
expect(config, exists);
|
||||||
final String contents = config.readAsStringSync();
|
final String contents = config.readAsStringSync();
|
||||||
// Dry run does not pass compiler info.
|
// Dry run does not pass compiler info.
|
||||||
if (contents.contains('dry_run: true')) {
|
if (contents.contains('"dry_run": true')) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
expect(contents, contains('cc: '));
|
expect(contents, contains('"cc": '));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue