(POC) Transitive dependency overriding #2981
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Proof of concept for #2899. Basically implements most of the hard parts; this PR should be easy to adjust based on the result of the discussion there.
Current design
Adds a new
[patch]
section togleam.toml
, which works exactly like[dependencies]
, except that any package in the root project's[patch]
will override any transitive dependencies to that package. For example, consider thisgleam.toml
in thetest1
project:If we assume that
test3
depends onsimplifile
1.7.0, what will happen here is that:test1
will depend ontest3
instead oftest2
(for now assuming the package attest3
is also namedtest2
).test2
will depend on simplifile 1.6.0 instead of 1.7.0, even if incompatible (the error is silenced).simplifile
1.6.0 (depended on by test2) will now depend on filepath at../filepath
instead of the Hex version it usually depends on (1.0.0).This
[patch]
section is added to themanifest.toml
to ensure the manifest updates when the[patch]
changes.Current implementation
compiler-core
, most changes occur independency
. There, we have a check for version incompatibilities; it is simply skipped when the package is patched by the root config. Additionally, when working with pubgrub's traits for dependency resolving, we ensure we filter packages' versions according to the root config patch, and also update the fetched packages' dependencies accordingly so pubgrub doesn't get confused. We also, of course, add thepatch
section toPackageConfig
, and also require specifying apatch
to access a config's dependencies.compiler-cli
, most changes are independencies
. Here, we had to refactor providing local and Git packages into aPackageProvider
struct containingprovide_*_package
as methods instead of top-level functions. This was necessary as thePackageFetcher
now stores the PackageProvider in a RefCell, such that, if a Hex package depends on a package which was patched to point to a local or Git package instead of a Hex package, the PackageProvider is invoked to provide that package instead of fetching from Hex (or get it from cache if the package was already provided before - hence the need for RefCell, so we can update the cache, which is also later reused to add those local packages to the manifest). Additionally, in theprovide_*_package
methods, we update each package's dependencies according to the root config's patch during traversal of dependencies. Finally, in the appropriate location withincompiler-cli
, we also ensure the manifest is updated when the patch section changes.TODO
I will wait for further discussion before progressing on this PR, so here's more or less what still needs to be done.