Skip to content

Commit

Permalink
Merge pull request #298 from kcl-lang/fix-entry-override-settings-file
Browse files Browse the repository at this point in the history
fix: entry override settings file
  • Loading branch information
Peefy committed Apr 11, 2024
2 parents 322f190 + bf53e56 commit bb39f68
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/api/kpm_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
10 changes: 10 additions & 0 deletions pkg/api/kpm_run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down

0 comments on commit bb39f68

Please sign in to comment.