Skip to content

Commit 8fb6139

Browse files
dcharkespull[bot]
authored andcommitted
Fix dep tracking (flutter#147709)
Fix dependency tracking in the build. * flutter#147643 ## Testing It's not clear to me where to test the caching behavior of specific targets. * test/general.shard/build_system/targets/common_test.dart * This doesn't test the caching behavior of any targets * test/general.shard/build_system/build_system_test.dart * test/general.shard/cache_test.dart * Both of these don't test specific `Target`s, these have `TestTarget`s. * test/integration.shard/isolated/native_assets_test.dart * This could work, but it's an integration test that already takes long to run.
1 parent 4e37b2f commit 8fb6139

File tree

2 files changed

+42
-13
lines changed

2 files changed

+42
-13
lines changed

packages/flutter_tools/lib/src/build_system/targets/common.dart

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,12 +143,15 @@ class KernelSnapshotProgram extends Target {
143143

144144
@override
145145
List<Source> get outputs => const <Source>[
146+
Source.pattern('{BUILD_DIR}/${KernelSnapshotProgram.dillName}'),
146147
// TODO(mosuem): Should output resources.json. https://github.com/flutter/flutter/issues/146263
147148
];
148149

150+
static const String depfile = 'kernel_snapshot_program.d';
151+
149152
@override
150-
List<String> get depfiles => <String>[
151-
'kernel_snapshot.d',
153+
List<String> get depfiles => const <String>[
154+
depfile,
152155
];
153156

154157
@override
@@ -258,7 +261,7 @@ class KernelSnapshotProgram extends Target {
258261
packagesPath: packagesFile.path,
259262
linkPlatformKernelIn: forceLinkPlatform || buildMode.isPrecompiled,
260263
mainPath: targetFileAbsolute,
261-
depFilePath: environment.buildDir.childFile('kernel_snapshot.d').path,
264+
depFilePath: environment.buildDir.childFile(depfile).path,
262265
frontendServerStarterPath: frontendServerStarterPath,
263266
extraFrontEndOptions: extraFrontEndOptions,
264267
fileSystemRoots: fileSystemRoots,
@@ -293,7 +296,9 @@ class KernelSnapshotNativeAssets extends Target {
293296
];
294297

295298
@override
296-
List<Source> get outputs => const <Source>[];
299+
List<Source> get outputs => const <Source>[
300+
Source.pattern('{BUILD_DIR}/${KernelSnapshotNativeAssets.dillName}'),
301+
];
297302

298303
@override
299304
List<String> get depfiles => const <String>[];
@@ -392,7 +397,10 @@ class KernelSnapshot extends Target {
392397
];
393398

394399
@override
395-
List<Source> get inputs => <Source>[];
400+
List<Source> get inputs => const <Source>[
401+
Source.pattern('{BUILD_DIR}/${KernelSnapshotProgram.dillName}'),
402+
Source.pattern('{BUILD_DIR}/${KernelSnapshotNativeAssets.dillName}'),
403+
];
396404

397405
@override
398406
List<Source> get outputs => <Source>[];

packages/flutter_tools/test/general.shard/build_system/targets/common_test.dart

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ native-assets:
121121
'--output-dill',
122122
'$build/program.dill',
123123
'--depfile',
124-
'$build/kernel_snapshot.d',
124+
'$build/kernel_snapshot_program.d',
125125
'--verbosity=error',
126126
'file:///lib/main.dart',
127127
], exitCode: 1),
@@ -161,7 +161,7 @@ native-assets:
161161
'--output-dill',
162162
'$build/program.dill',
163163
'--depfile',
164-
'$build/kernel_snapshot.d',
164+
'$build/kernel_snapshot_program.d',
165165
'--verbosity=error',
166166
'file:///lib/main.dart',
167167
], stdout: 'result $kBoundaryKey\n$kBoundaryKey\n$kBoundaryKey $build/program.dill 0\n'),
@@ -202,7 +202,7 @@ native-assets:
202202
'--output-dill',
203203
'$build/program.dill',
204204
'--depfile',
205-
'$build/kernel_snapshot.d',
205+
'$build/kernel_snapshot_program.d',
206206
'--verbosity=error',
207207
'file:///lib/main.dart',
208208
], stdout: 'result $kBoundaryKey\n$kBoundaryKey\n$kBoundaryKey $build/program.dill 0\n'),
@@ -244,7 +244,7 @@ native-assets:
244244
'--output-dill',
245245
'$build/program.dill',
246246
'--depfile',
247-
'$build/kernel_snapshot.d',
247+
'$build/kernel_snapshot_program.d',
248248
'--verbosity=error',
249249
'file:///lib/main.dart',
250250
], stdout: 'result $kBoundaryKey\n$kBoundaryKey\n$kBoundaryKey $build/program.dill 0\n'),
@@ -286,7 +286,7 @@ native-assets:
286286
'--output-dill',
287287
'$build/program.dill',
288288
'--depfile',
289-
'$build/kernel_snapshot.d',
289+
'$build/kernel_snapshot_program.d',
290290
'--verbosity=error',
291291
'foo',
292292
'bar',
@@ -327,7 +327,7 @@ native-assets:
327327
'--output-dill',
328328
'$build/program.dill',
329329
'--depfile',
330-
'$build/kernel_snapshot.d',
330+
'$build/kernel_snapshot_program.d',
331331
'--incremental',
332332
'--initialize-from-dill',
333333
'$build/program.dill',
@@ -368,7 +368,7 @@ native-assets:
368368
'--output-dill',
369369
'$build/program.dill',
370370
'--depfile',
371-
'$build/kernel_snapshot.d',
371+
'$build/kernel_snapshot_program.d',
372372
'--incremental',
373373
'--initialize-from-dill',
374374
'$build/program.dill',
@@ -424,7 +424,7 @@ native-assets:
424424
'--output-dill',
425425
'$build/program.dill',
426426
'--depfile',
427-
'$build/kernel_snapshot.d',
427+
'$build/kernel_snapshot_program.d',
428428
'--incremental',
429429
'--initialize-from-dill',
430430
'$build/program.dill',
@@ -488,6 +488,27 @@ native-assets:
488488
}
489489
}
490490

491+
for (final bool empty in <bool>[true, false]) {
492+
final String testName = empty ? 'empty' : 'non empty';
493+
testWithoutContext('KernelSnapshot native assets $testName', () async {
494+
const List<int> programDillBytes = <int>[1, 2, 3, 4];
495+
androidEnvironment.buildDir.childFile('program.dill')
496+
..createSync(recursive: true)
497+
..writeAsBytesSync(programDillBytes);
498+
final List<int> nativeAssetsDillBytes = empty ? <int>[] : <int>[5, 6, 7, 8];
499+
androidEnvironment.buildDir.childFile('native_assets.dill')
500+
..createSync(recursive: true)
501+
..writeAsBytesSync(nativeAssetsDillBytes);
502+
503+
await const KernelSnapshot().build(androidEnvironment);
504+
505+
expect(
506+
androidEnvironment.buildDir.childFile('app.dill').readAsBytesSync(),
507+
equals(<int>[...programDillBytes, ...nativeAssetsDillBytes]),
508+
);
509+
});
510+
}
511+
491512
testUsingContext('AotElfProfile Produces correct output directory', () async {
492513
final String build = androidEnvironment.buildDir.path;
493514
processManager.addCommands(<FakeCommand>[

0 commit comments

Comments
 (0)