Skip to content

Commit 6595118

Browse files
authored
Ensure the NativeAssetsBuildRunner.link() produces a BuildResult with all assets (#1633)
* Ensure the NativeAssetsBuildRunner.link() produces a BuildResult with all assets Before this change a bundling tool would * call `buildResult = nativeAssetsBuildRunner.build(...)` * call `linkResult = nativeAssetsBuildRunner.link(buildResult: buildResult, ...) * get all assets via `allAssets = [...buildResult.assets, ...linkResult.assets]` => This PR makes the `link()` command produce a `LinkResult` containing all assets of the final application. => One could view this as the assets from `build()` without a linker to go to a default linker that just emits all of it's inputs. => This allows the `link()` step to also perform the application-wide validation steps (not just over all linker outputs but across build & link outputs) Bundling tools now only have to deal with * `buildResult` in JIT mode (where linking is not enabled) * `linkResult` in AOT mode (where linking is enabled) Instead of dealing with both `buildResult` and `linkResult` in AOT mode. (In some sense one actually would prefer a `NativeAssetsBuilder.build` and `NativeAssetsBuilder.buildAndLink` instead of the current API that exposes the intermediary result from `build(linkingEnabled: true)` just to be explicitly passed on to link later on)
1 parent cbfe69e commit 6595118

File tree

5 files changed

+16
-11
lines changed

5 files changed

+16
-11
lines changed

pkgs/native_assets_builder/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@
1414
- **Breaking change**: Remove asset-type specific logic from `package:native_assets_builder`.
1515
Bundling tools have to now supply `supportedAssetTypes` and corresponding
1616
validation routines.
17+
- **Breaking change**: The `NativeAssetsBuildRunner.link()` command will now
18+
produce a `LinkResult` containing all assets for the application (not just
19+
those that happened to have a linker). This removes the need for a bundling
20+
tool to combine parts of `BuildResult` and `LinkResult` and possibly checking
21+
consistency of the sum of those parts. Effectively this means: Any asset that
22+
doesn't have an explicit linker will get a NOP linker that emits as outputs
23+
it's inputs.
1724

1825
## 0.8.3
1926

pkgs/native_assets_builder/lib/src/build_runner/build_runner.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,9 @@ class NativeAssetsBuildRunner {
234234
}
235235

236236
var hookResult = HookResult();
237+
if (hook == Hook.link) {
238+
hookResult.encodedAssets.addAll(buildResult!.encodedAssets);
239+
}
237240
final metadata = <String, Metadata>{};
238241
for (final package in buildPlan) {
239242
final DependencyMetadata? dependencyMetadata;

pkgs/native_assets_builder/lib/src/model/link_result.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import '../build_runner/build_runner.dart';
99
/// The result of executing the link hooks in dry run mode from all packages in
1010
/// the dependency tree of the entry point application.
1111
abstract interface class LinkResult {
12-
/// The native assets produced by the hooks, which should be bundled.
12+
/// All assets (produced by the build & link hooks) that have to be bundled
13+
/// with the app.
1314
List<EncodedAsset> get encodedAssets;
1415

1516
/// The files used by the hooks.

pkgs/native_assets_builder/test/build_runner/conflicting_dylib_test.dart

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,8 @@ void main() async {
7272
linkValidator: validateCodeAssetLinkOutput,
7373
applicationAssetValidator: validateCodeAssetsInApplication,
7474
);
75-
expect(linkResult.success, isTrue);
76-
77-
final allAssets = [
78-
...buildResult.encodedAssets,
79-
...linkResult.encodedAssets
80-
].where((e) => e.type == CodeAsset.type).toList();
81-
final validateResult = await validateCodeAssetsInApplication(allAssets);
82-
expect(validateResult, isNotEmpty);
75+
// Application validation error due to conflicting dylib name.
76+
expect(linkResult.success, isFalse);
8377
});
8478
});
8579
}

pkgs/native_assets_builder/test/build_runner/link_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,8 @@ void main() async {
121121
);
122122
expect(linkResult.success, true);
123123

124-
expect(
125-
_getNames(linkResult.encodedAssets), unorderedEquals(linkedAssets));
124+
expect(_getNames(linkResult.encodedAssets),
125+
unorderedEquals([...builtHelperAssets, ...linkedAssets]));
126126
});
127127
},
128128
);

0 commit comments

Comments
 (0)