Skip to content

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.19.4-wip 0.20.0
Got "0.19.4-wip" expected >= "0.20.0" (breaking changes)
⚠️
data_assets Breaking 0.19.1 0.19.2-wip 0.20.0
Got "0.19.2-wip" expected >= "0.20.0" (breaking changes)
⚠️
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 ✔️

This check can be disabled by tagging the PR with skip-breaking-check.

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: 82.27% (-2.3%) from 84.56%
when pulling a03078b 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
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

Copy link
Collaborator

Choose a reason for hiding this comment

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

We have coverage on the CI, but it doesn't collect coverage for the test
projects being run because those are separate dart process invocations. It might
be worth trying to see if we can get code coverage from those.

}) {
_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

@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.

@mosuem
Copy link
Member Author

mosuem commented Jul 30, 2025

Friendly ping @dcharkes or @goderbauer :)

@dcharkes
Copy link
Collaborator

Friendly ping @dcharkes or @goderbauer :)

Friendly ping to address the previously unaddressed comment(s). Including the schema test.

@mosuem
Copy link
Member Author

mosuem commented Jul 30, 2025

Is this not addressed? I did add the key to the test files. What else should be addressed?

@dcharkes
Copy link
Collaborator

dcharkes commented Jul 30, 2025

Is this not addressed? I did add the key to the test files. What else should be addressed?

Already answered:

Also, the guard for assets_for_linking should not skip link output anymore.

I've pushed a commit with what the test should do. Some already pass due to the test data you added 👍 , but not all.

@mosuem
Copy link
Member Author

mosuem commented Jul 30, 2025

Done!

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.

LGTM from my side once the last small comments are addressed.

Thanks! 🙏

Copy link
Collaborator

Choose a reason for hiding this comment

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

We have coverage on the CI, but it doesn't collect coverage for the test
projects being run because those are separate dart process invocations. It might
be worth trying to see if we can get code coverage from those.

@mosuem mosuem merged commit 16ae2d8 into main Jul 31, 2025
21 of 22 checks passed
@mosuem mosuem deleted the runLinkHooksInOrder branch July 31, 2025 12:20
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