@@ -9,25 +9,39 @@ import 'dart:io';
9
9
import 'package:yaml/yaml.dart' ;
10
10
11
11
import 'config.dart' ;
12
+ import 'encoded_asset.dart' ;
13
+ import 'extension.dart' ;
14
+ import 'user_defines.dart' ;
12
15
import 'validation.dart' ;
13
16
14
- /// Validate a build hook; this will throw an exception on validation errors.
17
+ /// Validates a build hook.
18
+ ///
19
+ /// This method will throw an exception on validation errors.
15
20
///
16
21
/// This is intended to be used from tests, e.g.:
17
22
///
18
23
/// ```
19
24
/// test('test my build hook', () async {
20
- /// await testCodeBuildHook (
25
+ /// await testBuildHook (
21
26
/// ...
22
27
/// );
23
28
/// });
24
29
/// ```
30
+ ///
31
+ /// The hook is run in isolation. No user-defines are read from the pubspec,
32
+ /// they must be provided via [userDefines] . No other hooks are run, if the hook
33
+ /// requires assets from other build hooks, the must be provided in [assets] .
25
34
Future <void > testBuildHook ({
26
- required void Function (BuildInputBuilder ) extraInputSetup,
27
35
required FutureOr <void > Function (List <String > arguments) mainMethod,
28
36
required FutureOr <void > Function (BuildInput input, BuildOutput output) check,
29
37
bool ? linkingEnabled,
38
+ required List <ProtocolExtension > extensions,
39
+ // TODO(https://github.com/dart-lang/native/issues/2241): Cleanup how the
40
+ // following parameters are passed in.
41
+ PackageUserDefines ? userDefines,
42
+ Map <String , List <EncodedAsset >>? assets,
30
43
}) async {
44
+ linkingEnabled ?? = false ;
31
45
const keepTempKey = 'KEEP_TEMPORARY_DIRECTORIES' ;
32
46
33
47
final tempDir = await Directory .systemTemp.createTemp ();
@@ -37,11 +51,9 @@ Future<void> testBuildHook({
37
51
final tempUri = Directory (
38
52
await tempDir.resolveSymbolicLinks (),
39
53
).uri.normalizePath ();
40
- final outputDirectory = tempUri.resolve ('output/' );
41
54
final outputDirectoryShared = tempUri.resolve ('output_shared/' );
42
55
final outputFile = tempUri.resolve ('output.json' );
43
56
44
- await Directory .fromUri (outputDirectory).create ();
45
57
await Directory .fromUri (outputDirectoryShared).create ();
46
58
47
59
final inputBuilder = BuildInputBuilder ();
@@ -51,26 +63,45 @@ Future<void> testBuildHook({
51
63
packageName: _readPackageNameFromPubspec (),
52
64
outputFile: outputFile,
53
65
outputDirectoryShared: outputDirectoryShared,
66
+ userDefines: userDefines,
54
67
)
55
- ..config.setupBuild (linkingEnabled: true );
56
- extraInputSetup (inputBuilder);
68
+ ..setupBuildInput (assets: assets)
69
+ ..config.setupBuild (linkingEnabled: linkingEnabled);
70
+ for (final extension in extensions) {
71
+ extension .setupBuildInput (inputBuilder);
72
+ }
73
+ final input = inputBuilder.build ();
57
74
58
- final input = BuildInput (inputBuilder.json);
75
+ final inputErrors = [
76
+ for (final extension in extensions)
77
+ ...await extension .validateBuildInput (input),
78
+ ];
79
+ if (inputErrors.isNotEmpty) {
80
+ throw ValidationFailure (
81
+ 'Encountered build input validation issues: $inputErrors ' ,
82
+ );
83
+ }
59
84
60
85
final inputUri = tempUri.resolve ('input.json' );
61
86
_writeJsonTo (inputUri, input.json);
62
87
await mainMethod (['--config=${inputUri .toFilePath ()}' ]);
63
88
final output = BuildOutput (_readJsonFrom (input.outputFile));
64
89
65
- // Test conformance of protocol invariants.
66
- final validationErrors = await validateBuildOutput (input, output);
67
- if (validationErrors.isNotEmpty) {
90
+ final outputErrors = [
91
+ ...await validateBuildOutput (input, output),
92
+ for (final extension in extensions) ...[
93
+ ...await extension .validateBuildOutput (input, output),
94
+ ...await extension .validateApplicationAssets (
95
+ output.assets.encodedAssets,
96
+ ),
97
+ ],
98
+ ];
99
+ if (outputErrors.isNotEmpty) {
68
100
throw ValidationFailure (
69
- 'encountered build output validation issues: $validationErrors ' ,
101
+ 'Encountered build output validation issues: $inputErrors ' ,
70
102
);
71
103
}
72
104
73
- // Run user-defined tests.
74
105
await check (input, output);
75
106
} finally {
76
107
final keepTempDir = (Platform .environment[keepTempKey] ?? '' ).isNotEmpty;
0 commit comments