Skip to content

Commit

Permalink
feat: set the 'kcl.mod' path as workdir
Browse files Browse the repository at this point in the history
  • Loading branch information
zong-zhe committed Sep 5, 2023
1 parent dcb5a11 commit 6b2c172
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pkg/api/kpm_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ 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
9 changes: 9 additions & 0 deletions pkg/api/kpm_run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,12 @@ func TestRunTar(t *testing.T) {
os.RemoveAll(untarPath)
}
}

func TestRunWithWorkdir(t *testing.T) {
pkgPath := getTestDir(filepath.Join("test_work_dir", "dev"))
opts := opt.DefaultCompileOptions()
opts.SetPkgPath(pkgPath)
result, err := RunPkgInPath(opts)
assert.Equal(t, err, nil)
assert.Equal(t, result, "base: base\nmain: main")
}
1 change: 1 addition & 0 deletions pkg/api/test_data/test_work_dir/base/base.k
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
base = "base"
8 changes: 8 additions & 0 deletions pkg/api/test_data/test_work_dir/dev/kcl.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
name = "helloworld"
edition = "0.5.0"
version = "0.1.0"

[profile]
entries = ["../base/base.k", "main.k"]

Empty file.
1 change: 1 addition & 0 deletions pkg/api/test_data/test_work_dir/dev/main.k
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
main = "main"

0 comments on commit 6b2c172

Please sign in to comment.