Skip to content

Commit

Permalink
Merge pull request #290 from kcl-lang/fix-oci-source-with-settings
Browse files Browse the repository at this point in the history
fix: oci source with settings files
  • Loading branch information
Peefy committed Mar 28, 2024
2 parents 7ed45e5 + c88106f commit 9760af0
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 @@ -409,9 +409,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 @@ -1367,3 +1368,15 @@ func TestAddWithLocalPath(t *testing.T) {
assert.Equal(t, gotpkg.Dependencies.Deps["dep_pkg"].LocalFullPath, filepath.Join(tmppath, "dep_pkg"))
assert.Equal(t, gotpkg.Dependencies.Deps["dep_pkg"].Source.Local.Path, "../dep_pkg")
}

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 9760af0

Please sign in to comment.