Skip to content

Commit

Permalink
Fix dep tracking (#147709)
Browse files Browse the repository at this point in the history
Fix dependency tracking in the build.

* flutter/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.
  • Loading branch information
dcharkes authored May 7, 2024
1 parent d04edd1 commit 6967ae5
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 13 deletions.
18 changes: 13 additions & 5 deletions packages/flutter_tools/lib/src/build_system/targets/common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,15 @@ class KernelSnapshotProgram extends Target {

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

static const String depfile = 'kernel_snapshot_program.d';

@override
List<String> get depfiles => <String>[
'kernel_snapshot.d',
List<String> get depfiles => const <String>[
depfile,
];

@override
Expand Down Expand Up @@ -258,7 +261,7 @@ class KernelSnapshotProgram extends Target {
packagesPath: packagesFile.path,
linkPlatformKernelIn: forceLinkPlatform || buildMode.isPrecompiled,
mainPath: targetFileAbsolute,
depFilePath: environment.buildDir.childFile('kernel_snapshot.d').path,
depFilePath: environment.buildDir.childFile(depfile).path,
frontendServerStarterPath: frontendServerStarterPath,
extraFrontEndOptions: extraFrontEndOptions,
fileSystemRoots: fileSystemRoots,
Expand Down Expand Up @@ -293,7 +296,9 @@ class KernelSnapshotNativeAssets extends Target {
];

@override
List<Source> get outputs => const <Source>[];
List<Source> get outputs => const <Source>[
Source.pattern('{BUILD_DIR}/${KernelSnapshotNativeAssets.dillName}'),
];

@override
List<String> get depfiles => const <String>[];
Expand Down Expand Up @@ -392,7 +397,10 @@ class KernelSnapshot extends Target {
];

@override
List<Source> get inputs => <Source>[];
List<Source> get inputs => const <Source>[
Source.pattern('{BUILD_DIR}/${KernelSnapshotProgram.dillName}'),
Source.pattern('{BUILD_DIR}/${KernelSnapshotNativeAssets.dillName}'),
];

@override
List<Source> get outputs => <Source>[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ native-assets:
'--output-dill',
'$build/program.dill',
'--depfile',
'$build/kernel_snapshot.d',
'$build/kernel_snapshot_program.d',
'--verbosity=error',
'file:///lib/main.dart',
], exitCode: 1),
Expand Down Expand Up @@ -161,7 +161,7 @@ native-assets:
'--output-dill',
'$build/program.dill',
'--depfile',
'$build/kernel_snapshot.d',
'$build/kernel_snapshot_program.d',
'--verbosity=error',
'file:///lib/main.dart',
], stdout: 'result $kBoundaryKey\n$kBoundaryKey\n$kBoundaryKey $build/program.dill 0\n'),
Expand Down Expand Up @@ -202,7 +202,7 @@ native-assets:
'--output-dill',
'$build/program.dill',
'--depfile',
'$build/kernel_snapshot.d',
'$build/kernel_snapshot_program.d',
'--verbosity=error',
'file:///lib/main.dart',
], stdout: 'result $kBoundaryKey\n$kBoundaryKey\n$kBoundaryKey $build/program.dill 0\n'),
Expand Down Expand Up @@ -244,7 +244,7 @@ native-assets:
'--output-dill',
'$build/program.dill',
'--depfile',
'$build/kernel_snapshot.d',
'$build/kernel_snapshot_program.d',
'--verbosity=error',
'file:///lib/main.dart',
], stdout: 'result $kBoundaryKey\n$kBoundaryKey\n$kBoundaryKey $build/program.dill 0\n'),
Expand Down Expand Up @@ -286,7 +286,7 @@ native-assets:
'--output-dill',
'$build/program.dill',
'--depfile',
'$build/kernel_snapshot.d',
'$build/kernel_snapshot_program.d',
'--verbosity=error',
'foo',
'bar',
Expand Down Expand Up @@ -327,7 +327,7 @@ native-assets:
'--output-dill',
'$build/program.dill',
'--depfile',
'$build/kernel_snapshot.d',
'$build/kernel_snapshot_program.d',
'--incremental',
'--initialize-from-dill',
'$build/program.dill',
Expand Down Expand Up @@ -368,7 +368,7 @@ native-assets:
'--output-dill',
'$build/program.dill',
'--depfile',
'$build/kernel_snapshot.d',
'$build/kernel_snapshot_program.d',
'--incremental',
'--initialize-from-dill',
'$build/program.dill',
Expand Down Expand Up @@ -424,7 +424,7 @@ native-assets:
'--output-dill',
'$build/program.dill',
'--depfile',
'$build/kernel_snapshot.d',
'$build/kernel_snapshot_program.d',
'--incremental',
'--initialize-from-dill',
'$build/program.dill',
Expand Down Expand Up @@ -488,6 +488,27 @@ native-assets:
}
}

for (final bool empty in <bool>[true, false]) {
final String testName = empty ? 'empty' : 'non empty';
testWithoutContext('KernelSnapshot native assets $testName', () async {
const List<int> programDillBytes = <int>[1, 2, 3, 4];
androidEnvironment.buildDir.childFile('program.dill')
..createSync(recursive: true)
..writeAsBytesSync(programDillBytes);
final List<int> nativeAssetsDillBytes = empty ? <int>[] : <int>[5, 6, 7, 8];
androidEnvironment.buildDir.childFile('native_assets.dill')
..createSync(recursive: true)
..writeAsBytesSync(nativeAssetsDillBytes);

await const KernelSnapshot().build(androidEnvironment);

expect(
androidEnvironment.buildDir.childFile('app.dill').readAsBytesSync(),
equals(<int>[...programDillBytes, ...nativeAssetsDillBytes]),
);
});
}

testUsingContext('AotElfProfile Produces correct output directory', () async {
final String build = androidEnvironment.buildDir.path;
processManager.addCommands(<FakeCommand>[
Expand Down

0 comments on commit 6967ae5

Please sign in to comment.