Skip to content

Commit

Permalink
fix: set pwd as workdir
Browse files Browse the repository at this point in the history
  • Loading branch information
zong-zhe committed Sep 5, 2023
1 parent 6b2c172 commit 4f04931
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
2 changes: 0 additions & 2 deletions pkg/api/kpm_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,6 @@ func RunPkgInPath(opts *opt.CompileOptions) (string, error) {
// no entry
opts.Merge(kcl.WithKFilenames(opts.PkgPath()))
}
// set the 'kcl.mod' path as the work dir.
opts.Merge(kcl.WithWorkDir(opts.PkgPath()))

// Calculate the absolute path of entry file described by '--input'.
compiler := runner.NewCompilerWithOpts(opts)
Expand Down
1 change: 1 addition & 0 deletions pkg/api/kpm_run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ func TestRunWithWorkdir(t *testing.T) {
pkgPath := getTestDir(filepath.Join("test_work_dir", "dev"))
opts := opt.DefaultCompileOptions()
opts.SetPkgPath(pkgPath)
opts.Merge(kcl.WithWorkDir(pkgPath))
result, err := RunPkgInPath(opts)
assert.Equal(t, err, nil)
assert.Equal(t, result, "base: base\nmain: main")
Expand Down
8 changes: 8 additions & 0 deletions pkg/cmd/cmd_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package cmd

import (
"fmt"
"os"

"github.com/urfave/cli/v2"
"kcl-lang.io/kcl-go/pkg/kcl"
Expand Down Expand Up @@ -79,6 +80,13 @@ func NewRunCmd() *cli.Command {

func KpmRun(c *cli.Context) error {
kclOpts := CompileOptionFromCli(c)
// set the pwd as the work dir.
pwd, err := os.Getwd()
if err != nil {
return err
}

kclOpts.Merge(kcl.WithWorkDir(pwd))
pkgWillBeCompiled := c.Args().First()
// 'kpm run' compile the current package undor '$pwd'.
if len(pkgWillBeCompiled) == 0 {
Expand Down

0 comments on commit 4f04931

Please sign in to comment.