Skip to content

Commit

Permalink
fix: oci source with settings files
Browse files Browse the repository at this point in the history
Signed-off-by: peefy <xpf6677@163.com>
  • Loading branch information
Peefy committed Mar 28, 2024
1 parent bede720 commit c88106f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
12 changes: 9 additions & 3 deletions pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,9 +378,15 @@ func (c *KpmClient) CompileWithOpts(opts *opt.CompileOptions) (*kcl.KCLResultLis
opts.Merge(kcl.WithKFilenames(filepath.Join(opts.PkgPath(), entry)))
}
}
} else if len(kclPkg.GetEntryKclFilesFromModFile()) == 0 && !opts.HasSettingsYaml() {
// no entry
opts.Merge(kcl.WithKFilenames(opts.PkgPath()))
} else if len(kclPkg.GetEntryKclFilesFromModFile()) == 0 {
// No entries profile in kcl.mod and no file settings in the settings file
if !opts.HasSettingsYaml() {
// No settings file.
opts.Merge(kcl.WithKFilenames(opts.PkgPath()))
} else if opts.HasSettingsYaml() && len(opts.KFilenameList) == 0 {
// Has settings file but no file config in the settings files.
opts.Merge(kcl.WithKFilenames(opts.PkgPath()))
}
}
opts.Merge(kcl.WithWorkDir(opts.PkgPath()))

Expand Down
13 changes: 13 additions & 0 deletions pkg/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/dominikbraun/graph"
"github.com/otiai10/copy"
"github.com/stretchr/testify/assert"
"kcl-lang.io/kcl-go/pkg/kcl"
"kcl-lang.io/kpm/pkg/env"
"kcl-lang.io/kpm/pkg/git"
"kcl-lang.io/kpm/pkg/opt"
Expand Down Expand Up @@ -1365,3 +1366,15 @@ func TestAddWithLocalPath(t *testing.T) {
assert.Equal(t, gotpkg.Dependencies.Deps["dep_pkg"].FullName, expectpkg.Dependencies.Deps["dep_pkg"].FullName)
assert.Equal(t, gotpkg.Dependencies.Deps["dep_pkg"].Version, expectpkg.Dependencies.Deps["dep_pkg"].Version)
}

func TestRunOciWithSettingsFile(t *testing.T) {
kpmcli, err := NewKpmClient()
assert.Equal(t, err, nil)
kpmcli.SetLogWriter(nil)
opts := opt.DefaultCompileOptions()
opts.SetEntries([]string{})
opts.Merge(kcl.WithSettings(filepath.Join(".", "test_data", "test_run_oci_with_settings", "kcl.yaml")))
opts.SetHasSettingsYaml(true)
_, err = kpmcli.CompileOciPkg("oci://ghcr.io/kcl-lang/helloworld", "", opts)
assert.Equal(t, err, nil)
}
1 change: 1 addition & 0 deletions pkg/client/test_data/test_run_oci_with_settings/kcl.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
kcl_cli_configs:

0 comments on commit c88106f

Please sign in to comment.