@@ -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,14 @@ 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
81
+ ///
82
+ /// The base protocol can be extended with [extensions] . See
83
+ /// [ProtocolExtension] for more documentation.
107
84
Future <BuildResult ?> build ({
108
- required BuildInputCreator inputCreator,
109
- required BuildInputValidator inputValidator,
110
- required BuildValidator buildValidator,
111
- required ApplicationAssetValidator applicationAssetValidator,
112
- required List <String > buildAssetTypes,
85
+ required List <ProtocolExtension > extensions,
113
86
required bool linkingEnabled,
114
87
}) async {
115
88
final (buildPlan, packageGraph) = await _makePlan (
@@ -132,11 +105,15 @@ class NativeAssetsBuildRunner {
132
105
targetMetadata: globalMetadata,
133
106
)? .forEach ((key, value) => metadata[key] = value);
134
107
135
- final inputBuilder =
136
- inputCreator ()
137
- ..config.setupShared (buildAssetTypes: buildAssetTypes)
138
- ..config.setupBuild (linkingEnabled: linkingEnabled)
139
- ..setupBuildInput (metadata: metadata);
108
+ final inputBuilder = BuildInputBuilder ();
109
+ inputBuilder.config.setupShared (
110
+ buildAssetTypes: [for (final e in extensions) ...e.buildAssetTypes],
111
+ );
112
+ for (final e in extensions) {
113
+ e.setupBuildInput (inputBuilder);
114
+ }
115
+ inputBuilder.config.setupBuild (linkingEnabled: linkingEnabled);
116
+ inputBuilder.setupBuildInput (metadata: metadata);
140
117
141
118
final (buildDirUri, outDirUri, outDirSharedUri) = await _setupDirectories (
142
119
Hook .build,
@@ -155,7 +132,7 @@ class NativeAssetsBuildRunner {
155
132
final input = BuildInput (inputBuilder.json);
156
133
final errors = [
157
134
...await validateBuildInput (input),
158
- ...await inputValidator (input),
135
+ for ( final e in extensions) ...await e. validateBuildInput (input),
159
136
];
160
137
if (errors.isNotEmpty) {
161
138
return _printErrors (
@@ -167,8 +144,13 @@ class NativeAssetsBuildRunner {
167
144
final result = await _runHookForPackageCached (
168
145
Hook .build,
169
146
input,
170
- (input, output) =>
171
- buildValidator (input as BuildInput , output as BuildOutput ),
147
+ (input, output) async => [
148
+ for (final e in extensions)
149
+ ...await e.validateBuildOutput (
150
+ input as BuildInput ,
151
+ output as BuildOutput ,
152
+ ),
153
+ ],
172
154
null ,
173
155
);
174
156
if (result == null ) return null ;
@@ -182,7 +164,10 @@ class NativeAssetsBuildRunner {
182
164
// in the link step if linking is enableD).
183
165
if (linkingEnabled) return hookResult;
184
166
185
- final errors = await applicationAssetValidator (hookResult.encodedAssets);
167
+ final errors = [
168
+ for (final e in extensions)
169
+ ...await e.validateApplicationAssets (hookResult.encodedAssets),
170
+ ];
186
171
if (errors.isEmpty) return hookResult;
187
172
188
173
_printErrors ('Application asset verification failed' , errors);
@@ -195,13 +180,12 @@ class NativeAssetsBuildRunner {
195
180
/// The native assets build runner does not support reentrancy for identical
196
181
/// [BuildInput] and [LinkInput] ! For more info see:
197
182
/// https://github.com/dart-lang/native/issues/1319
183
+ ///
184
+ /// The base protocol can be extended with [extensions] . See
185
+ /// [ProtocolExtension] for more documentation.
198
186
Future <LinkResult ?> link ({
199
- required LinkInputCreator inputCreator,
200
- required LinkInputValidator inputValidator,
201
- required LinkValidator linkValidator,
202
- required ApplicationAssetValidator applicationAssetValidator,
187
+ required List <ProtocolExtension > extensions,
203
188
Uri ? resourceIdentifiers,
204
- required List <String > buildAssetTypes,
205
189
required BuildResult buildResult,
206
190
}) async {
207
191
final (buildPlan, packageGraph) = await _makePlan (
@@ -212,8 +196,13 @@ class NativeAssetsBuildRunner {
212
196
213
197
var hookResult = HookResult (encodedAssets: buildResult.encodedAssets);
214
198
for (final package in buildPlan) {
215
- final inputBuilder =
216
- inputCreator ()..config.setupShared (buildAssetTypes: buildAssetTypes);
199
+ final inputBuilder = LinkInputBuilder ();
200
+ inputBuilder.config.setupShared (
201
+ buildAssetTypes: [for (final e in extensions) ...e.buildAssetTypes],
202
+ );
203
+ for (final e in extensions) {
204
+ e.setupLinkInput (inputBuilder);
205
+ }
217
206
218
207
final (buildDirUri, outDirUri, outDirSharedUri) = await _setupDirectories (
219
208
Hook .link,
@@ -243,7 +232,7 @@ class NativeAssetsBuildRunner {
243
232
final input = LinkInput (inputBuilder.json);
244
233
final errors = [
245
234
...await validateLinkInput (input),
246
- ...await inputValidator (input),
235
+ for ( final e in extensions) ...await e. validateLinkInput (input),
247
236
];
248
237
if (errors.isNotEmpty) {
249
238
print (input.assets.encodedAssets);
@@ -256,16 +245,24 @@ class NativeAssetsBuildRunner {
256
245
final result = await _runHookForPackageCached (
257
246
Hook .link,
258
247
input,
259
- (input, output) =>
260
- linkValidator (input as LinkInput , output as LinkOutput ),
248
+ (input, output) async => [
249
+ for (final e in extensions)
250
+ ...await e.validateLinkOutput (
251
+ input as LinkInput ,
252
+ output as LinkOutput ,
253
+ ),
254
+ ],
261
255
resourceIdentifiers,
262
256
);
263
257
if (result == null ) return null ;
264
258
final (hookOutput, hookDeps) = result;
265
259
hookResult = hookResult.copyAdd (hookOutput, hookDeps);
266
260
}
267
261
268
- final errors = await applicationAssetValidator (hookResult.encodedAssets);
262
+ final errors = [
263
+ for (final e in extensions)
264
+ ...await e.validateApplicationAssets (hookResult.encodedAssets),
265
+ ];
269
266
if (errors.isEmpty) return hookResult;
270
267
271
268
_printErrors ('Application asset verification failed' , errors);
0 commit comments