@@ -9,15 +9,12 @@ import 'config.dart';
9
9
import 'link_mode.dart' ;
10
10
11
11
Future <ValidationErrors > validateCodeAssetBuildInput (BuildInput input) async =>
12
- _validateCodeConfig (
13
- 'BuildInput.config.code' ,
12
+ _validateCodeConfig ('BuildInput.config.code' , input.config.code);
14
13
15
- // ignore: deprecated_member_use_from_same_package
16
- input.config.code,
17
- );
18
-
19
- Future <ValidationErrors > validateCodeAssetLinkInput (LinkInput input) async =>
20
- _validateCodeConfig ('LinkInput.config.code' , input.config.code);
14
+ Future <ValidationErrors > validateCodeAssetLinkInput (LinkInput input) async => [
15
+ ..._validateCodeConfig ('LinkInput.config.code' , input.config.code),
16
+ ...await _validateCodeAssetLinkInput (input.assets.encodedAssets),
17
+ ];
21
18
22
19
ValidationErrors _validateCodeConfig (String inputName, CodeConfig code) {
23
20
final errors = < String > [];
@@ -74,13 +71,25 @@ ValidationErrors _validateCodeConfig(String inputName, CodeConfig code) {
74
71
return errors;
75
72
}
76
73
74
+ Future <ValidationErrors > _validateCodeAssetLinkInput (
75
+ List <EncodedAsset > encodedAssets,
76
+ ) async => [
77
+ for (final asset in encodedAssets)
78
+ if (asset.type == CodeAsset .type)
79
+ ..._validateCodeAssetFile (CodeAsset .fromEncoded (asset)),
80
+ ];
81
+
77
82
Future <ValidationErrors > validateCodeAssetBuildOutput (
78
83
BuildInput input,
79
84
BuildOutput output,
80
85
) => _validateCodeAssetBuildOrLinkOutput (
81
86
input,
82
87
input.config.code,
83
88
output.assets.encodedAssets,
89
+ [
90
+ for (final assetList in output.assets.encodedAssetsForLinking.values)
91
+ ...assetList,
92
+ ],
84
93
output,
85
94
true ,
86
95
);
@@ -92,6 +101,7 @@ Future<ValidationErrors> validateCodeAssetLinkOutput(
92
101
input,
93
102
input.config.code,
94
103
output.assets.encodedAssets,
104
+ [],
95
105
output,
96
106
false ,
97
107
);
@@ -121,6 +131,7 @@ Future<ValidationErrors> _validateCodeAssetBuildOrLinkOutput(
121
131
HookInput input,
122
132
CodeConfig codeConfig,
123
133
List <EncodedAsset > encodedAssets,
134
+ List <EncodedAsset > encodedAssetsForLinking,
124
135
HookOutput output,
125
136
bool isBuild,
126
137
) async {
@@ -130,49 +141,68 @@ Future<ValidationErrors> _validateCodeAssetBuildOrLinkOutput(
130
141
131
142
for (final asset in encodedAssets) {
132
143
if (asset.type != CodeAsset .type) continue ;
133
- _validateCodeAssets (
144
+ _validateCodeAsset (
134
145
input,
135
146
codeConfig,
136
147
CodeAsset .fromEncoded (asset),
137
148
errors,
138
149
ids,
139
150
isBuild,
151
+ true ,
140
152
);
141
153
_groupCodeAssetsByFilename (
142
154
CodeAsset .fromEncoded (asset),
143
155
fileNameToEncodedAssetId,
144
156
);
145
157
}
158
+
159
+ for (final asset in encodedAssetsForLinking) {
160
+ if (asset.type != CodeAsset .type) continue ;
161
+ _validateCodeAsset (
162
+ input,
163
+ codeConfig,
164
+ CodeAsset .fromEncoded (asset),
165
+ errors,
166
+ ids,
167
+ isBuild,
168
+ false ,
169
+ );
170
+ }
146
171
_validateNoDuplicateDylibNames (errors, fileNameToEncodedAssetId);
147
172
return errors;
148
173
}
149
174
150
- void _validateCodeAssets (
175
+ void _validateCodeAsset (
151
176
HookInput input,
152
177
CodeConfig codeConfig,
153
178
CodeAsset codeAsset,
154
179
List <String > errors,
155
180
Set <String > ids,
156
- bool isBuild,
181
+ bool validateAssetId,
182
+ bool validateLinkMode,
157
183
) {
158
184
final id = codeAsset.id;
159
185
final prefix = 'package:${input .packageName }/' ;
160
- if (isBuild && ! id.startsWith (prefix)) {
186
+ if (validateAssetId && ! id.startsWith (prefix)) {
161
187
errors.add ('Code asset "$id " does not start with "$prefix ".' );
162
188
}
163
189
if (! ids.add (id)) {
164
190
errors.add ('More than one code asset with same "$id " id.' );
165
191
}
166
192
167
- final preference = codeConfig.linkModePreference;
168
- final linkMode = codeAsset.linkMode;
169
- if ((linkMode is DynamicLoading && preference == LinkModePreference .static ) ||
170
- (linkMode is StaticLinking && preference == LinkModePreference .dynamic )) {
171
- errors.add (
172
- 'CodeAsset "$id " has a link mode "$linkMode ", which '
173
- 'is not allowed by by the input link mode preference '
174
- '"$preference ".' ,
175
- );
193
+ if (validateLinkMode) {
194
+ final preference = codeConfig.linkModePreference;
195
+ final linkMode = codeAsset.linkMode;
196
+ if ((linkMode is DynamicLoading &&
197
+ preference == LinkModePreference .static ) ||
198
+ (linkMode is StaticLinking &&
199
+ preference == LinkModePreference .dynamic )) {
200
+ errors.add (
201
+ 'CodeAsset "$id " has a link mode "$linkMode ", which '
202
+ 'is not allowed by by the input link mode preference '
203
+ '"$preference ".' ,
204
+ );
205
+ }
176
206
}
177
207
178
208
final os = codeAsset.os;
@@ -194,13 +224,17 @@ void _validateCodeAssets(
194
224
);
195
225
}
196
226
227
+ errors.addAll (_validateCodeAssetFile (codeAsset));
228
+ }
229
+
230
+ List <String > _validateCodeAssetFile (CodeAsset codeAsset) {
231
+ final id = codeAsset.id;
197
232
final file = codeAsset.file;
198
- if (file == null && _mustHaveFile (codeAsset.linkMode)) {
199
- errors.add ('CodeAsset "$id " has no file.' );
200
- }
201
- if (file != null ) {
202
- errors.addAll (_validateFile ('Code asset "$id " file' , file));
203
- }
233
+ return [
234
+ if (file == null && _mustHaveFile (codeAsset.linkMode))
235
+ 'CodeAsset "$id " has no file.' ,
236
+ if (file != null ) ..._validateFile ('Code asset "$id " file' , file),
237
+ ];
204
238
}
205
239
206
240
bool _mustHaveFile (LinkMode linkMode) => switch (linkMode) {
0 commit comments