Skip to content

Commit

Permalink
[native_assets_builder] Add AssetRelativePath back in (#941)
Browse files Browse the repository at this point in the history
  • Loading branch information
dcharkes authored Jan 17, 2024
1 parent 85be813 commit 40382ef
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 3 deletions.
4 changes: 4 additions & 0 deletions pkgs/native_assets_builder/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.3.2

- Reintroduce `AssetRelativePath`, it's used in `dart build`.

## 0.3.1

- Add support for `runPackageName` to avoid native assets for packages that
Expand Down
13 changes: 12 additions & 1 deletion pkgs/native_assets_builder/lib/src/model/asset.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,16 @@ import 'package:native_assets_cli/native_assets_cli_internal.dart';

import '../utils/yaml.dart';

extension on AssetPath {}
/// Asset at absolute path [uri].
class AssetRelativePath implements AssetPath {
final Uri uri;

AssetRelativePath(this.uri);

// Never used in native_assets_cli, but the interface must be implemented.
@override
Map<String, Object> toYaml() => throw UnimplementedError();
}

extension AssetIterable on Iterable<Asset> {
Iterable<Asset> whereLinkMode(LinkMode linkMode) =>
Expand Down Expand Up @@ -43,6 +52,8 @@ List<String> _toDartConst(AssetPath path) {
switch (path) {
case AssetAbsolutePath _:
return ['absolute', path.uri.toFilePath()];
case AssetRelativePath _:
return ['relative', path.uri.toFilePath()];
case AssetSystemPath _:
return ['system', path.uri.toFilePath()];
case AssetInProcess _:
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.3.1
version: 0.3.2
repository: https://github.com/dart-lang/native/tree/main/pkgs/native_assets_builder

environment:
Expand Down
16 changes: 15 additions & 1 deletion pkgs/native_assets_builder/test/model/asset_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import 'package:test/test.dart';

void main() {
final fooUri = Uri.file('path/to/libfoo.so');
final foo2Uri = Uri.file('path/to/libfoo2.so');
final foo3Uri = Uri(path: 'libfoo3.so');
final barUri = Uri(path: 'path/to/libbar.a');
final blaUri = Uri(path: 'path/with spaces/bla.dll');
Expand All @@ -21,6 +22,12 @@ void main() {
target: Target.androidX64,
linkMode: LinkMode.dynamic,
),
Asset(
id: 'foo2',
path: AssetRelativePath(foo2Uri),
target: Target.androidX64,
linkMode: LinkMode.dynamic,
),
Asset(
id: 'foo3',
path: AssetSystemPath(foo3Uri),
Expand Down Expand Up @@ -62,6 +69,9 @@ native-assets:
foo:
- absolute
- ${fooUri.toFilePath()}
foo2:
- relative
- ${foo2Uri.toFilePath()}
foo3:
- system
- ${foo3Uri.toFilePath()}
Expand All @@ -85,6 +95,10 @@ native-assets:

test('List<Asset> whereLinkMode', () async {
final assets2 = assets.whereLinkMode(LinkMode.dynamic);
expect(assets2.length, 5);
expect(assets2.length, 6);
});

test('satisfy coverage', () async {
expect(() => assets[1].toYaml(), throwsUnimplementedError);
});
}

0 comments on commit 40382ef

Please sign in to comment.