Skip to content

Commit 0187d0e

Browse files
authored
[native_assets_cli] Rename Asset name to id (#113)
1 parent 1b984c7 commit 0187d0e

File tree

5 files changed

+36
-31
lines changed

5 files changed

+36
-31
lines changed

pkgs/native_assets_cli/CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
## 0.1.1-wip
1+
## 0.2.0
22

3+
- *Breaking change* Rename `Asset.name` to `Asset.id`
4+
([#100](https://github.com/dart-lang/native/issues/100)).
35
- Added topics.
46
- Fixed metadata example.
57
- Throws `FormatException`s instead of `TypeError`s when failing to parse Yaml

pkgs/native_assets_cli/lib/src/model/asset.dart

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -191,19 +191,19 @@ class AssetInExecutable implements AssetPath {
191191

192192
class Asset {
193193
final LinkMode linkMode;
194-
final String name;
194+
final String id;
195195
final Target target;
196196
final AssetPath path;
197197

198198
Asset({
199-
required this.name,
199+
required this.id,
200200
required this.linkMode,
201201
required this.target,
202202
required this.path,
203203
});
204204

205205
factory Asset.fromYaml(YamlMap yamlMap) => Asset(
206-
name: as<String>(yamlMap[_nameKey]),
206+
id: as<String>(yamlMap[_idKey] ?? yamlMap[_nameKey]),
207207
path: AssetPath.fromYaml(as<YamlMap>(yamlMap[_pathKey])),
208208
target: Target.fromString(as<String>(yamlMap[_targetKey])),
209209
linkMode: LinkMode.fromName(as<String>(yamlMap[_linkModeKey])),
@@ -227,12 +227,12 @@ class Asset {
227227

228228
Asset copyWith({
229229
LinkMode? linkMode,
230-
String? name,
230+
String? id,
231231
Target? target,
232232
AssetPath? path,
233233
}) =>
234234
Asset(
235-
name: name ?? this.name,
235+
id: id ?? this.id,
236236
linkMode: linkMode ?? this.linkMode,
237237
target: target ?? this.target,
238238
path: path ?? this.path,
@@ -243,28 +243,31 @@ class Asset {
243243
if (other is! Asset) {
244244
return false;
245245
}
246-
return other.name == name &&
246+
return other.id == id &&
247247
other.linkMode == linkMode &&
248248
other.target == target &&
249249
other.path == path;
250250
}
251251

252252
@override
253-
int get hashCode => Object.hash(name, linkMode, target, path);
253+
int get hashCode => Object.hash(id, linkMode, target, path);
254254

255255
Map<String, Object> toYaml() => {
256-
_nameKey: name,
256+
_idKey: id,
257257
_linkModeKey: linkMode.name,
258258
_pathKey: path.toYaml(),
259259
_targetKey: target.toString(),
260260
};
261261

262262
Map<String, List<String>> toDartConst() => {
263-
name: path.toDartConst(),
263+
id: path.toDartConst(),
264264
};
265265

266266
String toYamlString() => yamlEncode(toYaml());
267267

268+
static const _idKey = 'id';
269+
// TODO(https://github.com/dart-lang/native/issues/100): Remove name key when
270+
// rolling dependencies in example.
268271
static const _nameKey = 'name';
269272
static const _linkModeKey = 'link_mode';
270273
static const _pathKey = 'path';

pkgs/native_assets_cli/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: native_assets_cli
22
description: >-
33
A library that contains the argument and file formats for implementing a
44
native assets CLI.
5-
version: 0.1.1-wip
5+
version: 0.2.0
66
repository: https://github.com/dart-lang/native/tree/main/pkgs/native_assets_cli
77

88
topics:

pkgs/native_assets_cli/test/model/asset_test.dart

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,84 +14,84 @@ void main() {
1414
final blaUri = Uri(path: 'path/with spaces/bla.dll');
1515
final assets = [
1616
Asset(
17-
name: 'foo',
17+
id: 'foo',
1818
path: AssetAbsolutePath(fooUri),
1919
target: Target.androidX64,
2020
linkMode: LinkMode.dynamic,
2121
),
2222
Asset(
23-
name: 'foo2',
23+
id: 'foo2',
2424
path: AssetRelativePath(foo2Uri),
2525
target: Target.androidX64,
2626
linkMode: LinkMode.dynamic,
2727
),
2828
Asset(
29-
name: 'foo3',
29+
id: 'foo3',
3030
path: AssetSystemPath(foo3Uri),
3131
target: Target.androidX64,
3232
linkMode: LinkMode.dynamic,
3333
),
3434
Asset(
35-
name: 'foo4',
35+
id: 'foo4',
3636
path: AssetInExecutable(),
3737
target: Target.androidX64,
3838
linkMode: LinkMode.dynamic,
3939
),
4040
Asset(
41-
name: 'foo5',
41+
id: 'foo5',
4242
path: AssetInProcess(),
4343
target: Target.androidX64,
4444
linkMode: LinkMode.dynamic,
4545
),
4646
Asset(
47-
name: 'bar',
47+
id: 'bar',
4848
path: AssetAbsolutePath(barUri),
4949
target: Target.linuxArm64,
5050
linkMode: LinkMode.static,
5151
),
5252
Asset(
53-
name: 'bla',
53+
id: 'bla',
5454
path: AssetAbsolutePath(blaUri),
5555
target: Target.windowsX64,
5656
linkMode: LinkMode.dynamic,
5757
),
5858
];
5959

60-
final assetsYamlEncoding = '''- name: foo
60+
final assetsYamlEncoding = '''- id: foo
6161
link_mode: dynamic
6262
path:
6363
path_type: absolute
6464
uri: ${fooUri.toFilePath()}
6565
target: android_x64
66-
- name: foo2
66+
- id: foo2
6767
link_mode: dynamic
6868
path:
6969
path_type: relative
7070
uri: ${foo2Uri.toFilePath()}
7171
target: android_x64
72-
- name: foo3
72+
- id: foo3
7373
link_mode: dynamic
7474
path:
7575
path_type: system
7676
uri: ${foo3Uri.toFilePath()}
7777
target: android_x64
78-
- name: foo4
78+
- id: foo4
7979
link_mode: dynamic
8080
path:
8181
path_type: executable
8282
target: android_x64
83-
- name: foo5
83+
- id: foo5
8484
link_mode: dynamic
8585
path:
8686
path_type: process
8787
target: android_x64
88-
- name: bar
88+
- id: bar
8989
link_mode: static
9090
path:
9191
path_type: absolute
9292
uri: ${barUri.toFilePath()}
9393
target: linux_arm64
94-
- name: bla
94+
- id: bla
9595
link_mode: dynamic
9696
path:
9797
path_type: absolute
@@ -149,7 +149,7 @@ native-assets:
149149

150150
test('Asset hashCode copyWith', () async {
151151
final asset = assets.first;
152-
final asset2 = asset.copyWith(name: 'foo321');
152+
final asset2 = asset.copyWith(id: 'foo321');
153153
expect(asset.hashCode != asset2.hashCode, true);
154154

155155
final asset3 = asset.copyWith();
@@ -179,7 +179,7 @@ native-assets:
179179
expect(
180180
assets.first.toYamlString(),
181181
'''
182-
name: foo
182+
id: foo
183183
link_mode: dynamic
184184
path:
185185
path_type: absolute

pkgs/native_assets_cli/test/model/build_output_test.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ void main() {
2222
timestamp: DateTime.parse('2022-11-10 13:25:01.000'),
2323
assets: [
2424
Asset(
25-
name: 'foo',
25+
id: 'foo',
2626
path: AssetAbsolutePath(Uri(path: 'path/to/libfoo.so')),
2727
target: Target.androidX64,
2828
linkMode: LinkMode.dynamic,
2929
),
3030
Asset(
31-
name: 'foo2',
31+
id: 'foo2',
3232
path: AssetRelativePath(Uri(path: 'path/to/libfoo2.so')),
3333
target: Target.androidX64,
3434
linkMode: LinkMode.dynamic,
@@ -44,13 +44,13 @@ void main() {
4444

4545
final yamlEncoding = '''timestamp: 2022-11-10 13:25:01.000
4646
assets:
47-
- name: foo
47+
- id: foo
4848
link_mode: dynamic
4949
path:
5050
path_type: absolute
5151
uri: path/to/libfoo.so
5252
target: android_x64
53-
- name: foo2
53+
- id: foo2
5454
link_mode: dynamic
5555
path:
5656
path_type: relative

0 commit comments

Comments
 (0)