diff --git a/pkg/api/kpm_run.go b/pkg/api/kpm_run.go index 80612cb5..9f1a521f 100644 --- a/pkg/api/kpm_run.go +++ b/pkg/api/kpm_run.go @@ -69,6 +69,10 @@ func RunPkgInPath(opts *opt.CompileOptions) (string, error) { // CompileWithOpt will compile the kcl program without kcl package. // Deprecated: This method will not be maintained in the future. Use RunWithOpts instead. func RunWithOpt(opts *opt.CompileOptions) (*kcl.KCLResultList, error) { + // The entries will override the entries in the settings file. + if opts.HasSettingsYaml() && len(opts.KFilenameList) > 0 && len(opts.Entries()) > 0 { + opts.KFilenameList = []string{} + } if len(opts.Entries()) > 0 { for _, entry := range opts.Entries() { if filepath.IsAbs(entry) { diff --git a/pkg/api/kpm_run_test.go b/pkg/api/kpm_run_test.go index 0597c2ae..46b17718 100644 --- a/pkg/api/kpm_run_test.go +++ b/pkg/api/kpm_run_test.go @@ -131,6 +131,16 @@ func TestRunWithSettingsOpts(t *testing.T) { assert.Equal(t, err, nil) } +func TestRunWithSettingsOptsAndFile(t *testing.T) { + pkgPath := getTestDir("test_settings") + opts := opt.DefaultCompileOptions() + opts.Merge(kcl.WithSettings(filepath.Join(pkgPath, "kcl.yaml"))) + opts.SetHasSettingsYaml(true) + opts.SetEntries([]string{filepath.Join(pkgPath, "test.k")}) + _, err := RunWithOpt(opts) + assert.Equal(t, err, nil) +} + func TestRunTarPkg(t *testing.T) { pkgPath := getTestDir("test_run_tar_in_path") tarPath, _ := filepath.Abs(filepath.Join(pkgPath, "test.tar"))