Skip to content

Commit 6e12c3a

Browse files
authored
[native_assets_cli] Fix V1_0_0 backwards compatibility (#1055)
1 parent c141234 commit 6e12c3a

File tree

5 files changed

+93
-11
lines changed

5 files changed

+93
-11
lines changed

pkgs/native_assets_cli/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 0.5.3
2+
3+
- Fix V1_0_0 dry run backwards compatibility.
4+
https://github.com/dart-lang/native/issues/1053
5+
16
## 0.5.2
27

38
- Fix test.

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

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -90,16 +90,38 @@ final class BuildOutputImpl implements BuildOutput {
9090
);
9191
}
9292

93-
Map<String, Object> toJson(Version version) => {
94-
_timestampKey: timestamp.toString(),
95-
_assetsKey: [
96-
for (final asset in _assets) asset.toJson(version),
97-
],
98-
if (_dependencies.dependencies.isNotEmpty)
99-
_dependenciesKey: _dependencies.toJson(),
100-
_metadataKey: _metadata.toJson(),
101-
_versionKey: version.toString(),
102-
}..sortOnKey();
93+
Map<String, Object> toJson(Version version) {
94+
final assets = <AssetImpl>[];
95+
for (final asset in _assets) {
96+
switch (asset) {
97+
case NativeCodeAssetImpl _:
98+
if (version <= Version(1, 0, 0) && asset.architecture == null) {
99+
// Dry run does not report architecture. But old Dart and Flutter
100+
// expect architecture to be populated. So, populate assets for all
101+
// architectures.
102+
for (final architecture in asset.os.architectures) {
103+
assets.add(asset.copyWith(
104+
architecture: architecture,
105+
));
106+
}
107+
} else {
108+
assets.add(asset);
109+
}
110+
default:
111+
assets.add(asset);
112+
}
113+
}
114+
return {
115+
_timestampKey: timestamp.toString(),
116+
_assetsKey: [
117+
for (final asset in assets) asset.toJson(version),
118+
],
119+
if (_dependencies.dependencies.isNotEmpty)
120+
_dependenciesKey: _dependencies.toJson(),
121+
_metadataKey: _metadata.toJson(),
122+
_versionKey: version.toString(),
123+
}..sortOnKey();
124+
}
103125

104126
String toJsonString(Version version) =>
105127
const JsonEncoder.withIndent(' ').convert(toJson(version));

pkgs/native_assets_cli/lib/src/model/build_output_CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
Backwards compatibility older SDKs: emit the old format if an older BuildConfig was passed in.
1919
- Added `DataAsset`s.
2020
Backwards compatibility: These are ignored on older SDKs.
21+
- `architecture` is optional.
22+
Backwards compatibility older SDKs: expand the assets to include all architectures.
2123

2224
## 1.0.0
2325

pkgs/native_assets_cli/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description: >-
44
native assets CLI.
55
66
# Note: Bump BuildConfig.version and BuildOutput.version on breaking changes!
7-
version: 0.5.2
7+
version: 0.5.3
88
repository: https://github.com/dart-lang/native/tree/main/pkgs/native_assets_cli
99

1010
topics:

pkgs/native_assets_cli/test/model/build_output_test.dart

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,18 @@ void main() {
5858
}),
5959
);
6060

61+
final dryRunOutput = BuildOutputImpl(
62+
timestamp: DateTime.parse('2022-11-10 13:25:01.000'),
63+
assets: [
64+
NativeCodeAssetImpl(
65+
id: 'package:my_package/foo',
66+
file: Uri(path: 'path/to/libfoo.so'),
67+
linkMode: DynamicLoadingBundledImpl(),
68+
os: OSImpl.android,
69+
),
70+
],
71+
);
72+
6173
const yamlEncodingV1_0_0 = '''timestamp: 2022-11-10 13:25:01.000
6274
assets:
6375
- id: package:my_package/foo
@@ -88,6 +100,41 @@ metadata:
88100
key: value
89101
version: 1.0.0''';
90102

103+
const yamlEncodingV1_0_0dryRun = '''timestamp: 2022-11-10 13:25:01.000
104+
assets:
105+
- id: package:my_package/foo
106+
link_mode: dynamic
107+
path:
108+
path_type: absolute
109+
uri: path/to/libfoo.so
110+
target: android_arm
111+
- id: package:my_package/foo
112+
link_mode: dynamic
113+
path:
114+
path_type: absolute
115+
uri: path/to/libfoo.so
116+
target: android_arm64
117+
- id: package:my_package/foo
118+
link_mode: dynamic
119+
path:
120+
path_type: absolute
121+
uri: path/to/libfoo.so
122+
target: android_ia32
123+
- id: package:my_package/foo
124+
link_mode: dynamic
125+
path:
126+
path_type: absolute
127+
uri: path/to/libfoo.so
128+
target: android_x64
129+
- id: package:my_package/foo
130+
link_mode: dynamic
131+
path:
132+
path_type: absolute
133+
uri: path/to/libfoo.so
134+
target: android_riscv64
135+
metadata: {}
136+
version: 1.0.0''';
137+
91138
final yamlEncoding = '''timestamp: 2022-11-10 13:25:01.000
92139
assets:
93140
- architecture: x64
@@ -200,6 +247,12 @@ version: ${BuildOutputImpl.latestVersion}''';
200247
expect(yamlEncoding, yamlEncodingV1_0_0);
201248
});
202249

250+
test('built info yaml v1.0.0 serialization keeps working dry run', () {
251+
final yamlEncoding =
252+
yamlEncode(dryRunOutput.toJson(Version(1, 0, 0))).replaceAll('\\', '/');
253+
expect(yamlEncoding, yamlEncodingV1_0_0dryRun);
254+
});
255+
203256
test('BuildOutput.toString', buildOutput.toString);
204257

205258
test('BuildOutput.hashCode', () {

0 commit comments

Comments
 (0)