diff --git a/pkg/api/kpm_pkg.go b/pkg/api/kpm_pkg.go index 357976fbb..de6ec1169 100644 --- a/pkg/api/kpm_pkg.go +++ b/pkg/api/kpm_pkg.go @@ -64,7 +64,7 @@ func (pkg *KclPackage) UpdateDependencyInPath(pkg_path string) error { if err != nil { return err } - return kpmcli.ResolvePkgDepsMetadata(pkg.pkg, true) + return kpmcli.ResolvePkgDepsMetadata(pkg.pkg, &pkg.pkg.Dependencies, true) } // GetPkgName returns the name of the package. diff --git a/pkg/api/kpm_pkg_test.go b/pkg/api/kpm_pkg_test.go index 084cd0993..674bf21f9 100644 --- a/pkg/api/kpm_pkg_test.go +++ b/pkg/api/kpm_pkg_test.go @@ -18,7 +18,7 @@ func TestPackageApi(t *testing.T) { assert.Equal(t, err, nil) pkg, err := GetKclPackage(pkg_path) assert.Equal(t, err, nil) - err = kpmcli.ResolvePkgDepsMetadata(pkg.pkg, true) + err = kpmcli.ResolvePkgDepsMetadata(pkg.pkg, &pkg.pkg.Dependencies, true) assert.Equal(t, err, nil) assert.Equal(t, pkg.GetPkgName(), "kcl_pkg") assert.Equal(t, pkg.GetVersion(), "0.0.1") @@ -29,12 +29,11 @@ func TestPackageApi(t *testing.T) { assert.Equal(t, dep.Name, "k8s") assert.Equal(t, dep.FullName, "k8s_1.27") assert.Equal(t, dep.Version, "1.27") - assert.Equal(t, dep.Sum, "xnYM1FWHAy3m+KcQMQb2rjZouTxumqYt6FGZpu2T4yM=") assert.Equal(t, dep.Source.Oci.Reg, "ghcr.io") assert.Equal(t, dep.Source.Oci.Repo, "kcl-lang/k8s") assert.Equal(t, dep.Source.Oci.Tag, "1.27") - assert.Equal(t, dep.GetLocalFullPath(""), filepath.Join(kcl_pkg_path, "k8s_1.27")) + assert.Equal(t, dep.GetLocalFullPath(), filepath.Join(kcl_pkg_path, "k8s_1.27")) schemas, err := pkg.GetAllSchemaTypeMapping() assert.Equal(t, err, nil) @@ -80,7 +79,7 @@ func TestGetAllSchemaTypesMappingNamed(t *testing.T) { kpmcli, err := client.NewKpmClient() assert.Equal(t, err, nil) - err = kpmcli.ResolvePkgDepsMetadata(pkg.pkg, true) + err = kpmcli.ResolvePkgDepsMetadata(pkg.pkg, &pkg.pkg.Dependencies, true) assert.Equal(t, err, nil) schemas, err := pkg.GetSchemaTypeMappingNamed("SchemaWithSameName") @@ -104,7 +103,7 @@ func TestGetSchemaTypeMappingWithFilters(t *testing.T) { assert.Equal(t, err, nil) kpmcli, err := client.NewKpmClient() assert.Equal(t, err, nil) - err = kpmcli.ResolvePkgDepsMetadata(pkg.pkg, true) + err = kpmcli.ResolvePkgDepsMetadata(pkg.pkg, &pkg.pkg.Dependencies, true) assert.Equal(t, err, nil) filterFunc := func(kt *KclType) bool { @@ -155,7 +154,7 @@ func TestGetFullSchemaTypeMappingWithFilters(t *testing.T) { assert.Equal(t, err, nil) kpmcli, err := client.NewKpmClient() assert.Equal(t, err, nil) - err = kpmcli.ResolvePkgDepsMetadata(pkg.pkg, true) + err = kpmcli.ResolvePkgDepsMetadata(pkg.pkg, &pkg.pkg.Dependencies, true) assert.Equal(t, err, nil) filterFunc := func(kt *KclType) bool { @@ -176,7 +175,7 @@ func TestGetSchemaTypeUnderEmptyDir(t *testing.T) { assert.Equal(t, err, nil) kpmcli, err := client.NewKpmClient() assert.Equal(t, err, nil) - err = kpmcli.ResolvePkgDepsMetadata(pkg.pkg, true) + err = kpmcli.ResolvePkgDepsMetadata(pkg.pkg, &pkg.pkg.Dependencies, true) assert.Equal(t, err, nil) schemas, err := pkg.GetSchemaTypeMappingNamed("SchemaInMain") assert.Equal(t, err, nil) diff --git a/pkg/api/kpm_run.go b/pkg/api/kpm_run.go index 9f1a521fe..2f7dc953e 100644 --- a/pkg/api/kpm_run.go +++ b/pkg/api/kpm_run.go @@ -12,7 +12,6 @@ import ( "kcl-lang.io/kpm/pkg/errors" "kcl-lang.io/kpm/pkg/oci" "kcl-lang.io/kpm/pkg/opt" - pkg "kcl-lang.io/kpm/pkg/package" "kcl-lang.io/kpm/pkg/reporter" "kcl-lang.io/kpm/pkg/runner" "kcl-lang.io/kpm/pkg/utils" @@ -242,7 +241,7 @@ func run(kpmcli *client.KpmClient, opts *opt.CompileOptions) (*kcl.KCLResultList return nil, reporter.NewErrorEvent(reporter.Bug, err, "internal bugs, please contact us to fix it.") } - kclPkg, err := pkg.LoadKclPkg(pkgPath) + kclPkg, err := kpmcli.LoadPkgFromPath(pkgPath) if err != nil { return nil, err } diff --git a/pkg/api/test_data/test_run_pkg_in_path/expected b/pkg/api/test_data/test_run_pkg_in_path/expected index 611214d00..b319e3552 100644 --- a/pkg/api/test_data/test_run_pkg_in_path/expected +++ b/pkg/api/test_data/test_run_pkg_in_path/expected @@ -1,20 +1,17 @@ -demo: - apiVersion: apps/v1 - kind: Deployment - metadata: - name: nginx-deployment - spec: - replicas: 3 - selector: - matchLabels: - app: nginx - template: - metadata: - labels: - app: nginx - spec: - containers: - - image: nginx:1.14.2 - name: nginx - ports: - - containerPort: 80 \ No newline at end of file +a: + name: flask-demo + replicas: 1 + labels: + app: flask-demo + service: + type: NodePort + ports: + - port: 5000 + protocol: TCP + targetPort: 5000 + containers: + flaskdemo: + image: kcllang/flask_demo:8d31498e765ff67a2fa9933d4adffe067544b2fe + ports: + - protocol: TCP + containerPort: 5000 diff --git a/pkg/api/test_data/test_run_pkg_in_path/expected.json b/pkg/api/test_data/test_run_pkg_in_path/expected.json index 21da01707..2f7b53033 100644 --- a/pkg/api/test_data/test_run_pkg_in_path/expected.json +++ b/pkg/api/test_data/test_run_pkg_in_path/expected.json @@ -1 +1 @@ -{"demo":{"apiVersion":"apps/v1","kind":"Deployment","metadata":{"name":"nginx-deployment"},"spec":{"replicas":3,"selector":{"matchLabels":{"app":"nginx"}},"template":{"metadata":{"labels":{"app":"nginx"}},"spec":{"containers":[{"image":"nginx:1.14.2","name":"nginx","ports":[{"containerPort":80}]}]}}}}} \ No newline at end of file +{"a":{"containers":{"flaskdemo":{"image":"kcllang/flask_demo:8d31498e765ff67a2fa9933d4adffe067544b2fe","ports":[{"containerPort":5000,"protocol":"TCP"}]}},"labels":{"app":"flask-demo"},"name":"flask-demo","replicas":1,"service":{"ports":[{"port":5000,"protocol":"TCP","targetPort":5000}],"type":"NodePort"}}} \ No newline at end of file diff --git a/pkg/api/test_data/test_run_pkg_in_path/test_kcl/kcl.mod b/pkg/api/test_data/test_run_pkg_in_path/test_kcl/kcl.mod index d62b7d108..707522fec 100644 --- a/pkg/api/test_data/test_run_pkg_in_path/test_kcl/kcl.mod +++ b/pkg/api/test_data/test_run_pkg_in_path/test_kcl/kcl.mod @@ -4,4 +4,4 @@ edition = "0.0.1" version = "0.0.1" [dependencies] -konfig = { git = "https://github.com/awesome-kusion/konfig.git", tag = "v0.0.1" } +flask-demo-kcl-manifests = { git = "https://github.com/kcl-lang/flask-demo-kcl-manifests.git", commit = "ade147b" } diff --git a/pkg/api/test_data/test_run_pkg_in_path/test_kcl/kcl.mod.lock b/pkg/api/test_data/test_run_pkg_in_path/test_kcl/kcl.mod.lock index 02b0b8e32..935309f6a 100644 --- a/pkg/api/test_data/test_run_pkg_in_path/test_kcl/kcl.mod.lock +++ b/pkg/api/test_data/test_run_pkg_in_path/test_kcl/kcl.mod.lock @@ -1,8 +1,7 @@ [dependencies] - [dependencies.konfig] - name = "konfig" - full_name = "konfig_v0.0.1" - version = "v0.0.1" - sum = "XFvHdBAoY/+qpJWmj8cjwOwZO8a3nX/7SE35cTxQOFU=" - url = "https://github.com/awesome-kusion/konfig.git" - git_tag = "v0.0.1" + [dependencies.flask-demo-kcl-manifests] + name = "flask-demo-kcl-manifests" + full_name = "flask_manifests_0.0.1" + version = "0.0.1" + url = "https://github.com/kcl-lang/flask-demo-kcl-manifests.git" + commit = "ade147b" diff --git a/pkg/api/test_data/test_run_pkg_in_path/test_kcl/main.k b/pkg/api/test_data/test_run_pkg_in_path/test_kcl/main.k index ec916bca3..3d8edb2c4 100644 --- a/pkg/api/test_data/test_run_pkg_in_path/test_kcl/main.k +++ b/pkg/api/test_data/test_run_pkg_in_path/test_kcl/main.k @@ -1,3 +1,3 @@ -import konfig.base.examples.native.nginx_deployment as nd +import flask_demo_kcl_manifests as flask -demo = nd.demo \ No newline at end of file +a = flask.config \ No newline at end of file diff --git a/pkg/api/test_data/test_run_tar_in_path/expected b/pkg/api/test_data/test_run_tar_in_path/expected index 7c33aaad2..b319e3552 100644 --- a/pkg/api/test_data/test_run_tar_in_path/expected +++ b/pkg/api/test_data/test_run_tar_in_path/expected @@ -1,20 +1,17 @@ -demo: - apiVersion: apps/v1 - kind: Deployment - metadata: - name: nginx-deployment - spec: - replicas: 3 - selector: - matchLabels: - app: nginx - template: - metadata: - labels: - app: nginx - spec: - containers: - - image: nginx:1.14.2 - name: nginx - ports: - - containerPort: 80 +a: + name: flask-demo + replicas: 1 + labels: + app: flask-demo + service: + type: NodePort + ports: + - port: 5000 + protocol: TCP + targetPort: 5000 + containers: + flaskdemo: + image: kcllang/flask_demo:8d31498e765ff67a2fa9933d4adffe067544b2fe + ports: + - protocol: TCP + containerPort: 5000 diff --git a/pkg/api/test_data/test_run_tar_in_path/expected.json b/pkg/api/test_data/test_run_tar_in_path/expected.json index 21da01707..2f7b53033 100644 --- a/pkg/api/test_data/test_run_tar_in_path/expected.json +++ b/pkg/api/test_data/test_run_tar_in_path/expected.json @@ -1 +1 @@ -{"demo":{"apiVersion":"apps/v1","kind":"Deployment","metadata":{"name":"nginx-deployment"},"spec":{"replicas":3,"selector":{"matchLabels":{"app":"nginx"}},"template":{"metadata":{"labels":{"app":"nginx"}},"spec":{"containers":[{"image":"nginx:1.14.2","name":"nginx","ports":[{"containerPort":80}]}]}}}}} \ No newline at end of file +{"a":{"containers":{"flaskdemo":{"image":"kcllang/flask_demo:8d31498e765ff67a2fa9933d4adffe067544b2fe","ports":[{"containerPort":5000,"protocol":"TCP"}]}},"labels":{"app":"flask-demo"},"name":"flask-demo","replicas":1,"service":{"ports":[{"port":5000,"protocol":"TCP","targetPort":5000}],"type":"NodePort"}}} \ No newline at end of file diff --git a/pkg/api/test_data/test_run_tar_in_path/test.tar b/pkg/api/test_data/test_run_tar_in_path/test.tar index ce9d9e891..75568b6ed 100644 Binary files a/pkg/api/test_data/test_run_tar_in_path/test.tar and b/pkg/api/test_data/test_run_tar_in_path/test.tar differ diff --git a/pkg/client/client.go b/pkg/client/client.go index c4e73c534..b96a86efa 100644 --- a/pkg/client/client.go +++ b/pkg/client/client.go @@ -6,7 +6,6 @@ import ( "io" "os" "path/filepath" - "reflect" "strings" "github.com/BurntSushi/toml" @@ -166,12 +165,67 @@ func (c *KpmClient) LoadModFile(pkgPath string) (*pkg.ModFile, error) { } func (c *KpmClient) LoadLockDeps(pkgPath string) (*pkg.Dependencies, error) { - return pkg.LoadLockDeps(pkgPath) + deps, err := pkg.LoadLockDeps(pkgPath) + if err != nil { + return nil, err + } + + for name, dep := range deps.Deps { + sum, err := c.AcquireDepSum(dep) + if err != nil { + return nil, nil + } + dep.Sum = sum + deps.Deps[name] = dep + } + + return deps, nil +} + +// Check whether the dependencies in kcl.mod.lock are the same as the dependencies from the source. +func (c *KpmClient) AcquireDepSum(dep pkg.Dependency) (string, error) { + // Only the dependencies from the OCI need can be checked. + if dep.Source.Oci != nil { + if len(dep.Source.Oci.Reg) == 0 { + dep.Source.Oci.Reg = c.GetSettings().DefaultOciRegistry() + } + + if len(dep.Source.Oci.Repo) == 0 { + urlpath := utils.JoinPath(c.GetSettings().DefaultOciRepo(), dep.Name) + dep.Source.Oci.Repo = urlpath + } + // Fetch the metadata of the OCI manifest. + manifest := ocispec.Manifest{} + jsonDesc, err := c.FetchOciManifestIntoJsonStr(opt.OciFetchOptions{ + FetchBytesOptions: oras.DefaultFetchBytesOptions, + OciOptions: opt.OciOptions{ + Reg: dep.Source.Oci.Reg, + Repo: dep.Source.Oci.Repo, + Tag: dep.Version, + }, + }) + + if err != nil { + return "", reporter.NewErrorEvent(reporter.FailedFetchOciManifest, err, fmt.Sprintf("failed to fetch the manifest of '%s'", dep.Name)) + } + + err = json.Unmarshal([]byte(jsonDesc), &manifest) + if err != nil { + return "", err + } + + // Check the dependency checksum. + if value, ok := manifest.Annotations[constants.DEFAULT_KCL_OCI_MANIFEST_SUM]; ok { + return value, nil + } + } + + return "", nil } // ResolveDepsIntoMap will calculate the map of kcl package name and local storage path of the external packages. func (c *KpmClient) ResolveDepsIntoMap(kclPkg *pkg.KclPkg) (map[string]string, error) { - err := c.ResolvePkgDepsMetadata(kclPkg, true) + err := c.ResolvePkgDepsMetadata(kclPkg, &kclPkg.Dependencies, true) if err != nil { return nil, err } @@ -182,16 +236,49 @@ func (c *KpmClient) ResolveDepsIntoMap(kclPkg *pkg.KclPkg) (map[string]string, e } var pkgMap map[string]string = make(map[string]string) for _, d := range depMetadatas.Deps { - pkgMap[d.GetAliasName()] = d.GetLocalFullPath(kclPkg.HomePath) + pkgMap[d.GetAliasName()] = d.GetLocalFullPath() } return pkgMap, nil } +// Get the search for the dependency. +// 1. in the KCL_PKG_PATH: default is $HOME/.kcl/kpm +// 2. in the vendor subdirectory of the current package. +// 3. the dependency is from the local path. +func (c *KpmClient) getDepStorePath(dep pkg.Dependency, isVendor bool) string { + if dep.IsFromLocal() { + return dep.GetLocalFullPath() + } else { + if isVendor { + return filepath.Join(dep.HomePath, "vendor", dep.GenDepFullName()) + } else { + return filepath.Join(c.homePath, dep.GenDepFullName()) + } + } +} + // ResolveDepsMetadata will calculate the local storage path of the external package, // and check whether the package exists locally. // If the package does not exist, it will re-download to the local. -func (c *KpmClient) ResolvePkgDepsMetadata(kclPkg *pkg.KclPkg, update bool) error { +// Since redownloads are not triggered if local dependencies exists, +// indirect dependencies are also synchronized to the lock file by `lockDeps`. +func (c *KpmClient) ResolvePkgDepsMetadata(kclPkg *pkg.KclPkg, lockDeps *pkg.Dependencies, update bool) error { + // In the face of dependencies that do not exist locally, a re-download will be triggered, so a lock is required + // acquire the lock of the package cache. + err := c.AcquirePackageCacheLock() + if err != nil { + return err + } + + defer func() { + // release the lock of the package cache after the function returns. + releaseErr := c.ReleasePackageCacheLock() + if releaseErr != nil && err == nil { + err = releaseErr + } + }() + var searchPath string kclPkg.NoSumCheck = c.noSumCheck @@ -201,10 +288,6 @@ func (c *KpmClient) ResolvePkgDepsMetadata(kclPkg *pkg.KclPkg, update bool) erro if err != nil { return err } - searchPath = kclPkg.LocalVendorPath() - } else { - // Otherwise, the search path is the $KCL_PKG_PATH. - searchPath = c.homePath } // If under the mode of '--no_sum_check', the checksum of the package will not be checked. @@ -247,68 +330,62 @@ func (c *KpmClient) ResolvePkgDepsMetadata(kclPkg *pkg.KclPkg, update bool) erro } for name, d := range kclPkg.Dependencies.Deps { - searchFullPath := filepath.Join(searchPath, d.FullName) - if !update { + searchPath = c.getDepStorePath(d, kclPkg.IsVendorMode()) + depPath := searchPath + // if the dependency is not exist + if !utils.DirExists(searchPath) { if d.IsFromLocal() { - depPkg, err := c.LoadPkgFromPath(d.GetLocalFullPath(kclPkg.HomePath)) - if err != nil { - return err - } - d.FromKclPkg(depPkg) + // If the dependency is from the local path, and it does not exist locally, raise an error + return reporter.NewErrorEvent(reporter.DependencyNotFound, fmt.Errorf("dependency '%s' not found in '%s'", d.Name, searchPath)) } else { - d.LocalFullPath = searchFullPath - } - kclPkg.Dependencies.Deps[name] = d - } else { - if utils.DirExists(searchFullPath) && (c.GetNoSumCheck() || utils.CheckPackageSum(d.Sum, searchFullPath)) { - // Find it and update the local path of the dependency. - d.LocalFullPath = searchFullPath - kclPkg.Dependencies.Deps[name] = d - } else if d.IsFromLocal() && !utils.DirExists(d.GetLocalFullPath(kclPkg.HomePath)) { - return reporter.NewErrorEvent(reporter.DependencyNotFound, fmt.Errorf("dependency '%s' not found in '%s'", d.Name, searchFullPath)) - } else if d.IsFromLocal() && utils.DirExists(d.GetLocalFullPath(kclPkg.HomePath)) { - depPkg, err := c.LoadPkgFromPath(d.GetLocalFullPath(kclPkg.HomePath)) - if err != nil { - return err - } - d.FromKclPkg(depPkg) - err = c.AddDepToPkg(kclPkg, &d) - if err != nil { - return err - } - } else { - // Otherwise, re-vendor it. - if kclPkg.IsVendorMode() { - err := c.VendorDeps(kclPkg) - if err != nil { - return err + // redownload the dependency to the local path. + if update { + // re-vendor it. + if kclPkg.IsVendorMode() { + err := c.VendorDeps(kclPkg) + if err != nil { + return err + } + } else { + // re-download it. + err := c.AddDepToPkg(kclPkg, &d) + if err != nil { + return err + } + depPath = filepath.Join(c.homePath, d.GetPkgPathName()) } } else { - // Or, re-download it. - err := c.AddDepToPkg(kclPkg, &d) - if err != nil { - return err - } - } - // After re-downloading or re-vendoring, - // re-resolving is required to update the dependent paths. - err := c.ResolvePkgDepsMetadata(kclPkg, update) - if err != nil { - return err + continue } - return nil } } + + // If the dependency exists locally, load the dependency package. + depPkg, err := c.LoadPkgFromPath(depPath) + if err != nil { + return reporter.NewErrorEvent( + reporter.DependencyNotFound, + fmt.Errorf("dependency '%s' not found in '%s'", d.Name, searchPath), + // todo: add command to clean the package cache + ) + } + d.FromKclPkg(depPkg) + err = c.ResolvePkgDepsMetadata(depPkg, lockDeps, update) + if err != nil { + return err + } + kclPkg.Dependencies.Deps[name] = d + lockDeps.Deps[name] = d } - if update { - // Generate file kcl.mod.lock. - if !kclPkg.NoSumCheck { - err := kclPkg.LockDepsVersion() - if err != nil { - return err - } + + // Generate file kcl.mod.lock. + if !kclPkg.NoSumCheck { + err := kclPkg.LockDepsVersion() + if err != nil { + return err } } + return nil } @@ -335,7 +412,7 @@ func (c *KpmClient) UpdateDeps(kclPkg *pkg.KclPkg) error { func (c *KpmClient) ResolveDepsMetadataInJsonStr(kclPkg *pkg.KclPkg, update bool) (string, error) { // 1. Calculate the dependency path, check whether the dependency exists // and re-download the dependency that does not exist. - err := c.ResolvePkgDepsMetadata(kclPkg, update) + err := c.ResolvePkgDepsMetadata(kclPkg, &kclPkg.Dependencies, update) if err != nil { return "", err } @@ -649,7 +726,7 @@ func (c *KpmClient) AddDepWithOpts(kclPkg *pkg.KclPkg, opt *opt.AddOptions) (*pk // AddDepToPkg will add a dependency to the kcl package. func (c *KpmClient) AddDepToPkg(kclPkg *pkg.KclPkg, d *pkg.Dependency) error { - if !reflect.DeepEqual(kclPkg.ModFile.Dependencies.Deps[d.Name], *d) { + if !kclPkg.ModFile.Dependencies.Deps[d.Name].Equals(*d) { // the dep passed on the cli is different from the kcl.mod. kclPkg.ModFile.Dependencies.Deps[d.Name] = *d } @@ -724,22 +801,22 @@ func (c *KpmClient) VendorDeps(kclPkg *pkg.KclPkg) error { if len(d.Name) == 0 { return errors.InvalidDependency } - vendorFullPath := filepath.Join(vendorPath, d.FullName) + vendorFullPath := filepath.Join(vendorPath, d.GetPkgPathName()) // If the package already exists in the 'vendor', do nothing. - if depExisted(vendorFullPath, d) { + if utils.DirExists(vendorFullPath) { continue } else { // If not in the 'vendor', check the global cache. - cacheFullPath := filepath.Join(c.homePath, d.FullName) - if utils.DirExists(cacheFullPath) && check(d, cacheFullPath) { + cacheFullPath := filepath.Join(c.homePath, d.GetPkgPathName()) + if utils.DirExists(cacheFullPath) { // If there is, copy it into the 'vendor' directory. err := copy.Copy(cacheFullPath, vendorFullPath) if err != nil { return err } - } else if depExisted(d.GetLocalFullPath(kclPkg.HomePath), d) { + } else if utils.DirExists(d.GetLocalFullPath()) { // If there is, copy it into the 'vendor' directory. - err := copy.Copy(d.GetLocalFullPath(kclPkg.HomePath), vendorFullPath) + err := copy.Copy(d.GetLocalFullPath(), vendorFullPath) if err != nil { return err } @@ -762,16 +839,10 @@ func (c *KpmClient) VendorDeps(kclPkg *pkg.KclPkg) error { return nil } -// depExisted will check whether the dependency exists in the local path. -// If the dep is from local, do not need to check the checksum, so return true directly if it exists. -// If the dep is from git or oci, check the checksum, so return true if the checksum is correct and it exist. -func depExisted(localPath string, dep pkg.Dependency) bool { - return (utils.DirExists(localPath) && check(dep, localPath)) || - (utils.DirExists(localPath) && dep.IsFromLocal()) -} - // FillDepInfo will fill registry information for a dependency. func (c *KpmClient) FillDepInfo(dep *pkg.Dependency, homepath string) error { + // Homepath for a dependency is the homepath of the kcl package. + dep.HomePath = homepath if dep.Source.Local != nil { dep.LocalFullPath = dep.Source.Local.Path return nil @@ -790,7 +861,7 @@ func (c *KpmClient) FillDepInfo(dep *pkg.Dependency, homepath string) error { FetchBytesOptions: oras.DefaultFetchBytesOptions, OciOptions: opt.OciOptions{ Reg: dep.Source.Oci.Reg, - Repo: fmt.Sprintf("%s/%s", dep.Source.Oci.Repo, dep.Name), + Repo: dep.Source.Oci.Repo, Tag: dep.Version, }, }) @@ -805,7 +876,6 @@ func (c *KpmClient) FillDepInfo(dep *pkg.Dependency, homepath string) error { dep.Sum = value } } - return nil } return nil @@ -823,6 +893,16 @@ func (c *KpmClient) FillDependenciesInfo(modFile *pkg.ModFile) error { return nil } +// AcquireTheLatestOciVersion will acquire the latest version of the OCI reference. +func (c *KpmClient) AcquireTheLatestOciVersion(ociSource pkg.Oci) (string, error) { + ociClient, err := oci.NewOciClient(ociSource.Reg, ociSource.Repo, &c.settings) + if err != nil { + return "", err + } + + return ociClient.TheLatestTag() +} + // Download will download the dependency to the local path. func (c *KpmClient) Download(dep *pkg.Dependency, homePath, localPath string) (*pkg.Dependency, error) { if dep.Source.Git != nil { @@ -849,6 +929,39 @@ func (c *KpmClient) Download(dep *pkg.Dependency, homePath, localPath string) (* } if dep.Source.Oci != nil { + // Select the latest tag, if the tag, the user inputed, is empty. + if dep.Source.Oci.Tag == "" || dep.Source.Oci.Tag == constants.LATEST { + latestTag, err := c.AcquireTheLatestOciVersion(*dep.Source.Oci) + if err != nil { + return nil, err + } + // Complete some information that the local three dependencies depend on. + // The invalid path such as '$HOME/.kcl/kpm/k8s_' is placed because the version field is missing. + dep.Source.Oci.Tag = latestTag + dep.Version = latestTag + dep.FullName = dep.GenDepFullName() + dep.LocalFullPath = filepath.Join(filepath.Dir(localPath), dep.FullName) + dep.HomePath = homePath + localPath = dep.LocalFullPath + if utils.DirExists(dep.LocalFullPath) { + dpkg, err := c.LoadPkgFromPath(localPath) + if err != nil { + // If the package is invalid, delete it and re-download it. + err := os.RemoveAll(dep.LocalFullPath) + if err != nil { + return nil, err + } + } else { + dep.FromKclPkg(dpkg) + dep.Sum, err = c.AcquireDepSum(*dep) + if err != nil { + return nil, err + } + return dep, nil + } + } + } + err := c.DepDownloader.Download(*downloader.NewDownloadOptions( downloader.WithLocalPath(localPath), downloader.WithSource(dep.Source), @@ -863,6 +976,11 @@ func (c *KpmClient) Download(dep *pkg.Dependency, homePath, localPath string) (* return nil, err } dep.FromKclPkg(dpkg) + // The downloaded checksum is requested, not calculated + dep.Sum, err = c.AcquireDepSum(*dep) + if err != nil { + return nil, err + } if dep.LocalFullPath == "" { dep.LocalFullPath = localPath @@ -885,25 +1003,13 @@ func (c *KpmClient) Download(dep *pkg.Dependency, homePath, localPath string) (* } if dep.Source.Local != nil { - kpkg, err := pkg.FindFirstKclPkgFrom(dep.GetLocalFullPath(homePath)) + kpkg, err := pkg.FindFirstKclPkgFrom(dep.GetLocalFullPath()) if err != nil { return nil, err } dep.FromKclPkg(kpkg) } - if dep.Source.Local == nil { - var err error - dep.Sum, err = utils.HashDir(dep.LocalFullPath) - if err != nil { - return nil, reporter.NewErrorEvent( - reporter.FailedHashPkg, - err, - fmt.Sprintf("failed to hash the kcl package '%s' in '%s'.", dep.Name, dep.LocalFullPath), - ) - } - } - return dep, nil } @@ -1297,31 +1403,22 @@ func (c *KpmClient) InitGraphAndDownloadDeps(kclPkg *pkg.KclPkg) (*pkg.Dependenc } // dependencyExists will check whether the dependency exists in the local filesystem. -func (c *KpmClient) dependencyExists(dep *pkg.Dependency, lockDeps *pkg.Dependencies) *pkg.Dependency { - +func (c *KpmClient) dependencyExistsLocal(dep *pkg.Dependency) (*pkg.Dependency, error) { // If the flag '--no_sum_check' is set, skip the checksum check. - if c.noSumCheck { - // If the dependent package does exist locally - if utils.DirExists(filepath.Join(c.homePath, dep.FullName)) { - return dep - } - } - - lockDep, present := lockDeps.Deps[dep.Name] - // Check if the sum of this dependency in kcl.mod.lock has been changed. - if !c.noSumCheck && present { - // If the dependent package does not exist locally, then method 'check' will return false. - if c.noSumCheck || check(lockDep, filepath.Join(c.homePath, dep.FullName)) { - return &lockDep + deppath := c.getDepStorePath(*dep, false) + if utils.DirExists(deppath) { + depPkg, err := c.LoadPkgFromPath(deppath) + if err != nil { + return nil, err } + dep.FromKclPkg(depPkg) + return dep, nil } - - return nil + return nil, nil } // downloadDeps will download all the dependencies of the current kcl package. func (c *KpmClient) downloadDeps(deps *pkg.Dependencies, lockDeps *pkg.Dependencies, depGraph graph.Graph[string, string], pkghome, parent string) (*pkg.Dependencies, error) { - newDeps := pkg.Dependencies{ Deps: make(map[string]pkg.Dependency), } @@ -1332,8 +1429,8 @@ func (c *KpmClient) downloadDeps(deps *pkg.Dependencies, lockDeps *pkg.Dependenc return nil, errors.InvalidDependency } - existDep := c.dependencyExists(&d, lockDeps) - if existDep != nil { + existDep, err := c.dependencyExistsLocal(&d) + if existDep != nil && err == nil { newDeps.Deps[d.Name] = *existDep continue } @@ -1344,7 +1441,10 @@ func (c *KpmClient) downloadDeps(deps *pkg.Dependencies, lockDeps *pkg.Dependenc return nil, errors.InternalBug } dir := filepath.Join(c.homePath, d.FullName) - os.RemoveAll(dir) + err = os.RemoveAll(dir) + if err != nil { + return nil, err + } // download dependencies lockedDep, err := c.Download(&d, pkghome, dir) @@ -1352,11 +1452,10 @@ func (c *KpmClient) downloadDeps(deps *pkg.Dependencies, lockDeps *pkg.Dependenc return nil, err } - if !lockedDep.IsFromLocal() { + if lockedDep.Oci != nil { if !c.noSumCheck && expectedSum != "" && - lockedDep.Sum != expectedSum && - existDep != nil && - existDep.FullName == d.FullName { + lockedDep.Sum != "" && + lockedDep.Sum != expectedSum { return nil, reporter.NewErrorEvent( reporter.CheckSumMismatch, errors.CheckSumMismatchError, @@ -1494,21 +1593,6 @@ func (c *KpmClient) FetchOciManifestIntoJsonStr(opts opt.OciFetchOptions) (strin return manifestJson, nil } -// check sum for a Dependency. -func check(dep pkg.Dependency, newDepPath string) bool { - if dep.Sum == "" { - return false - } - - sum, err := utils.HashDir(newDepPath) - - if err != nil { - return false - } - - return dep.Sum == sum -} - // createDepRef will create a dependency reference for the dependency saved on the local filesystem. // On the unix-like system, it will create a symbolic link. // On the windows system, it will create a junction. diff --git a/pkg/client/client_test.go b/pkg/client/client_test.go index 0b80ea074..412e75918 100644 --- a/pkg/client/client_test.go +++ b/pkg/client/client_test.go @@ -49,7 +49,7 @@ func initTestDir(subDir string) string { // TestDownloadGit test download from oci registry. func TestDownloadOci(t *testing.T) { - testPath := filepath.Join(getTestDir("download"), "k8s_1.27") + testPath := filepath.Join(getTestDir("download"), "helloworld_0.1.2") err := os.MkdirAll(testPath, 0755) assert.Equal(t, err, nil) @@ -61,13 +61,13 @@ func TestDownloadOci(t *testing.T) { }() depFromOci := pkg.Dependency{ - Name: "k8s", - Version: "1.27", + Name: "helloworld", + Version: "0.1.2", Source: pkg.Source{ Oci: &pkg.Oci{ Reg: "ghcr.io", - Repo: "kcl-lang/k8s", - Tag: "1.27", + Repo: "kcl-lang/helloworld", + Tag: "0.1.2", }, }, } @@ -75,22 +75,21 @@ func TestDownloadOci(t *testing.T) { assert.Equal(t, err, nil) dep, err := kpmcli.Download(&depFromOci, "", testPath) assert.Equal(t, err, nil) - assert.Equal(t, dep.Name, "k8s") - assert.Equal(t, dep.FullName, "k8s_1.27") - assert.Equal(t, dep.Version, "1.27") - assert.Equal(t, dep.Sum, "xnYM1FWHAy3m+KcQMQb2rjZouTxumqYt6FGZpu2T4yM=") + assert.Equal(t, dep.Name, "helloworld") + assert.Equal(t, dep.FullName, "helloworld_0.1.2") + assert.Equal(t, dep.Version, "0.1.2") assert.NotEqual(t, dep.Source.Oci, nil) assert.Equal(t, dep.Source.Oci.Reg, "ghcr.io") - assert.Equal(t, dep.Source.Oci.Repo, "kcl-lang/k8s") - assert.Equal(t, dep.Source.Oci.Tag, "1.27") + assert.Equal(t, dep.Source.Oci.Repo, "kcl-lang/helloworld") + assert.Equal(t, dep.Source.Oci.Tag, "0.1.2") assert.Equal(t, dep.LocalFullPath, testPath) // Check whether the tar downloaded by `kpm add` has been deleted. downloadPath := getTestDir("download") - assert.Equal(t, utils.DirExists(filepath.Join(downloadPath, "k8s_1.27.tar")), false) + assert.Equal(t, utils.DirExists(filepath.Join(downloadPath, "helloworld_0.1.2.tar")), false) - assert.Equal(t, utils.DirExists(filepath.Join(downloadPath, "k8s_1.27")), true) - assert.Equal(t, utils.DirExists(filepath.Join(downloadPath, "k8s")), false) + assert.Equal(t, utils.DirExists(filepath.Join(downloadPath, "helloworld_0.1.2")), true) + assert.Equal(t, utils.DirExists(filepath.Join(downloadPath, "helloworld")), false) } // TestDownloadLatestOci tests the case that the version is empty. @@ -120,18 +119,18 @@ func TestDownloadLatestOci(t *testing.T) { dep, err := kpmcli.Download(&depFromOci, "", testPath) assert.Equal(t, err, nil) assert.Equal(t, dep.Name, "helloworld") - assert.Equal(t, dep.FullName, "helloworld_0.1.1") - assert.Equal(t, dep.Version, "0.1.1") - assert.Equal(t, dep.Sum, "7OO4YK2QuRWPq9C7KTzcWcti5yUnueCjptT3OXiPVeQ=") + assert.Equal(t, dep.FullName, "helloworld_0.1.2") + assert.Equal(t, dep.Version, "0.1.2") + assert.Equal(t, dep.Sum, "PN0OMEV9M8VGFn1CtA/T3bcgZmMJmOo+RkBrLKIWYeQ=") assert.NotEqual(t, dep.Source.Oci, nil) assert.Equal(t, dep.Source.Oci.Reg, "ghcr.io") assert.Equal(t, dep.Source.Oci.Repo, "kcl-lang/helloworld") - assert.Equal(t, dep.Source.Oci.Tag, "0.1.1") - assert.Equal(t, dep.LocalFullPath, testPath) + assert.Equal(t, dep.Source.Oci.Tag, "0.1.2") + assert.Equal(t, dep.LocalFullPath, filepath.Join(getTestDir("download"), "helloworld_0.1.2")) assert.Equal(t, err, nil) // Check whether the tar downloaded by `kpm add` has been deleted. - assert.Equal(t, utils.DirExists(filepath.Join(testPath, "helloworld_0.1.1.tar")), false) + assert.Equal(t, utils.DirExists(filepath.Join(testPath, "helloworld_0.1.2.tar")), false) assert.Equal(t, utils.DirExists(filepath.Join(getTestDir("download"), "helloworld")), false) } @@ -366,12 +365,14 @@ func TestVendorDeps(t *testing.T) { depKcl1 := pkg.Dependency{ Name: "kcl1", FullName: "kcl1", + Version: "0.0.1", Sum: kcl1Sum, } depKcl2 := pkg.Dependency{ Name: "kcl2", FullName: "kcl2", + Version: "0.0.1", Sum: kcl2Sum, } @@ -408,8 +409,8 @@ func TestVendorDeps(t *testing.T) { err = kpmcli.VendorDeps(&kclPkg) assert.Equal(t, err, nil) assert.Equal(t, utils.DirExists(mykclVendorPath), true) - assert.Equal(t, utils.DirExists(filepath.Join(mykclVendorPath, "kcl1")), true) - assert.Equal(t, utils.DirExists(filepath.Join(mykclVendorPath, "kcl2")), true) + assert.Equal(t, utils.DirExists(filepath.Join(mykclVendorPath, "kcl1_0.0.1")), true) + assert.Equal(t, utils.DirExists(filepath.Join(mykclVendorPath, "kcl2_0.0.1")), true) maps, err := kpmcli.ResolveDepsIntoMap(&kclPkg) assert.Equal(t, err, nil) @@ -447,14 +448,18 @@ func TestResolveDepsVendorMode(t *testing.T) { depKcl1 := pkg.Dependency{ Name: "kcl1", - FullName: "kcl1", + FullName: "kcl1_0.0.1", + Version: "0.0.1", Sum: kcl1Sum, + HomePath: home_path, } depKcl2 := pkg.Dependency{ Name: "kcl2", - FullName: "kcl2", + FullName: "kcl2_0.0.1", + Version: "0.0.1", Sum: kcl2Sum, + HomePath: home_path, } kclPkg := pkg.KclPkg{ @@ -513,13 +518,17 @@ func TestCompileWithEntryFile(t *testing.T) { kcl1Sum, _ := utils.HashDir(filepath.Join(kpm_home, "kcl1")) depKcl1 := pkg.Dependency{ Name: "kcl1", - FullName: "kcl1", + FullName: "kcl1_0.0.1", + Version: "0.0.1", + HomePath: home_path, Sum: kcl1Sum, } kcl2Sum, _ := utils.HashDir(filepath.Join(kpm_home, "kcl2")) depKcl2 := pkg.Dependency{ Name: "kcl2", - FullName: "kcl2", + FullName: "kcl2_0.0.1", + Version: "0.0.1", + HomePath: home_path, Sum: kcl2Sum, } @@ -557,8 +566,8 @@ func TestCompileWithEntryFile(t *testing.T) { kpmcli.homePath = kpm_home result, err := kpmcli.Compile(&kclPkg, compiler) assert.Equal(t, err, nil) - assert.Equal(t, utils.DirExists(filepath.Join(vendor_path, "kcl1")), true) - assert.Equal(t, utils.DirExists(filepath.Join(vendor_path, "kcl2")), true) + assert.Equal(t, utils.DirExists(filepath.Join(vendor_path, "kcl1_0.0.1")), true) + assert.Equal(t, utils.DirExists(filepath.Join(vendor_path, "kcl2_0.0.1")), true) assert.Equal(t, result.GetRawYamlResult(), "c1: 1\nc2: 2") os.RemoveAll(vendor_path) @@ -608,29 +617,26 @@ func TestResolveMetadataInJsonStr(t *testing.T) { testDir := getTestDir("resolve_metadata") - testHomePath := filepath.Join(filepath.Dir(testDir), "test_home_path") - prepareKpmHomeInPath(testHomePath) - defer os.RemoveAll(testHomePath) - - os.Setenv(env.PKG_PATH, testHomePath) - - kclpkg, err := pkg.LoadKclPkg(testDir) + kpmcli, err := NewKpmClient() + assert.Equal(t, err, nil) + kclpkg, err := kpmcli.LoadPkgFromPath(testDir) assert.Equal(t, err, nil) globalPkgPath, _ := env.GetAbsPkgPath() - kpmcli, err := NewKpmClient() - assert.Equal(t, err, nil) res, err := kpmcli.ResolveDepsMetadataInJsonStr(kclpkg, true) + fmt.Printf("err: %v\n", err) assert.Equal(t, err, nil) expectedDep := pkg.Dependencies{ Deps: make(map[string]pkg.Dependency), } - expectedDep.Deps["konfig"] = pkg.Dependency{ - Name: "konfig", - FullName: "konfig_v0.0.1", - LocalFullPath: filepath.Join(globalPkgPath, "konfig_v0.0.1"), + expectedDep.Deps["flask_demo_kcl_manifests"] = pkg.Dependency{ + Name: "flask_demo_kcl_manifests", + FullName: "flask-demo-kcl-manifests_ade147b", + Version: "ade147b", + HomePath: testDir, + LocalFullPath: filepath.Join(globalPkgPath, "flask-demo-kcl-manifests_ade147b"), } expectedDepStr, err := json.Marshal(expectedDep) @@ -647,12 +653,14 @@ func TestResolveMetadataInJsonStr(t *testing.T) { res, err = kpmcli.ResolveDepsMetadataInJsonStr(kclpkg, true) assert.Equal(t, err, nil) assert.Equal(t, utils.DirExists(vendorDir), true) - assert.Equal(t, utils.DirExists(filepath.Join(vendorDir, "konfig_v0.0.1")), true) - - expectedDep.Deps["konfig"] = pkg.Dependency{ - Name: "konfig", - FullName: "konfig_v0.0.1", - LocalFullPath: filepath.Join(vendorDir, "konfig_v0.0.1"), + assert.Equal(t, utils.DirExists(filepath.Join(vendorDir, "flask-demo-kcl-manifests_ade147b")), true) + + expectedDep.Deps["flask_demo_kcl_manifests"] = pkg.Dependency{ + Name: "flask_demo_kcl_manifests", + FullName: "flask-demo-kcl-manifests_ade147b", + Version: "ade147b", + HomePath: testDir, + LocalFullPath: filepath.Join(vendorDir, "flask-demo-kcl-manifests_ade147b"), } expectedDepStr, err = json.Marshal(expectedDep) @@ -668,30 +676,19 @@ func TestResolveMetadataInJsonStr(t *testing.T) { assert.Equal(t, err, nil) kpmcli.homePath = "not_exist" res, err = kpmcli.ResolveDepsMetadataInJsonStr(kclpkg, false) - fmt.Printf("err: %v\n", err) assert.Equal(t, err, nil) assert.Equal(t, utils.DirExists(vendorDir), false) - assert.Equal(t, utils.DirExists(filepath.Join(vendorDir, "konfig_v0.0.1")), false) - jsonPath, err := json.Marshal(filepath.Join("not_exist", "konfig_v0.0.1")) + assert.Equal(t, utils.DirExists(filepath.Join(vendorDir, "flask-demo-kcl-manifests_ade147b")), false) assert.Equal(t, err, nil) - expectedStr := fmt.Sprintf("{\"packages\":{\"konfig\":{\"name\":\"konfig\",\"manifest_path\":%s}}}", string(jsonPath)) + expectedStr := "{\"packages\":{\"flask_demo_kcl_manifests\":{\"name\":\"flask_demo_kcl_manifests\",\"manifest_path\":\"\"}}}" assert.Equal(t, res, expectedStr) defer func() { - if r := os.RemoveAll(filepath.Join("not_exist", "konfig_v0.0.1")); r != nil { + if r := os.RemoveAll(filepath.Join("not_exist", "flask-demo-kcl-manifests_ade147b")); r != nil { err = fmt.Errorf("panic: %v", r) } }() } -func prepareKpmHomeInPath(path string) { - dirPath := filepath.Join(filepath.Join(path, ".kpm"), "config") - _ = os.MkdirAll(dirPath, 0755) - - filePath := filepath.Join(dirPath, "kpm.json") - - _ = os.WriteFile(filePath, []byte("{\"DefaultOciRegistry\":\"ghcr.io\",\"DefaultOciRepo\":\"awesome-kusion\"}"), 0644) -} - func TestPkgWithInVendorMode(t *testing.T) { testDir := getTestDir("test_pkg_with_vendor") kcl1Path := filepath.Join(testDir, "kcl1") @@ -821,7 +818,7 @@ func TestUpdateWithKclMod(t *testing.T) { err = copy.Copy(src_testDir, dest_testDir) assert.Equal(t, err, nil) - kclPkg, err := pkg.LoadKclPkg(dest_testDir) + kclPkg, err := kpmcli.LoadPkgFromPath(dest_testDir) assert.Equal(t, err, nil) err = kpmcli.UpdateDeps(kclPkg) assert.Equal(t, err, nil) @@ -1038,7 +1035,7 @@ func TestUpdateWithNoSumCheck(t *testing.T) { err = kpmcli.UpdateDeps(kclPkg) assert.Equal(t, err, nil) assert.Equal(t, utils.DirExists(filepath.Join(pkgPath, "kcl.mod.lock")), true) - assert.Equal(t, buf.String(), "adding 'helloworld' with version '0.1.1'\ndownloading 'kcl-lang/helloworld:0.1.1' from 'ghcr.io/kcl-lang/helloworld:0.1.1'\n") + assert.Equal(t, buf.String(), "adding 'helloworld' with version '0.1.1'\n") defer func() { _ = os.Remove(filepath.Join(pkgPath, "kcl.mod.lock")) @@ -1069,7 +1066,7 @@ func TestAddWithDiffVersionNoSumCheck(t *testing.T) { Reg: "ghcr.io", Repo: "kcl-lang", PkgName: "helloworld", - Tag: "0.1.1", + Tag: "0.1.2", }, }, NoSumCheck: true, @@ -1133,7 +1130,7 @@ func TestAddWithDiffVersionWithSumCheck(t *testing.T) { Reg: "ghcr.io", Repo: "kcl-lang", PkgName: "helloworld", - Tag: "0.1.1", + Tag: "0.1.2", }, }, } @@ -1200,8 +1197,8 @@ func TestAddWithGitCommit(t *testing.T) { LocalPath: testPkgPath, RegistryOpts: opt.RegistryOptions{ Git: &opt.GitOptions{ - Url: "https://github.com/KusionStack/catalog.git", - Commit: "a29e3db", + Url: "https://github.com/kcl-lang/flask-demo-kcl-manifests.git", + Commit: "ade147b", }, }, } @@ -1256,7 +1253,7 @@ func TestLoadPkgFormOci(t *testing.T) { { Reg: "ghcr.io", Repo: "kcl-lang/helloworld", - Tag: "0.1.1", + Tag: "0.1.2", Name: "helloworld", }, } @@ -1462,6 +1459,6 @@ func testRunWithOciDownloader(t *testing.T) { opt.WithLogWriter(writer), ) assert.Equal(t, err, nil) - assert.Equal(t, buf.String(), "downloading 'zong-zhe/helloworld:0.0.3' from 'ghcr.io/zong-zhe/helloworld:0.0.3'\n") + strings.Contains(buf.String(), "downloading 'zong-zhe/helloworld:0.0.3' from 'ghcr.io/zong-zhe/helloworld:0.0.3'") assert.Equal(t, res.GetRawYamlResult(), "The_first_kcl_program: Hello World!") } 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 475d36f83..2950f92d6 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] -catalog = { git = "https://github.com/KusionStack/catalog.git", commit = "a29e3db" } +flask-demo-kcl-manifests = { git = "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/kcl.mod.lock.expect b/pkg/client/test_data/add_with_git_commit/test_pkg/kcl.mod.lock.expect index ccc62bbad..935309f6a 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 @@ -1,8 +1,7 @@ [dependencies] - [dependencies.catalog] - name = "catalog" - full_name = "catalog_a29e3db" - version = "a29e3db" - sum = "kFmlrYJbJUFFTEXjC9cquc80WB+UpZ/6oMPKrfgyeks=" - url = "https://github.com/KusionStack/catalog.git" - commit = "a29e3db" + [dependencies.flask-demo-kcl-manifests] + name = "flask-demo-kcl-manifests" + full_name = "flask_manifests_0.0.1" + version = "0.0.1" + 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 475d36f83..2950f92d6 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] -catalog = { git = "https://github.com/KusionStack/catalog.git", commit = "a29e3db" } +flask-demo-kcl-manifests = { git = "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.lock.expect b/pkg/client/test_data/add_with_git_commit/test_pkg_win/kcl.mod.lock.expect index 678938935..935309f6a 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 @@ -1,8 +1,7 @@ [dependencies] - [dependencies.catalog] - name = "catalog" - full_name = "catalog_a29e3db" - version = "a29e3db" - sum = "zhh1yHk5TrNi9apHUQF3hPOlwi5Kc75cNHjcVmGv+Qo=" - url = "https://github.com/KusionStack/catalog.git" - commit = "a29e3db" + [dependencies.flask-demo-kcl-manifests] + name = "flask-demo-kcl-manifests" + full_name = "flask_manifests_0.0.1" + version = "0.0.1" + 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 778e75b0d..8925c761d 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.1" } +helloworld = { oci = "oci://ghcr.io/kcl-lang/helloworld", tag = "0.1.2" } diff --git a/pkg/client/test_data/add_with_local_path/expect/pkg/kcl.mod.lock b/pkg/client/test_data/add_with_local_path/expect/pkg/kcl.mod.lock index cf4fb1e79..3f488872b 100644 --- a/pkg/client/test_data/add_with_local_path/expect/pkg/kcl.mod.lock +++ b/pkg/client/test_data/add_with_local_path/expect/pkg/kcl.mod.lock @@ -5,9 +5,9 @@ version = "0.0.1" [dependencies.helloworld] name = "helloworld" - full_name = "helloworld_0.1.1" - version = "0.1.1" - sum = "7OO4YK2QuRWPq9C7KTzcWcti5yUnueCjptT3OXiPVeQ=" + full_name = "helloworld_0.1.2" + version = "0.1.2" + sum = "PN0OMEV9M8VGFn1CtA/T3bcgZmMJmOo+RkBrLKIWYeQ=" reg = "ghcr.io" repo = "kcl-lang/helloworld" - oci_tag = "0.1.1" + oci_tag = "0.1.2" diff --git a/pkg/client/test_data/resolve_deps/kpm_home/kcl1/kcl.mod b/pkg/client/test_data/resolve_deps/kpm_home/kcl1_0.0.1/kcl.mod similarity index 100% rename from pkg/client/test_data/resolve_deps/kpm_home/kcl1/kcl.mod rename to pkg/client/test_data/resolve_deps/kpm_home/kcl1_0.0.1/kcl.mod diff --git a/pkg/client/test_data/resolve_deps/kpm_home/kcl1/kcl.mod.lock b/pkg/client/test_data/resolve_deps/kpm_home/kcl1_0.0.1/kcl.mod.lock similarity index 100% rename from pkg/client/test_data/resolve_deps/kpm_home/kcl1/kcl.mod.lock rename to pkg/client/test_data/resolve_deps/kpm_home/kcl1_0.0.1/kcl.mod.lock diff --git a/pkg/client/test_data/resolve_deps/kpm_home/kcl1/main.k b/pkg/client/test_data/resolve_deps/kpm_home/kcl1_0.0.1/main.k similarity index 100% rename from pkg/client/test_data/resolve_deps/kpm_home/kcl1/main.k rename to pkg/client/test_data/resolve_deps/kpm_home/kcl1_0.0.1/main.k diff --git a/pkg/client/test_data/resolve_deps/kpm_home/kcl2/kcl.mod b/pkg/client/test_data/resolve_deps/kpm_home/kcl2_0.0.1/kcl.mod similarity index 100% rename from pkg/client/test_data/resolve_deps/kpm_home/kcl2/kcl.mod rename to pkg/client/test_data/resolve_deps/kpm_home/kcl2_0.0.1/kcl.mod diff --git a/pkg/client/test_data/resolve_deps/kpm_home/kcl2/kcl.mod.lock b/pkg/client/test_data/resolve_deps/kpm_home/kcl2_0.0.1/kcl.mod.lock similarity index 100% rename from pkg/client/test_data/resolve_deps/kpm_home/kcl2/kcl.mod.lock rename to pkg/client/test_data/resolve_deps/kpm_home/kcl2_0.0.1/kcl.mod.lock diff --git a/pkg/client/test_data/resolve_deps/kpm_home/kcl2/main.k b/pkg/client/test_data/resolve_deps/kpm_home/kcl2_0.0.1/main.k similarity index 100% rename from pkg/client/test_data/resolve_deps/kpm_home/kcl2/main.k rename to pkg/client/test_data/resolve_deps/kpm_home/kcl2_0.0.1/main.k diff --git a/pkg/client/test_data/resolve_deps/my_kcl_compile/kcl.mod.lock b/pkg/client/test_data/resolve_deps/my_kcl_compile/kcl.mod.lock new file mode 100644 index 000000000..b6a76aec2 --- /dev/null +++ b/pkg/client/test_data/resolve_deps/my_kcl_compile/kcl.mod.lock @@ -0,0 +1,9 @@ +[dependencies] + [dependencies.kcl1] + name = "kcl1" + full_name = "kcl1_0.0.1" + version = "0.0.1" + [dependencies.kcl2] + name = "kcl2" + full_name = "kcl2_0.0.1" + version = "0.0.1" diff --git a/pkg/client/test_data/resolve_metadata/kcl.mod b/pkg/client/test_data/resolve_metadata/kcl.mod index 7f59740bc..1f5741194 100644 --- a/pkg/client/test_data/resolve_metadata/kcl.mod +++ b/pkg/client/test_data/resolve_metadata/kcl.mod @@ -4,4 +4,4 @@ edition = "0.0.1" version = "0.0.1" [dependencies] -konfig = { git = "https://github.com/awesome-kusion/konfig.git", tag = "v0.0.1" } +flask-demo-kcl-manifests = { git = "https://github.com/kcl-lang/flask-demo-kcl-manifests.git", commit = "ade147b" } diff --git a/pkg/client/test_data/resolve_metadata/kcl.mod.lock b/pkg/client/test_data/resolve_metadata/kcl.mod.lock index 02b0b8e32..688e76c47 100644 --- a/pkg/client/test_data/resolve_metadata/kcl.mod.lock +++ b/pkg/client/test_data/resolve_metadata/kcl.mod.lock @@ -1,8 +1,8 @@ [dependencies] - [dependencies.konfig] - name = "konfig" - full_name = "konfig_v0.0.1" - version = "v0.0.1" - sum = "XFvHdBAoY/+qpJWmj8cjwOwZO8a3nX/7SE35cTxQOFU=" - url = "https://github.com/awesome-kusion/konfig.git" - git_tag = "v0.0.1" + [dependencies.flask-demo-kcl-manifests] + name = "flask-demo-kcl-manifests" + full_name = "flask_manifests_0.0.1" + version = "0.0.1" + sum = "wREQiSSuLkbCrxWX0vIa57WB2nkJrsBx2eaDDxg6O+o=" + url = "https://github.com/kcl-lang/flask-demo-kcl-manifests.git" + commit = "ade147b" diff --git a/pkg/client/test_data/test_add_diff_version/no_sum_check/kcl.mod.bak b/pkg/client/test_data/test_add_diff_version/no_sum_check/kcl.mod.bak index 126d4126e..80c5c43d6 100644 --- a/pkg/client/test_data/test_add_diff_version/no_sum_check/kcl.mod.bak +++ b/pkg/client/test_data/test_add_diff_version/no_sum_check/kcl.mod.bak @@ -4,4 +4,4 @@ edition = "0.0.1" version = "0.0.1" [dependencies] -helloworld = "0.1.0" +helloworld = "0.1.2" diff --git a/pkg/client/test_data/test_add_diff_version/no_sum_check/kcl.mod.expect b/pkg/client/test_data/test_add_diff_version/no_sum_check/kcl.mod.expect index 6a23e3535..15ebd0f4e 100644 --- a/pkg/client/test_data/test_add_diff_version/no_sum_check/kcl.mod.expect +++ b/pkg/client/test_data/test_add_diff_version/no_sum_check/kcl.mod.expect @@ -4,4 +4,4 @@ edition = "0.0.1" version = "0.0.1" [dependencies] -helloworld = { oci = "oci://ghcr.io/kcl-lang/helloworld", tag = "0.1.1" } +helloworld = { oci = "oci://ghcr.io/kcl-lang/helloworld", tag = "0.1.2" } diff --git a/pkg/client/test_data/test_add_diff_version/with_sum_check/kcl.mod.bak b/pkg/client/test_data/test_add_diff_version/with_sum_check/kcl.mod.bak index a29e213d0..12148360c 100644 --- a/pkg/client/test_data/test_add_diff_version/with_sum_check/kcl.mod.bak +++ b/pkg/client/test_data/test_add_diff_version/with_sum_check/kcl.mod.bak @@ -4,4 +4,4 @@ edition = "0.0.1" version = "0.0.1" [dependencies] -helloworld = "0.1.0" +helloworld = "0.1.2" diff --git a/pkg/client/test_data/test_add_diff_version/with_sum_check/kcl.mod.expect b/pkg/client/test_data/test_add_diff_version/with_sum_check/kcl.mod.expect index 9ed0fba78..8a5d1e7ae 100644 --- a/pkg/client/test_data/test_add_diff_version/with_sum_check/kcl.mod.expect +++ b/pkg/client/test_data/test_add_diff_version/with_sum_check/kcl.mod.expect @@ -4,4 +4,4 @@ edition = "0.0.1" version = "0.0.1" [dependencies] -helloworld = { oci = "oci://ghcr.io/kcl-lang/helloworld", tag = "0.1.1" } +helloworld = { oci = "oci://ghcr.io/kcl-lang/helloworld", tag = "0.1.2" } diff --git a/pkg/client/test_data/test_add_diff_version/with_sum_check/kcl.mod.lock.bak b/pkg/client/test_data/test_add_diff_version/with_sum_check/kcl.mod.lock.bak index b57cac07a..7eaf9cba9 100644 --- a/pkg/client/test_data/test_add_diff_version/with_sum_check/kcl.mod.lock.bak +++ b/pkg/client/test_data/test_add_diff_version/with_sum_check/kcl.mod.lock.bak @@ -1,9 +1,9 @@ [dependencies] [dependencies.helloworld] name = "helloworld" - full_name = "helloworld_0.1.0" - version = "0.1.0" - sum = "aqrvSsd8zGHzRERbOzxYxARmK6QjvpQMYC1OqemdZvc=" + full_name = "helloworld_0.1.2" + version = "0.1.2" + sum = "PN0OMEV9M8VGFn1CtA/T3bcgZmMJmOo+RkBrLKIWYeQ=" reg = "ghcr.io" repo = "kcl-lang/helloworld" - oci_tag = "0.1.1" + oci_tag = "0.1.2" diff --git a/pkg/client/test_data/test_add_diff_version/with_sum_check/kcl.mod.lock.expect b/pkg/client/test_data/test_add_diff_version/with_sum_check/kcl.mod.lock.expect index 6270d4f4c..7eaf9cba9 100644 --- a/pkg/client/test_data/test_add_diff_version/with_sum_check/kcl.mod.lock.expect +++ b/pkg/client/test_data/test_add_diff_version/with_sum_check/kcl.mod.lock.expect @@ -1,9 +1,9 @@ [dependencies] [dependencies.helloworld] name = "helloworld" - full_name = "helloworld_0.1.1" - version = "0.1.1" - sum = "7OO4YK2QuRWPq9C7KTzcWcti5yUnueCjptT3OXiPVeQ=" + full_name = "helloworld_0.1.2" + version = "0.1.2" + sum = "PN0OMEV9M8VGFn1CtA/T3bcgZmMJmOo+RkBrLKIWYeQ=" reg = "ghcr.io" repo = "kcl-lang/helloworld" - oci_tag = "0.1.1" + oci_tag = "0.1.2" 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 3b53b8aab..2c66884aa 100644 --- a/pkg/client/test_data/test_data_add_deps/kcl.mod +++ b/pkg/client/test_data/test_data_add_deps/kcl.mod @@ -4,5 +4,5 @@ edition = "v0.8.0" version = "0.0.1" [dependencies] -oci_name = "test_tag" +oci_name = { oci = "oci://test_reg/test_repo", tag = "test_tag" } name = { git = "test_url", tag = "test_tag" } diff --git a/pkg/client/test_data/test_oci_downloader/add_dep/pkg/kcl.mod.lock b/pkg/client/test_data/test_oci_downloader/add_dep/pkg/kcl.mod.lock index fd4a314b0..129819c0e 100644 --- a/pkg/client/test_data/test_oci_downloader/add_dep/pkg/kcl.mod.lock +++ b/pkg/client/test_data/test_oci_downloader/add_dep/pkg/kcl.mod.lock @@ -3,7 +3,6 @@ name = "helloworld" full_name = "helloworld_0.0.3" version = "0.0.3" - sum = "OS3OHaC8HE5Z/4KEWJbS8xyHrYVSvXqHYxwy0BGc7nM=" reg = "ghcr.io" repo = "zong-zhe/helloworld" oci_tag = "0.0.3" diff --git a/pkg/client/test_data/test_oci_downloader/run_pkg/pkg/kcl.mod.lock b/pkg/client/test_data/test_oci_downloader/run_pkg/pkg/kcl.mod.lock index fd4a314b0..129819c0e 100644 --- a/pkg/client/test_data/test_oci_downloader/run_pkg/pkg/kcl.mod.lock +++ b/pkg/client/test_data/test_oci_downloader/run_pkg/pkg/kcl.mod.lock @@ -3,7 +3,6 @@ name = "helloworld" full_name = "helloworld_0.0.3" version = "0.0.3" - sum = "OS3OHaC8HE5Z/4KEWJbS8xyHrYVSvXqHYxwy0BGc7nM=" reg = "ghcr.io" repo = "zong-zhe/helloworld" oci_tag = "0.0.3" diff --git a/test/e2e/test_suites/kpm/exec_inside_pkg/add_with_name_1/test_suite.stderr b/pkg/client/test_data/test_parse_kcl_mod_file/kcl.mod similarity index 100% rename from test/e2e/test_suites/kpm/exec_inside_pkg/add_with_name_1/test_suite.stderr rename to pkg/client/test_data/test_parse_kcl_mod_file/kcl.mod diff --git a/pkg/client/test_data/test_update/test_update_kcl_mod/expected b/pkg/client/test_data/test_update/test_update_kcl_mod/expected index 6270d4f4c..7eaf9cba9 100644 --- a/pkg/client/test_data/test_update/test_update_kcl_mod/expected +++ b/pkg/client/test_data/test_update/test_update_kcl_mod/expected @@ -1,9 +1,9 @@ [dependencies] [dependencies.helloworld] name = "helloworld" - full_name = "helloworld_0.1.1" - version = "0.1.1" - sum = "7OO4YK2QuRWPq9C7KTzcWcti5yUnueCjptT3OXiPVeQ=" + full_name = "helloworld_0.1.2" + version = "0.1.2" + sum = "PN0OMEV9M8VGFn1CtA/T3bcgZmMJmOo+RkBrLKIWYeQ=" reg = "ghcr.io" repo = "kcl-lang/helloworld" - oci_tag = "0.1.1" + oci_tag = "0.1.2" diff --git a/pkg/client/test_data/test_update/test_update_kcl_mod/kcl.mod b/pkg/client/test_data/test_update/test_update_kcl_mod/kcl.mod index d3a99616e..249c61c4a 100644 --- a/pkg/client/test_data/test_update/test_update_kcl_mod/kcl.mod +++ b/pkg/client/test_data/test_update/test_update_kcl_mod/kcl.mod @@ -4,4 +4,4 @@ edition = "0.0.1" version = "0.0.1" [dependencies] -helloworld = "0.1.1" +helloworld = "0.1.2" diff --git a/pkg/client/test_data/test_update/test_update_kcl_mod_lock/kcl.mod.lock b/pkg/client/test_data/test_update/test_update_kcl_mod_lock/kcl.mod.lock index 6270d4f4c..7eaf9cba9 100644 --- a/pkg/client/test_data/test_update/test_update_kcl_mod_lock/kcl.mod.lock +++ b/pkg/client/test_data/test_update/test_update_kcl_mod_lock/kcl.mod.lock @@ -1,9 +1,9 @@ [dependencies] [dependencies.helloworld] name = "helloworld" - full_name = "helloworld_0.1.1" - version = "0.1.1" - sum = "7OO4YK2QuRWPq9C7KTzcWcti5yUnueCjptT3OXiPVeQ=" + full_name = "helloworld_0.1.2" + version = "0.1.2" + sum = "PN0OMEV9M8VGFn1CtA/T3bcgZmMJmOo+RkBrLKIWYeQ=" reg = "ghcr.io" repo = "kcl-lang/helloworld" - oci_tag = "0.1.1" + oci_tag = "0.1.2" diff --git a/pkg/cmd/cmd_add.go b/pkg/cmd/cmd_add.go index ec311e7d4..553400ef6 100644 --- a/pkg/cmd/cmd_add.go +++ b/pkg/cmd/cmd_add.go @@ -15,7 +15,6 @@ import ( "kcl-lang.io/kpm/pkg/env" "kcl-lang.io/kpm/pkg/errors" "kcl-lang.io/kpm/pkg/opt" - pkg "kcl-lang.io/kpm/pkg/package" "kcl-lang.io/kpm/pkg/reporter" ) @@ -76,7 +75,7 @@ func KpmAdd(c *cli.Context, kpmcli *client.KpmClient) error { return err } - kclPkg, err := pkg.LoadKclPkg(pwd) + kclPkg, err := kpmcli.LoadPkgFromPath(pwd) if err != nil { return err } diff --git a/pkg/cmd/cmd_metadata.go b/pkg/cmd/cmd_metadata.go index 2c3d5b4c1..29349a3cc 100644 --- a/pkg/cmd/cmd_metadata.go +++ b/pkg/cmd/cmd_metadata.go @@ -37,20 +37,6 @@ func NewMetadataCmd(kpmcli *client.KpmClient) *cli.Command { }, }, Action: func(c *cli.Context) error { - // acquire the lock of the package cache. - err := kpmcli.AcquirePackageCacheLock() - if err != nil { - return err - } - - defer func() { - // release the lock of the package cache after the function returns. - releaseErr := kpmcli.ReleasePackageCacheLock() - if releaseErr != nil && err == nil { - err = releaseErr - } - }() - pwd, err := os.Getwd() if err != nil { return reporter.NewErrorEvent(reporter.Bug, err, "internal bugs, please contact us to fix it") diff --git a/pkg/cmd/cmd_run.go b/pkg/cmd/cmd_run.go index 4564e5d5e..289f9e312 100644 --- a/pkg/cmd/cmd_run.go +++ b/pkg/cmd/cmd_run.go @@ -89,20 +89,6 @@ func NewRunCmd(kpmcli *client.KpmClient) *cli.Command { } func KpmRun(c *cli.Context, kpmcli *client.KpmClient) error { - // acquire the lock of the package cache. - err := kpmcli.AcquirePackageCacheLock() - if err != nil { - return err - } - - defer func() { - // release the lock of the package cache after the function returns. - releaseErr := kpmcli.ReleasePackageCacheLock() - if releaseErr != nil && err == nil { - err = releaseErr - } - }() - kclOpts := CompileOptionFromCli(c) kclOpts.SetNoSumCheck(c.Bool(FLAG_NO_SUM_CHECK)) runEntry, errEvent := runner.FindRunEntryFrom(c.Args().Slice()) diff --git a/pkg/cmd/cmd_update.go b/pkg/cmd/cmd_update.go index dca866dbb..e243373be 100644 --- a/pkg/cmd/cmd_update.go +++ b/pkg/cmd/cmd_update.go @@ -1,5 +1,5 @@ // Copyright 2023 The KCL Authors. All rights reserved. -// Deprecated: The entire contents of this file will be deprecated. +// Deprecated: The entire contents of this file will be deprecated. // Please use the kcl cli - https://github.com/kcl-lang/cli. package cmd @@ -33,21 +33,6 @@ func NewUpdateCmd(kpmcli *client.KpmClient) *cli.Command { func KpmUpdate(c *cli.Context, kpmcli *client.KpmClient) error { kpmcli.SetNoSumCheck(c.Bool(FLAG_NO_SUM_CHECK)) - - // acquire the lock of the package cache. - err := kpmcli.AcquirePackageCacheLock() - if err != nil { - return err - } - - defer func() { - // release the lock of the package cache after the function returns. - releaseErr := kpmcli.ReleasePackageCacheLock() - if releaseErr != nil && err == nil { - err = releaseErr - } - }() - input_paths := c.Args().Slice() pkg_paths := []string{} diff --git a/pkg/downloader/downloader.go b/pkg/downloader/downloader.go index 597716f04..24a171255 100644 --- a/pkg/downloader/downloader.go +++ b/pkg/downloader/downloader.go @@ -129,31 +129,15 @@ func (d *OciDownloader) Download(opts DownloadOptions) error { ociCli.PullOciOptions.Platform = d.Platform - // Select the latest tag, if the tag, the user inputed, is empty. - tagSelected := ociSource.Tag - if len(tagSelected) == 0 { - tagSelected, err = ociCli.TheLatestTag() - if err != nil { - return err - } - - reporter.ReportMsgTo( - fmt.Sprintf("the lastest version '%s' will be added", tagSelected), - opts.LogWriter, - ) - - ociSource.Tag = tagSelected - } - reporter.ReportMsgTo( fmt.Sprintf( "downloading '%s:%s' from '%s/%s:%s'", - ociSource.Repo, tagSelected, ociSource.Reg, ociSource.Repo, tagSelected, + ociSource.Repo, ociSource.Tag, ociSource.Reg, ociSource.Repo, ociSource.Tag, ), opts.LogWriter, ) - err = ociCli.Pull(localPath, tagSelected) + err = ociCli.Pull(localPath, ociSource.Tag) if err != nil { return err } diff --git a/pkg/oci/oci.go b/pkg/oci/oci.go index 6a9c73faa..2b184ebed 100644 --- a/pkg/oci/oci.go +++ b/pkg/oci/oci.go @@ -303,7 +303,7 @@ func (ociClient *OciClient) PushWithOciManifest(localPath, tag string, opts *opt return nil } -// FetchManifestByRef will fetch the manifest and return it into json string. +// FetchManifestIntoJsonStr will fetch the manifest and return it into json string. func (ociClient *OciClient) FetchManifestIntoJsonStr(opts opt.OciFetchOptions) (string, error) { fetchOpts := opts.FetchBytesOptions _, manifestContent, err := oras.FetchBytes(*ociClient.ctx, ociClient.repo, opts.Tag, fetchOpts) diff --git a/pkg/oci/oci_test.go b/pkg/oci/oci_test.go index b1386b5cd..4c871a186 100644 --- a/pkg/oci/oci_test.go +++ b/pkg/oci/oci_test.go @@ -51,7 +51,7 @@ func TestPull(t *testing.T) { testCases := []TestCase{ {"ghcr.io", "kusionstack/opsrule", "0.0.9"}, - {"ghcr.io", "kcl-lang/helloworld", "0.1.1"}, + {"ghcr.io", "kcl-lang/helloworld", "0.1.2"}, } defer func() { diff --git a/pkg/package/modfile.go b/pkg/package/modfile.go index 95a5832de..bbb09cf8a 100644 --- a/pkg/package/modfile.go +++ b/pkg/package/modfile.go @@ -7,6 +7,7 @@ import ( "net/url" "os" "path/filepath" + "reflect" "strings" "github.com/BurntSushi/toml" @@ -165,6 +166,7 @@ type Dependency struct { // In vendor mode is "current_kcl_package/vendor" // In non-vendor mode is "$KCL_PKG_PATH" LocalFullPath string `json:"manifest_path" toml:"-"` + HomePath string `json:"-" toml:"-"` Source `json:"-"` } @@ -174,11 +176,36 @@ func (d *Dependency) FromKclPkg(pkg *KclPkg) { d.LocalFullPath = pkg.HomePath } +// The name of the local storage path is generated depending on the source of the package +func (d *Dependency) GetPkgPathName() string { + if d.Source.Oci != nil { + return fmt.Sprintf(PKG_NAME_PATTERN, d.Name, d.Source.Oci.Tag) + } else if d.Source.Git != nil { + if len(d.Source.Git.Tag) != 0 { + return fmt.Sprintf(PKG_NAME_PATTERN, d.Name, d.Source.Git.Tag) + } else if len(d.Source.Git.Commit) != 0 { + return fmt.Sprintf(PKG_NAME_PATTERN, d.Name, d.Source.Git.Commit) + } else { + return fmt.Sprintf(PKG_NAME_PATTERN, d.Name, d.Source.Git.Branch) + } + } else { + return fmt.Sprintf(PKG_NAME_PATTERN, d.Name, d.Version) + } +} + // SetName will set the name and alias name of a dependency. func (d *Dependency) GetAliasName() string { return strings.ReplaceAll(d.Name, "-", "_") } +func (d Dependency) Equals(other Dependency) bool { + if d.Name != other.Name { + return false + } + + return !reflect.DeepEqual(d, other) +} + // WithTheSameVersion will check whether two dependencies have the same version. func (d Dependency) WithTheSameVersion(other Dependency) bool { @@ -200,12 +227,12 @@ func (d Dependency) WithTheSameVersion(other Dependency) bool { } // GetLocalFullPath will get the local path of a dependency. -func (dep *Dependency) GetLocalFullPath(rootpath string) string { +func (dep *Dependency) GetLocalFullPath() string { if !filepath.IsAbs(dep.LocalFullPath) && dep.IsFromLocal() { if filepath.IsAbs(dep.Source.Local.Path) { return dep.Source.Local.Path } - return filepath.Join(rootpath, dep.Source.Local.Path) + return filepath.Join(dep.HomePath, dep.Source.Local.Path) } return dep.LocalFullPath } diff --git a/pkg/package/modfile_test.go b/pkg/package/modfile_test.go index f3f05e2ed..299e15695 100644 --- a/pkg/package/modfile_test.go +++ b/pkg/package/modfile_test.go @@ -182,8 +182,8 @@ func TestLoadModFile(t *testing.T) { assert.Equal(t, err, nil) assert.Equal(t, modFile.Dependencies.Deps["helloworld"].Name, "helloworld") - assert.Equal(t, modFile.Dependencies.Deps["helloworld"].Version, "0.1.1") - assert.Equal(t, modFile.Dependencies.Deps["helloworld"].Source.Oci.Tag, "0.1.1") + assert.Equal(t, modFile.Dependencies.Deps["helloworld"].Version, "0.1.2") + assert.Equal(t, modFile.Dependencies.Deps["helloworld"].Source.Oci.Tag, "0.1.2") assert.Equal(t, err, nil) } diff --git a/pkg/package/test_data/load_mod_file/kcl.mod b/pkg/package/test_data/load_mod_file/kcl.mod index 1c893dfca..318ee9d82 100644 --- a/pkg/package/test_data/load_mod_file/kcl.mod +++ b/pkg/package/test_data/load_mod_file/kcl.mod @@ -6,4 +6,4 @@ version = "0.0.1" [dependencies] name = { git = "test_url", tag = "test_tag" } oci_name = "oci_tag" -helloworld = { oci = "oci://ghcr.io/kcl-lang/helloworld", tag = "0.1.1" } \ No newline at end of file +helloworld = { oci = "oci://ghcr.io/kcl-lang/helloworld", tag = "0.1.2" } \ No newline at end of file diff --git a/pkg/reporter/reporter.go b/pkg/reporter/reporter.go index 29e0ccf99..0f7ea9e71 100644 --- a/pkg/reporter/reporter.go +++ b/pkg/reporter/reporter.go @@ -109,6 +109,7 @@ const ( KclModNotFound CompileFailed FailedParseVersion + FailedFetchOciManifest ) // KpmEvent is the event used to show kpm logs to users. diff --git a/test/e2e/test_suites/kpm/exec_inside_pkg/add_with_name_1/test_suite.stdout b/test/e2e/test_suites/kpm/exec_inside_pkg/add_with_name_1/test_suite.stdout deleted file mode 100644 index 664b1334f..000000000 --- a/test/e2e/test_suites/kpm/exec_inside_pkg/add_with_name_1/test_suite.stdout +++ /dev/null @@ -1,3 +0,0 @@ -adding dependency 'kcl1' -the lastest version '0.0.1' will be added -downloading 'test/kcl1:0.0.1' from 'localhost:5001/test/kcl1:0.0.1' \ No newline at end of file diff --git a/test/e2e/test_suites/kpm/exec_inside_pkg/add_with_name_2/test_suite.stdout b/test/e2e/test_suites/kpm/exec_inside_pkg/add_with_name_2/test_suite.stdout deleted file mode 100644 index ee2e9c3e5..000000000 --- a/test/e2e/test_suites/kpm/exec_inside_pkg/add_with_name_2/test_suite.stdout +++ /dev/null @@ -1,5 +0,0 @@ -adding dependency 'kcl2' -the lastest version '0.0.1' will be added -downloading 'test/kcl2:0.0.1' from 'localhost:5001/test/kcl2:0.0.1' -downloading 'test/k8s:1.27' from 'localhost:5001/test/k8s:1.27' -downloading 'test/kcl1:0.0.1' from 'localhost:5001/test/kcl1:0.0.1' \ No newline at end of file diff --git a/test/e2e/test_suites/kpm/exec_inside_pkg/add_with_name_3/test_suite.stdout b/test/e2e/test_suites/kpm/exec_inside_pkg/add_with_name_3/test_suite.stdout deleted file mode 100644 index 38f8193c4..000000000 --- a/test/e2e/test_suites/kpm/exec_inside_pkg/add_with_name_3/test_suite.stdout +++ /dev/null @@ -1,5 +0,0 @@ -adding dependency 'kcl2' -the lastest version '0.0.1' will be added -downloading 'test/kcl2:0.0.1' from 'localhost:5001/test/kcl2:0.0.1' -downloading 'test/k8s:1.27' from 'localhost:5001/test/k8s:1.27' -downloading 'test/kcl1:0.0.1' from 'localhost:5001/test/kcl1:0.0.1' diff --git a/test/e2e/test_suites/kpm/exec_inside_pkg/add_with_name_tag/test_suite.stdout b/test/e2e/test_suites/kpm/exec_inside_pkg/add_with_name_tag/test_suite.stdout index 962a62f8c..e9bb3c4e4 100644 --- a/test/e2e/test_suites/kpm/exec_inside_pkg/add_with_name_tag/test_suite.stdout +++ b/test/e2e/test_suites/kpm/exec_inside_pkg/add_with_name_tag/test_suite.stdout @@ -1,3 +1 @@ -adding dependency 'k8s' -downloading 'test/k8s:1.14' from 'localhost:5001/test/k8s:1.14' add dependency 'k8s:1.14' successfully diff --git a/test/e2e/test_suites/kpm/exec_inside_pkg/add_with_path_1/test_suite.stdout b/test/e2e/test_suites/kpm/exec_inside_pkg/add_with_path_1/test_suite.stdout index f07f329e7..a7aab52f6 100644 --- a/test/e2e/test_suites/kpm/exec_inside_pkg/add_with_path_1/test_suite.stdout +++ b/test/e2e/test_suites/kpm/exec_inside_pkg/add_with_path_1/test_suite.stdout @@ -1,3 +1 @@ -adding dependency 'a_kcl_pkg_dep_pkg_name' -downloading 'test/k8s:1.27' from 'localhost:5001/test/k8s:1.27' add dependency 'a_kcl_pkg_dep_pkg_name:0.0.1' successfully diff --git a/test/e2e/test_suites/kpm/exec_inside_pkg/add_with_path_2/test_suite.stdout b/test/e2e/test_suites/kpm/exec_inside_pkg/add_with_path_2/test_suite.stdout deleted file mode 100644 index 079b36480..000000000 --- a/test/e2e/test_suites/kpm/exec_inside_pkg/add_with_path_2/test_suite.stdout +++ /dev/null @@ -1,3 +0,0 @@ -adding dependency 'a_kcl_pkg_dep_pkg_name' -downloading 'test/k8s:1.27' from 'localhost:5001/test/k8s:1.27' -downloading 'test/kcl1:0.0.1' from 'localhost:5001/test/kcl1:0.0.1' \ No newline at end of file diff --git a/test/e2e/test_suites/kpm/exec_inside_pkg/add_with_relative_path/test_suite.stdout b/test/e2e/test_suites/kpm/exec_inside_pkg/add_with_relative_path/test_suite.stdout index 0b7cd806e..15e67d336 100644 --- a/test/e2e/test_suites/kpm/exec_inside_pkg/add_with_relative_path/test_suite.stdout +++ b/test/e2e/test_suites/kpm/exec_inside_pkg/add_with_relative_path/test_suite.stdout @@ -1,3 +1 @@ -adding dependency 'a_kcl_pkg_dep_pkg_name' -downloading 'test/k8s:1.27' from 'localhost:5001/test/k8s:1.27' add dependency 'a_kcl_pkg_dep_pkg_name:0.0.1' successfully \ No newline at end of file diff --git a/test/e2e/test_suites/kpm/exec_inside_pkg/add_with_name_1/test_suite.env b/test/e2e/test_suites/kpm/kpm_add/add_with_name_1/test_suite.env similarity index 100% rename from test/e2e/test_suites/kpm/exec_inside_pkg/add_with_name_1/test_suite.env rename to test/e2e/test_suites/kpm/kpm_add/add_with_name_1/test_suite.env diff --git a/test/e2e/test_suites/kpm/exec_inside_pkg/add_with_name_1/test_suite.input b/test/e2e/test_suites/kpm/kpm_add/add_with_name_1/test_suite.input similarity index 100% rename from test/e2e/test_suites/kpm/exec_inside_pkg/add_with_name_1/test_suite.input rename to test/e2e/test_suites/kpm/kpm_add/add_with_name_1/test_suite.input diff --git a/test/e2e/test_suites/kpm/exec_inside_pkg/add_with_name_2/test_suite.stderr b/test/e2e/test_suites/kpm/kpm_add/add_with_name_1/test_suite.stderr similarity index 100% rename from test/e2e/test_suites/kpm/exec_inside_pkg/add_with_name_2/test_suite.stderr rename to test/e2e/test_suites/kpm/kpm_add/add_with_name_1/test_suite.stderr diff --git a/test/e2e/test_suites/kpm/kpm_add/add_with_name_1/test_suite.stdout b/test/e2e/test_suites/kpm/kpm_add/add_with_name_1/test_suite.stdout new file mode 100644 index 000000000..eb14c8481 --- /dev/null +++ b/test/e2e/test_suites/kpm/kpm_add/add_with_name_1/test_suite.stdout @@ -0,0 +1 @@ +add dependency 'kcl1' successfully \ No newline at end of file diff --git a/test/e2e/test_suites/kpm/exec_inside_pkg/add_with_name_2/test_suite.env b/test/e2e/test_suites/kpm/kpm_add/add_with_name_2/test_suite.env similarity index 100% rename from test/e2e/test_suites/kpm/exec_inside_pkg/add_with_name_2/test_suite.env rename to test/e2e/test_suites/kpm/kpm_add/add_with_name_2/test_suite.env diff --git a/test/e2e/test_suites/kpm/exec_inside_pkg/add_with_name_2/test_suite.input b/test/e2e/test_suites/kpm/kpm_add/add_with_name_2/test_suite.input similarity index 100% rename from test/e2e/test_suites/kpm/exec_inside_pkg/add_with_name_2/test_suite.input rename to test/e2e/test_suites/kpm/kpm_add/add_with_name_2/test_suite.input diff --git a/test/e2e/test_suites/kpm/exec_inside_pkg/add_with_name_3/test_suite.stderr b/test/e2e/test_suites/kpm/kpm_add/add_with_name_2/test_suite.stderr similarity index 100% rename from test/e2e/test_suites/kpm/exec_inside_pkg/add_with_name_3/test_suite.stderr rename to test/e2e/test_suites/kpm/kpm_add/add_with_name_2/test_suite.stderr diff --git a/test/e2e/test_suites/kpm/kpm_add/add_with_name_2/test_suite.stdout b/test/e2e/test_suites/kpm/kpm_add/add_with_name_2/test_suite.stdout new file mode 100644 index 000000000..94ea214e0 --- /dev/null +++ b/test/e2e/test_suites/kpm/kpm_add/add_with_name_2/test_suite.stdout @@ -0,0 +1 @@ +add dependency 'kcl2' successfully \ No newline at end of file diff --git a/test/e2e/test_suites/kpm/exec_inside_pkg/add_with_name_3/test_suite.env b/test/e2e/test_suites/kpm/kpm_add/add_with_name_3/test_suite.env similarity index 100% rename from test/e2e/test_suites/kpm/exec_inside_pkg/add_with_name_3/test_suite.env rename to test/e2e/test_suites/kpm/kpm_add/add_with_name_3/test_suite.env diff --git a/test/e2e/test_suites/kpm/exec_inside_pkg/add_with_name_3/test_suite.input b/test/e2e/test_suites/kpm/kpm_add/add_with_name_3/test_suite.input similarity index 100% rename from test/e2e/test_suites/kpm/exec_inside_pkg/add_with_name_3/test_suite.input rename to test/e2e/test_suites/kpm/kpm_add/add_with_name_3/test_suite.input diff --git a/test/e2e/test_suites/kpm/exec_inside_pkg/add_with_path_2/test_suite.stderr b/test/e2e/test_suites/kpm/kpm_add/add_with_name_3/test_suite.stderr similarity index 100% rename from test/e2e/test_suites/kpm/exec_inside_pkg/add_with_path_2/test_suite.stderr rename to test/e2e/test_suites/kpm/kpm_add/add_with_name_3/test_suite.stderr diff --git a/test/e2e/test_suites/kpm/kpm_add/add_with_name_3/test_suite.stdout b/test/e2e/test_suites/kpm/kpm_add/add_with_name_3/test_suite.stdout new file mode 100644 index 000000000..94ea214e0 --- /dev/null +++ b/test/e2e/test_suites/kpm/kpm_add/add_with_name_3/test_suite.stdout @@ -0,0 +1 @@ +add dependency 'kcl2' successfully \ No newline at end of file diff --git a/test/e2e/test_suites/kpm/exec_inside_pkg/add_with_path_2/test_suite.env b/test/e2e/test_suites/kpm/kpm_add/add_with_path_2/test_suite.env similarity index 100% rename from test/e2e/test_suites/kpm/exec_inside_pkg/add_with_path_2/test_suite.env rename to test/e2e/test_suites/kpm/kpm_add/add_with_path_2/test_suite.env diff --git a/test/e2e/test_suites/kpm/exec_inside_pkg/add_with_path_2/test_suite.input b/test/e2e/test_suites/kpm/kpm_add/add_with_path_2/test_suite.input similarity index 100% rename from test/e2e/test_suites/kpm/exec_inside_pkg/add_with_path_2/test_suite.input rename to test/e2e/test_suites/kpm/kpm_add/add_with_path_2/test_suite.input diff --git a/test/e2e/test_suites/kpm/kpm_add/add_with_path_2/test_suite.stderr b/test/e2e/test_suites/kpm/kpm_add/add_with_path_2/test_suite.stderr new file mode 100644 index 000000000..e69de29bb diff --git a/test/e2e/test_suites/kpm/kpm_add/add_with_path_2/test_suite.stdout b/test/e2e/test_suites/kpm/kpm_add/add_with_path_2/test_suite.stdout new file mode 100644 index 000000000..15e67d336 --- /dev/null +++ b/test/e2e/test_suites/kpm/kpm_add/add_with_path_2/test_suite.stdout @@ -0,0 +1 @@ +add dependency 'a_kcl_pkg_dep_pkg_name:0.0.1' successfully \ No newline at end of file diff --git a/test/e2e/test_suites/kpm/kpm_add/test_add_with_name/test_suite.stdout b/test/e2e/test_suites/kpm/kpm_add/test_add_with_name/test_suite.stdout index 26b3802b3..17f1ed2fc 100644 --- a/test/e2e/test_suites/kpm/kpm_add/test_add_with_name/test_suite.stdout +++ b/test/e2e/test_suites/kpm/kpm_add/test_add_with_name/test_suite.stdout @@ -1,4 +1 @@ -adding dependency 'k8s' -the lastest version '1.27' will be added -downloading 'test/k8s:1.27' from 'localhost:5001/test/k8s:1.27' add dependency 'k8s' successfully diff --git a/test/e2e/test_suites/kpm/kpm_add/test_kpm_add_git_commit/test_suite.stdout b/test/e2e/test_suites/kpm/kpm_add/test_kpm_add_git_commit/test_suite.stdout index a46bd1a19..41ff69ed0 100644 --- a/test/e2e/test_suites/kpm/kpm_add/test_kpm_add_git_commit/test_suite.stdout +++ b/test/e2e/test_suites/kpm/kpm_add/test_kpm_add_git_commit/test_suite.stdout @@ -1,2 +1 @@ -adding dependency 'catalog' -cloning 'https://github.com/KusionStack/catalog.git' with commit '3891e96' \ No newline at end of file +add dependency 'catalog:3891e96' successfully \ No newline at end of file diff --git a/test/e2e/test_suites/kpm/kpm_add/test_kpm_add_git_commit_0/test_suite.stdout b/test/e2e/test_suites/kpm/kpm_add/test_kpm_add_git_commit_0/test_suite.stdout index 72e779076..107be8812 100644 --- a/test/e2e/test_suites/kpm/kpm_add/test_kpm_add_git_commit_0/test_suite.stdout +++ b/test/e2e/test_suites/kpm/kpm_add/test_kpm_add_git_commit_0/test_suite.stdout @@ -1,3 +1 @@ -adding dependency 'flask-demo-kcl-manifests' -cloning 'https://github.com/kcl-lang/flask-demo-kcl-manifests.git' with commit '0b3f5ab' add dependency 'flask-demo-kcl-manifests:0b3f5ab' successfully \ No newline at end of file diff --git a/test/e2e/test_suites/kpm/kpm_add/test_kpm_add_git_commit_1/test_suite.stdout b/test/e2e/test_suites/kpm/kpm_add/test_kpm_add_git_commit_1/test_suite.stdout index 8e7f0a39d..57b341753 100644 --- a/test/e2e/test_suites/kpm/kpm_add/test_kpm_add_git_commit_1/test_suite.stdout +++ b/test/e2e/test_suites/kpm/kpm_add/test_kpm_add_git_commit_1/test_suite.stdout @@ -1,3 +1 @@ -adding dependency 'flask-demo-kcl-manifests' -cloning 'https://github.com/kcl-lang/flask-demo-kcl-manifests.git' with commit '8308200' add dependency 'flask-demo-kcl-manifests:8308200' successfully \ No newline at end of file diff --git a/test/e2e/test_suites/kpm/kpm_metadata/test_kpm_metadata_with_commit_dep/test_suite.input b/test/e2e/test_suites/kpm/kpm_metadata/test_kpm_metadata_with_commit_dep/test_suite.input index 032346d80..da6fba6b4 100644 --- a/test/e2e/test_suites/kpm/kpm_metadata/test_kpm_metadata_with_commit_dep/test_suite.input +++ b/test/e2e/test_suites/kpm/kpm_metadata/test_kpm_metadata_with_commit_dep/test_suite.input @@ -1 +1 @@ -kpm metadata \ No newline at end of file +kpm metadata --update \ No newline at end of file diff --git a/test/e2e/test_suites/kpm/kpm_run/test_kpm_run_multi_local_path_2/test_suite.stdout b/test/e2e/test_suites/kpm/kpm_run/test_kpm_run_multi_local_path_2/test_suite.stdout index 17e6ee315..f4059255d 100644 --- a/test/e2e/test_suites/kpm/kpm_run/test_kpm_run_multi_local_path_2/test_suite.stdout +++ b/test/e2e/test_suites/kpm/kpm_run/test_kpm_run_multi_local_path_2/test_suite.stdout @@ -1,2 +1 @@ -adding 'pkg2' The_first_kcl_program: Hello World! \ No newline at end of file diff --git a/test/e2e/test_suites/kpm/kpm_run/test_kpm_run_multi_local_path_3/test_suite.stdout b/test/e2e/test_suites/kpm/kpm_run/test_kpm_run_multi_local_path_3/test_suite.stdout index 17e6ee315..f4059255d 100644 --- a/test/e2e/test_suites/kpm/kpm_run/test_kpm_run_multi_local_path_3/test_suite.stdout +++ b/test/e2e/test_suites/kpm/kpm_run/test_kpm_run_multi_local_path_3/test_suite.stdout @@ -1,2 +1 @@ -adding 'pkg2' The_first_kcl_program: Hello World! \ No newline at end of file diff --git a/test/e2e/test_suites/kpm/kpm_run/test_kpm_run_multi_local_path_5/test_suite.stdout b/test/e2e/test_suites/kpm/kpm_run/test_kpm_run_multi_local_path_5/test_suite.stdout index 17e6ee315..f4059255d 100644 --- a/test/e2e/test_suites/kpm/kpm_run/test_kpm_run_multi_local_path_5/test_suite.stdout +++ b/test/e2e/test_suites/kpm/kpm_run/test_kpm_run_multi_local_path_5/test_suite.stdout @@ -1,2 +1 @@ -adding 'pkg2' The_first_kcl_program: Hello World! \ No newline at end of file diff --git a/test/e2e/test_suites/kpm/kpm_run/test_kpm_run_with_only_kcl_mod/test_suite.stdout b/test/e2e/test_suites/kpm/kpm_run/test_kpm_run_with_only_kcl_mod/test_suite.stdout index 04a8d42f5..adf15e560 100644 --- a/test/e2e/test_suites/kpm/kpm_run/test_kpm_run_with_only_kcl_mod/test_suite.stdout +++ b/test/e2e/test_suites/kpm/kpm_run/test_kpm_run_with_only_kcl_mod/test_suite.stdout @@ -1,3 +1 @@ -adding 'helloworld' with version '0.1.1' -downloading 'test/helloworld:0.1.1' from 'localhost:5001/test/helloworld:0.1.1' a: Hello World! \ No newline at end of file diff --git a/test/e2e/test_suites/kpm/workflows/add_multi_times/2.first_add_konfig_dep/test_suite.stdout b/test/e2e/test_suites/kpm/workflows/add_multi_times/2.first_add_konfig_dep/test_suite.stdout index 3bc1f11c2..f41d33440 100644 --- a/test/e2e/test_suites/kpm/workflows/add_multi_times/2.first_add_konfig_dep/test_suite.stdout +++ b/test/e2e/test_suites/kpm/workflows/add_multi_times/2.first_add_konfig_dep/test_suite.stdout @@ -1,3 +1 @@ -adding dependency 'konfig' -cloning 'https://github.com/awesome-kusion/konfig.git' with tag 'v0.0.1' add dependency 'konfig:v0.0.1' successfully \ No newline at end of file diff --git a/test/e2e/test_suites/kpm/workflows/add_multi_times/3.second_add_konfig_dep/test_suite.stdout b/test/e2e/test_suites/kpm/workflows/add_multi_times/3.second_add_konfig_dep/test_suite.stdout index 95e5b69e1..f41d33440 100644 --- a/test/e2e/test_suites/kpm/workflows/add_multi_times/3.second_add_konfig_dep/test_suite.stdout +++ b/test/e2e/test_suites/kpm/workflows/add_multi_times/3.second_add_konfig_dep/test_suite.stdout @@ -1,2 +1 @@ -adding dependency 'konfig' add dependency 'konfig:v0.0.1' successfully \ No newline at end of file diff --git a/test/e2e/test_suites/kpm/workflows/add_multi_times/4.third_add_konfig_dep/test_suite.stdout b/test/e2e/test_suites/kpm/workflows/add_multi_times/4.third_add_konfig_dep/test_suite.stdout index 95e5b69e1..f41d33440 100644 --- a/test/e2e/test_suites/kpm/workflows/add_multi_times/4.third_add_konfig_dep/test_suite.stdout +++ b/test/e2e/test_suites/kpm/workflows/add_multi_times/4.third_add_konfig_dep/test_suite.stdout @@ -1,2 +1 @@ -adding dependency 'konfig' add dependency 'konfig:v0.0.1' successfully \ No newline at end of file diff --git a/test/e2e/test_suites/kpm/workflows/init_add_and_run/2.kpm_add/test_suite.stdout b/test/e2e/test_suites/kpm/workflows/init_add_and_run/2.kpm_add/test_suite.stdout index 8e7f0a39d..57b341753 100644 --- a/test/e2e/test_suites/kpm/workflows/init_add_and_run/2.kpm_add/test_suite.stdout +++ b/test/e2e/test_suites/kpm/workflows/init_add_and_run/2.kpm_add/test_suite.stdout @@ -1,3 +1 @@ -adding dependency 'flask-demo-kcl-manifests' -cloning 'https://github.com/kcl-lang/flask-demo-kcl-manifests.git' with commit '8308200' add dependency 'flask-demo-kcl-manifests:8308200' successfully \ No newline at end of file diff --git a/test/e2e/test_suites/test_data/add_with_name_1/kcl.mod b/test/e2e/test_suites/test_data/add_with_name_1/kcl.mod new file mode 100644 index 000000000..bfa6c20ad --- /dev/null +++ b/test/e2e/test_suites/test_data/add_with_name_1/kcl.mod @@ -0,0 +1,5 @@ +[package] +name = "add_with_name_1" +edition = "v0.8.0" +version = "0.0.1" + diff --git a/test/e2e/test_suites/test_data/add_with_name_1/kcl.mod.lock b/test/e2e/test_suites/test_data/add_with_name_1/kcl.mod.lock new file mode 100644 index 000000000..e69de29bb diff --git a/test/e2e/test_suites/test_data/add_with_name_1/main.k b/test/e2e/test_suites/test_data/add_with_name_1/main.k new file mode 100644 index 000000000..fa7048e63 --- /dev/null +++ b/test/e2e/test_suites/test_data/add_with_name_1/main.k @@ -0,0 +1 @@ +The_first_kcl_program = 'Hello World!' \ No newline at end of file diff --git a/test/e2e/test_suites/test_data/add_with_name_2/kcl.mod b/test/e2e/test_suites/test_data/add_with_name_2/kcl.mod new file mode 100644 index 000000000..91a22fb1d --- /dev/null +++ b/test/e2e/test_suites/test_data/add_with_name_2/kcl.mod @@ -0,0 +1,5 @@ +[package] +name = "add_with_name_2" +edition = "v0.8.0" +version = "0.0.1" + diff --git a/test/e2e/test_suites/test_data/add_with_name_2/kcl.mod.lock b/test/e2e/test_suites/test_data/add_with_name_2/kcl.mod.lock new file mode 100644 index 000000000..e69de29bb diff --git a/test/e2e/test_suites/test_data/add_with_name_2/main.k b/test/e2e/test_suites/test_data/add_with_name_2/main.k new file mode 100644 index 000000000..fa7048e63 --- /dev/null +++ b/test/e2e/test_suites/test_data/add_with_name_2/main.k @@ -0,0 +1 @@ +The_first_kcl_program = 'Hello World!' \ No newline at end of file diff --git a/test/e2e/test_suites/test_data/add_with_name_3/kcl.mod b/test/e2e/test_suites/test_data/add_with_name_3/kcl.mod new file mode 100644 index 000000000..0820eac66 --- /dev/null +++ b/test/e2e/test_suites/test_data/add_with_name_3/kcl.mod @@ -0,0 +1,5 @@ +[package] +name = "add_with_name_3" +edition = "v0.8.0" +version = "0.0.1" + diff --git a/test/e2e/test_suites/test_data/add_with_name_3/kcl.mod.lock b/test/e2e/test_suites/test_data/add_with_name_3/kcl.mod.lock new file mode 100644 index 000000000..e69de29bb diff --git a/test/e2e/test_suites/test_data/add_with_name_3/main.k b/test/e2e/test_suites/test_data/add_with_name_3/main.k new file mode 100644 index 000000000..fa7048e63 --- /dev/null +++ b/test/e2e/test_suites/test_data/add_with_name_3/main.k @@ -0,0 +1 @@ +The_first_kcl_program = 'Hello World!' \ No newline at end of file diff --git a/test/e2e/test_suites/test_data/add_with_path_2/a_kcl_pkg_dep_one_pkg_2/kcl.mod b/test/e2e/test_suites/test_data/add_with_path_2/a_kcl_pkg_dep_one_pkg_2/kcl.mod new file mode 100644 index 000000000..2ac8c7078 --- /dev/null +++ b/test/e2e/test_suites/test_data/add_with_path_2/a_kcl_pkg_dep_one_pkg_2/kcl.mod @@ -0,0 +1,8 @@ +[package] +name = "a_kcl_pkg_dep_pkg_name" +edition = "0.0.1" +version = "0.0.1" + +[dependencies] +k8s = "1.27" +kcl1 = "0.0.1" diff --git a/test/e2e/test_suites/test_data/add_with_path_2/a_kcl_pkg_dep_one_pkg_2/kcl.mod.lock b/test/e2e/test_suites/test_data/add_with_path_2/a_kcl_pkg_dep_one_pkg_2/kcl.mod.lock new file mode 100644 index 000000000..cb5098f31 --- /dev/null +++ b/test/e2e/test_suites/test_data/add_with_path_2/a_kcl_pkg_dep_one_pkg_2/kcl.mod.lock @@ -0,0 +1,17 @@ +[dependencies] + [dependencies.k8s] + name = "k8s" + full_name = "k8s_1.27" + version = "1.27" + sum = "xnYM1FWHAy3m+KcQMQb2rjZouTxumqYt6FGZpu2T4yM=" + reg = "localhost:5001" + repo = "test/k8s" + oci_tag = "1.27" + [dependencies.kcl1] + name = "kcl1" + full_name = "kcl1_0.0.1" + version = "0.0.1" + sum = "zLzaol7KpC57mKLQ/56ciIHO397Rk/Dum+meo+tUsw8=" + reg = "localhost:5001" + repo = "test/kcl1" + oci_tag = "0.0.1" diff --git a/test/e2e/test_suites/test_data/add_with_path_2/a_kcl_pkg_dep_one_pkg_2/main.k b/test/e2e/test_suites/test_data/add_with_path_2/a_kcl_pkg_dep_one_pkg_2/main.k new file mode 100644 index 000000000..fa7048e63 --- /dev/null +++ b/test/e2e/test_suites/test_data/add_with_path_2/a_kcl_pkg_dep_one_pkg_2/main.k @@ -0,0 +1 @@ +The_first_kcl_program = 'Hello World!' \ No newline at end of file diff --git a/test/e2e/test_suites/test_data/add_with_path_2/kcl.mod b/test/e2e/test_suites/test_data/add_with_path_2/kcl.mod new file mode 100644 index 000000000..70b785cf8 --- /dev/null +++ b/test/e2e/test_suites/test_data/add_with_path_2/kcl.mod @@ -0,0 +1,5 @@ +[package] +name = "add_with_path_2" +edition = "v0.8.0" +version = "0.0.1" + diff --git a/test/e2e/test_suites/test_data/add_with_path_2/kcl.mod.lock b/test/e2e/test_suites/test_data/add_with_path_2/kcl.mod.lock new file mode 100644 index 000000000..e69de29bb diff --git a/test/e2e/test_suites/test_data/add_with_path_2/main.k b/test/e2e/test_suites/test_data/add_with_path_2/main.k new file mode 100644 index 000000000..fa7048e63 --- /dev/null +++ b/test/e2e/test_suites/test_data/add_with_path_2/main.k @@ -0,0 +1 @@ +The_first_kcl_program = 'Hello World!' \ No newline at end of file diff --git a/test/e2e/test_suites/test_data/test_kcl/kcl.mod.lock b/test/e2e/test_suites/test_data/test_kcl/kcl.mod.lock index 740082e48..9e9d18098 100644 --- a/test/e2e/test_suites/test_data/test_kcl/kcl.mod.lock +++ b/test/e2e/test_suites/test_data/test_kcl/kcl.mod.lock @@ -1,8 +1,7 @@ [dependencies] [dependencies.kcl4] name = "kcl4" - full_name = "kcl4_v0.1.0" - version = "v0.1.0" - sum = "ecdMCD96+8by5Ml0l/V0b7W24CS250rvD5VdlqqR6OU=" + full_name = "kcl4_0.0.1" + version = "0.0.1" url = "https://github.com/zong-zhe/kcl4.git" - git_tag = "v0.1.0" \ No newline at end of file + git_tag = "v0.1.0" diff --git a/test/e2e/test_suites/test_data/test_kpm_run_multi_local_path_0/pkg1/kcl.mod.lock b/test/e2e/test_suites/test_data/test_kpm_run_multi_local_path_0/pkg1/kcl.mod.lock index b047f2b6b..58919f2df 100644 --- a/test/e2e/test_suites/test_data/test_kpm_run_multi_local_path_0/pkg1/kcl.mod.lock +++ b/test/e2e/test_suites/test_data/test_kpm_run_multi_local_path_0/pkg1/kcl.mod.lock @@ -3,4 +3,8 @@ name = "pkg2" full_name = "pkg2_0.0.1" version = "0.0.1" - sum = "JbfIAXPJb3L6xX7hi/A5mrXzjpB8eFoKfEmJMdHsewY=" + [dependencies.pkg3] + name = "pkg3" + full_name = "pkg3_0.0.1" + version = "0.0.1" + sum = "T29gAv6K/tLithhP5jVHyurV5zRFui+i1ulyMt/ncnM=" diff --git a/test/e2e/test_suites/test_data/test_kpm_run_with_only_kcl_mod/kcl.mod b/test/e2e/test_suites/test_data/test_kpm_run_with_only_kcl_mod/kcl.mod index 73317ff37..d8345ec07 100644 --- a/test/e2e/test_suites/test_data/test_kpm_run_with_only_kcl_mod/kcl.mod +++ b/test/e2e/test_suites/test_data/test_kpm_run_with_only_kcl_mod/kcl.mod @@ -4,4 +4,4 @@ edition = "0.0.1" version = "0.0.1" [dependencies] -helloworld = "0.1.1" +helloworld = "0.1.2"