diff --git a/pkg/api/test_data/store_mod_and_lock/dep1_0.0.1/kcl.mod b/pkg/api/test_data/store_mod_and_lock/dep1_0.0.1/kcl.mod index 8f80cb27..80ff075e 100644 --- a/pkg/api/test_data/store_mod_and_lock/dep1_0.0.1/kcl.mod +++ b/pkg/api/test_data/store_mod_and_lock/dep1_0.0.1/kcl.mod @@ -4,4 +4,4 @@ edition = "0.0.1" version = "0.0.1" [dependencies] -dep1 = { oci = "oci://ghcr.io/kcl-lang/dep1", tag = "0.0.1" } +dep1 = { oci = "oci://ghcr.io/kcl-lang/dep1", tag = "0.0.1" } \ No newline at end of file diff --git a/pkg/client/client.go b/pkg/client/client.go index ea3bd0fd..0f4e343a 100644 --- a/pkg/client/client.go +++ b/pkg/client/client.go @@ -772,6 +772,7 @@ func (c *KpmClient) AddDepWithOpts(kclPkg *pkg.KclPkg, opt *opt.AddOptions) (*pk return nil, fmt.Errorf("dependency '%s' not found in 'kcl.mod'", d.Name) } tempDeps.Name = opt.NewPkgName + tempDeps.Package = d.Name kclPkg.ModFile.Dependencies.Deps.Set(d.Name, tempDeps) // update the kcl.mod.lock with NewPkgName diff --git a/pkg/client/pull_test.go b/pkg/client/pull_test.go index d00cf84f..9c84b458 100644 --- a/pkg/client/pull_test.go +++ b/pkg/client/pull_test.go @@ -2,6 +2,7 @@ package client import ( "bytes" + "io/ioutil" "os" "path/filepath" "testing" @@ -11,7 +12,11 @@ import ( ) func TestPull(t *testing.T) { - pulledPath := getTestDir("test_pull") + tmpDir, err := ioutil.TempDir("", "test_pull") + if err != nil { + t.Fatal(err) + } + defer os.RemoveAll(tmpDir) kpmcli, err := NewKpmClient() assert.NilError(t, err) @@ -20,7 +25,7 @@ func TestPull(t *testing.T) { kpmcli.SetLogWriter(&buf) kPkg, err := kpmcli.Pull( - WithLocalPath(pulledPath), + WithLocalPath(tmpDir), WithPullSource(&downloader.Source{ Oci: &downloader.Oci{ Reg: "ghcr.io", @@ -30,24 +35,25 @@ func TestPull(t *testing.T) { }), ) - pkgPath := filepath.Join(pulledPath, "oci", "ghcr.io", "kcl-lang", "helloworld", "0.0.1") + pkgPath := filepath.Join(tmpDir, "oci", "ghcr.io", "kcl-lang", "helloworld", "0.0.1") assert.NilError(t, err) assert.Equal(t, kPkg.GetPkgName(), "helloworld") assert.Equal(t, kPkg.GetPkgVersion(), "0.0.1") assert.Equal(t, kPkg.HomePath, pkgPath) kPkg, err = kpmcli.Pull( - WithLocalPath(pulledPath), + WithLocalPath(tmpDir), WithPullSourceUrl("oci://ghcr.io/kcl-lang/helloworld?tag=0.1.0"), ) - pkgPath = filepath.Join(pulledPath, "oci", "ghcr.io", "kcl-lang", "helloworld", "0.1.0") + pkgPath = filepath.Join(tmpDir, "oci", "ghcr.io", "kcl-lang", "helloworld", "0.1.0") assert.NilError(t, err) assert.Equal(t, kPkg.GetPkgName(), "helloworld") assert.Equal(t, kPkg.GetPkgVersion(), "0.1.0") assert.Equal(t, kPkg.HomePath, pkgPath) - defer func() { - err = os.RemoveAll(filepath.Join(pulledPath, "oci")) - assert.NilError(t, err) - }() + // Handle cleanup within the same filesystem + err = os.RemoveAll(filepath.Join(tmpDir, "oci")) + if err != nil { + t.Errorf("Failed to remove directory: %v", err) + } } diff --git a/pkg/client/test_data/add_with_git_commit/test_pkg/kcl.mod.expect b/pkg/client/test_data/add_with_git_commit/test_pkg/kcl.mod.expect index 2950f92d..6d9aa970 100644 --- a/pkg/client/test_data/add_with_git_commit/test_pkg/kcl.mod.expect +++ b/pkg/client/test_data/add_with_git_commit/test_pkg/kcl.mod.expect @@ -4,4 +4,4 @@ edition = "0.0.1" version = "0.0.1" [dependencies] -flask-demo-kcl-manifests = { git = "https://github.com/kcl-lang/flask-demo-kcl-manifests.git", commit = "ade147b" } +flask-demo-kcl-manifests = { git = "https://github.com/kcl-lang/flask-demo-kcl-manifests.git", commit = "ade147b", package = "flask-demo-kcl-manifests" } diff --git a/pkg/client/test_data/add_with_git_commit/test_pkg/kcl.mod.lock.expect b/pkg/client/test_data/add_with_git_commit/test_pkg/kcl.mod.lock.expect index 935309f6..893d4a6a 100644 --- a/pkg/client/test_data/add_with_git_commit/test_pkg/kcl.mod.lock.expect +++ b/pkg/client/test_data/add_with_git_commit/test_pkg/kcl.mod.lock.expect @@ -3,5 +3,6 @@ name = "flask-demo-kcl-manifests" full_name = "flask_manifests_0.0.1" version = "0.0.1" + package = "flask-demo-kcl-manifests" url = "https://github.com/kcl-lang/flask-demo-kcl-manifests.git" commit = "ade147b" diff --git a/pkg/client/test_data/add_with_git_commit/test_pkg_win/kcl.mod.expect b/pkg/client/test_data/add_with_git_commit/test_pkg_win/kcl.mod.expect index 2950f92d..6d9aa970 100644 --- a/pkg/client/test_data/add_with_git_commit/test_pkg_win/kcl.mod.expect +++ b/pkg/client/test_data/add_with_git_commit/test_pkg_win/kcl.mod.expect @@ -4,4 +4,4 @@ edition = "0.0.1" version = "0.0.1" [dependencies] -flask-demo-kcl-manifests = { git = "https://github.com/kcl-lang/flask-demo-kcl-manifests.git", commit = "ade147b" } +flask-demo-kcl-manifests = { git = "https://github.com/kcl-lang/flask-demo-kcl-manifests.git", commit = "ade147b", package = "flask-demo-kcl-manifests" } diff --git a/pkg/client/test_data/add_with_git_commit/test_pkg_win/kcl.mod.lock.expect b/pkg/client/test_data/add_with_git_commit/test_pkg_win/kcl.mod.lock.expect index 935309f6..893d4a6a 100644 --- a/pkg/client/test_data/add_with_git_commit/test_pkg_win/kcl.mod.lock.expect +++ b/pkg/client/test_data/add_with_git_commit/test_pkg_win/kcl.mod.lock.expect @@ -3,5 +3,6 @@ name = "flask-demo-kcl-manifests" full_name = "flask_manifests_0.0.1" version = "0.0.1" + package = "flask-demo-kcl-manifests" url = "https://github.com/kcl-lang/flask-demo-kcl-manifests.git" commit = "ade147b" diff --git a/pkg/client/test_data/add_with_local_path/expect/pkg/kcl.mod b/pkg/client/test_data/add_with_local_path/expect/pkg/kcl.mod index ce22bb77..0edb191d 100644 --- a/pkg/client/test_data/add_with_local_path/expect/pkg/kcl.mod +++ b/pkg/client/test_data/add_with_local_path/expect/pkg/kcl.mod @@ -5,4 +5,4 @@ version = "0.0.1" [dependencies] dep_pkg = { path = "../dep_pkg" } -helloworld = { oci = "oci://ghcr.io/kcl-lang/helloworld", tag = "0.1.2" } +helloworld = { oci = "oci://ghcr.io/kcl-lang/helloworld", tag = "0.1.2", package = "helloworld" } diff --git a/pkg/client/test_data/expected/kcl.reverse.mod b/pkg/client/test_data/expected/kcl.reverse.mod index 99457e69..f8f17b55 100644 --- a/pkg/client/test_data/expected/kcl.reverse.mod +++ b/pkg/client/test_data/expected/kcl.reverse.mod @@ -4,5 +4,5 @@ edition = "v0.10.0" version = "0.0.1" [dependencies] -name = { git = "test_url", tag = "test_tag" } -oci_name = { oci = "oci://test_reg/test_repo", tag = "test_tag" } +name = git = "test_url", tag = "test_tag" +oci_name = oci = "oci://test_reg/test_repo", tag = "test_tag" diff --git a/pkg/client/test_data/test_data_add_deps/kcl.mod b/pkg/client/test_data/test_data_add_deps/kcl.mod index 909a628f..bc1a88cb 100644 --- a/pkg/client/test_data/test_data_add_deps/kcl.mod +++ b/pkg/client/test_data/test_data_add_deps/kcl.mod @@ -5,5 +5,4 @@ version = "0.0.1" [dependencies] oci_name = { oci = "oci://test_reg/test_repo", tag = "test_tag" } -name = { git = "test_url", tag = "test_tag" } - +name = { git = "test_url", tag = "test_tag" } \ No newline at end of file diff --git a/pkg/client/test_data/test_dep_order/expect.mod b/pkg/client/test_data/test_dep_order/expect.mod index 94a3cfa3..95c7efce 100644 --- a/pkg/client/test_data/test_dep_order/expect.mod +++ b/pkg/client/test_data/test_dep_order/expect.mod @@ -4,8 +4,8 @@ edition = "v0.10.0" version = "0.0.1" [dependencies] -helloworld = { oci = "oci://ghcr.io/kcl-lang/helloworld", tag = "0.1.2" } -jsonpatch = { oci = "oci://ghcr.io/kcl-lang/jsonpatch", tag = "0.0.5" } +helloworld = { oci = "oci://ghcr.io/kcl-lang/helloworld", tag = "0.1.2", package = "helloworld" } +jsonpatch = { oci = "oci://ghcr.io/kcl-lang/jsonpatch", tag = "0.0.5", package = "jsonpatch" } [profile] entries = ["./sub/main.k"] diff --git a/pkg/client/test_data/test_dep_order/kcl.mod b/pkg/client/test_data/test_dep_order/kcl.mod index 94a3cfa3..95c7efce 100644 --- a/pkg/client/test_data/test_dep_order/kcl.mod +++ b/pkg/client/test_data/test_dep_order/kcl.mod @@ -4,8 +4,8 @@ edition = "v0.10.0" version = "0.0.1" [dependencies] -helloworld = { oci = "oci://ghcr.io/kcl-lang/helloworld", tag = "0.1.2" } -jsonpatch = { oci = "oci://ghcr.io/kcl-lang/jsonpatch", tag = "0.0.5" } +helloworld = { oci = "oci://ghcr.io/kcl-lang/helloworld", tag = "0.1.2", package = "helloworld" } +jsonpatch = { oci = "oci://ghcr.io/kcl-lang/jsonpatch", tag = "0.0.5", package = "jsonpatch" } [profile] entries = ["./sub/main.k"] diff --git a/pkg/client/test_data/test_oci_downloader/add_dep/pkg/except b/pkg/client/test_data/test_oci_downloader/add_dep/pkg/except index 10fd17db..0ad39cda 100644 --- a/pkg/client/test_data/test_oci_downloader/add_dep/pkg/except +++ b/pkg/client/test_data/test_oci_downloader/add_dep/pkg/except @@ -4,4 +4,4 @@ edition = "v0.10.0" version = "0.0.1" [dependencies] -helloworld = { oci = "oci://ghcr.io/zong-zhe/helloworld", tag = "0.0.3" } +helloworld = { oci = "oci://ghcr.io/zong-zhe/helloworld", tag = "0.0.3", package = "helloworld" } diff --git a/pkg/client/test_data/test_oci_downloader/add_dep/pkg/kcl.mod b/pkg/client/test_data/test_oci_downloader/add_dep/pkg/kcl.mod index 10fd17db..1b60b3b7 100644 --- a/pkg/client/test_data/test_oci_downloader/add_dep/pkg/kcl.mod +++ b/pkg/client/test_data/test_oci_downloader/add_dep/pkg/kcl.mod @@ -4,4 +4,5 @@ edition = "v0.10.0" version = "0.0.1" [dependencies] -helloworld = { oci = "oci://ghcr.io/zong-zhe/helloworld", tag = "0.0.3" } +helloworld = { oci = "oci://ghcr.io/zong-zhe/helloworld", tag = "0.0.3", package = "helloworld" } + diff --git a/pkg/client/test_data/test_oci_downloader/run_pkg/pkg/kcl.mod b/pkg/client/test_data/test_oci_downloader/run_pkg/pkg/kcl.mod index 10fd17db..0ad39cda 100644 --- a/pkg/client/test_data/test_oci_downloader/run_pkg/pkg/kcl.mod +++ b/pkg/client/test_data/test_oci_downloader/run_pkg/pkg/kcl.mod @@ -4,4 +4,4 @@ edition = "v0.10.0" version = "0.0.1" [dependencies] -helloworld = { oci = "oci://ghcr.io/zong-zhe/helloworld", tag = "0.0.3" } +helloworld = { oci = "oci://ghcr.io/zong-zhe/helloworld", tag = "0.0.3", package = "helloworld" } diff --git a/pkg/package/modfile.go b/pkg/package/modfile.go index b4fb3b49..bad08bbd 100644 --- a/pkg/package/modfile.go +++ b/pkg/package/modfile.go @@ -193,6 +193,7 @@ type Dependency struct { FullName string `json:"-" toml:"full_name,omitempty"` Version string `json:"-" toml:"version,omitempty"` Sum string `json:"-" toml:"sum,omitempty"` + Package string `json:"-" toml:"package,omitempty"` // The actual local path of the package. // In vendor mode is "current_kcl_package/vendor" // In non-vendor mode is "$KCL_PKG_PATH" diff --git a/pkg/package/toml.go b/pkg/package/toml.go index 76569b8d..dbbc43e0 100644 --- a/pkg/package/toml.go +++ b/pkg/package/toml.go @@ -89,6 +89,10 @@ const DEP_PATTERN = "%s = %s" func (dep *Dependency) MarshalTOML() string { source := dep.Source.MarshalTOML() var sb strings.Builder + if len(dep.Package) != 0 { + source = source[:len(source)-2] + fmt.Sprintf(", package = \"%s\" }", dep.Package) + } + if len(source) != 0 { sb.WriteString(fmt.Sprintf(DEP_PATTERN, dep.Name, source)) }