From 0187d0e04b4ecec7a3b3797ea8906f0760af0fee Mon Sep 17 00:00:00 2001 From: Daco Harkes Date: Mon, 7 Aug 2023 15:24:51 +0200 Subject: [PATCH] [native_assets_cli] Rename `Asset` `name` to `id` (#113) --- pkgs/native_assets_cli/CHANGELOG.md | 4 ++- .../lib/src/model/asset.dart | 21 ++++++------ pkgs/native_assets_cli/pubspec.yaml | 2 +- .../test/model/asset_test.dart | 32 +++++++++---------- .../test/model/build_output_test.dart | 8 ++--- 5 files changed, 36 insertions(+), 31 deletions(-) diff --git a/pkgs/native_assets_cli/CHANGELOG.md b/pkgs/native_assets_cli/CHANGELOG.md index d83fc1bbe..f8d90ea35 100644 --- a/pkgs/native_assets_cli/CHANGELOG.md +++ b/pkgs/native_assets_cli/CHANGELOG.md @@ -1,5 +1,7 @@ -## 0.1.1-wip +## 0.2.0 +- *Breaking change* Rename `Asset.name` to `Asset.id` + ([#100](https://github.com/dart-lang/native/issues/100)). - Added topics. - Fixed metadata example. - Throws `FormatException`s instead of `TypeError`s when failing to parse Yaml diff --git a/pkgs/native_assets_cli/lib/src/model/asset.dart b/pkgs/native_assets_cli/lib/src/model/asset.dart index 2bc3a01a3..bb9a19b3f 100644 --- a/pkgs/native_assets_cli/lib/src/model/asset.dart +++ b/pkgs/native_assets_cli/lib/src/model/asset.dart @@ -191,19 +191,19 @@ class AssetInExecutable implements AssetPath { class Asset { final LinkMode linkMode; - final String name; + final String id; final Target target; final AssetPath path; Asset({ - required this.name, + required this.id, required this.linkMode, required this.target, required this.path, }); factory Asset.fromYaml(YamlMap yamlMap) => Asset( - name: as(yamlMap[_nameKey]), + id: as(yamlMap[_idKey] ?? yamlMap[_nameKey]), path: AssetPath.fromYaml(as(yamlMap[_pathKey])), target: Target.fromString(as(yamlMap[_targetKey])), linkMode: LinkMode.fromName(as(yamlMap[_linkModeKey])), @@ -227,12 +227,12 @@ class Asset { Asset copyWith({ LinkMode? linkMode, - String? name, + String? id, Target? target, AssetPath? path, }) => Asset( - name: name ?? this.name, + id: id ?? this.id, linkMode: linkMode ?? this.linkMode, target: target ?? this.target, path: path ?? this.path, @@ -243,28 +243,31 @@ class Asset { if (other is! Asset) { return false; } - return other.name == name && + return other.id == id && other.linkMode == linkMode && other.target == target && other.path == path; } @override - int get hashCode => Object.hash(name, linkMode, target, path); + int get hashCode => Object.hash(id, linkMode, target, path); Map toYaml() => { - _nameKey: name, + _idKey: id, _linkModeKey: linkMode.name, _pathKey: path.toYaml(), _targetKey: target.toString(), }; Map> toDartConst() => { - name: path.toDartConst(), + id: path.toDartConst(), }; String toYamlString() => yamlEncode(toYaml()); + static const _idKey = 'id'; + // TODO(https://github.com/dart-lang/native/issues/100): Remove name key when + // rolling dependencies in example. static const _nameKey = 'name'; static const _linkModeKey = 'link_mode'; static const _pathKey = 'path'; diff --git a/pkgs/native_assets_cli/pubspec.yaml b/pkgs/native_assets_cli/pubspec.yaml index 35a6f6de5..21fd0e17d 100644 --- a/pkgs/native_assets_cli/pubspec.yaml +++ b/pkgs/native_assets_cli/pubspec.yaml @@ -2,7 +2,7 @@ name: native_assets_cli description: >- A library that contains the argument and file formats for implementing a native assets CLI. -version: 0.1.1-wip +version: 0.2.0 repository: https://github.com/dart-lang/native/tree/main/pkgs/native_assets_cli topics: diff --git a/pkgs/native_assets_cli/test/model/asset_test.dart b/pkgs/native_assets_cli/test/model/asset_test.dart index a4aa644b3..93a2a073b 100644 --- a/pkgs/native_assets_cli/test/model/asset_test.dart +++ b/pkgs/native_assets_cli/test/model/asset_test.dart @@ -14,84 +14,84 @@ void main() { final blaUri = Uri(path: 'path/with spaces/bla.dll'); final assets = [ Asset( - name: 'foo', + id: 'foo', path: AssetAbsolutePath(fooUri), target: Target.androidX64, linkMode: LinkMode.dynamic, ), Asset( - name: 'foo2', + id: 'foo2', path: AssetRelativePath(foo2Uri), target: Target.androidX64, linkMode: LinkMode.dynamic, ), Asset( - name: 'foo3', + id: 'foo3', path: AssetSystemPath(foo3Uri), target: Target.androidX64, linkMode: LinkMode.dynamic, ), Asset( - name: 'foo4', + id: 'foo4', path: AssetInExecutable(), target: Target.androidX64, linkMode: LinkMode.dynamic, ), Asset( - name: 'foo5', + id: 'foo5', path: AssetInProcess(), target: Target.androidX64, linkMode: LinkMode.dynamic, ), Asset( - name: 'bar', + id: 'bar', path: AssetAbsolutePath(barUri), target: Target.linuxArm64, linkMode: LinkMode.static, ), Asset( - name: 'bla', + id: 'bla', path: AssetAbsolutePath(blaUri), target: Target.windowsX64, linkMode: LinkMode.dynamic, ), ]; - final assetsYamlEncoding = '''- name: foo + final assetsYamlEncoding = '''- id: foo link_mode: dynamic path: path_type: absolute uri: ${fooUri.toFilePath()} target: android_x64 -- name: foo2 +- id: foo2 link_mode: dynamic path: path_type: relative uri: ${foo2Uri.toFilePath()} target: android_x64 -- name: foo3 +- id: foo3 link_mode: dynamic path: path_type: system uri: ${foo3Uri.toFilePath()} target: android_x64 -- name: foo4 +- id: foo4 link_mode: dynamic path: path_type: executable target: android_x64 -- name: foo5 +- id: foo5 link_mode: dynamic path: path_type: process target: android_x64 -- name: bar +- id: bar link_mode: static path: path_type: absolute uri: ${barUri.toFilePath()} target: linux_arm64 -- name: bla +- id: bla link_mode: dynamic path: path_type: absolute @@ -149,7 +149,7 @@ native-assets: test('Asset hashCode copyWith', () async { final asset = assets.first; - final asset2 = asset.copyWith(name: 'foo321'); + final asset2 = asset.copyWith(id: 'foo321'); expect(asset.hashCode != asset2.hashCode, true); final asset3 = asset.copyWith(); @@ -179,7 +179,7 @@ native-assets: expect( assets.first.toYamlString(), ''' -name: foo +id: foo link_mode: dynamic path: path_type: absolute diff --git a/pkgs/native_assets_cli/test/model/build_output_test.dart b/pkgs/native_assets_cli/test/model/build_output_test.dart index c7f70c04c..849fe406f 100644 --- a/pkgs/native_assets_cli/test/model/build_output_test.dart +++ b/pkgs/native_assets_cli/test/model/build_output_test.dart @@ -22,13 +22,13 @@ void main() { timestamp: DateTime.parse('2022-11-10 13:25:01.000'), assets: [ Asset( - name: 'foo', + id: 'foo', path: AssetAbsolutePath(Uri(path: 'path/to/libfoo.so')), target: Target.androidX64, linkMode: LinkMode.dynamic, ), Asset( - name: 'foo2', + id: 'foo2', path: AssetRelativePath(Uri(path: 'path/to/libfoo2.so')), target: Target.androidX64, linkMode: LinkMode.dynamic, @@ -44,13 +44,13 @@ void main() { final yamlEncoding = '''timestamp: 2022-11-10 13:25:01.000 assets: - - name: foo + - id: foo link_mode: dynamic path: path_type: absolute uri: path/to/libfoo.so target: android_x64 - - name: foo2 + - id: foo2 link_mode: dynamic path: path_type: relative