Reland "[flutter_tools] Cleanup of native asset related code (removes around 50% of the native asset related code) (#155430)" (#155745)
Changes to original CL: The code that issues an error on unsupported
operating system in the dry-run case was missing a case for iOS and
Android
Original CL description
tl;dr Removes 50% (>1650 locs) of native asset related code in
`packages/flutter_tools`
Before this PR the invocation of dart build/link/dry-run was implemented
per OS. This lead to very large code duplication of almost identical,
but slightly different code. It also led to similarly duplicated test
code.
Almost the entire dart build/link/dry-run implementation is identical
across OSes. There's small variations:
- configuration of the build (e.g. android/macos/ios version, ios sdk,
...)
- determining target locations & copying the final shared libraries
This PR unifies the implementation by reducing the code to basically two
main functions:
* `runFlutterSpecificDartBuild` which is responsible for
- obtain flutter configuration
- perform dart build (& link)
- determine target location & install binaries
* `runFlutterSpecificDartDryRunOnPlatforms` which is responsible for a
similar (but not same):
- obtain flutter configuration
- perform dart dry run
- determine target location
these two functions will call out to helpers for the OS specific
functionality:
* `_assetTargetLocationsForOS` for determining the location of the code
assets
* `_copyNativeCodeAssetsForOS` for copying the code assets (and possibly
overriting the install name, etc)
=> Since we get rid of the code duplication across OSes and have only a
single code path for the build/link/dry-run, we can also remove the
duplicated tests that were pretty much identical across OSes.
We also harden the building code by adding asserts, e.g.
* the dry fun functionality should never be used by `flutter test`
* the `build/native_assets/<os>/native_assets.yaml` should only be used
by `flutter test` and the dry-run of `flutter run`
=> We change the tests to also comply with these invariants (so the
tests are not testing things that cannot happen in reality)
We also rename `{,Flutter}NativeAssetsBuildRunner` to disambiguate it
from the `package:native_asset_builder`'s `NativeAssetsBuildRunner`.
This commit is contained in:
committed by
GitHub
parent
a5c7b068f8
commit
abcba1fa7e
@@ -3,22 +3,14 @@
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:meta/meta.dart';
|
||||
import 'package:native_assets_builder/native_assets_builder.dart' hide NativeAssetsBuildRunner;
|
||||
import 'package:native_assets_builder/native_assets_builder.dart';
|
||||
import 'package:package_config/package_config_types.dart';
|
||||
|
||||
import '../../android/gradle_utils.dart';
|
||||
import '../../base/common.dart';
|
||||
import '../../base/file_system.dart';
|
||||
import '../../base/platform.dart';
|
||||
import '../../build_info.dart';
|
||||
import '../../dart/package_map.dart';
|
||||
import '../../isolated/native_assets/android/native_assets.dart';
|
||||
import '../../isolated/native_assets/ios/native_assets.dart';
|
||||
import '../../isolated/native_assets/linux/native_assets.dart';
|
||||
import '../../isolated/native_assets/macos/native_assets.dart';
|
||||
import '../../isolated/native_assets/native_assets.dart';
|
||||
import '../../isolated/native_assets/windows/native_assets.dart';
|
||||
import '../../macos/xcode.dart';
|
||||
import '../build_system.dart';
|
||||
import '../depfile.dart';
|
||||
import '../exceptions.dart';
|
||||
@@ -43,20 +35,21 @@ import 'common.dart';
|
||||
/// rebuild.
|
||||
class NativeAssets extends Target {
|
||||
const NativeAssets({
|
||||
@visibleForTesting NativeAssetsBuildRunner? buildRunner,
|
||||
@visibleForTesting FlutterNativeAssetsBuildRunner? buildRunner,
|
||||
}) : _buildRunner = buildRunner;
|
||||
|
||||
final NativeAssetsBuildRunner? _buildRunner;
|
||||
final FlutterNativeAssetsBuildRunner? _buildRunner;
|
||||
|
||||
@override
|
||||
Future<void> build(Environment environment) async {
|
||||
final String? nativeAssetsEnvironment = environment.defines[kNativeAssets];
|
||||
final List<Uri> dependencies;
|
||||
final FileSystem fileSystem = environment.fileSystem;
|
||||
final File nativeAssetsFile = environment.buildDir.childFile('native_assets.yaml');
|
||||
final Uri nativeAssetsFileUri = environment.buildDir.childFile('native_assets.yaml').uri;
|
||||
|
||||
final DartBuildResult result;
|
||||
if (nativeAssetsEnvironment == 'false') {
|
||||
dependencies = <Uri>[];
|
||||
await writeNativeAssetsYaml(KernelAssets(), environment.buildDir.uri, fileSystem);
|
||||
result = const DartBuildResult.empty();
|
||||
await writeNativeAssetsYaml(KernelAssets(), nativeAssetsFileUri, fileSystem);
|
||||
} else {
|
||||
final String? targetPlatformEnvironment = environment.defines[kTargetPlatform];
|
||||
if (targetPlatformEnvironment == null) {
|
||||
@@ -69,8 +62,8 @@ class NativeAssets extends Target {
|
||||
fileSystem.file(environment.packageConfigPath),
|
||||
logger: environment.logger,
|
||||
);
|
||||
final NativeAssetsBuildRunner buildRunner = _buildRunner ??
|
||||
NativeAssetsBuildRunnerImpl(
|
||||
final FlutterNativeAssetsBuildRunner buildRunner = _buildRunner ??
|
||||
FlutterNativeAssetsBuildRunnerImpl(
|
||||
projectUri,
|
||||
environment.packageConfigPath,
|
||||
packageConfig,
|
||||
@@ -78,102 +71,22 @@ class NativeAssets extends Target {
|
||||
environment.logger,
|
||||
);
|
||||
|
||||
switch (targetPlatform) {
|
||||
case TargetPlatform.ios:
|
||||
dependencies = await _buildIOS(
|
||||
environment,
|
||||
projectUri,
|
||||
fileSystem,
|
||||
buildRunner,
|
||||
);
|
||||
case TargetPlatform.darwin:
|
||||
dependencies = await _buildMacOS(
|
||||
environment,
|
||||
projectUri,
|
||||
fileSystem,
|
||||
buildRunner,
|
||||
);
|
||||
case TargetPlatform.linux_arm64:
|
||||
case TargetPlatform.linux_x64:
|
||||
dependencies = await _buildLinux(
|
||||
environment,
|
||||
targetPlatform,
|
||||
projectUri,
|
||||
fileSystem,
|
||||
buildRunner,
|
||||
);
|
||||
case TargetPlatform.windows_arm64:
|
||||
case TargetPlatform.windows_x64:
|
||||
dependencies = await _buildWindows(
|
||||
environment,
|
||||
targetPlatform,
|
||||
projectUri,
|
||||
fileSystem,
|
||||
buildRunner,
|
||||
);
|
||||
case TargetPlatform.tester:
|
||||
if (const LocalPlatform().isMacOS) {
|
||||
(_, dependencies) = await buildNativeAssetsMacOS(
|
||||
buildMode: BuildMode.debug,
|
||||
projectUri: projectUri,
|
||||
codesignIdentity: environment.defines[kCodesignIdentity],
|
||||
yamlParentDirectory: environment.buildDir.uri,
|
||||
fileSystem: fileSystem,
|
||||
buildRunner: buildRunner,
|
||||
flutterTester: true,
|
||||
);
|
||||
} else if (const LocalPlatform().isLinux) {
|
||||
(_, dependencies) = await buildNativeAssetsLinux(
|
||||
buildMode: BuildMode.debug,
|
||||
projectUri: projectUri,
|
||||
yamlParentDirectory: environment.buildDir.uri,
|
||||
fileSystem: fileSystem,
|
||||
buildRunner: buildRunner,
|
||||
flutterTester: true,
|
||||
);
|
||||
} else if (const LocalPlatform().isWindows) {
|
||||
(_, dependencies) = await buildNativeAssetsWindows(
|
||||
buildMode: BuildMode.debug,
|
||||
projectUri: projectUri,
|
||||
yamlParentDirectory: environment.buildDir.uri,
|
||||
fileSystem: fileSystem,
|
||||
buildRunner: buildRunner,
|
||||
flutterTester: true,
|
||||
);
|
||||
} else {
|
||||
// TODO(dacoharkes): Implement other OSes. https://github.com/flutter/flutter/issues/129757
|
||||
// Write the file we claim to have in the [outputs].
|
||||
await writeNativeAssetsYaml(KernelAssets(), environment.buildDir.uri, fileSystem);
|
||||
dependencies = <Uri>[];
|
||||
}
|
||||
case TargetPlatform.android_arm:
|
||||
case TargetPlatform.android_arm64:
|
||||
case TargetPlatform.android_x64:
|
||||
case TargetPlatform.android_x86:
|
||||
case TargetPlatform.android:
|
||||
(_, dependencies) = await _buildAndroid(
|
||||
environment,
|
||||
targetPlatform,
|
||||
projectUri,
|
||||
fileSystem,
|
||||
buildRunner,
|
||||
);
|
||||
case TargetPlatform.fuchsia_arm64:
|
||||
case TargetPlatform.fuchsia_x64:
|
||||
case TargetPlatform.web_javascript:
|
||||
// TODO(dacoharkes): Implement other OSes. https://github.com/flutter/flutter/issues/129757
|
||||
// Write the file we claim to have in the [outputs].
|
||||
await writeNativeAssetsYaml(KernelAssets(), environment.buildDir.uri, fileSystem);
|
||||
dependencies = <Uri>[];
|
||||
}
|
||||
(result, _) = await runFlutterSpecificDartBuild(
|
||||
environmentDefines: environment.defines,
|
||||
buildRunner: buildRunner,
|
||||
targetPlatform: targetPlatform,
|
||||
projectUri: projectUri,
|
||||
nativeAssetsYamlUri : nativeAssetsFileUri,
|
||||
fileSystem: fileSystem,
|
||||
);
|
||||
}
|
||||
|
||||
final Depfile depfile = Depfile(
|
||||
<File>[
|
||||
for (final Uri dependency in dependencies) fileSystem.file(dependency),
|
||||
for (final Uri dependency in result.dependencies) fileSystem.file(dependency),
|
||||
],
|
||||
<File>[
|
||||
nativeAssetsFile,
|
||||
fileSystem.file(nativeAssetsFileUri),
|
||||
],
|
||||
);
|
||||
final File outputDepfile = environment.buildDir.childFile('native_assets.d');
|
||||
@@ -181,188 +94,14 @@ class NativeAssets extends Target {
|
||||
outputDepfile.parent.createSync(recursive: true);
|
||||
}
|
||||
environment.depFileService.writeToFile(depfile, outputDepfile);
|
||||
if (!await nativeAssetsFile.exists()) {
|
||||
throwToolExit("${nativeAssetsFile.path} doesn't exist.");
|
||||
if (!await fileSystem.file(nativeAssetsFileUri).exists()) {
|
||||
throwToolExit("${nativeAssetsFileUri.path} doesn't exist.");
|
||||
}
|
||||
if (!await outputDepfile.exists()) {
|
||||
throwToolExit("${outputDepfile.path} doesn't exist.");
|
||||
}
|
||||
}
|
||||
|
||||
Future<List<Uri>> _buildWindows(
|
||||
Environment environment,
|
||||
TargetPlatform targetPlatform,
|
||||
Uri projectUri,
|
||||
FileSystem fileSystem,
|
||||
NativeAssetsBuildRunner buildRunner,
|
||||
) async {
|
||||
final String? environmentBuildMode = environment.defines[kBuildMode];
|
||||
if (environmentBuildMode == null) {
|
||||
throw MissingDefineException(kBuildMode, name);
|
||||
}
|
||||
final BuildMode buildMode = BuildMode.fromCliName(environmentBuildMode);
|
||||
final (_, List<Uri> dependencies) = await buildNativeAssetsWindows(
|
||||
targetPlatform: targetPlatform,
|
||||
buildMode: buildMode,
|
||||
projectUri: projectUri,
|
||||
yamlParentDirectory: environment.buildDir.uri,
|
||||
fileSystem: fileSystem,
|
||||
buildRunner: buildRunner,
|
||||
);
|
||||
return dependencies;
|
||||
}
|
||||
|
||||
Future<List<Uri>> _buildLinux(
|
||||
Environment environment,
|
||||
TargetPlatform targetPlatform,
|
||||
Uri projectUri,
|
||||
FileSystem fileSystem,
|
||||
NativeAssetsBuildRunner buildRunner,
|
||||
) async {
|
||||
final String? environmentBuildMode = environment.defines[kBuildMode];
|
||||
if (environmentBuildMode == null) {
|
||||
throw MissingDefineException(kBuildMode, name);
|
||||
}
|
||||
final BuildMode buildMode = BuildMode.fromCliName(environmentBuildMode);
|
||||
final (_, List<Uri> dependencies) = await buildNativeAssetsLinux(
|
||||
targetPlatform: targetPlatform,
|
||||
buildMode: buildMode,
|
||||
projectUri: projectUri,
|
||||
yamlParentDirectory: environment.buildDir.uri,
|
||||
fileSystem: fileSystem,
|
||||
buildRunner: buildRunner,
|
||||
);
|
||||
return dependencies;
|
||||
}
|
||||
|
||||
Future<List<Uri>> _buildMacOS(
|
||||
Environment environment,
|
||||
Uri projectUri,
|
||||
FileSystem fileSystem,
|
||||
NativeAssetsBuildRunner buildRunner,
|
||||
) async {
|
||||
final List<DarwinArch> darwinArchs =
|
||||
_emptyToNull(environment.defines[kDarwinArchs])
|
||||
?.split(' ')
|
||||
.map(getDarwinArchForName)
|
||||
.toList() ??
|
||||
<DarwinArch>[DarwinArch.x86_64, DarwinArch.arm64];
|
||||
final String? environmentBuildMode = environment.defines[kBuildMode];
|
||||
if (environmentBuildMode == null) {
|
||||
throw MissingDefineException(kBuildMode, name);
|
||||
}
|
||||
final BuildMode buildMode = BuildMode.fromCliName(environmentBuildMode);
|
||||
final (_, List<Uri> dependencies) = await buildNativeAssetsMacOS(
|
||||
darwinArchs: darwinArchs,
|
||||
buildMode: buildMode,
|
||||
projectUri: projectUri,
|
||||
codesignIdentity: environment.defines[kCodesignIdentity],
|
||||
yamlParentDirectory: environment.buildDir.uri,
|
||||
fileSystem: fileSystem,
|
||||
buildRunner: buildRunner,
|
||||
);
|
||||
return dependencies;
|
||||
}
|
||||
|
||||
Future<List<Uri>> _buildIOS(
|
||||
Environment environment,
|
||||
Uri projectUri,
|
||||
FileSystem fileSystem,
|
||||
NativeAssetsBuildRunner buildRunner,
|
||||
) {
|
||||
final List<DarwinArch> iosArchs =
|
||||
_emptyToNull(environment.defines[kIosArchs])
|
||||
?.split(' ')
|
||||
.map(getIOSArchForName)
|
||||
.toList() ??
|
||||
<DarwinArch>[DarwinArch.arm64];
|
||||
final String? environmentBuildMode = environment.defines[kBuildMode];
|
||||
if (environmentBuildMode == null) {
|
||||
throw MissingDefineException(kBuildMode, name);
|
||||
}
|
||||
final BuildMode buildMode = BuildMode.fromCliName(environmentBuildMode);
|
||||
final String? sdkRoot = environment.defines[kSdkRoot];
|
||||
if (sdkRoot == null) {
|
||||
throw MissingDefineException(kSdkRoot, name);
|
||||
}
|
||||
final EnvironmentType environmentType =
|
||||
environmentTypeFromSdkroot(sdkRoot, environment.fileSystem)!;
|
||||
return buildNativeAssetsIOS(
|
||||
environmentType: environmentType,
|
||||
darwinArchs: iosArchs,
|
||||
buildMode: buildMode,
|
||||
projectUri: projectUri,
|
||||
codesignIdentity: environment.defines[kCodesignIdentity],
|
||||
fileSystem: fileSystem,
|
||||
buildRunner: buildRunner,
|
||||
yamlParentDirectory: environment.buildDir.uri,
|
||||
);
|
||||
}
|
||||
|
||||
Future<(Uri? nativeAssetsYaml, List<Uri> dependencies)> _buildAndroid(
|
||||
Environment environment,
|
||||
TargetPlatform targetPlatform,
|
||||
Uri projectUri,
|
||||
FileSystem fileSystem,
|
||||
NativeAssetsBuildRunner buildRunner) {
|
||||
final String? androidArchsEnvironment = environment.defines[kAndroidArchs];
|
||||
final List<AndroidArch> androidArchs = _androidArchs(
|
||||
targetPlatform,
|
||||
androidArchsEnvironment,
|
||||
);
|
||||
final int targetAndroidNdkApi =
|
||||
int.parse(environment.defines[kMinSdkVersion] ?? minSdkVersion);
|
||||
final String? environmentBuildMode = environment.defines[kBuildMode];
|
||||
if (environmentBuildMode == null) {
|
||||
throw MissingDefineException(kBuildMode, name);
|
||||
}
|
||||
final BuildMode buildMode = BuildMode.fromCliName(environmentBuildMode);
|
||||
return buildNativeAssetsAndroid(
|
||||
buildMode: buildMode,
|
||||
projectUri: projectUri,
|
||||
yamlParentDirectory: environment.buildDir.uri,
|
||||
fileSystem: fileSystem,
|
||||
buildRunner: buildRunner,
|
||||
androidArchs: androidArchs,
|
||||
targetAndroidNdkApi: targetAndroidNdkApi,
|
||||
);
|
||||
}
|
||||
|
||||
List<AndroidArch> _androidArchs(
|
||||
TargetPlatform targetPlatform,
|
||||
String? androidArchsEnvironment,
|
||||
) {
|
||||
switch (targetPlatform) {
|
||||
case TargetPlatform.android_arm:
|
||||
return <AndroidArch>[AndroidArch.armeabi_v7a];
|
||||
case TargetPlatform.android_arm64:
|
||||
return <AndroidArch>[AndroidArch.arm64_v8a];
|
||||
case TargetPlatform.android_x64:
|
||||
return <AndroidArch>[AndroidArch.x86_64];
|
||||
case TargetPlatform.android_x86:
|
||||
return <AndroidArch>[AndroidArch.x86];
|
||||
case TargetPlatform.android:
|
||||
if (androidArchsEnvironment == null) {
|
||||
throw MissingDefineException(kAndroidArchs, name);
|
||||
}
|
||||
return androidArchsEnvironment
|
||||
.split(' ')
|
||||
.map(getAndroidArchForName)
|
||||
.toList();
|
||||
case TargetPlatform.darwin:
|
||||
case TargetPlatform.fuchsia_arm64:
|
||||
case TargetPlatform.fuchsia_x64:
|
||||
case TargetPlatform.ios:
|
||||
case TargetPlatform.linux_arm64:
|
||||
case TargetPlatform.linux_x64:
|
||||
case TargetPlatform.tester:
|
||||
case TargetPlatform.web_javascript:
|
||||
case TargetPlatform.windows_x64:
|
||||
case TargetPlatform.windows_arm64:
|
||||
throwToolExit('Unsupported Android target platform: $targetPlatform.');
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
List<String> get depfiles => <String>[
|
||||
'native_assets.d',
|
||||
@@ -390,10 +129,3 @@ class NativeAssets extends Target {
|
||||
Source.pattern('{BUILD_DIR}/native_assets.yaml'),
|
||||
];
|
||||
}
|
||||
|
||||
String? _emptyToNull(String? input) {
|
||||
if (input == null || input.isEmpty) {
|
||||
return null;
|
||||
}
|
||||
return input;
|
||||
}
|
||||
|
||||
@@ -2,145 +2,24 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:native_assets_builder/native_assets_builder.dart'
|
||||
hide NativeAssetsBuildRunner;
|
||||
import 'package:native_assets_builder/native_assets_builder.dart';
|
||||
import 'package:native_assets_cli/native_assets_cli.dart';
|
||||
import 'package:native_assets_cli/native_assets_cli_internal.dart';
|
||||
|
||||
import '../../../android/android_sdk.dart';
|
||||
import '../../../android/gradle_utils.dart';
|
||||
import '../../../base/common.dart';
|
||||
import '../../../base/file_system.dart';
|
||||
import '../../../build_info.dart';
|
||||
import '../../../build_info.dart' hide BuildMode;
|
||||
import '../../../globals.dart' as globals;
|
||||
import '../native_assets.dart';
|
||||
|
||||
/// Dry run the native builds.
|
||||
///
|
||||
/// This does not build native assets, it only simulates what the final paths
|
||||
/// of all assets will be so that this can be embedded in the kernel file.
|
||||
Future<Uri?> dryRunNativeAssetsAndroid({
|
||||
required NativeAssetsBuildRunner buildRunner,
|
||||
required Uri projectUri,
|
||||
bool flutterTester = false,
|
||||
required FileSystem fileSystem,
|
||||
}) async {
|
||||
if (!await nativeBuildRequired(buildRunner)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final Uri buildUri_ = nativeAssetsBuildUri(projectUri, OSImpl.android);
|
||||
final Iterable<KernelAsset> nativeAssetPaths =
|
||||
await dryRunNativeAssetsAndroidInternal(
|
||||
fileSystem,
|
||||
projectUri,
|
||||
buildRunner,
|
||||
);
|
||||
final Uri nativeAssetsUri = await writeNativeAssetsYaml(
|
||||
KernelAssets(nativeAssetPaths),
|
||||
buildUri_,
|
||||
fileSystem,
|
||||
);
|
||||
return nativeAssetsUri;
|
||||
int targetAndroidNdkApi(Map<String, String> environmentDefines) {
|
||||
return int.parse(environmentDefines[kMinSdkVersion] ?? minSdkVersion);
|
||||
}
|
||||
|
||||
Future<Iterable<KernelAsset>> dryRunNativeAssetsAndroidInternal(
|
||||
FileSystem fileSystem,
|
||||
Uri projectUri,
|
||||
NativeAssetsBuildRunner buildRunner,
|
||||
) async {
|
||||
const OSImpl targetOS = OSImpl.android;
|
||||
|
||||
globals.logger.printTrace('Dry running native assets for $targetOS.');
|
||||
final BuildDryRunResult buildDryRunResult = await buildRunner.buildDryRun(
|
||||
linkModePreference: LinkModePreferenceImpl.dynamic,
|
||||
targetOS: targetOS,
|
||||
workingDirectory: projectUri,
|
||||
includeParentEnvironment: true,
|
||||
);
|
||||
ensureNativeAssetsBuildDryRunSucceed(buildDryRunResult);
|
||||
// No link hooks in JIT mode.
|
||||
final List<AssetImpl> nativeAssets = buildDryRunResult.assets;
|
||||
globals.logger.printTrace('Dry running native assets for $targetOS done.');
|
||||
final Map<AssetImpl, KernelAsset> assetTargetLocations =
|
||||
_assetTargetLocations(nativeAssets);
|
||||
return assetTargetLocations.values;
|
||||
}
|
||||
|
||||
/// Builds native assets.
|
||||
Future<(Uri? nativeAssetsYaml, List<Uri> dependencies)>
|
||||
buildNativeAssetsAndroid({
|
||||
required NativeAssetsBuildRunner buildRunner,
|
||||
required Iterable<AndroidArch> androidArchs,
|
||||
required Uri projectUri,
|
||||
required BuildMode buildMode,
|
||||
String? codesignIdentity,
|
||||
Uri? yamlParentDirectory,
|
||||
required FileSystem fileSystem,
|
||||
required int targetAndroidNdkApi,
|
||||
}) async {
|
||||
const OSImpl targetOS = OSImpl.android;
|
||||
final Uri buildUri_ = nativeAssetsBuildUri(projectUri, targetOS);
|
||||
if (!await nativeBuildRequired(buildRunner)) {
|
||||
final Uri nativeAssetsYaml = await writeNativeAssetsYaml(
|
||||
KernelAssets(),
|
||||
yamlParentDirectory ?? buildUri_,
|
||||
fileSystem,
|
||||
);
|
||||
return (nativeAssetsYaml, <Uri>[]);
|
||||
}
|
||||
|
||||
final List<Target> targets = androidArchs.map(_getNativeTarget).toList();
|
||||
final BuildModeImpl buildModeCli =
|
||||
nativeAssetsBuildMode(buildMode);
|
||||
final bool linkingEnabled = buildModeCli == BuildModeImpl.release;
|
||||
|
||||
globals.logger
|
||||
.printTrace('Building native assets for $targets $buildModeCli.');
|
||||
final List<AssetImpl> nativeAssets = <AssetImpl>[];
|
||||
final Set<Uri> dependencies = <Uri>{};
|
||||
for (final Target target in targets) {
|
||||
final BuildResult buildResult = await buildRunner.build(
|
||||
linkModePreference: LinkModePreferenceImpl.dynamic,
|
||||
target: target,
|
||||
buildMode: buildModeCli,
|
||||
workingDirectory: projectUri,
|
||||
includeParentEnvironment: true,
|
||||
cCompilerConfig: await buildRunner.ndkCCompilerConfigImpl,
|
||||
targetAndroidNdkApi: targetAndroidNdkApi,
|
||||
linkingEnabled: linkingEnabled,
|
||||
);
|
||||
ensureNativeAssetsBuildSucceed(buildResult);
|
||||
nativeAssets.addAll(buildResult.assets);
|
||||
dependencies.addAll(buildResult.dependencies);
|
||||
if (linkingEnabled) {
|
||||
final LinkResult linkResult = await buildRunner.link(
|
||||
linkModePreference: LinkModePreferenceImpl.dynamic,
|
||||
target: target,
|
||||
buildMode: buildModeCli,
|
||||
workingDirectory: projectUri,
|
||||
includeParentEnvironment: true,
|
||||
cCompilerConfig: await buildRunner.ndkCCompilerConfigImpl,
|
||||
targetAndroidNdkApi: targetAndroidNdkApi,
|
||||
buildResult: buildResult,
|
||||
);
|
||||
ensureNativeAssetsLinkSucceed(linkResult);
|
||||
nativeAssets.addAll(linkResult.assets);
|
||||
dependencies.addAll(linkResult.dependencies);
|
||||
}
|
||||
}
|
||||
globals.logger.printTrace('Building native assets for $targets done.');
|
||||
final Map<AssetImpl, KernelAsset> assetTargetLocations =
|
||||
_assetTargetLocations(nativeAssets);
|
||||
await _copyNativeAssetsAndroid(buildUri_, assetTargetLocations, fileSystem);
|
||||
final Uri nativeAssetsUri = await writeNativeAssetsYaml(
|
||||
KernelAssets(assetTargetLocations.values),
|
||||
yamlParentDirectory ?? buildUri_,
|
||||
fileSystem);
|
||||
return (nativeAssetsUri, dependencies.toList());
|
||||
}
|
||||
|
||||
Future<void> _copyNativeAssetsAndroid(
|
||||
Future<void> copyNativeCodeAssetsAndroid(
|
||||
Uri buildUri,
|
||||
Map<AssetImpl, KernelAsset> assetTargetLocations,
|
||||
Map<NativeCodeAssetImpl, KernelAsset> assetTargetLocations,
|
||||
FileSystem fileSystem,
|
||||
) async {
|
||||
if (assetTargetLocations.isNotEmpty) {
|
||||
@@ -154,7 +33,7 @@ Future<void> _copyNativeAssetsAndroid(
|
||||
final Uri archUri = buildUri.resolve('jniLibs/lib/$jniArchDir/');
|
||||
await fileSystem.directory(archUri).create(recursive: true);
|
||||
}
|
||||
for (final MapEntry<AssetImpl, KernelAsset> assetMapping
|
||||
for (final MapEntry<NativeCodeAssetImpl, KernelAsset> assetMapping
|
||||
in assetTargetLocations.entries) {
|
||||
final Uri source = assetMapping.key.file!;
|
||||
final Uri target = (assetMapping.value.path as KernelAssetAbsolutePath).uri;
|
||||
@@ -171,7 +50,7 @@ Future<void> _copyNativeAssetsAndroid(
|
||||
}
|
||||
|
||||
/// Get the [Target] for [androidArch].
|
||||
Target _getNativeTarget(AndroidArch androidArch) {
|
||||
Target getNativeAndroidTarget(AndroidArch androidArch) {
|
||||
return switch (androidArch) {
|
||||
AndroidArch.armeabi_v7a => Target.androidArm,
|
||||
AndroidArch.arm64_v8a => Target.androidArm64,
|
||||
@@ -192,27 +71,27 @@ AndroidArch _getAndroidArch(Target target) {
|
||||
};
|
||||
}
|
||||
|
||||
Map<AssetImpl, KernelAsset> _assetTargetLocations(
|
||||
List<AssetImpl> nativeAssets) {
|
||||
return <AssetImpl, KernelAsset>{
|
||||
for (final AssetImpl asset in nativeAssets)
|
||||
Map<NativeCodeAssetImpl, KernelAsset> assetTargetLocationsAndroid(
|
||||
List<NativeCodeAssetImpl> nativeAssets) {
|
||||
return <NativeCodeAssetImpl, KernelAsset>{
|
||||
for (final NativeCodeAssetImpl asset in nativeAssets)
|
||||
asset: _targetLocationAndroid(asset),
|
||||
};
|
||||
}
|
||||
|
||||
/// Converts the `path` of [asset] as output from a `build.dart` invocation to
|
||||
/// the path used inside the Flutter app bundle.
|
||||
KernelAsset _targetLocationAndroid(AssetImpl asset) {
|
||||
final LinkModeImpl linkMode = (asset as NativeCodeAssetImpl).linkMode;
|
||||
KernelAsset _targetLocationAndroid(NativeCodeAssetImpl asset) {
|
||||
final LinkMode linkMode = asset.linkMode;
|
||||
final KernelAssetPath kernelAssetPath;
|
||||
switch (linkMode) {
|
||||
case DynamicLoadingSystemImpl _:
|
||||
case DynamicLoadingSystem _:
|
||||
kernelAssetPath = KernelAssetSystemPath(linkMode.uri);
|
||||
case LookupInExecutableImpl _:
|
||||
case LookupInExecutable _:
|
||||
kernelAssetPath = KernelAssetInExecutable();
|
||||
case LookupInProcessImpl _:
|
||||
case LookupInProcess _:
|
||||
kernelAssetPath = KernelAssetInProcess();
|
||||
case DynamicLoadingBundledImpl _:
|
||||
case DynamicLoadingBundled _:
|
||||
final String fileName = asset.file!.pathSegments.last;
|
||||
kernelAssetPath = KernelAssetAbsolutePath(Uri(path: fileName));
|
||||
default:
|
||||
@@ -234,7 +113,6 @@ KernelAsset _targetLocationAndroid(AssetImpl asset) {
|
||||
/// Should only be invoked if a native assets build is performed. If the native
|
||||
/// assets feature is disabled, or none of the packages have native assets, a
|
||||
/// missing NDK is okay.
|
||||
@override
|
||||
Future<CCompilerConfigImpl> cCompilerConfigAndroid() async {
|
||||
final AndroidSdk? androidSdk = AndroidSdk.locateAndroidSdk();
|
||||
if (androidSdk == null) {
|
||||
|
||||
@@ -2,147 +2,20 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:native_assets_builder/native_assets_builder.dart'
|
||||
hide NativeAssetsBuildRunner;
|
||||
import 'package:native_assets_builder/native_assets_builder.dart';
|
||||
import 'package:native_assets_cli/native_assets_cli.dart';
|
||||
import 'package:native_assets_cli/native_assets_cli_internal.dart';
|
||||
|
||||
import '../../../base/file_system.dart';
|
||||
import '../../../build_info.dart';
|
||||
import '../../../build_info.dart' hide BuildMode;
|
||||
import '../../../build_info.dart' as build_info;
|
||||
import '../../../globals.dart' as globals;
|
||||
import '../macos/native_assets_host.dart';
|
||||
import '../native_assets.dart';
|
||||
|
||||
/// Dry run the native builds.
|
||||
///
|
||||
/// This does not build native assets, it only simulates what the final paths
|
||||
/// of all assets will be so that this can be embedded in the kernel file and
|
||||
/// the Xcode project.
|
||||
Future<Uri?> dryRunNativeAssetsIOS({
|
||||
required NativeAssetsBuildRunner buildRunner,
|
||||
required Uri projectUri,
|
||||
required FileSystem fileSystem,
|
||||
}) async {
|
||||
if (!await nativeBuildRequired(buildRunner)) {
|
||||
return null;
|
||||
}
|
||||
// TODO(dcharkes): Fetch minimum iOS version from somewhere. https://github.com/flutter/flutter/issues/145104
|
||||
const int targetIOSVersion = 12;
|
||||
|
||||
final Uri buildUri = nativeAssetsBuildUri(projectUri, OSImpl.iOS);
|
||||
final Iterable<KernelAsset> assetTargetLocations = await dryRunNativeAssetsIOSInternal(
|
||||
fileSystem,
|
||||
projectUri,
|
||||
buildRunner,
|
||||
);
|
||||
final Uri nativeAssetsUri = await writeNativeAssetsYaml(
|
||||
KernelAssets(assetTargetLocations),
|
||||
buildUri,
|
||||
fileSystem,
|
||||
);
|
||||
return nativeAssetsUri;
|
||||
}
|
||||
|
||||
Future<Iterable<KernelAsset>> dryRunNativeAssetsIOSInternal(
|
||||
FileSystem fileSystem,
|
||||
Uri projectUri,
|
||||
NativeAssetsBuildRunner buildRunner,
|
||||
) async {
|
||||
const OSImpl targetOS = OSImpl.iOS;
|
||||
globals.logger.printTrace('Dry running native assets for $targetOS.');
|
||||
final BuildDryRunResult buildDryRunResult = await buildRunner.buildDryRun(
|
||||
linkModePreference: LinkModePreferenceImpl.dynamic,
|
||||
targetOS: targetOS,
|
||||
workingDirectory: projectUri,
|
||||
includeParentEnvironment: true,
|
||||
);
|
||||
ensureNativeAssetsBuildDryRunSucceed(buildDryRunResult);
|
||||
// No link hooks in JIT.
|
||||
final List<AssetImpl> nativeAssets = buildDryRunResult.assets;
|
||||
globals.logger.printTrace('Dry running native assets for $targetOS done.');
|
||||
return _assetTargetLocations(nativeAssets).values;
|
||||
}
|
||||
|
||||
/// Builds native assets.
|
||||
Future<List<Uri>> buildNativeAssetsIOS({
|
||||
required NativeAssetsBuildRunner buildRunner,
|
||||
required List<DarwinArch> darwinArchs,
|
||||
required EnvironmentType environmentType,
|
||||
required Uri projectUri,
|
||||
required BuildMode buildMode,
|
||||
String? codesignIdentity,
|
||||
required Uri yamlParentDirectory,
|
||||
required FileSystem fileSystem,
|
||||
}) async {
|
||||
if (!await nativeBuildRequired(buildRunner)) {
|
||||
await writeNativeAssetsYaml(KernelAssets(), yamlParentDirectory, fileSystem);
|
||||
return <Uri>[];
|
||||
}
|
||||
|
||||
final List<Target> targets = darwinArchs.map(_getNativeTarget).toList();
|
||||
final BuildModeImpl buildModeCli = nativeAssetsBuildMode(buildMode);
|
||||
final bool linkingEnabled = buildModeCli == BuildModeImpl.release;
|
||||
|
||||
const OSImpl targetOS = OSImpl.iOS;
|
||||
final Uri buildUri = nativeAssetsBuildUri(projectUri, targetOS);
|
||||
final IOSSdkImpl iosSdk = _getIOSSdkImpl(environmentType);
|
||||
|
||||
globals.logger.printTrace('Building native assets for $targets $buildModeCli.');
|
||||
final List<AssetImpl> nativeAssets = <AssetImpl>[];
|
||||
final Set<Uri> dependencies = <Uri>{};
|
||||
for (final Target target in targets) {
|
||||
final BuildResult buildResult = await buildRunner.build(
|
||||
linkModePreference: LinkModePreferenceImpl.dynamic,
|
||||
target: target,
|
||||
targetIOSSdkImpl: iosSdk,
|
||||
buildMode: buildModeCli,
|
||||
workingDirectory: projectUri,
|
||||
includeParentEnvironment: true,
|
||||
cCompilerConfig: await buildRunner.cCompilerConfig,
|
||||
// TODO(dcharkes): Fetch minimum iOS version from somewhere. https://github.com/flutter/flutter/issues/145104
|
||||
targetIOSVersion: 12,
|
||||
linkingEnabled: linkingEnabled,
|
||||
);
|
||||
ensureNativeAssetsBuildSucceed(buildResult);
|
||||
nativeAssets.addAll(buildResult.assets);
|
||||
dependencies.addAll(buildResult.dependencies);
|
||||
if (linkingEnabled) {
|
||||
final LinkResult linkResult = await buildRunner.link(
|
||||
linkModePreference: LinkModePreferenceImpl.dynamic,
|
||||
target: target,
|
||||
targetIOSSdkImpl: iosSdk,
|
||||
buildMode: buildModeCli,
|
||||
workingDirectory: projectUri,
|
||||
includeParentEnvironment: true,
|
||||
cCompilerConfig: await buildRunner.cCompilerConfig,
|
||||
buildResult: buildResult,
|
||||
// TODO(dcharkes): Fetch minimum iOS version from somewhere. https://github.com/flutter/flutter/issues/145104
|
||||
targetIOSVersion: 12,
|
||||
);
|
||||
ensureNativeAssetsLinkSucceed(linkResult);
|
||||
nativeAssets.addAll(linkResult.assets);
|
||||
dependencies.addAll(linkResult.dependencies);
|
||||
}
|
||||
}
|
||||
globals.logger.printTrace('Building native assets for $targets done.');
|
||||
final Map<KernelAssetPath, List<AssetImpl>> fatAssetTargetLocations =
|
||||
_fatAssetTargetLocations(nativeAssets);
|
||||
await _copyNativeAssetsIOS(
|
||||
buildUri,
|
||||
fatAssetTargetLocations,
|
||||
codesignIdentity,
|
||||
buildMode,
|
||||
fileSystem,
|
||||
);
|
||||
|
||||
final Map<AssetImpl, KernelAsset> assetTargetLocations =
|
||||
_assetTargetLocations(nativeAssets);
|
||||
await writeNativeAssetsYaml(
|
||||
KernelAssets(assetTargetLocations.values),
|
||||
yamlParentDirectory,
|
||||
fileSystem,
|
||||
);
|
||||
return dependencies.toList();
|
||||
}
|
||||
|
||||
IOSSdkImpl _getIOSSdkImpl(EnvironmentType environmentType) {
|
||||
IOSSdkImpl getIOSSdk(EnvironmentType environmentType) {
|
||||
return switch (environmentType) {
|
||||
EnvironmentType.physical => IOSSdkImpl.iPhoneOS,
|
||||
EnvironmentType.simulator => IOSSdkImpl.iPhoneSimulator,
|
||||
@@ -150,7 +23,7 @@ IOSSdkImpl _getIOSSdkImpl(EnvironmentType environmentType) {
|
||||
}
|
||||
|
||||
/// Extract the [Target] from a [DarwinArch].
|
||||
Target _getNativeTarget(DarwinArch darwinArch) {
|
||||
Target getNativeIOSTarget(DarwinArch darwinArch) {
|
||||
return switch (darwinArch) {
|
||||
DarwinArch.armv7 => Target.iOSArm,
|
||||
DarwinArch.arm64 => Target.iOSArm64,
|
||||
@@ -158,13 +31,13 @@ Target _getNativeTarget(DarwinArch darwinArch) {
|
||||
};
|
||||
}
|
||||
|
||||
Map<KernelAssetPath, List<AssetImpl>> _fatAssetTargetLocations(
|
||||
List<AssetImpl> nativeAssets) {
|
||||
Map<KernelAssetPath, List<NativeCodeAssetImpl>> fatAssetTargetLocationsIOS(
|
||||
List<NativeCodeAssetImpl> nativeAssets) {
|
||||
final Set<String> alreadyTakenNames = <String>{};
|
||||
final Map<KernelAssetPath, List<AssetImpl>> result =
|
||||
<KernelAssetPath, List<AssetImpl>>{};
|
||||
final Map<KernelAssetPath, List<NativeCodeAssetImpl>> result =
|
||||
<KernelAssetPath, List<NativeCodeAssetImpl>>{};
|
||||
final Map<String, KernelAssetPath> idToPath = <String, KernelAssetPath>{};
|
||||
for (final AssetImpl asset in nativeAssets) {
|
||||
for (final NativeCodeAssetImpl asset in nativeAssets) {
|
||||
// Use same target path for all assets with the same id.
|
||||
final KernelAssetPath path = idToPath[asset.id] ??
|
||||
_targetLocationIOS(
|
||||
@@ -172,23 +45,24 @@ Map<KernelAssetPath, List<AssetImpl>> _fatAssetTargetLocations(
|
||||
alreadyTakenNames,
|
||||
).path;
|
||||
idToPath[asset.id] = path;
|
||||
result[path] ??= <AssetImpl>[];
|
||||
result[path] ??= <NativeCodeAssetImpl>[];
|
||||
result[path]!.add(asset);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Map<AssetImpl, KernelAsset> _assetTargetLocations(
|
||||
List<AssetImpl> nativeAssets) {
|
||||
Map<NativeCodeAssetImpl, KernelAsset> assetTargetLocationsIOS(
|
||||
List<NativeCodeAssetImpl> nativeAssets) {
|
||||
final Set<String> alreadyTakenNames = <String>{};
|
||||
final Map<String, KernelAssetPath> idToPath = <String, KernelAssetPath>{};
|
||||
final Map<AssetImpl, KernelAsset> result = <AssetImpl, KernelAsset>{};
|
||||
for (final AssetImpl asset in nativeAssets) {
|
||||
final KernelAssetPath path = idToPath[asset.id] ??
|
||||
_targetLocationIOS(asset, alreadyTakenNames).path;
|
||||
final Map<NativeCodeAssetImpl, KernelAsset> result =
|
||||
<NativeCodeAssetImpl, KernelAsset>{};
|
||||
for (final NativeCodeAssetImpl asset in nativeAssets) {
|
||||
final KernelAssetPath path =
|
||||
idToPath[asset.id] ?? _targetLocationIOS(asset, alreadyTakenNames).path;
|
||||
idToPath[asset.id] = path;
|
||||
result[asset] = KernelAsset(
|
||||
id: (asset as NativeCodeAssetImpl).id,
|
||||
id: asset.id,
|
||||
target: Target.fromArchitectureAndOS(asset.architecture!, asset.os),
|
||||
path: path,
|
||||
);
|
||||
@@ -196,17 +70,18 @@ Map<AssetImpl, KernelAsset> _assetTargetLocations(
|
||||
return result;
|
||||
}
|
||||
|
||||
KernelAsset _targetLocationIOS(AssetImpl asset, Set<String> alreadyTakenNames) {
|
||||
final LinkModeImpl linkMode = (asset as NativeCodeAssetImpl).linkMode;
|
||||
final KernelAssetPath kernelAssetPath;
|
||||
KernelAsset _targetLocationIOS(
|
||||
NativeCodeAssetImpl asset, Set<String> alreadyTakenNames) {
|
||||
final LinkMode linkMode = asset.linkMode;
|
||||
final KernelAssetPath kernelAssetPath;
|
||||
switch (linkMode) {
|
||||
case DynamicLoadingSystemImpl _:
|
||||
case DynamicLoadingSystem _:
|
||||
kernelAssetPath = KernelAssetSystemPath(linkMode.uri);
|
||||
case LookupInExecutableImpl _:
|
||||
case LookupInExecutable _:
|
||||
kernelAssetPath = KernelAssetInExecutable();
|
||||
case LookupInProcessImpl _:
|
||||
case LookupInProcess _:
|
||||
kernelAssetPath = KernelAssetInProcess();
|
||||
case DynamicLoadingBundledImpl _:
|
||||
case DynamicLoadingBundled _:
|
||||
final String fileName = asset.file!.pathSegments.last;
|
||||
kernelAssetPath = KernelAssetAbsolutePath(frameworkUri(
|
||||
fileName,
|
||||
@@ -236,11 +111,11 @@ final KernelAssetPath kernelAssetPath;
|
||||
///
|
||||
/// Code signing is also done here, so that it doesn't have to be done in
|
||||
/// in xcode_backend.dart.
|
||||
Future<void> _copyNativeAssetsIOS(
|
||||
Future<void> copyNativeCodeAssetsIOS(
|
||||
Uri buildUri,
|
||||
Map<KernelAssetPath, List<AssetImpl>> assetTargetLocations,
|
||||
Map<KernelAssetPath, List<NativeCodeAssetImpl>> assetTargetLocations,
|
||||
String? codesignIdentity,
|
||||
BuildMode buildMode,
|
||||
build_info.BuildMode buildMode,
|
||||
FileSystem fileSystem,
|
||||
) async {
|
||||
if (assetTargetLocations.isNotEmpty) {
|
||||
@@ -250,11 +125,12 @@ Future<void> _copyNativeAssetsIOS(
|
||||
final Map<String, String> oldToNewInstallNames = <String, String>{};
|
||||
final List<(File, String, Directory)> dylibs = <(File, String, Directory)>[];
|
||||
|
||||
for (final MapEntry<KernelAssetPath, List<AssetImpl>> assetMapping
|
||||
for (final MapEntry<KernelAssetPath, List<NativeCodeAssetImpl>> assetMapping
|
||||
in assetTargetLocations.entries) {
|
||||
final Uri target = (assetMapping.key as KernelAssetAbsolutePath).uri;
|
||||
final List<File> sources = <File>[
|
||||
for (final AssetImpl source in assetMapping.value) fileSystem.file(source.file)
|
||||
for (final NativeCodeAssetImpl source in assetMapping.value)
|
||||
fileSystem.file(source.file)
|
||||
];
|
||||
final Uri targetUri = buildUri.resolveUri(target);
|
||||
final File dylibFile = fileSystem.file(targetUri);
|
||||
@@ -265,7 +141,8 @@ Future<void> _copyNativeAssetsIOS(
|
||||
await lipoDylibs(dylibFile, sources);
|
||||
|
||||
final String dylibFileName = dylibFile.basename;
|
||||
final String newInstallName = '@rpath/$dylibFileName.framework/$dylibFileName';
|
||||
final String newInstallName =
|
||||
'@rpath/$dylibFileName.framework/$dylibFileName';
|
||||
final Set<String> oldInstallNames = await getInstallNamesDylib(dylibFile);
|
||||
for (final String oldInstallName in oldInstallNames) {
|
||||
oldToNewInstallNames[oldInstallName] = newInstallName;
|
||||
|
||||
@@ -2,70 +2,12 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:native_assets_builder/native_assets_builder.dart'
|
||||
hide NativeAssetsBuildRunner;
|
||||
import 'package:native_assets_cli/native_assets_cli_internal.dart';
|
||||
|
||||
import '../../../base/common.dart';
|
||||
import '../../../base/file_system.dart';
|
||||
import '../../../base/io.dart';
|
||||
import '../../../build_info.dart';
|
||||
import '../../../globals.dart' as globals;
|
||||
import '../native_assets.dart';
|
||||
|
||||
/// Dry run the native builds.
|
||||
///
|
||||
/// This does not build native assets, it only simulates what the final paths
|
||||
/// of all assets will be so that this can be embedded in the kernel file.
|
||||
Future<Uri?> dryRunNativeAssetsLinux({
|
||||
required NativeAssetsBuildRunner buildRunner,
|
||||
required Uri projectUri,
|
||||
bool flutterTester = false,
|
||||
required FileSystem fileSystem,
|
||||
}) {
|
||||
return dryRunNativeAssetsSingleArchitecture(
|
||||
buildRunner: buildRunner,
|
||||
projectUri: projectUri,
|
||||
flutterTester: flutterTester,
|
||||
fileSystem: fileSystem,
|
||||
os: OSImpl.linux,
|
||||
);
|
||||
}
|
||||
|
||||
Future<Iterable<KernelAsset>> dryRunNativeAssetsLinuxInternal(
|
||||
FileSystem fileSystem,
|
||||
Uri projectUri,
|
||||
bool flutterTester,
|
||||
NativeAssetsBuildRunner buildRunner,
|
||||
) {
|
||||
return dryRunNativeAssetsSingleArchitectureInternal(
|
||||
fileSystem,
|
||||
projectUri,
|
||||
flutterTester,
|
||||
buildRunner,
|
||||
OSImpl.linux,
|
||||
);
|
||||
}
|
||||
|
||||
Future<(Uri? nativeAssetsYaml, List<Uri> dependencies)> buildNativeAssetsLinux({
|
||||
required NativeAssetsBuildRunner buildRunner,
|
||||
TargetPlatform? targetPlatform,
|
||||
required Uri projectUri,
|
||||
required BuildMode buildMode,
|
||||
bool flutterTester = false,
|
||||
Uri? yamlParentDirectory,
|
||||
required FileSystem fileSystem,
|
||||
}) {
|
||||
return buildNativeAssetsSingleArchitecture(
|
||||
buildRunner: buildRunner,
|
||||
targetPlatform: targetPlatform,
|
||||
projectUri: projectUri,
|
||||
buildMode: buildMode,
|
||||
flutterTester: flutterTester,
|
||||
yamlParentDirectory: yamlParentDirectory,
|
||||
fileSystem: fileSystem,
|
||||
);
|
||||
}
|
||||
|
||||
/// Flutter expects `clang++` to be on the path on Linux hosts.
|
||||
///
|
||||
|
||||
@@ -2,179 +2,21 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:native_assets_builder/native_assets_builder.dart'
|
||||
hide NativeAssetsBuildRunner;
|
||||
import 'package:native_assets_builder/native_assets_builder.dart';
|
||||
import 'package:native_assets_cli/native_assets_cli.dart';
|
||||
import 'package:native_assets_cli/native_assets_cli_internal.dart';
|
||||
|
||||
import '../../../base/file_system.dart';
|
||||
import '../../../build_info.dart';
|
||||
import '../../../build_info.dart' hide BuildMode;
|
||||
import '../../../build_info.dart' as build_info;
|
||||
import '../../../globals.dart' as globals;
|
||||
import '../native_assets.dart';
|
||||
import 'native_assets_host.dart';
|
||||
|
||||
/// Dry run the native builds.
|
||||
///
|
||||
/// This does not build native assets, it only simulates what the final paths
|
||||
/// of all assets will be so that this can be embedded in the kernel file and
|
||||
/// the Xcode project.
|
||||
Future<Uri?> dryRunNativeAssetsMacOS({
|
||||
required NativeAssetsBuildRunner buildRunner,
|
||||
required Uri projectUri,
|
||||
bool flutterTester = false,
|
||||
required FileSystem fileSystem,
|
||||
}) async {
|
||||
if (!await nativeBuildRequired(buildRunner)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final Uri buildUri = nativeAssetsBuildUri(projectUri, OSImpl.macOS);
|
||||
final Iterable<KernelAsset> nativeAssetPaths = await dryRunNativeAssetsMacOSInternal(
|
||||
fileSystem,
|
||||
projectUri,
|
||||
flutterTester,
|
||||
buildRunner,
|
||||
);
|
||||
final Uri nativeAssetsUri = await writeNativeAssetsYaml(
|
||||
KernelAssets(nativeAssetPaths),
|
||||
buildUri,
|
||||
fileSystem,
|
||||
);
|
||||
return nativeAssetsUri;
|
||||
}
|
||||
|
||||
Future<Iterable<KernelAsset>> dryRunNativeAssetsMacOSInternal(
|
||||
FileSystem fileSystem,
|
||||
Uri projectUri,
|
||||
bool flutterTester,
|
||||
NativeAssetsBuildRunner buildRunner,
|
||||
) async {
|
||||
const OSImpl targetOS = OSImpl.macOS;
|
||||
final Uri buildUri = nativeAssetsBuildUri(projectUri, targetOS);
|
||||
|
||||
globals.logger.printTrace('Dry running native assets for $targetOS.');
|
||||
final BuildDryRunResult buildDryRunResult = await buildRunner.buildDryRun(
|
||||
linkModePreference: LinkModePreferenceImpl.dynamic,
|
||||
targetOS: targetOS,
|
||||
workingDirectory: projectUri,
|
||||
includeParentEnvironment: true,
|
||||
);
|
||||
ensureNativeAssetsBuildDryRunSucceed(buildDryRunResult);
|
||||
// No link hooks in JIT mode.
|
||||
final List<AssetImpl> nativeAssets = buildDryRunResult.assets;
|
||||
globals.logger.printTrace('Dry running native assets for $targetOS done.');
|
||||
final Uri? absolutePath = flutterTester ? buildUri : null;
|
||||
final Map<AssetImpl, KernelAsset> assetTargetLocations =
|
||||
_assetTargetLocations(
|
||||
nativeAssets,
|
||||
absolutePath,
|
||||
);
|
||||
return assetTargetLocations.values;
|
||||
}
|
||||
|
||||
/// Builds native assets.
|
||||
///
|
||||
/// If [darwinArchs] is omitted, the current target architecture is used.
|
||||
///
|
||||
/// If [flutterTester] is true, absolute paths are emitted in the native
|
||||
/// assets mapping. This can be used for JIT mode without sandbox on the host.
|
||||
/// This is used in `flutter test` and `flutter run -d flutter-tester`.
|
||||
Future<(Uri? nativeAssetsYaml, List<Uri> dependencies)> buildNativeAssetsMacOS({
|
||||
required NativeAssetsBuildRunner buildRunner,
|
||||
List<DarwinArch>? darwinArchs,
|
||||
required Uri projectUri,
|
||||
required BuildMode buildMode,
|
||||
bool flutterTester = false,
|
||||
String? codesignIdentity,
|
||||
Uri? yamlParentDirectory,
|
||||
required FileSystem fileSystem,
|
||||
}) async {
|
||||
const OSImpl targetOS = OSImpl.macOS;
|
||||
final Uri buildUri = nativeAssetsBuildUri(projectUri, targetOS);
|
||||
if (!await nativeBuildRequired(buildRunner)) {
|
||||
final Uri nativeAssetsYaml = await writeNativeAssetsYaml(
|
||||
KernelAssets(),
|
||||
yamlParentDirectory ?? buildUri,
|
||||
fileSystem,
|
||||
);
|
||||
return (nativeAssetsYaml, <Uri>[]);
|
||||
}
|
||||
|
||||
final List<Target> targets = darwinArchs != null
|
||||
? darwinArchs.map(_getNativeTarget).toList()
|
||||
: <Target>[Target.current];
|
||||
final BuildModeImpl buildModeCli =
|
||||
nativeAssetsBuildMode(buildMode);
|
||||
final bool linkingEnabled = buildModeCli == BuildModeImpl.release;
|
||||
|
||||
globals.logger
|
||||
.printTrace('Building native assets for $targets $buildModeCli.');
|
||||
final List<AssetImpl> nativeAssets = <AssetImpl>[];
|
||||
final Set<Uri> dependencies = <Uri>{};
|
||||
for (final Target target in targets) {
|
||||
final BuildResult buildResult = await buildRunner.build(
|
||||
linkModePreference: LinkModePreferenceImpl.dynamic,
|
||||
target: target,
|
||||
buildMode: buildModeCli,
|
||||
workingDirectory: projectUri,
|
||||
includeParentEnvironment: true,
|
||||
cCompilerConfig: await buildRunner.cCompilerConfig,
|
||||
// TODO(dcharkes): Fetch minimum MacOS version from somewhere. https://github.com/flutter/flutter/issues/145104
|
||||
targetMacOSVersion: 13,
|
||||
linkingEnabled: linkingEnabled,
|
||||
);
|
||||
ensureNativeAssetsBuildSucceed(buildResult);
|
||||
nativeAssets.addAll(buildResult.assets);
|
||||
dependencies.addAll(buildResult.dependencies);
|
||||
if (linkingEnabled) {
|
||||
final LinkResult linkResult = await buildRunner.link(
|
||||
linkModePreference: LinkModePreferenceImpl.dynamic,
|
||||
target: target,
|
||||
buildMode: buildModeCli,
|
||||
workingDirectory: projectUri,
|
||||
includeParentEnvironment: true,
|
||||
cCompilerConfig: await buildRunner.cCompilerConfig,
|
||||
buildResult: buildResult,
|
||||
// TODO(dcharkes): Fetch minimum MacOS version from somewhere. https://github.com/flutter/flutter/issues/145104
|
||||
targetMacOSVersion: 13,
|
||||
);
|
||||
ensureNativeAssetsLinkSucceed(linkResult);
|
||||
nativeAssets.addAll(linkResult.assets);
|
||||
dependencies.addAll(linkResult.dependencies);
|
||||
}
|
||||
}
|
||||
globals.logger.printTrace('Building native assets for $targets done.');
|
||||
final Uri? absolutePath = flutterTester ? buildUri : null;
|
||||
final Map<AssetImpl, KernelAsset> assetTargetLocations =
|
||||
_assetTargetLocations(nativeAssets, absolutePath);
|
||||
final Map<KernelAssetPath, List<AssetImpl>> fatAssetTargetLocations =
|
||||
_fatAssetTargetLocations(nativeAssets, absolutePath);
|
||||
if (flutterTester) {
|
||||
await _copyNativeAssetsMacOSFlutterTester(
|
||||
buildUri,
|
||||
fatAssetTargetLocations,
|
||||
codesignIdentity,
|
||||
buildMode,
|
||||
fileSystem,
|
||||
);
|
||||
} else {
|
||||
await _copyNativeAssetsMacOS(
|
||||
buildUri,
|
||||
fatAssetTargetLocations,
|
||||
codesignIdentity,
|
||||
buildMode,
|
||||
fileSystem,
|
||||
);
|
||||
}
|
||||
final Uri nativeAssetsUri = await writeNativeAssetsYaml(
|
||||
KernelAssets(assetTargetLocations.values),
|
||||
yamlParentDirectory ?? buildUri,
|
||||
fileSystem,
|
||||
);
|
||||
return (nativeAssetsUri, dependencies.toList());
|
||||
}
|
||||
// TODO(dcharkes): Fetch minimum MacOS version from somewhere. https://github.com/flutter/flutter/issues/145104
|
||||
const int targetMacOSVersion = 13;
|
||||
|
||||
/// Extract the [Target] from a [DarwinArch].
|
||||
Target _getNativeTarget(DarwinArch darwinArch) {
|
||||
Target getNativeMacOSTarget(DarwinArch darwinArch) {
|
||||
return switch (darwinArch) {
|
||||
DarwinArch.arm64 => Target.macOSArm64,
|
||||
DarwinArch.x86_64 => Target.macOSX64,
|
||||
@@ -182,15 +24,15 @@ Target _getNativeTarget(DarwinArch darwinArch) {
|
||||
};
|
||||
}
|
||||
|
||||
Map<KernelAssetPath, List<AssetImpl>> _fatAssetTargetLocations(
|
||||
List<AssetImpl> nativeAssets,
|
||||
Map<KernelAssetPath, List<NativeCodeAssetImpl>> fatAssetTargetLocationsMacOS(
|
||||
List<NativeCodeAssetImpl> nativeAssets,
|
||||
Uri? absolutePath,
|
||||
) {
|
||||
final Set<String> alreadyTakenNames = <String>{};
|
||||
final Map<KernelAssetPath, List<AssetImpl>> result =
|
||||
<KernelAssetPath, List<AssetImpl>>{};
|
||||
final Map<KernelAssetPath, List<NativeCodeAssetImpl>> result =
|
||||
<KernelAssetPath, List<NativeCodeAssetImpl>>{};
|
||||
final Map<String, KernelAssetPath> idToPath = <String, KernelAssetPath>{};
|
||||
for (final AssetImpl asset in nativeAssets) {
|
||||
for (final NativeCodeAssetImpl asset in nativeAssets) {
|
||||
// Use same target path for all assets with the same id.
|
||||
final KernelAssetPath path = idToPath[asset.id] ??
|
||||
_targetLocationMacOS(
|
||||
@@ -199,25 +41,25 @@ Map<KernelAssetPath, List<AssetImpl>> _fatAssetTargetLocations(
|
||||
alreadyTakenNames,
|
||||
).path;
|
||||
idToPath[asset.id] = path;
|
||||
result[path] ??= <AssetImpl>[];
|
||||
result[path] ??= <NativeCodeAssetImpl>[];
|
||||
result[path]!.add(asset);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Map<AssetImpl, KernelAsset> _assetTargetLocations(
|
||||
List<AssetImpl> nativeAssets,
|
||||
Map<NativeCodeAssetImpl, KernelAsset> assetTargetLocationsMacOS(
|
||||
List<NativeCodeAssetImpl> nativeAssets,
|
||||
Uri? absolutePath,
|
||||
) {
|
||||
final Set<String> alreadyTakenNames = <String>{};
|
||||
final Map<String, KernelAssetPath> idToPath = <String, KernelAssetPath>{};
|
||||
final Map<AssetImpl, KernelAsset> result = <AssetImpl, KernelAsset>{};
|
||||
for (final AssetImpl asset in nativeAssets) {
|
||||
final Map<NativeCodeAssetImpl, KernelAsset> result = <NativeCodeAssetImpl, KernelAsset>{};
|
||||
for (final NativeCodeAssetImpl asset in nativeAssets) {
|
||||
final KernelAssetPath path = idToPath[asset.id] ??
|
||||
_targetLocationMacOS(asset, absolutePath, alreadyTakenNames).path;
|
||||
idToPath[asset.id] = path;
|
||||
result[asset] = KernelAsset(
|
||||
id: (asset as NativeCodeAssetImpl).id,
|
||||
id: asset.id,
|
||||
target: Target.fromArchitectureAndOS(asset.architecture!, asset.os),
|
||||
path: path,
|
||||
);
|
||||
@@ -226,20 +68,20 @@ Map<AssetImpl, KernelAsset> _assetTargetLocations(
|
||||
}
|
||||
|
||||
KernelAsset _targetLocationMacOS(
|
||||
AssetImpl asset,
|
||||
NativeCodeAssetImpl asset,
|
||||
Uri? absolutePath,
|
||||
Set<String> alreadyTakenNames,
|
||||
) {
|
||||
final LinkModeImpl linkMode = (asset as NativeCodeAssetImpl).linkMode;
|
||||
final LinkMode linkMode = asset.linkMode;
|
||||
final KernelAssetPath kernelAssetPath;
|
||||
switch (linkMode) {
|
||||
case DynamicLoadingSystemImpl _:
|
||||
case DynamicLoadingSystem _:
|
||||
kernelAssetPath = KernelAssetSystemPath(linkMode.uri);
|
||||
case LookupInExecutableImpl _:
|
||||
case LookupInExecutable _:
|
||||
kernelAssetPath = KernelAssetInExecutable();
|
||||
case LookupInProcessImpl _:
|
||||
case LookupInProcess _:
|
||||
kernelAssetPath = KernelAssetInProcess();
|
||||
case DynamicLoadingBundledImpl _:
|
||||
case DynamicLoadingBundled _:
|
||||
final String fileName = asset.file!.pathSegments.last;
|
||||
Uri uri;
|
||||
if (absolutePath != null) {
|
||||
@@ -279,11 +121,11 @@ KernelAsset _targetLocationMacOS(
|
||||
///
|
||||
/// Code signing is also done here, so that it doesn't have to be done in
|
||||
/// in macos_assemble.sh.
|
||||
Future<void> _copyNativeAssetsMacOS(
|
||||
Future<void> copyNativeCodeAssetsMacOS(
|
||||
Uri buildUri,
|
||||
Map<KernelAssetPath, List<AssetImpl>> assetTargetLocations,
|
||||
Map<KernelAssetPath, List<NativeCodeAssetImpl>> assetTargetLocations,
|
||||
String? codesignIdentity,
|
||||
BuildMode buildMode,
|
||||
build_info.BuildMode buildMode,
|
||||
FileSystem fileSystem,
|
||||
) async {
|
||||
if (assetTargetLocations.isNotEmpty) {
|
||||
@@ -294,11 +136,11 @@ Future<void> _copyNativeAssetsMacOS(
|
||||
final Map<String, String> oldToNewInstallNames = <String, String>{};
|
||||
final List<(File, String, Directory)> dylibs = <(File, String, Directory)>[];
|
||||
|
||||
for (final MapEntry<KernelAssetPath, List<AssetImpl>> assetMapping
|
||||
for (final MapEntry<KernelAssetPath, List<NativeCodeAssetImpl>> assetMapping
|
||||
in assetTargetLocations.entries) {
|
||||
final Uri target = (assetMapping.key as KernelAssetAbsolutePath).uri;
|
||||
final List<File> sources = <File>[
|
||||
for (final AssetImpl source in assetMapping.value) fileSystem.file(source.file),
|
||||
for (final NativeCodeAssetImpl source in assetMapping.value) fileSystem.file(source.file),
|
||||
];
|
||||
final Uri targetUri = buildUri.resolveUri(target);
|
||||
final String name = targetUri.pathSegments.last;
|
||||
@@ -373,11 +215,11 @@ Future<void> _copyNativeAssetsMacOS(
|
||||
/// so that the referenced library can be found the dynamic linker.
|
||||
///
|
||||
/// Code signing is also done here.
|
||||
Future<void> _copyNativeAssetsMacOSFlutterTester(
|
||||
Future<void> copyNativeCodeAssetsMacOSFlutterTester(
|
||||
Uri buildUri,
|
||||
Map<KernelAssetPath, List<AssetImpl>> assetTargetLocations,
|
||||
Map<KernelAssetPath, List<NativeCodeAssetImpl>> assetTargetLocations,
|
||||
String? codesignIdentity,
|
||||
BuildMode buildMode,
|
||||
build_info.BuildMode buildMode,
|
||||
FileSystem fileSystem,
|
||||
) async {
|
||||
if (assetTargetLocations.isNotEmpty) {
|
||||
@@ -388,11 +230,11 @@ Future<void> _copyNativeAssetsMacOSFlutterTester(
|
||||
final Map<String, String> oldToNewInstallNames = <String, String>{};
|
||||
final List<(File, String)> dylibs = <(File, String)>[];
|
||||
|
||||
for (final MapEntry<KernelAssetPath, List<AssetImpl>> assetMapping
|
||||
for (final MapEntry<KernelAssetPath, List<NativeCodeAssetImpl>> assetMapping
|
||||
in assetTargetLocations.entries) {
|
||||
final Uri target = (assetMapping.key as KernelAssetAbsolutePath).uri;
|
||||
final List<File> sources = <File>[
|
||||
for (final AssetImpl source in assetMapping.value) fileSystem.file(source.file),
|
||||
for (final NativeCodeAssetImpl source in assetMapping.value) fileSystem.file(source.file),
|
||||
];
|
||||
final Uri targetUri = buildUri.resolveUri(target);
|
||||
final File dylibFile = fileSystem.file(targetUri);
|
||||
|
||||
@@ -4,13 +4,13 @@
|
||||
|
||||
// Shared logic between iOS and macOS implementations of native assets.
|
||||
|
||||
import 'package:native_assets_cli/native_assets_cli.dart' show Architecture;
|
||||
import 'package:native_assets_cli/native_assets_cli.dart';
|
||||
import 'package:native_assets_cli/native_assets_cli_internal.dart';
|
||||
|
||||
import '../../../base/common.dart';
|
||||
import '../../../base/file_system.dart';
|
||||
import '../../../base/io.dart';
|
||||
import '../../../build_info.dart';
|
||||
import '../../../build_info.dart' as build_info;
|
||||
import '../../../convert.dart';
|
||||
import '../../../globals.dart' as globals;
|
||||
|
||||
@@ -99,13 +99,13 @@ Future<void> setInstallNamesDylib(
|
||||
String newInstallName,
|
||||
Map<String, String> oldToNewInstallNames,
|
||||
) async {
|
||||
final ProcessResult setInstallNamesResult = await globals.processManager.run(
|
||||
final ProcessResult setInstallNamesResult = await globals.processManager.run(
|
||||
<String>[
|
||||
'install_name_tool',
|
||||
'-id',
|
||||
newInstallName,
|
||||
for (final MapEntry<String, String> entry in oldToNewInstallNames.entries)
|
||||
...<String>['-change', entry.key, entry.value],
|
||||
for (final MapEntry<String, String> entry in oldToNewInstallNames
|
||||
.entries) ...<String>['-change', entry.key, entry.value],
|
||||
dylibFile.path,
|
||||
],
|
||||
);
|
||||
@@ -135,18 +135,16 @@ Future<Set<String>> getInstallNamesDylib(File dylibFile) async {
|
||||
|
||||
return <String>{
|
||||
for (final List<String> architectureSection
|
||||
in parseOtoolArchitectureSections(installNameResult.stdout as String).values)
|
||||
in parseOtoolArchitectureSections(installNameResult.stdout as String).values)
|
||||
// For each architecture, a separate install name is reported, which are
|
||||
// not necessarily the same.
|
||||
architectureSection.single,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
Future<void> codesignDylib(
|
||||
String? codesignIdentity,
|
||||
BuildMode buildMode,
|
||||
build_info.BuildMode buildMode,
|
||||
FileSystemEntity target,
|
||||
) async {
|
||||
if (codesignIdentity == null || codesignIdentity.isEmpty) {
|
||||
@@ -157,7 +155,7 @@ Future<void> codesignDylib(
|
||||
'--force',
|
||||
'--sign',
|
||||
codesignIdentity,
|
||||
if (buildMode != BuildMode.release) ...<String>[
|
||||
if (buildMode != build_info.BuildMode.release) ...<String>[
|
||||
// Mimic Xcode's timestamp codesigning behavior on non-release binaries.
|
||||
'--timestamp=none',
|
||||
],
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -6,16 +6,12 @@
|
||||
|
||||
import 'package:native_assets_cli/native_assets_cli.dart';
|
||||
|
||||
import '../../../base/os.dart';
|
||||
import '../../../base/platform.dart';
|
||||
import '../../../build_info.dart';
|
||||
import '../../../globals.dart' as globals;
|
||||
import '../../../native_assets.dart';
|
||||
import '../../../project.dart';
|
||||
import '../linux/native_assets.dart';
|
||||
import '../macos/native_assets.dart';
|
||||
import '../native_assets.dart';
|
||||
import '../windows/native_assets.dart';
|
||||
|
||||
class TestCompilerNativeAssetsBuilderImpl
|
||||
implements TestCompilerNativeAssetsBuilder {
|
||||
@@ -31,57 +27,36 @@ class TestCompilerNativeAssetsBuilderImpl
|
||||
}
|
||||
|
||||
Future<Uri?> testCompilerBuildNativeAssets(BuildInfo buildInfo) async {
|
||||
Uri? nativeAssetsYaml;
|
||||
if (!buildInfo.buildNativeAssets) {
|
||||
nativeAssetsYaml = null;
|
||||
} else {
|
||||
final Uri projectUri = FlutterProject.current().directory.uri;
|
||||
final NativeAssetsBuildRunner buildRunner = NativeAssetsBuildRunnerImpl(
|
||||
projectUri,
|
||||
buildInfo.packageConfigPath,
|
||||
buildInfo.packageConfig,
|
||||
globals.fs,
|
||||
globals.logger,
|
||||
);
|
||||
if (globals.platform.isMacOS) {
|
||||
(nativeAssetsYaml, _) = await buildNativeAssetsMacOS(
|
||||
buildMode: buildInfo.mode,
|
||||
projectUri: projectUri,
|
||||
flutterTester: true,
|
||||
fileSystem: globals.fs,
|
||||
buildRunner: buildRunner,
|
||||
);
|
||||
} else if (globals.platform.isLinux) {
|
||||
(nativeAssetsYaml, _) = await buildNativeAssetsLinux(
|
||||
buildMode: buildInfo.mode,
|
||||
projectUri: projectUri,
|
||||
flutterTester: true,
|
||||
fileSystem: globals.fs,
|
||||
buildRunner: buildRunner,
|
||||
);
|
||||
} else if (globals.platform.isWindows) {
|
||||
final TargetPlatform targetPlatform;
|
||||
if (globals.os.hostPlatform == HostPlatform.windows_x64) {
|
||||
targetPlatform = TargetPlatform.windows_x64;
|
||||
} else {
|
||||
targetPlatform = TargetPlatform.windows_arm64;
|
||||
}
|
||||
(nativeAssetsYaml, _) = await buildNativeAssetsWindows(
|
||||
buildMode: buildInfo.mode,
|
||||
targetPlatform: targetPlatform,
|
||||
projectUri: projectUri,
|
||||
flutterTester: true,
|
||||
fileSystem: globals.fs,
|
||||
buildRunner: buildRunner,
|
||||
);
|
||||
} else {
|
||||
await ensureNoNativeAssetsOrOsIsSupported(
|
||||
projectUri,
|
||||
const LocalPlatform().operatingSystem,
|
||||
globals.fs,
|
||||
buildRunner,
|
||||
);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
final Uri projectUri = FlutterProject.current().directory.uri;
|
||||
final FlutterNativeAssetsBuildRunner buildRunner = FlutterNativeAssetsBuildRunnerImpl(
|
||||
projectUri,
|
||||
buildInfo.packageConfigPath,
|
||||
buildInfo.packageConfig,
|
||||
globals.fs,
|
||||
globals.logger,
|
||||
);
|
||||
|
||||
if (!globals.platform.isMacOS &&
|
||||
!globals.platform.isLinux &&
|
||||
!globals.platform.isWindows) {
|
||||
await ensureNoNativeAssetsOrOsIsSupported(
|
||||
projectUri,
|
||||
const LocalPlatform().operatingSystem,
|
||||
globals.fs,
|
||||
buildRunner,
|
||||
);
|
||||
return null;
|
||||
}
|
||||
final (_, Uri nativeAssetsYaml) = await runFlutterSpecificDartBuild(
|
||||
environmentDefines: <String, String>{
|
||||
kBuildMode: buildInfo.mode.cliName,
|
||||
},
|
||||
buildRunner: buildRunner,
|
||||
targetPlatform: TargetPlatform.tester,
|
||||
projectUri: projectUri,
|
||||
fileSystem: globals.fs);
|
||||
return nativeAssetsYaml;
|
||||
}
|
||||
|
||||
@@ -2,70 +2,10 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:native_assets_builder/native_assets_builder.dart'
|
||||
hide NativeAssetsBuildRunner;
|
||||
import 'package:native_assets_cli/native_assets_cli_internal.dart';
|
||||
|
||||
import '../../../base/file_system.dart';
|
||||
import '../../../build_info.dart';
|
||||
import '../../../globals.dart' as globals;
|
||||
import '../../../windows/visual_studio.dart';
|
||||
import '../native_assets.dart';
|
||||
|
||||
/// Dry run the native builds.
|
||||
///
|
||||
/// This does not build native assets, it only simulates what the final paths
|
||||
/// of all assets will be so that this can be embedded in the kernel file.
|
||||
Future<Uri?> dryRunNativeAssetsWindows({
|
||||
required NativeAssetsBuildRunner buildRunner,
|
||||
required Uri projectUri,
|
||||
bool flutterTester = false,
|
||||
required FileSystem fileSystem,
|
||||
}) {
|
||||
return dryRunNativeAssetsSingleArchitecture(
|
||||
buildRunner: buildRunner,
|
||||
projectUri: projectUri,
|
||||
flutterTester: flutterTester,
|
||||
fileSystem: fileSystem,
|
||||
os: OSImpl.windows,
|
||||
);
|
||||
}
|
||||
|
||||
Future<Iterable<KernelAsset>> dryRunNativeAssetsWindowsInternal(
|
||||
FileSystem fileSystem,
|
||||
Uri projectUri,
|
||||
bool flutterTester,
|
||||
NativeAssetsBuildRunner buildRunner,
|
||||
) {
|
||||
return dryRunNativeAssetsSingleArchitectureInternal(
|
||||
fileSystem,
|
||||
projectUri,
|
||||
flutterTester,
|
||||
buildRunner,
|
||||
OSImpl.windows,
|
||||
);
|
||||
}
|
||||
|
||||
Future<(Uri? nativeAssetsYaml, List<Uri> dependencies)>
|
||||
buildNativeAssetsWindows({
|
||||
required NativeAssetsBuildRunner buildRunner,
|
||||
TargetPlatform? targetPlatform,
|
||||
required Uri projectUri,
|
||||
required BuildMode buildMode,
|
||||
bool flutterTester = false,
|
||||
Uri? yamlParentDirectory,
|
||||
required FileSystem fileSystem,
|
||||
}) {
|
||||
return buildNativeAssetsSingleArchitecture(
|
||||
buildRunner: buildRunner,
|
||||
targetPlatform: targetPlatform,
|
||||
projectUri: projectUri,
|
||||
buildMode: buildMode,
|
||||
flutterTester: flutterTester,
|
||||
yamlParentDirectory: yamlParentDirectory,
|
||||
fileSystem: fileSystem,
|
||||
);
|
||||
}
|
||||
|
||||
Future<CCompilerConfigImpl> cCompilerConfigWindows() async {
|
||||
final VisualStudio visualStudio = VisualStudio(
|
||||
|
||||
Reference in New Issue
Block a user