From 6967ae551eaff91e2d0b483f31564993803282d6 Mon Sep 17 00:00:00 2001 From: Daco Harkes Date: Tue, 7 May 2024 19:44:12 +0200 Subject: [PATCH] Fix dep tracking (#147709) Fix dependency tracking in the build. * https://github.com/flutter/flutter/issues/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. --- .../lib/src/build_system/targets/common.dart | 18 ++++++--- .../build_system/targets/common_test.dart | 37 +++++++++++++++---- 2 files changed, 42 insertions(+), 13 deletions(-) diff --git a/packages/flutter_tools/lib/src/build_system/targets/common.dart b/packages/flutter_tools/lib/src/build_system/targets/common.dart index 258eaa8618..e7ae8228e8 100644 --- a/packages/flutter_tools/lib/src/build_system/targets/common.dart +++ b/packages/flutter_tools/lib/src/build_system/targets/common.dart @@ -143,12 +143,15 @@ class KernelSnapshotProgram extends Target { @override List get outputs => const [ + 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 get depfiles => [ - 'kernel_snapshot.d', + List get depfiles => const [ + depfile, ]; @override @@ -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, @@ -293,7 +296,9 @@ class KernelSnapshotNativeAssets extends Target { ]; @override - List get outputs => const []; + List get outputs => const [ + Source.pattern('{BUILD_DIR}/${KernelSnapshotNativeAssets.dillName}'), + ]; @override List get depfiles => const []; @@ -392,7 +397,10 @@ class KernelSnapshot extends Target { ]; @override - List get inputs => []; + List get inputs => const [ + Source.pattern('{BUILD_DIR}/${KernelSnapshotProgram.dillName}'), + Source.pattern('{BUILD_DIR}/${KernelSnapshotNativeAssets.dillName}'), + ]; @override List get outputs => []; diff --git a/packages/flutter_tools/test/general.shard/build_system/targets/common_test.dart b/packages/flutter_tools/test/general.shard/build_system/targets/common_test.dart index 79a778e067..00baf8b001 100644 --- a/packages/flutter_tools/test/general.shard/build_system/targets/common_test.dart +++ b/packages/flutter_tools/test/general.shard/build_system/targets/common_test.dart @@ -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), @@ -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'), @@ -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'), @@ -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'), @@ -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', @@ -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', @@ -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', @@ -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', @@ -488,6 +488,27 @@ native-assets: } } + for (final bool empty in [true, false]) { + final String testName = empty ? 'empty' : 'non empty'; + testWithoutContext('KernelSnapshot native assets $testName', () async { + const List programDillBytes = [1, 2, 3, 4]; + androidEnvironment.buildDir.childFile('program.dill') + ..createSync(recursive: true) + ..writeAsBytesSync(programDillBytes); + final List nativeAssetsDillBytes = empty ? [] : [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([...programDillBytes, ...nativeAssetsDillBytes]), + ); + }); + } + testUsingContext('AotElfProfile Produces correct output directory', () async { final String build = androidEnvironment.buildDir.path; processManager.addCommands([