From 2f83aabe418397d04769675bdac3ef2d22a7186c Mon Sep 17 00:00:00 2001 From: Daco Harkes Date: Tue, 12 Sep 2023 17:32:34 +0200 Subject: [PATCH] [native_assets_builder] Faster planning for <= 1 packages --- .../lib/src/build_runner/build_runner.dart | 70 ++++++++++++------- 1 file changed, 44 insertions(+), 26 deletions(-) diff --git a/pkgs/native_assets_builder/lib/src/build_runner/build_runner.dart b/pkgs/native_assets_builder/lib/src/build_runner/build_runner.dart index 30857c517..d312db754 100644 --- a/pkgs/native_assets_builder/lib/src/build_runner/build_runner.dart +++ b/pkgs/native_assets_builder/lib/src/build_runner/build_runner.dart @@ -7,6 +7,7 @@ import 'dart:io'; import 'package:logging/logging.dart'; import 'package:native_assets_cli/native_assets_cli.dart'; +import 'package:package_config/package_config.dart'; import '../package_layout/package_layout.dart'; import '../utils/run_process.dart'; @@ -47,27 +48,38 @@ class NativeAssetsBuildRunner { packageLayout ??= await PackageLayout.fromRootPackageRoot(workingDirectory); final packagesWithNativeAssets = await packageLayout.packagesWithNativeAssets; - final planner = await NativeAssetsBuildPlanner.fromRootPackageRoot( - rootPackageRoot: packageLayout.rootPackageRoot, - packagesWithNativeAssets: packagesWithNativeAssets, - dartExecutable: Uri.file(Platform.resolvedExecutable), - logger: logger, - ); - final (plan, planSuccess) = planner.plan(); - if (!planSuccess) { - return _BuildResultImpl( - assets: [], - dependencies: [], - success: false, + final List buildPlan; + final PackageGraph packageGraph; + if (packagesWithNativeAssets.length <= 1) { + buildPlan = packagesWithNativeAssets; + packageGraph = PackageGraph({ + for (final p in packagesWithNativeAssets) p.name: [], + }); + } else { + final planner = await NativeAssetsBuildPlanner.fromRootPackageRoot( + rootPackageRoot: packageLayout.rootPackageRoot, + packagesWithNativeAssets: packagesWithNativeAssets, + dartExecutable: Uri.file(Platform.resolvedExecutable), + logger: logger, ); + final (plan, planSuccess) = planner.plan(); + if (!planSuccess) { + return _BuildResultImpl( + assets: [], + dependencies: [], + success: false, + ); + } + buildPlan = plan; + packageGraph = planner.packageGraph; } final assets = []; final dependencies = []; final metadata = {}; var success = true; - for (final package in plan) { + for (final package in buildPlan) { final dependencyMetadata = _metadataForPackage( - packageGraph: planner.packageGraph, + packageGraph: packageGraph, packageName: package.name, targetMetadata: metadata, ); @@ -123,22 +135,28 @@ class NativeAssetsBuildRunner { packageLayout ??= await PackageLayout.fromRootPackageRoot(workingDirectory); final packagesWithNativeAssets = await packageLayout.packagesWithNativeAssets; - final planner = await NativeAssetsBuildPlanner.fromRootPackageRoot( - rootPackageRoot: packageLayout.rootPackageRoot, - packagesWithNativeAssets: packagesWithNativeAssets, - dartExecutable: Uri.file(Platform.resolvedExecutable), - logger: logger, - ); - final (plan, planSuccess) = planner.plan(); - if (!planSuccess) { - return _DryRunResultImpl( - assets: [], - success: false, + final List buildPlan; + if (packagesWithNativeAssets.length <= 1) { + buildPlan = packagesWithNativeAssets; + } else { + final planner = await NativeAssetsBuildPlanner.fromRootPackageRoot( + rootPackageRoot: packageLayout.rootPackageRoot, + packagesWithNativeAssets: packagesWithNativeAssets, + dartExecutable: Uri.file(Platform.resolvedExecutable), + logger: logger, ); + final (plan, planSuccess) = planner.plan(); + if (!planSuccess) { + return _DryRunResultImpl( + assets: [], + success: false, + ); + } + buildPlan = plan; } final assets = []; var success = true; - for (final package in plan) { + for (final package in buildPlan) { final config = await _cliConfigDryRun( packageName: package.name, packageRoot: packageLayout.packageRoot(package.name),