Skip to content
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

Enhancement: refactor the dependency graph module and completing the MVS #465

Open
zong-zhe opened this issue Aug 27, 2024 · 0 comments
Open

Comments

@zong-zhe
Copy link
Contributor

zong-zhe commented Aug 27, 2024

Issue

  1. The calculation of the dependency graph previously implemented by kpm is coupled to the function used to add dependency, resulting in subsequent development work being difficult.

_, depGraph, err := kpmcli.InitGraphAndDownloadDeps(kclPkg)

  1. The functional implementation of the MVS module has some problems; whenever a dependency conflict is encountered, kpm always adds the latest release version of the dependency conflict to the dependency. The correct way is to keep the latest version in the current dependency graph, not the latest version of release.

Solution

For issue 1, use Resolver to refactor the calculation of the dependency graph

The part of the dependency graph generated should be moved out from the kpm add and extracted into a module named Resolver. Resolver abstracts the part of the dependency tree traversed and takes a closure method as the input parameter, which performs corresponding operations on each dependency tree node traversed.

The closure method looks like:

func(current, parent *pkg.KclPkg) error 

current is the current kcl package when traversing the dependency graph. parent is the node traversed last time.

Resolver is responsible for receiving a KCL Package Source and some functions, traversing the dependency tree of the KCL package corresponding to the source, and executing the functions in each node. When Resolver traverses the dependency tree, the capacity to access KCL packages through Source provided by Visitor and the capacity to download and cache KCL remote package provided by Downloader The clear three-layer structure formed between them will help the future development process.



Resolver - Traverse the dependency tree and use a "Visitor" to access the KCL Package corresponding to the source
                                                      | 
    |-------------------------------------------------| 
    |
Visitor - Load the KCL Package from the source, including the local path, the remote Git Repo, or OCI Registry. 
          Use the "Downloader" to complete the download and cache management. 
                       | 
    |------------------| 
    |
Downloader - Download the package from Git Repo or OCI Registry, and manage the local cache.

[] PR Here

For issue 2, use Resolver traverse the entire dependency tree complete the MVS function

In Resolver, during the traversal of the dependency tree, each dependency node is added to the dependency graph, and the largest version number of each dependency in the whole graph is selected according to the version number in the graph.

[] PR Here

Pre Work

The downloader currently provided in kpm has no cache management and can result in repeated downloads.

[] PR Here

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

No branches or pull requests

2 participants
@zong-zhe and others