Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkgs/code_assets/lib/src/code_assets/config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<CodeAsset> get code =>
encodedAssets.where((e) => e.isCodeAsset).map(CodeAsset.fromEncoded);
Expand Down
6 changes: 3 additions & 3 deletions pkgs/data_assets/lib/src/data_assets/config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ extension BuildOutputBuilderAddDataAssetsDirectories on BuildOutputBuilder {
),
routing: routing,
);
addDependency(file.uri);
dependencies.add(file.uri);
}

for (final path in paths) {
Expand All @@ -52,15 +52,15 @@ 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,
)) {
if (entity is File) {
addAsset(entity);
} else {
addDependency(entity.uri);
dependencies.add(entity.uri);
}
}
} on FileSystemException catch (e) {
Expand Down
4 changes: 4 additions & 0 deletions pkgs/hooks/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion pkgs/hooks/example/build/local_asset/hook/build.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Future<void> main(List<String> 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.
Expand Down
4 changes: 2 additions & 2 deletions pkgs/hooks/example/link/package_with_assets/hook/build.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ void main(List<String> 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) {
Expand All @@ -32,7 +32,7 @@ void main(List<String> args) async {
? ToLinkHook(packageName)
: const ToAppBundle(),
);
output.addDependency(dataAsset.uri);
output.dependencies.add(dataAsset.uri);
}
});
}
1 change: 1 addition & 0 deletions pkgs/hooks/lib/hooks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export 'src/config.dart'
HookInputUserDefines,
HookOutput,
HookOutputBuilder,
HookOutputDependenciesBuilder,
HookOutputFailure,
InfraError,
LinkAssetRouting,
Expand Down
37 changes: 33 additions & 4 deletions pkgs/hooks/lib/src/config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<Uri> 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;
Expand All @@ -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<Uri> 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.
Expand Down
2 changes: 1 addition & 1 deletion pkgs/hooks/test/api/build_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ void main() async {
input,
output,
) async {
output.addDependency(packageRootUri.resolve('foo'));
output.dependencies.add(packageRootUri.resolve('foo'));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand the aesthetic reasoning behind this but as a user now I would at least expect dependencies to be an Iterable.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a builder, only when you use .build() you get the built value where you can access the values you've added. It's how the whole API is structured.

(I'm happy to receive feedback on the API as a whole, you can give it a spin and file usability issues. Then we can address those in separate PRs.)

});
final buildOutputUri = input.outputFile;
expect(File.fromUri(buildOutputUri), exists);
Expand Down
4 changes: 2 additions & 2 deletions pkgs/hooks/test/build_output_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions pkgs/hooks/test/link_output_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion pkgs/hooks_runner/test_data/add_asset_link/hook/link.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ void main(List<String> arguments) async {
file: builtDylib.file,
),
)
..addDependency(input.packageRoot.resolve('hook/link.dart'));
..dependencies.add(input.packageRoot.resolve('hook/link.dart'));
});
}
4 changes: 2 additions & 2 deletions pkgs/hooks_runner/test_data/complex_link/hook/build.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ void main(List<String> 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) {
Expand All @@ -32,7 +32,7 @@ void main(List<String> args) async {
? ToLinkHook(packageName)
: const ToAppBundle(),
);
output.addDependency(dataAsset.uri);
output.dependencies.add(dataAsset.uri);
}
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ void main(List<String> 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) {
Expand All @@ -33,7 +33,7 @@ void main(List<String> args) async {
? const ToLinkHook('complex_link')
: const ToAppBundle(),
);
output.addDependency(dataAsset.uri);
output.dependencies.add(dataAsset.uri);
}
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ void main(List<String> arguments) async {
? ToLinkHook(packageName)
: const ToAppBundle(),
);
output.addDependencies(tempBuildOutput.dependencies);
output.dependencies.addAll(tempBuildOutput.dependencies);
});
}
4 changes: 2 additions & 2 deletions pkgs/hooks_runner/test_data/simple_link/hook/build.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ void main(List<String> 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) {
Expand All @@ -32,7 +32,7 @@ void main(List<String> args) async {
? ToLinkHook(packageName)
: const ToAppBundle(),
);
output.addDependency(dataAsset.uri);
output.dependencies.add(dataAsset.uri);
}
});
}
2 changes: 1 addition & 1 deletion pkgs/hooks_runner/test_data/simple_link/hook/link.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ void shake(LinkOutputBuilder output, Iterable<DataAsset> 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);
}
}
4 changes: 2 additions & 2 deletions pkgs/hooks_runner/test_data/transformer/hook/build.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ void main(List<String> 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;
Expand Down Expand Up @@ -58,7 +58,7 @@ void main(List<String> 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));
Expand Down
2 changes: 1 addition & 1 deletion pkgs/hooks_runner/test_data/use_all_api/hook/build.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,6 @@ void main(List<String> args) async {
? const ToLinkHook('foo')
: const ToAppBundle(),
);
output.addDependency(input.packageRoot.resolve('x.txt'));
output.dependencies.add(input.packageRoot.resolve('x.txt'));
});
}
2 changes: 1 addition & 1 deletion pkgs/hooks_runner/test_data/use_all_api/hook/link.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ void main(List<String> 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'));
});
}
2 changes: 1 addition & 1 deletion pkgs/hooks_runner/test_data/user_defines/hook/build.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ void main(List<String> 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),
);
Expand Down
2 changes: 1 addition & 1 deletion pkgs/native_toolchain_c/lib/src/cbuilder/cbuilder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion pkgs/native_toolchain_c/lib/src/cbuilder/clinker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 2 additions & 3 deletions pkgs/native_toolchain_c/lib/src/cbuilder/ctool.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> frameworks;

/// The default [frameworks].
Expand Down
Loading