From 09ba1ca5c5d41d6a027696ecfb34eee6df93b692 Mon Sep 17 00:00:00 2001 From: Akash Kumar Date: Tue, 23 Jan 2024 21:57:34 +0530 Subject: [PATCH 1/3] update kcl.mod package.edition with the kcl compiler version Signed-off-by: Akash Kumar --- pkg/client/client.go | 5 +++++ pkg/client/test_data/test_run_no_sum_check/kcl.mod | 2 +- pkg/package/package.go | 5 +++++ pkg/runner/runner.go | 5 +++++ 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/pkg/client/client.go b/pkg/client/client.go index 7cc86f14..7d334a0d 100644 --- a/pkg/client/client.go +++ b/pkg/client/client.go @@ -325,6 +325,11 @@ func (c *KpmClient) Compile(kclPkg *pkg.KclPkg, kclvmCompiler *runner.Compiler) kclvmCompiler.AddDepPath(dName, dPath) } + kclPkg.UpdatePkgEdition(kclvmCompiler.GetKclVersion()) + if err := kclPkg.ModFile.StoreModFile(); err != nil { + return nil, err + } + return kclvmCompiler.Run() } diff --git a/pkg/client/test_data/test_run_no_sum_check/kcl.mod b/pkg/client/test_data/test_run_no_sum_check/kcl.mod index 27e24ba4..8aaa28a0 100644 --- a/pkg/client/test_data/test_run_no_sum_check/kcl.mod +++ b/pkg/client/test_data/test_run_no_sum_check/kcl.mod @@ -1,6 +1,6 @@ [package] name = "test_run_no_sum_check" -edition = "0.0.1" +edition = "v0.7.0" version = "0.0.1" [dependencies] diff --git a/pkg/package/package.go b/pkg/package/package.go index bd16ebfb..33469ed6 100644 --- a/pkg/package/package.go +++ b/pkg/package/package.go @@ -114,6 +114,11 @@ func (kclPkg *KclPkg) UpdateModAndLockFile() error { return nil } +// update compile edition of package +func (kclPkg *KclPkg) UpdatePkgEdition(newEdition string) { + kclPkg.ModFile.Pkg.Edition = newEdition +} + // LockDepsVersion locks the dependencies of the current kcl package into kcl.mod.lock. func (kclPkg *KclPkg) LockDepsVersion() error { fullPath := filepath.Join(kclPkg.HomePath, MOD_LOCK_FILE) diff --git a/pkg/runner/runner.go b/pkg/runner/runner.go index 170af36b..4abc732e 100644 --- a/pkg/runner/runner.go +++ b/pkg/runner/runner.go @@ -4,6 +4,7 @@ import ( "fmt" "kcl-lang.io/kcl-go/pkg/kcl" + "kcl-lang.io/kcl-go/scripts" "kcl-lang.io/kpm/pkg/opt" ) @@ -46,6 +47,10 @@ func (compiler *Compiler) AddDepPath(depName string, depPath string) *Compiler { return compiler } +func (compiler *Compiler) GetKclVersion() string { + return string(scripts.KclvmVersionType_latest) +} + // Call KCL Compiler and return the result. func (compiler *Compiler) Run() (*kcl.KCLResultList, error) { return kcl.RunWithOpts(*compiler.opts.Option) From 11790dad07ac38fc9ecaaaf163eada54c3499692 Mon Sep 17 00:00:00 2001 From: Akash Kumar Date: Tue, 23 Jan 2024 21:59:26 +0530 Subject: [PATCH 2/3] fix typo Signed-off-by: Akash Kumar --- pkg/client/test_data/test_run_no_sum_check/kcl.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/client/test_data/test_run_no_sum_check/kcl.mod b/pkg/client/test_data/test_run_no_sum_check/kcl.mod index 8aaa28a0..27e24ba4 100644 --- a/pkg/client/test_data/test_run_no_sum_check/kcl.mod +++ b/pkg/client/test_data/test_run_no_sum_check/kcl.mod @@ -1,6 +1,6 @@ [package] name = "test_run_no_sum_check" -edition = "v0.7.0" +edition = "0.0.1" version = "0.0.1" [dependencies] From af84cdefbdc164720143a9a12a564b270f232318 Mon Sep 17 00:00:00 2001 From: Akash Kumar Date: Sun, 18 Feb 2024 13:45:14 +0530 Subject: [PATCH 3/3] address review comments Signed-off-by: Akash Kumar --- pkg/client/client.go | 5 ----- pkg/client/client_test.go | 2 +- pkg/client/test_data/expected/kcl.mod | 2 +- pkg/client/test_data/expected/kcl.reverse.mod | 2 +- pkg/package/modfile.go | 3 ++- pkg/package/modfile_test.go | 3 ++- pkg/package/package.go | 5 ----- pkg/package/package_test.go | 3 ++- pkg/runner/runner.go | 9 +++++---- 9 files changed, 14 insertions(+), 20 deletions(-) diff --git a/pkg/client/client.go b/pkg/client/client.go index d458a863..fa92363a 100644 --- a/pkg/client/client.go +++ b/pkg/client/client.go @@ -327,11 +327,6 @@ func (c *KpmClient) Compile(kclPkg *pkg.KclPkg, kclvmCompiler *runner.Compiler) kclvmCompiler.AddDepPath(dName, dPath) } - kclPkg.UpdatePkgEdition(kclvmCompiler.GetKclVersion()) - if err := kclPkg.ModFile.StoreModFile(); err != nil { - return nil, err - } - return kclvmCompiler.Run() } diff --git a/pkg/client/client_test.go b/pkg/client/client_test.go index b9706ea3..e14ea0a5 100644 --- a/pkg/client/client_test.go +++ b/pkg/client/client_test.go @@ -169,7 +169,7 @@ func TestInitEmptyPkg(t *testing.T) { assert.Equal(t, err, nil) assert.Equal(t, testKclPkg.ModFile.Pkg.Name, "test_name") assert.Equal(t, testKclPkg.ModFile.Pkg.Version, "0.0.1") - assert.Equal(t, testKclPkg.ModFile.Pkg.Edition, "0.0.1") + assert.Equal(t, testKclPkg.ModFile.Pkg.Edition, runner.GetKclVersion()) } func TestUpdateKclModAndLock(t *testing.T) { diff --git a/pkg/client/test_data/expected/kcl.mod b/pkg/client/test_data/expected/kcl.mod index 72026f01..7a6eb717 100644 --- a/pkg/client/test_data/expected/kcl.mod +++ b/pkg/client/test_data/expected/kcl.mod @@ -1,6 +1,6 @@ [package] name = "test_add_deps" -edition = "0.0.1" +edition = "v0.7.0" version = "0.0.1" [dependencies] diff --git a/pkg/client/test_data/expected/kcl.reverse.mod b/pkg/client/test_data/expected/kcl.reverse.mod index 23d46102..8fd5f2a4 100644 --- a/pkg/client/test_data/expected/kcl.reverse.mod +++ b/pkg/client/test_data/expected/kcl.reverse.mod @@ -1,6 +1,6 @@ [package] name = "test_add_deps" -edition = "0.0.1" +edition = "v0.7.0" version = "0.0.1" [dependencies] diff --git a/pkg/package/modfile.go b/pkg/package/modfile.go index e41af695..eda42258 100644 --- a/pkg/package/modfile.go +++ b/pkg/package/modfile.go @@ -12,6 +12,7 @@ import ( "kcl-lang.io/kcl-go/pkg/kcl" "kcl-lang.io/kpm/pkg/opt" "kcl-lang.io/kpm/pkg/reporter" + "kcl-lang.io/kpm/pkg/runner" "kcl-lang.io/kpm/pkg/settings" "kcl-lang.io/kpm/pkg/utils" ) @@ -315,7 +316,7 @@ func (mfile *ModFile) GetModLockFilePath() string { } const defaultVerion = "0.0.1" -const defaultEdition = "0.0.1" +var defaultEdition = runner.GetKclVersion() func NewModFile(opts *opt.InitOptions) *ModFile { return &ModFile{ diff --git a/pkg/package/modfile_test.go b/pkg/package/modfile_test.go index 4269a4e5..de89f2a1 100644 --- a/pkg/package/modfile_test.go +++ b/pkg/package/modfile_test.go @@ -7,6 +7,7 @@ import ( "github.com/stretchr/testify/assert" "kcl-lang.io/kpm/pkg/opt" + "kcl-lang.io/kpm/pkg/runner" "kcl-lang.io/kpm/pkg/utils" ) @@ -81,7 +82,7 @@ func TestModFileExists(t *testing.T) { } NewModFile, err := LoadModFile(testDir) - if err != nil || NewModFile.Pkg.Name != "test_kcl_pkg" || NewModFile.Pkg.Version != "0.0.1" || NewModFile.Pkg.Edition != "0.0.1" { + if err != nil || NewModFile.Pkg.Name != "test_kcl_pkg" || NewModFile.Pkg.Version != "0.0.1" || NewModFile.Pkg.Edition != runner.GetKclVersion() { t.Errorf("test 'LoadModFile' failed.") } } diff --git a/pkg/package/package.go b/pkg/package/package.go index 7d76e87a..1134e5f5 100644 --- a/pkg/package/package.go +++ b/pkg/package/package.go @@ -114,11 +114,6 @@ func (kclPkg *KclPkg) UpdateModAndLockFile() error { return nil } -// update compile edition of package -func (kclPkg *KclPkg) UpdatePkgEdition(newEdition string) { - kclPkg.ModFile.Pkg.Edition = newEdition -} - // LockDepsVersion locks the dependencies of the current kcl package into kcl.mod.lock. func (kclPkg *KclPkg) LockDepsVersion() error { fullPath := filepath.Join(kclPkg.HomePath, MOD_LOCK_FILE) diff --git a/pkg/package/package_test.go b/pkg/package/package_test.go index 56ba976f..f4d7d41d 100644 --- a/pkg/package/package_test.go +++ b/pkg/package/package_test.go @@ -9,6 +9,7 @@ import ( "kcl-lang.io/kpm/pkg/env" "kcl-lang.io/kpm/pkg/opt" "kcl-lang.io/kpm/pkg/reporter" + "kcl-lang.io/kpm/pkg/runner" "kcl-lang.io/kpm/pkg/utils" ) @@ -47,7 +48,7 @@ func TestLoadKclPkg(t *testing.T) { } assert.Equal(t, kclPkg.ModFile.Pkg.Name, "test_name") assert.Equal(t, kclPkg.ModFile.Pkg.Version, "0.0.1") - assert.Equal(t, kclPkg.ModFile.Pkg.Edition, "0.0.1") + assert.Equal(t, kclPkg.ModFile.Pkg.Edition, runner.GetKclVersion()) assert.Equal(t, len(kclPkg.ModFile.Dependencies.Deps), 0) assert.Equal(t, len(kclPkg.Dependencies.Deps), 0) } diff --git a/pkg/runner/runner.go b/pkg/runner/runner.go index 4abc732e..07f31b70 100644 --- a/pkg/runner/runner.go +++ b/pkg/runner/runner.go @@ -47,11 +47,12 @@ func (compiler *Compiler) AddDepPath(depName string, depPath string) *Compiler { return compiler } -func (compiler *Compiler) GetKclVersion() string { - return string(scripts.KclvmVersionType_latest) -} - // Call KCL Compiler and return the result. func (compiler *Compiler) Run() (*kcl.KCLResultList, error) { return kcl.RunWithOpts(*compiler.opts.Option) } + +// GetKclVersion fetches the kcl version +func GetKclVersion() string { + return string(scripts.KclvmVersionType_latest) +} \ No newline at end of file