Skip to content

Commit

Permalink
Merge pull request #487 from kcl-lang/fix-add-bug
Browse files Browse the repository at this point in the history
fix: fixed an issue where the 'full_name' in kcl.mod.lock changed when there was already a local dependency
  • Loading branch information
Peefy authored Sep 20, 2024
2 parents 73207d0 + 94a7149 commit 72dd5e0
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 21 deletions.
3 changes: 3 additions & 0 deletions pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1811,6 +1811,9 @@ func (c *KpmClient) dependencyExistsLocal(searchPath string, dep *pkg.Dependency
return nil, err
}
dep.FromKclPkg(depPkg)
// TODO: new local dependency structure will replace this
// issue: https://github.com/kcl-lang/kpm/issues/384
dep.FullName = dep.GenDepFullName()
return dep, nil
}
return nil, nil
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[dependencies]
[dependencies.flask-demo-kcl-manifests]
name = "flask-demo-kcl-manifests"
full_name = "flask_manifests_0.0.1"
full_name = "flask-demo-kcl-manifests_ade147b"
version = "0.0.1"
url = "https://github.com/kcl-lang/flask-demo-kcl-manifests.git"
commit = "ade147b"
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[dependencies]
[dependencies.flask-demo-kcl-manifests]
name = "flask-demo-kcl-manifests"
full_name = "flask_manifests_0.0.1"
full_name = "flask-demo-kcl-manifests_ade147b"
version = "0.0.1"
url = "https://github.com/kcl-lang/flask-demo-kcl-manifests.git"
commit = "ade147b"
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[dependencies]
[dependencies.cc]
name = "cc"
full_name = "flask_manifests_0.0.1"
full_name = "flask-demo-kcl-manifests_8308200"
version = "0.0.1"
url = "https://github.com/kcl-lang/flask-demo-kcl-manifests.git"
commit = "8308200"
Expand Down
30 changes: 13 additions & 17 deletions pkg/package/modfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,32 +315,28 @@ func (dep *Dependency) FillDepInfo(homepath string) error {
if dep.Source.Local != nil {
dep.LocalFullPath = dep.Source.Local.Path
}
if dep.Source.Git != nil && dep.Source.Git.GetPackage() != "" {
name := utils.ParseRepoNameFromGitUrl(dep.Source.Git.Url)
if len(dep.Source.Git.Tag) != 0 {
dep.FullName = fmt.Sprintf(PKG_NAME_PATTERN, name, dep.Source.Git.Tag)
} else if len(dep.Source.Git.Commit) != 0 {
dep.FullName = fmt.Sprintf(PKG_NAME_PATTERN, name, dep.Source.Git.Commit)
} else {
dep.FullName = fmt.Sprintf(PKG_NAME_PATTERN, name, dep.Source.Git.Branch)
}
}

dep.FullName = dep.GenDepFullName()

return nil
}

// GenDepFullName will generate the full name of a dependency by its name and version
// based on the '<package_name>_<package_tag>' format.
func (dep *Dependency) GenDepFullName() string {
name := dep.Name
if dep.Source.Git != nil && dep.Source.Git.GetPackage() != "" {
url := dep.Source.Git.Url
if strings.HasSuffix(url, ".git") {
url = strings.TrimSuffix(url, ".git")
dep.FullName = fmt.Sprintf(PKG_NAME_PATTERN, filepath.Base(url), dep.Version)
return dep.FullName
if dep.Source.Git != nil {
name := utils.ParseRepoNameFromGitUrl(dep.Source.Git.Url)
if len(dep.Source.Git.Tag) != 0 {
dep.FullName = fmt.Sprintf(PKG_NAME_PATTERN, name, dep.Source.Git.Tag)
} else if len(dep.Source.Git.Commit) != 0 {
dep.FullName = fmt.Sprintf(PKG_NAME_PATTERN, name, dep.Source.Git.Commit)
} else {
dep.FullName = fmt.Sprintf(PKG_NAME_PATTERN, name, dep.Source.Git.Branch)
}
} else {
dep.FullName = fmt.Sprintf(PKG_NAME_PATTERN, name, dep.Version)
}
dep.FullName = fmt.Sprintf(PKG_NAME_PATTERN, name, dep.Version)
return dep.FullName
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/package/modfile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ func TestLoadModFile(t *testing.T) {
assert.Equal(t, modFile.Dependencies.Deps.GetOrDefault("name", TestPkgDependency).Name, "name")
assert.Equal(t, modFile.Dependencies.Deps.GetOrDefault("name", TestPkgDependency).Source.Git.Url, "test_url")
assert.Equal(t, modFile.Dependencies.Deps.GetOrDefault("name", TestPkgDependency).Source.Git.Tag, "test_tag")
assert.Equal(t, modFile.Dependencies.Deps.GetOrDefault("name", TestPkgDependency).FullName, "name_test_tag")
assert.Equal(t, modFile.Dependencies.Deps.GetOrDefault("name", TestPkgDependency).FullName, "test_url_test_tag")

assert.Equal(t, modFile.Dependencies.Deps.GetOrDefault("oci_name", TestPkgDependency).Name, "oci_name")
assert.Equal(t, modFile.Dependencies.Deps.GetOrDefault("oci_name", TestPkgDependency).Version, "oci_tag")
Expand Down

0 comments on commit 72dd5e0

Please sign in to comment.