Skip to content

Commit

Permalink
[native_assets_builder] Take packageLayout for build and dryRun (#127)
Browse files Browse the repository at this point in the history
  • Loading branch information
dcharkes authored Sep 12, 2023
1 parent a7cd31e commit 7f30f4b
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 12 deletions.
5 changes: 5 additions & 0 deletions pkgs/native_assets_builder/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.2.2

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

## 0.2.1

- Provide a `PackageLayout` constructor for already parsed `PackageConfig`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ class NativeAssetsBuildRunner {
IOSSdk? targetIOSSdk,
int? targetAndroidNdkApi,
required bool includeParentEnvironment,
PackageLayout? packageLayout,
}) async {
final packageLayout =
await PackageLayout.fromRootPackageRoot(workingDirectory);
packageLayout ??= await PackageLayout.fromRootPackageRoot(workingDirectory);
final packagesWithNativeAssets =
await packageLayout.packagesWithNativeAssets;
final planner = await NativeAssetsBuildPlanner.fromRootPackageRoot(
Expand Down Expand Up @@ -118,9 +118,9 @@ class NativeAssetsBuildRunner {
required OS targetOs,
required Uri workingDirectory,
required bool includeParentEnvironment,
PackageLayout? packageLayout,
}) async {
final packageLayout =
await PackageLayout.fromRootPackageRoot(workingDirectory);
packageLayout ??= await PackageLayout.fromRootPackageRoot(workingDirectory);
final packagesWithNativeAssets =
await packageLayout.packagesWithNativeAssets;
final planner = await NativeAssetsBuildPlanner.fromRootPackageRoot(
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.1
version: 0.2.2
repository: https://github.com/dart-lang/native/tree/main/pkgs/native_assets_builder

environment:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import 'dart:io';

import 'package:native_assets_builder/native_assets_builder.dart';
import 'package:test/test.dart';

import '../helpers.dart';
Expand Down Expand Up @@ -36,15 +37,25 @@ void main() async {
}

// Trigger a build, should not invoke anything.
{
for (final passPackageLayout in [true, false]) {
PackageLayout? packageLayout;
if (passPackageLayout) {
packageLayout = await PackageLayout.fromRootPackageRoot(packageUri);
}
final logMessages = <String>[];
final result = await build(packageUri, logger, dartExecutable,
capturedLogs: logMessages);
final result = await build(
packageUri,
logger,
dartExecutable,
capturedLogs: logMessages,
packageLayout: packageLayout,
);
expect(
false,
logMessages
.join('\n')
.contains('native_add${Platform.pathSeparator}build.dart'));
false,
logMessages
.join('\n')
.contains('native_add${Platform.pathSeparator}build.dart'),
);
expect(result.assets.length, 1);
}
});
Expand Down
4 changes: 4 additions & 0 deletions pkgs/native_assets_builder/test/build_runner/helpers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Future<BuildResult> build(
CCompilerConfig? cCompilerConfig,
bool includeParentEnvironment = true,
List<String>? capturedLogs,
PackageLayout? packageLayout,
}) async {
StreamSubscription<LogRecord>? subscription;
if (capturedLogs != null) {
Expand All @@ -51,6 +52,7 @@ Future<BuildResult> build(
workingDirectory: packageUri,
cCompilerConfig: cCompilerConfig,
includeParentEnvironment: includeParentEnvironment,
packageLayout: packageLayout,
);
if (result.success) {
await expectAssetsExist(result.assets);
Expand All @@ -71,6 +73,7 @@ Future<DryRunResult> dryRun(
CCompilerConfig? cCompilerConfig,
bool includeParentEnvironment = true,
List<String>? capturedLogs,
PackageLayout? packageLayout,
}) async {
StreamSubscription<LogRecord>? subscription;
if (capturedLogs != null) {
Expand All @@ -86,6 +89,7 @@ Future<DryRunResult> dryRun(
targetOs: Target.current.os,
workingDirectory: packageUri,
includeParentEnvironment: includeParentEnvironment,
packageLayout: packageLayout,
);

if (subscription != null) {
Expand Down

0 comments on commit 7f30f4b

Please sign in to comment.