Skip to content

[hooks] Run link hooks in order #2417

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

[hooks] Run link hooks in order #2417

wants to merge 5 commits into from

Conversation

mosuem
Copy link
Member

@mosuem mosuem commented Jul 16, 2025

Fixes #2381

This brings an order in which the link hooks are run - reverse to the build hook run order. This starts at the application link hook, then it's dependencies, and so on.
This enables us to pass information from on link hook to another as MetadataAssets - but also means that now link hooks must be invoked, regardless of whether assets are sent to the from a build hook.

Seems to work: https://dart-review.googlesource.com/c/sdk/+/441201


  • I’ve reviewed the contributor guide and applied the relevant portions to this PR.
Contribution guidelines:

Note that many Dart repos have a weekly cadence for reviewing PRs - please allow for some latency before initial review feedback.

Copy link

github-actions bot commented Jul 16, 2025

PR Health

Breaking changes ✔️
Package Change Current Version New Version Needed Version Looking good?
code_assets Breaking 0.19.4 0.20.0-wip 0.20.0 ✔️
data_assets Breaking 0.19.1 0.20.0-wip 0.20.0 ✔️
hooks Breaking 0.19.5 0.20.0-wip 0.20.0 ✔️
hooks_runner Breaking 0.21.0 0.22.0-wip 0.22.0 ✔️
native_toolchain_c Breaking 0.17.0 0.18.0-wip 0.18.0 ✔️
Changelog Entry ✔️
Package Changed Files

Changes to files need to be accounted for in their respective changelogs.

API leaks ✔️

The following packages contain symbols visible in the public API, but not exported by the library. Export these symbols or remove them from your publicly visible API.

Package Leaked API symbols
License Headers ✔️
// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
Files
no missing headers

All source files should start with a license header.

Unrelated files missing license headers
Files
pkgs/jni/lib/src/third_party/generated_bindings.dart
pkgs/native_doc_dartifier/lib/native_doc_dartifier.dart
pkgs/native_doc_dartifier/lib/src/native_doc_dartifier_base.dart
pkgs/objective_c/lib/src/ns_input_stream.dart

@coveralls
Copy link

coveralls commented Jul 17, 2025

Coverage Status

coverage: 84.407% (-0.2%) from 84.56%
when pulling 91bdfe1 on runLinkHooksInOrder
into 68ddbca on main.

@mosuem mosuem changed the title Run link hooks in order [hooks] Run link hooks in order Jul 18, 2025
Copy link

github-actions bot commented Jul 18, 2025

Package publishing

Package Version Status Publish tag (post-merge)
package:code_assets 0.20.0 ready to publish code_assets-v0.20.0
package:data_assets 0.20.0 ready to publish data_assets-v0.20.0
package:ffi 2.1.5-wip WIP (no publish necessary)
package:hooks 0.20.0 ready to publish hooks-v0.20.0
package:hooks_runner 0.22.0 ready to publish hooks_runner-v0.22.0
package:native_doc_dartifier 0.0.1-pre already published at pub.dev
package:native_toolchain_c 0.18.0 ready to publish native_toolchain_c-v0.18.0
package:swift2objc 0.0.1-wip WIP (no publish necessary)
package:swiftgen 0.0.1-wip WIP (no publish necessary)

Documentation at https://github.com/dart-lang/ecosystem/wiki/Publishing-automation.

@mosuem mosuem requested a review from dcharkes July 18, 2025 12:37
Copy link
Collaborator

@dcharkes dcharkes left a comment

Choose a reason for hiding this comment

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

General approach LGTM. I left a bunch of detailed comments.

@mosuem mosuem marked this pull request as ready for review July 23, 2025 08:21
@mosuem mosuem requested a review from dcharkes July 23, 2025 08:21
@mosuem mosuem force-pushed the runLinkHooksInOrder branch 2 times, most recently from 2f596d8 to fb5a45b Compare July 24, 2025 11:40
@mosuem mosuem requested a review from goderbauer July 24, 2025 11:41
@@ -185,11 +185,19 @@ final class LinkOutputCodeAssetBuilder {

LinkOutputCodeAssetBuilder._(this._output);

/// Adds the given [asset] to the link hook output.
void add(CodeAsset asset) => _output.addEncodedAsset(asset.encode());
/// Adds the given [asset] to the hook output with [routing].
Copy link
Contributor

Choose a reason for hiding this comment

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

Routing deserve some better documentation. For a developer seeing this for the first time it is unclear what routing is and there are no breadcrumbs in the docs to find out more about it.

Questions the docs should answer:

  • What is routing?
  • Why/When should I set it?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think documentation is lacking in general - so far there are little to no starting points for developers. I will also add some here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Looking through this, it seems kind of well documented though.

Copy link
Contributor

Choose a reason for hiding this comment

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

I would have expected to see some tests that call the add/addAll API while providing a value to the new routing parameter to test that its plumped through correctly?

Copy link
Member Author

Choose a reason for hiding this comment

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

This should also be covered by the tests of pkgs/hooks_runner/test_data/flag_app

Copy link
Contributor

Choose a reason for hiding this comment

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

Should there be new tests in this package to cover the new functionality?

Copy link
Member Author

Choose a reason for hiding this comment

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

This should be covered by the added test at pkgs/hooks_runner/test/build_runner/link_test.dart

}) {
_syntax.setup(
assets: [
for (final asset in assets) AssetSyntax.fromJson(asset.toJson()),
],
assetsFromLinking: [
for (final asset in assetsFromLinking)
AssetSyntax.fromJson(asset.toJson()),
Copy link
Contributor

Choose a reason for hiding this comment

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

I see that we are doing this above as well, but it seems strange that we are converting something to json only to decode it from json again...

Copy link
Member Author

Choose a reason for hiding this comment

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

I would assume this is from the input/output json files.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Don't assume, verify. (Git blame is your friend.)

As for the JSON ecoding

Copy link
Collaborator

@dcharkes dcharkes left a comment

Choose a reason for hiding this comment

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

We need to cover the unhappy paths with tests as well.

  • cyclic dependencies with link hooks (and only one build hook, so no cycles for the build hooks)
  • outputting an asset for a link hook not directly in the dependencies, that should not be visible. (Actually we should probably make that an error, but it looks like pkgs/hooks/lib/src/validation.dart does not throw an error on that right now.)

}) {
_syntax.setup(
assets: [
for (final asset in assets) AssetSyntax.fromJson(asset.toJson()),
],
assetsFromLinking: [
for (final asset in assetsFromLinking)
AssetSyntax.fromJson(asset.toJson()),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Don't assume, verify. (Git blame is your friend.)

As for the JSON ecoding

@@ -250,6 +250,12 @@
"$ref": "#/definitions/Asset"
}
},
"assets_from_linking": {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please cover this in pkgs/hooks/test/json_schema/schema_test.dart
Also, the guard for assets_for_linking should not skip link output anymore.

You'll need to also add test data for the schema in pkgs/hooks/test/data

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't understand that test - is there documentation for what it is testing somewhere? Or do you know what has to be changed to make it pass?

Copy link
Collaborator

Choose a reason for hiding this comment

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

The test loads data, checks no validation errors, then modifies the data, and checks that the validation finds an error.

All the tests print the schema and the data file used in the test name:

file:///Users/dacoharkes/src/dart-lang/native/pkgs/hooks/doc/schema/hook/link_input.generated.schema.json file:///Users/dacoharkes/src/dart-lang/native/pkgs/hooks/test/data/link_input.json assets.assets_from_linking.1.encoding.key missing

You can run the tests in the debugger to figure out why they are failing.

Copy link
Collaborator

Choose a reason for hiding this comment

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

(Or, eyeball it with git blame on the history of the test file 😆 )

@mosuem mosuem force-pushed the runLinkHooksInOrder branch from dce41a1 to 15cf956 Compare July 28, 2025 14:03
@mosuem mosuem requested a review from dcharkes July 28, 2025 14:15
@mosuem
Copy link
Member Author

mosuem commented Jul 28, 2025

Changing assets to assetsFromBuilding is a rather large API change - are you sure that you want this? @dcharkes

@dcharkes
Copy link
Collaborator

Changing assets to assetsFromBuilding is a rather large API change - are you sure that you want this? @dcharkes

Because it's user-facing in the hooks as well?

Maybe skip it for now and keep the version -wip. We need to do another pass on the public API anyways.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[hooks] Sending tree-shaking info between link hooks
4 participants