-
Notifications
You must be signed in to change notification settings - Fork 203
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
Support for resolving package config and pubspec.lock in workspaces #3684
base: master
Are you sure you want to change the base?
Conversation
The CI failures seem unrelated. |
@@ -78,14 +78,31 @@ class PackageGraph { | |||
'pubspec.yaml.'); | |||
} | |||
|
|||
final packageConfig = | |||
await findPackageConfig(Directory(packagePath), recurse: false); | |||
// The path of the directory that contains .dart_tool/package_config.json. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this different from just passing recurse: true
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only difference is that we can use the discovered path rootDir
where we find the package config below.
With recurse: true
that would not be the case - we would only be given the packageConfig itself...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, we could just set the root dir as the parent of the package config dir though. Not a big difference either way but I would slightly prefer it that way.
On a related note though - I am not sure we actually want to load the pubspec from the workspace root instead of the package root? We will end up seeing all the deps used by any package in the workspace then, instead of just the deps of the current package. Unless the current package doesn't list its deps at all?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With workspaces there is only a single pubspec.lock
.
I'm not sure how build runner uses this dependency graph - we might need to prune it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only way I can see to do that would be to parse pubspec.yaml of the current package and all its dependencies transitively.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a new problem? Did we know the ordering before?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry I hadn't seen your other comments when I did my last response :).
But in any case:
I'm not sure how build runner uses this dependency graph - we might need to prune it?
Some builders will generate code for all packages in the whole dependency graph, so we could do extra work here if we see deps that are never used.
The only way I can see to do that would be to parse pubspec.yaml of the current package and all its dependencies transitively.
Right, this is what we do today, we parse all transitive pubspec.yaml files. We want to know the entire dependency structure including cycles, as it influences the order in which we build things.
Problem is, that with findPackageConfig we don't get a package config dir. Only the package config object (that doesn't expose it's location if I understand right).
Oh, ok then this code makes sense. Is there a different API that just gives us the location?
Is this a new problem? Did we know the ordering before?
Answered above, we crawl transitive pubspecs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Answered above, we crawl transitive pubspecs.
Ah - then there should be no problem if we just start from the pubspec in packagePath
(which we still do with this change) the workspace-wide package config and lockfile will just contain a superset of the needed packages.
Is there a different API that just gives us the location?
I don't think so. That's why I wrote it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah ok, if we are still reading the actual package pubspec and not a root one, this is probably all fine. As long as we handle the case where there are more packages in the package config than we can find in the pubspecs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I read this code right: https://github.com/dart-lang/build/blob/db5180c903b27fd1c3d344c5b22c396540ea0c78/build_runner_core/lib/src/package_graph/package_graph.dart#L133-L144
The package graph will contain all packages in the workspace-wide resolution, but will have the correct root. And if I'm not wrong, only the reachable packages are handled according to:
final orderedPackages = stronglyConnectedComponents<PackageNode>( |
I added a test of the package graph creation. And support for .packages. |
Not sure what goes wrong in the community test. I am not able to reproduce the failures locally. |
I can look into that, but probably not until next week. Or possibly @simolus3 would have some idea, but it seems like the code just isn't getting generated for some reason. |
The failure looks surprising to me as well. I commit generated code into the repository and the build integrity test shows that re-running My best guess is that we hit a race condition where the build integrity test started running (and thus deleting previous generated sources) while the other tests were being loaded, thus causing these errors? I have disabled concurrency for the community tests in the drift repository, I hope that resolves the problem. |
I restarted the job and it passed 👍 |
Anything more blocking this? |
This is really another good case for adding the dependency types and relationships in |
Yeah - lets do that another time! |
Gentle ping |
Instead of expecting
pubspec.lock
and.dart_tool/package_config.json
to reside in the same folder as pubspec.yaml, we visit each parent of the current directory until we find a.dart_tool/package_config.json
, and expectpubspec.lock
to exist next to that.Also invoke the generated scripts with an explicit packageConfig.
This is to support running
build_runner build
in a workspace package, as implemented in dart-lang/pub#4127