@@ -33,29 +33,6 @@ typedef LinkInputCreator = LinkInputBuilder Function();
33
33
typedef _HookValidator =
34
34
Future <ValidationErrors > Function (HookInput input, HookOutput output);
35
35
36
- // A callback that validates the invariants of the [BuildInput].
37
- typedef BuildInputValidator =
38
- Future <ValidationErrors > Function (BuildInput input);
39
-
40
- // A callback that validates the invariants of the [LinkInput].
41
- typedef LinkInputValidator = Future <ValidationErrors > Function (LinkInput input);
42
-
43
- // A callback that validates the output of a `hook/link.dart` invocation is
44
- // valid (it may valid asset-type specific information).
45
- typedef BuildValidator =
46
- Future <ValidationErrors > Function (BuildInput input, BuildOutput outup);
47
-
48
- // A callback that validates the output of a `hook/link.dart` invocation is
49
- // valid (it may valid asset-type specific information).
50
- typedef LinkValidator =
51
- Future <ValidationErrors > Function (LinkInput input, LinkOutput output);
52
-
53
- // A callback that validates assets emitted across all packages are valid / can
54
- // be used together (it may valid asset-type specific information - e.g. that
55
- // there are no classes in shared library filenames).
56
- typedef ApplicationAssetValidator =
57
- Future <ValidationErrors > Function (List <EncodedAsset > assets);
58
-
59
36
/// The programmatic API to be used by Dart launchers to invoke native builds.
60
37
///
61
38
/// These methods are invoked by launchers such as dartdev (for `dart run` )
@@ -98,18 +75,11 @@ class NativeAssetsBuildRunner {
98
75
/// This method is invoked by launchers such as dartdev (for `dart run` ) and
99
76
/// flutter_tools (for `flutter run` and `flutter build` ).
100
77
///
101
- /// The given [applicationAssetValidator] is only used if the build is
102
- /// performed without linking (i.e. [linkingEnabled] is `false` ).
103
- ///
104
78
/// The native assets build runner does not support reentrancy for identical
105
79
/// [BuildInput] and [LinkInput] ! For more info see:
106
80
/// https://github.com/dart-lang/native/issues/1319
107
81
Future <BuildResult ?> build ({
108
- required BuildInputCreator inputCreator,
109
- required BuildInputValidator inputValidator,
110
- required BuildValidator buildValidator,
111
- required ApplicationAssetValidator applicationAssetValidator,
112
- required List <String > buildAssetTypes,
82
+ required List <ProtocolExtension > extensions,
113
83
required bool linkingEnabled,
114
84
}) async {
115
85
final (buildPlan, packageGraph) = await _makePlan (
@@ -132,11 +102,15 @@ class NativeAssetsBuildRunner {
132
102
targetMetadata: globalMetadata,
133
103
)? .forEach ((key, value) => metadata[key] = value);
134
104
135
- final inputBuilder =
136
- inputCreator ()
137
- ..config.setupShared (buildAssetTypes: buildAssetTypes)
138
- ..config.setupBuild (linkingEnabled: linkingEnabled)
139
- ..setupBuildInput (metadata: metadata);
105
+ final inputBuilder = BuildInputBuilder ();
106
+ inputBuilder.config.setupShared (
107
+ buildAssetTypes: [for (final e in extensions) ...e.buildAssetTypes],
108
+ );
109
+ for (final e in extensions) {
110
+ e.setupBuildInput (inputBuilder);
111
+ }
112
+ inputBuilder.config.setupBuild (linkingEnabled: linkingEnabled);
113
+ inputBuilder.setupBuildInput (metadata: metadata);
140
114
141
115
final (buildDirUri, outDirUri, outDirSharedUri) = await _setupDirectories (
142
116
Hook .build,
@@ -155,7 +129,7 @@ class NativeAssetsBuildRunner {
155
129
final input = BuildInput (inputBuilder.json);
156
130
final errors = [
157
131
...await validateBuildInput (input),
158
- ...await inputValidator (input),
132
+ for ( final e in extensions) ...await e. validateBuildInput (input),
159
133
];
160
134
if (errors.isNotEmpty) {
161
135
return _printErrors (
@@ -167,8 +141,13 @@ class NativeAssetsBuildRunner {
167
141
final result = await _runHookForPackageCached (
168
142
Hook .build,
169
143
input,
170
- (input, output) =>
171
- buildValidator (input as BuildInput , output as BuildOutput ),
144
+ (input, output) async => [
145
+ for (final e in extensions)
146
+ ...await e.validateBuildOutput (
147
+ input as BuildInput ,
148
+ output as BuildOutput ,
149
+ ),
150
+ ],
172
151
null ,
173
152
);
174
153
if (result == null ) return null ;
@@ -182,7 +161,10 @@ class NativeAssetsBuildRunner {
182
161
// in the link step if linking is enableD).
183
162
if (linkingEnabled) return hookResult;
184
163
185
- final errors = await applicationAssetValidator (hookResult.encodedAssets);
164
+ final errors = [
165
+ for (final e in extensions)
166
+ ...await e.validateApplicationAssets (hookResult.encodedAssets),
167
+ ];
186
168
if (errors.isEmpty) return hookResult;
187
169
188
170
_printErrors ('Application asset verification failed' , errors);
@@ -196,12 +178,8 @@ class NativeAssetsBuildRunner {
196
178
/// [BuildInput] and [LinkInput] ! For more info see:
197
179
/// https://github.com/dart-lang/native/issues/1319
198
180
Future <LinkResult ?> link ({
199
- required LinkInputCreator inputCreator,
200
- required LinkInputValidator inputValidator,
201
- required LinkValidator linkValidator,
202
- required ApplicationAssetValidator applicationAssetValidator,
181
+ required List <ProtocolExtension > extensions,
203
182
Uri ? resourceIdentifiers,
204
- required List <String > buildAssetTypes,
205
183
required BuildResult buildResult,
206
184
}) async {
207
185
final (buildPlan, packageGraph) = await _makePlan (
@@ -212,8 +190,13 @@ class NativeAssetsBuildRunner {
212
190
213
191
var hookResult = HookResult (encodedAssets: buildResult.encodedAssets);
214
192
for (final package in buildPlan) {
215
- final inputBuilder =
216
- inputCreator ()..config.setupShared (buildAssetTypes: buildAssetTypes);
193
+ final inputBuilder = LinkInputBuilder ();
194
+ inputBuilder.config.setupShared (
195
+ buildAssetTypes: [for (final e in extensions) ...e.buildAssetTypes],
196
+ );
197
+ for (final e in extensions) {
198
+ e.setupLinkInput (inputBuilder);
199
+ }
217
200
218
201
final (buildDirUri, outDirUri, outDirSharedUri) = await _setupDirectories (
219
202
Hook .link,
@@ -243,7 +226,7 @@ class NativeAssetsBuildRunner {
243
226
final input = LinkInput (inputBuilder.json);
244
227
final errors = [
245
228
...await validateLinkInput (input),
246
- ...await inputValidator (input),
229
+ for ( final e in extensions) ...await e. validateLinkInput (input),
247
230
];
248
231
if (errors.isNotEmpty) {
249
232
print (input.assets.encodedAssets);
@@ -256,16 +239,24 @@ class NativeAssetsBuildRunner {
256
239
final result = await _runHookForPackageCached (
257
240
Hook .link,
258
241
input,
259
- (input, output) =>
260
- linkValidator (input as LinkInput , output as LinkOutput ),
242
+ (input, output) async => [
243
+ for (final e in extensions)
244
+ ...await e.validateLinkOutput (
245
+ input as LinkInput ,
246
+ output as LinkOutput ,
247
+ ),
248
+ ],
261
249
resourceIdentifiers,
262
250
);
263
251
if (result == null ) return null ;
264
252
final (hookOutput, hookDeps) = result;
265
253
hookResult = hookResult.copyAdd (hookOutput, hookDeps);
266
254
}
267
255
268
- final errors = await applicationAssetValidator (hookResult.encodedAssets);
256
+ final errors = [
257
+ for (final e in extensions)
258
+ ...await e.validateApplicationAssets (hookResult.encodedAssets),
259
+ ];
269
260
if (errors.isEmpty) return hookResult;
270
261
271
262
_printErrors ('Application asset verification failed' , errors);
0 commit comments