Skip to content

Commit

Permalink
[native_assets_builder] Speedup builds for 0 or 1 packages with nativ…
Browse files Browse the repository at this point in the history
…e assets (#129)

Closes: #128
  • Loading branch information
dcharkes authored Sep 12, 2023
1 parent 7f30f4b commit 5177659
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 29 deletions.
9 changes: 7 additions & 2 deletions pkgs/native_assets_builder/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
## 0.2.3

- Quicker build planning for 0 or 1 packages with native assets
([#128](https://github.com/dart-lang/native/issues/128)).

## 0.2.2

- Take a `PackageLayout` argument for `build` and `dryRun`
[flutter#134427](https://github.com/flutter/flutter/issues/134427).
([flutter#134427](https://github.com/flutter/flutter/issues/134427)).

## 0.2.1

- Provide a `PackageLayout` constructor for already parsed `PackageConfig`
[flutter#134427](https://github.com/flutter/flutter/issues/134427).
([flutter#134427](https://github.com/flutter/flutter/issues/134427)).

## 0.2.0

Expand Down
70 changes: 44 additions & 26 deletions pkgs/native_assets_builder/lib/src/build_runner/build_runner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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<Package> 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 = <Asset>[];
final dependencies = <Uri>[];
final metadata = <String, 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,
);
Expand Down Expand Up @@ -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<Package> 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 = <Asset>[];
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),
Expand Down
2 changes: 1 addition & 1 deletion pkgs/native_assets_builder/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: native_assets_builder
description: >-
This package is the backend that invokes top-level `build.dart` scripts.
version: 0.2.2
version: 0.2.3
repository: https://github.com/dart-lang/native/tree/main/pkgs/native_assets_builder

environment:
Expand Down

0 comments on commit 5177659

Please sign in to comment.