Skip to content

[hooks_runner] Don't report immutable Dart sources as dependencies #2296

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

Merged
merged 1 commit into from
May 14, 2025
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
9 changes: 8 additions & 1 deletion pkgs/hooks_runner/lib/src/build_runner/build_runner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,9 @@ class NativeAssetsBuildRunner {

final modifiedDuringBuild = await dependenciesHashes.hashDependencies(
[
...dartSources.where((e) => e != packageLayout.packageConfigUri),
...dartSources.where(
(e) => e != packageLayout.packageConfigUri && !_isImmutable(e),
),
packageLayout.packageConfigUri,
// If the Dart version changed, recompile.
dartExecutable.resolve('../version'),
Expand All @@ -682,6 +684,11 @@ class NativeAssetsBuildRunner {
return Success((kernelFile, dependenciesHashes));
}

// TODO(https://github.com/dart-lang/pub/issues/4577): Use immutability bit
// when available.
static bool _isImmutable(Uri e) =>
e.toFilePath(windows: false).contains('/hosted/pub.dev/');
Copy link

Choose a reason for hiding this comment

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

I think we store the pub cache in package_config.json.

You could check if that is a prefix of the package path.

But remember that a cached package potentially can depend on a path-dependency, and thus be mutable. Perhaps you need to calculate the transitive dependency closure via package_graph.json...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We get all Dart sources in a list, and I'm just filtering out the ones in the pub cache.

Copy link

@sigurdm sigurdm May 16, 2025

Choose a reason for hiding this comment

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

Right - what I'm saying is that your filter is imprecise (having false positives). You don't want lib/src/hosted/pub.dev/my_file.dart to be assumed immutable.

Rather you could look up package_config.json['pubCache'] And see if the file is p.within that url.


Future<Result<void, HooksRunnerFailure>> _compileHookForPackage(
String packageName,
Uri scriptUri,
Expand Down
22 changes: 22 additions & 0 deletions pkgs/hooks_runner/test/build_runner/build_runner_caching_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,32 @@ void main() async {
'${Platform.pathSeparator}build.dart',
),
);

// Dependencies reported in the hook should be in the result.
expect(
result.dependencies,
contains(packageUri.resolve('src/native_add.c')),
);

final dependenciesAsPaths =
result.dependencies
.map((uri) => uri.toFilePath(windows: false))
.toList();

// The source of the hook should be in the result.
expect(
dependenciesAsPaths,
contains(contains('native_add/hook/build.dart')),
);

// `package:logging` sources should be from pub.dev and not in the
// result.
expect(
dependenciesAsPaths,
isNot(
contains(stringContainsInOrder(['logging-', 'lib/logging.dart'])),
),
);
}

{
Expand Down
Loading