Skip to content

Commit 0eeaa2d

Browse files
authored
[native_assets_cli] Fix snake casing in JSON (#2128)
Closes: #2037 Closes: #2038 Fixes spelling in the JSON format: * `prefer-dynamic` -> `prefer_dynamic` * `prefer-static` -> `prefer_static` * `assetsForLinking` -> `assets_for_linking` ### PR changes * `pkgs/hook`, `pkgs/code_assets`, and `pkgs/data_assets` * Introduces new schemas in the non-generated `.schema.json` files * Updates the generated schemas to pick up on the new spelling for `assets_for_linking`. * Adds test data for the new spelling. * Added JSON schema tests for the new spelling. * `package:native_assets_cli` * Generated the syntax classes * Deal with version skew in the mapping between syntax classes and semantic API ### Version skew between hooks and SDKs * For #2037 * Backwards compatibility older SDKs: Also still emit `assetsForLinking`, instead of only `assets_for_linking`. * Backwards compatibility older hooks: Also still read `assetsForLinking`, instead of only `assets_for_linking`. * For #2038 * Backwards compatibility older SDKs: Still read the casing with dashes. * Backwards compatibility older hooks: Irrelevant. Both Flutter and Dart only use `dynamic`.
1 parent 4073532 commit 0eeaa2d

File tree

21 files changed

+228
-38
lines changed

21 files changed

+228
-38
lines changed

pkgs/code_assets/doc/schema/shared/shared_definitions.generated.schema.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,15 @@
3131
"$ref": "shared_definitions.schema.json#/definitions/Asset"
3232
}
3333
}
34+
},
35+
"assets_for_linking": {
36+
"type": "object",
37+
"additionalProperties": {
38+
"type": "array",
39+
"items": {
40+
"$ref": "shared_definitions.schema.json#/definitions/Asset"
41+
}
42+
}
3443
}
3544
}
3645
}

pkgs/code_assets/doc/schema/shared/shared_definitions.schema.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,12 @@
335335
{
336336
"const": "dynamic"
337337
},
338+
{
339+
"const": "prefer_dynamic"
340+
},
341+
{
342+
"const": "prefer_static"
343+
},
338344
{
339345
"const": "prefer-dynamic"
340346
},

pkgs/code_assets/test/data/build_output_macos.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,20 @@
6464
}
6565
]
6666
},
67+
"assets_for_linking": {
68+
"package_with_linker": [
69+
{
70+
"architecture": "arm64",
71+
"file": "/private/var/folders/2y/mngq9h194yzglt4kzttzfq6800klzg/T/iv6i0d/native_add/.dart_tool/native_assets_builder/native_add/c6b312c90c95d2d98ffb6760a738fb36/out/libnative_add.a",
72+
"id": "package:native_add/src/native_add_bindings_generated.dart",
73+
"link_mode": {
74+
"type": "static"
75+
},
76+
"os": "macos",
77+
"type": "native_code"
78+
}
79+
]
80+
},
6781
"dependencies": [
6882
"/private/var/folders/2y/mngq9h194yzglt4kzttzfq6800klzg/T/ZnD2I3/native_add/src/native_add.c"
6983
],

pkgs/code_assets/test/schema/schema_test.dart

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,14 @@ FieldsFunction _codeFields(AllTestData allTestData) {
116116
(['assets', 0, ...field], expectRequiredFieldMissing),
117117
if (hook == Hook.build) ...[
118118
for (final field in requiredCodeAssetFields)
119-
(
120-
['assetsForLinking', 'package_with_linker', 0, ...field],
121-
expectRequiredFieldMissing,
122-
),
119+
for (final assetsForLinking in [
120+
'assetsForLinking',
121+
'assets_for_linking',
122+
])
123+
(
124+
[assetsForLinking, 'package_with_linker', 0, ...field],
125+
expectRequiredFieldMissing,
126+
),
123127
],
124128
(['assets', staticIndex, 'file'], expectRequiredFieldMissing),
125129
(

pkgs/data_assets/doc/schema/shared/shared_definitions.generated.schema.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,15 @@
3131
"$ref": "shared_definitions.schema.json#/definitions/Asset"
3232
}
3333
}
34+
},
35+
"assets_for_linking": {
36+
"type": "object",
37+
"additionalProperties": {
38+
"type": "array",
39+
"items": {
40+
"$ref": "shared_definitions.schema.json#/definitions/Asset"
41+
}
42+
}
3443
}
3544
}
3645
}

pkgs/data_assets/test/data/build_output.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,22 @@
3030
}
3131
]
3232
},
33+
"assets_for_linking": {
34+
"package_with_linker": [
35+
{
36+
"file": "/private/var/folders/2y/mngq9h194yzglt4kzttzfq6800klzg/T/0s5bKi/simple_link/assets/data_0.json",
37+
"name": "assets/data_0.json",
38+
"package": "simple_link",
39+
"type": "data"
40+
},
41+
{
42+
"file": "/private/var/folders/2y/mngq9h194yzglt4kzttzfq6800klzg/T/0s5bKi/simple_link/assets/data_1.json",
43+
"name": "assets/data_1.json",
44+
"package": "simple_link",
45+
"type": "data"
46+
}
47+
]
48+
},
3349
"dependencies": [
3450
"/private/var/folders/2y/mngq9h194yzglt4kzttzfq6800klzg/T/0s5bKi/simple_link/assets/data_2.json",
3551
"/private/var/folders/2y/mngq9h194yzglt4kzttzfq6800klzg/T/0s5bKi/simple_link/assets/data_3.json"

pkgs/data_assets/test/schema/schema_test.dart

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,14 @@ List<(List<Object>, void Function(ValidationResults result))> _dataFields({
5050
(['assets', 0, field], expectRequiredFieldMissing),
5151
if (hook == Hook.build) ...[
5252
for (final field in _dataAssetFields)
53-
(
54-
['assetsForLinking', 'package_with_linker', 0, field],
55-
expectRequiredFieldMissing,
56-
),
53+
for (final assetsForLinking in [
54+
'assetsForLinking',
55+
'assets_for_linking',
56+
])
57+
(
58+
[assetsForLinking, 'package_with_linker', 0, field],
59+
expectRequiredFieldMissing,
60+
),
5761
],
5862
],
5963
];

pkgs/hook/doc/schema/hook/shared_definitions.schema.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55
"BuildInput": {},
66
"BuildOutput": {
77
"$ref": "../shared/shared_definitions.schema.json#/definitions/BuildOutput",
8+
"properties": {
9+
"assets_for_linking": {
10+
"$comment": "Older SDKs will only read 'assetsForLinking', so it must be emitted as well."
11+
}
12+
},
813
"unevaluatedProperties": false
914
},
1015
"HookInput": {

pkgs/hook/doc/schema/sdk/shared_definitions.schema.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,16 @@
66
"$ref": "../shared/shared_definitions.schema.json#/definitions/BuildInput",
77
"unevaluatedProperties": false
88
},
9-
"BuildOutput": {},
9+
"BuildOutput": {
10+
"properties": {
11+
"assetsForLinking": {
12+
"deprecated": true
13+
},
14+
"assets_for_linking": {
15+
"$comment": "Older hooks will still emit 'assetsForLinking', so it must be read."
16+
}
17+
}
18+
},
1019
"HookInput": {
1120
"properties": {
1221
"out_file": {

pkgs/hook/doc/schema/shared/shared_definitions.schema.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,15 @@
6161
}
6262
}
6363
},
64+
"assets_for_linking": {
65+
"type": "object",
66+
"additionalProperties": {
67+
"type": "array",
68+
"items": {
69+
"$ref": "#/definitions/Asset"
70+
}
71+
}
72+
},
6473
"metadata": {
6574
"type": "object",
6675
"additionalProperties": true

0 commit comments

Comments
 (0)