Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[native_assets_builder] Speedup builds for 0 or 1 packages with native assets #129

Merged
merged 2 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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