diff --git a/pkgs/code_assets/lib/src/code_assets/config.dart b/pkgs/code_assets/lib/src/code_assets/config.dart index 0a5d158b1f..875cb6b102 100644 --- a/pkgs/code_assets/lib/src/code_assets/config.dart +++ b/pkgs/code_assets/lib/src/code_assets/config.dart @@ -32,7 +32,7 @@ extension LinkInputCodeAssets on LinkInputAssets { /// NOTE: If the linker implementation depends on the contents of the files /// the code assets refer (e.g. looks at static archives and links them) then /// the linker script has to add those files as dependencies via - /// [HookOutputBuilder.addDependencies] to ensure the linker script will be + /// [HookOutputBuilder.dependencies] to ensure the linker script will be /// re-run if the content of the files changes. Iterable get code => encodedAssets.where((e) => e.isCodeAsset).map(CodeAsset.fromEncoded); diff --git a/pkgs/data_assets/lib/src/data_assets/config.dart b/pkgs/data_assets/lib/src/data_assets/config.dart index 4e72b2f20d..3ef99d587b 100644 --- a/pkgs/data_assets/lib/src/data_assets/config.dart +++ b/pkgs/data_assets/lib/src/data_assets/config.dart @@ -42,7 +42,7 @@ extension BuildOutputBuilderAddDataAssetsDirectories on BuildOutputBuilder { ), routing: routing, ); - addDependency(file.uri); + dependencies.add(file.uri); } for (final path in paths) { @@ -52,7 +52,7 @@ extension BuildOutputBuilderAddDataAssetsDirectories on BuildOutputBuilder { if (await directory.exists()) { try { - addDependency(directory.uri); + dependencies.add(directory.uri); await for (final entity in directory.list( recursive: recursive, followLinks: false, @@ -60,7 +60,7 @@ extension BuildOutputBuilderAddDataAssetsDirectories on BuildOutputBuilder { if (entity is File) { addAsset(entity); } else { - addDependency(entity.uri); + dependencies.add(entity.uri); } } } on FileSystemException catch (e) { diff --git a/pkgs/hooks/CHANGELOG.md b/pkgs/hooks/CHANGELOG.md index b947796ffc..95bb7fe644 100644 --- a/pkgs/hooks/CHANGELOG.md +++ b/pkgs/hooks/CHANGELOG.md @@ -1,6 +1,10 @@ ## 0.20.1-wip - Update outdated documentation. +- Deprecate `HookOutputBuilder.addDependency` and + `HookOutputBuilder.addDependencies` in favor of + `HookOutputBuilder.dependencies.add` and + `HookOutputBuilder.dependencies.addAll`. ## 0.20.0 diff --git a/pkgs/hooks/example/build/local_asset/hook/build.dart b/pkgs/hooks/example/build/local_asset/hook/build.dart index 608c385614..17a996705b 100644 --- a/pkgs/hooks/example/build/local_asset/hook/build.dart +++ b/pkgs/hooks/example/build/local_asset/hook/build.dart @@ -24,7 +24,7 @@ Future main(List args) async { // Insert code that downloads or builds the asset to `assetPath`. await File.fromUri(assetSourcePath).copy(assetPath.toFilePath()); - output.addDependencies([assetSourcePath]); + output.dependencies.add(assetSourcePath); output.assets.code.add( // TODO: Change to DataAsset once the Dart/Flutter SDK can consume it. diff --git a/pkgs/hooks/example/link/package_with_assets/hook/build.dart b/pkgs/hooks/example/link/package_with_assets/hook/build.dart index b581834126..814ade870d 100644 --- a/pkgs/hooks/example/link/package_with_assets/hook/build.dart +++ b/pkgs/hooks/example/link/package_with_assets/hook/build.dart @@ -14,7 +14,7 @@ void main(List args) async { input.packageRoot.resolve('assets/'), ); // If assets are added, rerun hook. - output.addDependency(assetDirectory.uri); + output.dependencies.add(assetDirectory.uri); await for (final dataAsset in assetDirectory.list()) { if (dataAsset is! File) { @@ -32,7 +32,7 @@ void main(List args) async { ? ToLinkHook(packageName) : const ToAppBundle(), ); - output.addDependency(dataAsset.uri); + output.dependencies.add(dataAsset.uri); } }); } diff --git a/pkgs/hooks/lib/hooks.dart b/pkgs/hooks/lib/hooks.dart index 758fca07a9..18dfac26ad 100644 --- a/pkgs/hooks/lib/hooks.dart +++ b/pkgs/hooks/lib/hooks.dart @@ -39,6 +39,7 @@ export 'src/config.dart' HookInputUserDefines, HookOutput, HookOutputBuilder, + HookOutputDependenciesBuilder, HookOutputFailure, InfraError, LinkAssetRouting, diff --git a/pkgs/hooks/lib/src/config.dart b/pkgs/hooks/lib/src/config.dart index 1bd38906d4..8a77285769 100644 --- a/pkgs/hooks/lib/src/config.dart +++ b/pkgs/hooks/lib/src/config.dart @@ -487,22 +487,24 @@ sealed class HookOutputBuilder { /// /// If any of the files are modified after [BuildOutput.timestamp], the // build will be re-run. + @Deprecated('Use dependencies.add() instead.') void addDependency(Uri uri) { - final dependencies = _syntax.dependencies ?? []; dependencies.add(uri); - _syntax.dependencies = dependencies; } /// Adds files used by this build. /// /// If any of the files are modified after [BuildOutput.timestamp], the // build will be re-run. + @Deprecated('Use dependencies.addAll() instead.') void addDependencies(Iterable uris) { - final dependencies = _syntax.dependencies ?? []; dependencies.addAll(uris); - _syntax.dependencies = dependencies; } + /// The dependencies builder for this hook output. + HookOutputDependenciesBuilder get dependencies => + HookOutputDependenciesBuilder._(this); + /// Sets the failure of this output. void setFailure(FailureType value) { _syntax.status = OutputStatusSyntax.failure; @@ -517,6 +519,33 @@ sealed class HookOutputBuilder { } } +/// The builder for [HookOutput.dependencies]. +class HookOutputDependenciesBuilder { + final HookOutputBuilder _output; + + HookOutputDependenciesBuilder._(this._output); + + /// Adds file used by this build. + /// + /// If any of the files are modified after [BuildOutput.timestamp], the + // build will be re-run. + void add(Uri uri) { + final dependencies = _output._syntax.dependencies ?? []; + dependencies.add(uri); + _output._syntax.dependencies = dependencies; + } + + /// Adds files used by this build. + /// + /// If any of the files are modified after [BuildOutput.timestamp], the + // build will be re-run. + void addAll(Iterable uris) { + final dependencies = _output._syntax.dependencies ?? []; + dependencies.addAll(uris); + _output._syntax.dependencies = dependencies; + } +} + /// The output from a `hook/build.dart` on success. /// /// See [BuildOutputFailure] for failure. diff --git a/pkgs/hooks/test/api/build_test.dart b/pkgs/hooks/test/api/build_test.dart index 86cb392966..fae5715186 100644 --- a/pkgs/hooks/test/api/build_test.dart +++ b/pkgs/hooks/test/api/build_test.dart @@ -50,7 +50,7 @@ void main() async { input, output, ) async { - output.addDependency(packageRootUri.resolve('foo')); + output.dependencies.add(packageRootUri.resolve('foo')); }); final buildOutputUri = input.outputFile; expect(File.fromUri(buildOutputUri), exists); diff --git a/pkgs/hooks/test/build_output_test.dart b/pkgs/hooks/test/build_output_test.dart index 489c7e4b89..dc52bfbcfc 100644 --- a/pkgs/hooks/test/build_output_test.dart +++ b/pkgs/hooks/test/build_output_test.dart @@ -17,8 +17,8 @@ void main() { final builder = BuildOutputBuilder(); final after = DateTime.now().roundDownToSeconds(); - builder.addDependency(uris.first); - builder.addDependencies(uris.skip(1).toList()); + builder.dependencies.add(uris.first); + builder.dependencies.addAll(uris.skip(1).toList()); builder.assets.addEncodedAsset(assets.first); builder.assets.addEncodedAsset( diff --git a/pkgs/hooks/test/link_output_test.dart b/pkgs/hooks/test/link_output_test.dart index b815373083..759b2e8eb0 100644 --- a/pkgs/hooks/test/link_output_test.dart +++ b/pkgs/hooks/test/link_output_test.dart @@ -17,8 +17,8 @@ void main() { final builder = LinkOutputBuilder(); final after = DateTime.now().roundDownToSeconds(); - builder.addDependency(uris.take(1).single); - builder.addDependencies(uris.skip(1).toList()); + builder.dependencies.add(uris.take(1).single); + builder.dependencies.addAll(uris.skip(1).toList()); builder.assets.addEncodedAsset(assets.take(1).single); builder.assets.addEncodedAssets(assets.skip(1).take(2).toList()); diff --git a/pkgs/hooks_runner/test_data/add_asset_link/hook/link.dart b/pkgs/hooks_runner/test_data/add_asset_link/hook/link.dart index d67ba42197..31b0ae2050 100644 --- a/pkgs/hooks_runner/test_data/add_asset_link/hook/link.dart +++ b/pkgs/hooks_runner/test_data/add_asset_link/hook/link.dart @@ -17,6 +17,6 @@ void main(List arguments) async { file: builtDylib.file, ), ) - ..addDependency(input.packageRoot.resolve('hook/link.dart')); + ..dependencies.add(input.packageRoot.resolve('hook/link.dart')); }); } diff --git a/pkgs/hooks_runner/test_data/complex_link/hook/build.dart b/pkgs/hooks_runner/test_data/complex_link/hook/build.dart index b581834126..814ade870d 100644 --- a/pkgs/hooks_runner/test_data/complex_link/hook/build.dart +++ b/pkgs/hooks_runner/test_data/complex_link/hook/build.dart @@ -14,7 +14,7 @@ void main(List args) async { input.packageRoot.resolve('assets/'), ); // If assets are added, rerun hook. - output.addDependency(assetDirectory.uri); + output.dependencies.add(assetDirectory.uri); await for (final dataAsset in assetDirectory.list()) { if (dataAsset is! File) { @@ -32,7 +32,7 @@ void main(List args) async { ? ToLinkHook(packageName) : const ToAppBundle(), ); - output.addDependency(dataAsset.uri); + output.dependencies.add(dataAsset.uri); } }); } diff --git a/pkgs/hooks_runner/test_data/complex_link_helper/hook/build.dart b/pkgs/hooks_runner/test_data/complex_link_helper/hook/build.dart index 2e9e0af1f7..384d0df637 100644 --- a/pkgs/hooks_runner/test_data/complex_link_helper/hook/build.dart +++ b/pkgs/hooks_runner/test_data/complex_link_helper/hook/build.dart @@ -14,7 +14,7 @@ void main(List args) async { input.packageRoot.resolve('assets/'), ); // If assets are added, rerun hook. - output.addDependency(assetDirectory.uri); + output.dependencies.add(assetDirectory.uri); await for (final dataAsset in assetDirectory.list()) { if (dataAsset is! File) { @@ -33,7 +33,7 @@ void main(List args) async { ? const ToLinkHook('complex_link') : const ToAppBundle(), ); - output.addDependency(dataAsset.uri); + output.dependencies.add(dataAsset.uri); } }); } diff --git a/pkgs/hooks_runner/test_data/native_add_duplicate/hook/build.dart b/pkgs/hooks_runner/test_data/native_add_duplicate/hook/build.dart index daefbbafe2..eb8d36c22a 100644 --- a/pkgs/hooks_runner/test_data/native_add_duplicate/hook/build.dart +++ b/pkgs/hooks_runner/test_data/native_add_duplicate/hook/build.dart @@ -35,6 +35,6 @@ void main(List arguments) async { ? ToLinkHook(packageName) : const ToAppBundle(), ); - output.addDependencies(tempBuildOutput.dependencies); + output.dependencies.addAll(tempBuildOutput.dependencies); }); } diff --git a/pkgs/hooks_runner/test_data/simple_link/hook/build.dart b/pkgs/hooks_runner/test_data/simple_link/hook/build.dart index b581834126..814ade870d 100644 --- a/pkgs/hooks_runner/test_data/simple_link/hook/build.dart +++ b/pkgs/hooks_runner/test_data/simple_link/hook/build.dart @@ -14,7 +14,7 @@ void main(List args) async { input.packageRoot.resolve('assets/'), ); // If assets are added, rerun hook. - output.addDependency(assetDirectory.uri); + output.dependencies.add(assetDirectory.uri); await for (final dataAsset in assetDirectory.list()) { if (dataAsset is! File) { @@ -32,7 +32,7 @@ void main(List args) async { ? ToLinkHook(packageName) : const ToAppBundle(), ); - output.addDependency(dataAsset.uri); + output.dependencies.add(dataAsset.uri); } }); } diff --git a/pkgs/hooks_runner/test_data/simple_link/hook/link.dart b/pkgs/hooks_runner/test_data/simple_link/hook/link.dart index ae0f176e4f..0d4a37c528 100644 --- a/pkgs/hooks_runner/test_data/simple_link/hook/link.dart +++ b/pkgs/hooks_runner/test_data/simple_link/hook/link.dart @@ -16,6 +16,6 @@ void shake(LinkOutputBuilder output, Iterable assets) { output.assets.data.add(asset); // If the file changes we'd like to re-run the linker. - output.addDependency(asset.file); + output.dependencies.add(asset.file); } } diff --git a/pkgs/hooks_runner/test_data/transformer/hook/build.dart b/pkgs/hooks_runner/test_data/transformer/hook/build.dart index 963a16f90b..fbbc2d1b98 100644 --- a/pkgs/hooks_runner/test_data/transformer/hook/build.dart +++ b/pkgs/hooks_runner/test_data/transformer/hook/build.dart @@ -14,7 +14,7 @@ void main(List arguments) async { await build(arguments, (input, output) async { final dataDirectory = Directory.fromUri(input.packageRoot.resolve('data/')); // If data are added, rerun hook. - output.addDependency(dataDirectory.uri); + output.dependencies.add(dataDirectory.uri); var transformedFiles = 0; var cachedFiles = 0; @@ -58,7 +58,7 @@ void main(List arguments) async { output.assets.data.add( DataAsset(package: input.packageName, name: name, file: targetFile.uri), ); - output.addDependency(sourceFile.uri); + output.dependencies.add(sourceFile.uri); } await hashesFile.writeAsString(json.encoder.convert(newHashes)); diff --git a/pkgs/hooks_runner/test_data/use_all_api/hook/build.dart b/pkgs/hooks_runner/test_data/use_all_api/hook/build.dart index c888655558..fdbc56633d 100644 --- a/pkgs/hooks_runner/test_data/use_all_api/hook/build.dart +++ b/pkgs/hooks_runner/test_data/use_all_api/hook/build.dart @@ -51,6 +51,6 @@ void main(List args) async { ? const ToLinkHook('foo') : const ToAppBundle(), ); - output.addDependency(input.packageRoot.resolve('x.txt')); + output.dependencies.add(input.packageRoot.resolve('x.txt')); }); } diff --git a/pkgs/hooks_runner/test_data/use_all_api/hook/link.dart b/pkgs/hooks_runner/test_data/use_all_api/hook/link.dart index c5ec189a76..e53786299a 100644 --- a/pkgs/hooks_runner/test_data/use_all_api/hook/link.dart +++ b/pkgs/hooks_runner/test_data/use_all_api/hook/link.dart @@ -36,6 +36,6 @@ void main(List args) async { output.assets.code.addAll(input.assets.code); output.assets.data.addAll(input.assets.data); - output.addDependency(input.packageRoot.resolve('x.txt')); + output.dependencies.add(input.packageRoot.resolve('x.txt')); }); } diff --git a/pkgs/hooks_runner/test_data/user_defines/hook/build.dart b/pkgs/hooks_runner/test_data/user_defines/hook/build.dart index 00b8b38e12..2d99a7cfaa 100644 --- a/pkgs/hooks_runner/test_data/user_defines/hook/build.dart +++ b/pkgs/hooks_runner/test_data/user_defines/hook/build.dart @@ -34,7 +34,7 @@ void main(List arguments) async { ); } final file = File.fromUri(someFile); - output.addDependency(file.uri); + output.dependencies.add(file.uri); output.assets.data.add( DataAsset(file: file.uri, name: 'data.json', package: input.packageName), ); diff --git a/pkgs/native_toolchain_c/lib/src/cbuilder/cbuilder.dart b/pkgs/native_toolchain_c/lib/src/cbuilder/cbuilder.dart index 82eeafe08a..4ee9f81827 100644 --- a/pkgs/native_toolchain_c/lib/src/cbuilder/cbuilder.dart +++ b/pkgs/native_toolchain_c/lib/src/cbuilder/cbuilder.dart @@ -224,7 +224,7 @@ class CBuilder extends CTool implements Builder { ) .toList(); - output.addDependencies({ + output.dependencies.addAll({ // Note: We use a Set here to deduplicate the dependencies. ...sources, ...includeFiles, diff --git a/pkgs/native_toolchain_c/lib/src/cbuilder/clinker.dart b/pkgs/native_toolchain_c/lib/src/cbuilder/clinker.dart index 4d7cb7608b..7c33d8121e 100644 --- a/pkgs/native_toolchain_c/lib/src/cbuilder/clinker.dart +++ b/pkgs/native_toolchain_c/lib/src/cbuilder/clinker.dart @@ -116,7 +116,7 @@ class CLinker extends CTool implements Linker { ) .toList(); - output.addDependencies({ + output.dependencies.addAll({ // Note: We use a Set here to deduplicate the dependencies. ...sources, ...includeFiles, diff --git a/pkgs/native_toolchain_c/lib/src/cbuilder/ctool.dart b/pkgs/native_toolchain_c/lib/src/cbuilder/ctool.dart index b48f49634f..064ff58469 100644 --- a/pkgs/native_toolchain_c/lib/src/cbuilder/ctool.dart +++ b/pkgs/native_toolchain_c/lib/src/cbuilder/ctool.dart @@ -73,9 +73,8 @@ abstract class CTool { /// Frameworks will not be automatically reported as dependencies of the hook. /// Frameworks can be mentioned by name if they are available on the system, /// so the file path is not known. If you're depending on your own frameworks - /// report them as dependencies of the hook by calling - /// [BuildOutputBuilder.addDependency] / [LinkOutputBuilder.addDependency] - /// manually. + /// report them as dependencies of the hook by adding them to + /// [HookOutputBuilder.dependencies] manually. final List frameworks; /// The default [frameworks].