Skip to content

Commit b65d5ed

Browse files
authored
Merge pull request #386 from zong-zhe/fix-run-bug
fix: fix wrong root path with 'kcl run'
2 parents 5e556c8 + c3ca1fd commit b65d5ed

File tree

8 files changed

+25
-2
lines changed

8 files changed

+25
-2
lines changed

pkg/client/client_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1760,6 +1760,7 @@ func TestRunLocalWithoutArgs(t *testing.T) {
17601760
{"run_5", true, "", "kcl_6: KCL 6\na: sub6\nkcl_7: KCL 7\nb: sub7"},
17611761
{filepath.Join("run_6", "main"), true, "", "The_sub_kcl_program: Hello Sub World!\nThe_first_kcl_program: Hello World!"},
17621762
{"run_7", true, "", "hello: Hello World!\nThe_first_kcl_program: Hello World!"},
1763+
{filepath.Join("run_8", "sub"), true, "", "sub: Hello Sub !"},
17631764
}
17641765

17651766
for _, test := range tests {

pkg/client/run.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,18 @@ func (o *RunOptions) getRootPkgSource() (*downloader.Source, error) {
461461
}
462462
}
463463
}
464+
465+
if rootPkgSource.IsLocalKPath() || rootPkgSource.IsDir() {
466+
rootPath, err = rootPkgSource.FindRootPath()
467+
if err != nil {
468+
return nil, err
469+
}
470+
471+
rootPkgSource, err = downloader.NewSourceFromStr(rootPath)
472+
if err != nil {
473+
return nil, err
474+
}
475+
}
464476
}
465477

466478
if rootPkgSource == nil {
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[package]
2+
name = "run_7"
3+
edition = "v0.9.0"
4+
version = "0.0.1"
5+

pkg/client/test_data/test_run_options/no_args/run_8/kcl.mod.lock

Whitespace-only changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
hello = 'Hello World!'
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
sub = 'Hello Sub !'

pkg/client/visitor.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func (vpv *VirtualPkgVisitor) Visit(s *downloader.Source, v visitFunc) error {
7272
return fmt.Errorf("source is not local")
7373
}
7474

75-
sourcePath, err := s.FindRootPath()
75+
sourcePath, err := s.ToFilePath()
7676
if err != nil {
7777
return err
7878
}
@@ -244,7 +244,7 @@ func NewVisitor(source downloader.Source, kpmcli *KpmClient) Visitor {
244244
} else if source.IsLocalTarPath() || source.IsLocalTgzPath() {
245245
return NewArchiveVisitor(NewPkgVisitor(kpmcli))
246246
} else if source.IsLocalPath() {
247-
rootPath, err := source.FindRootPath()
247+
rootPath, err := source.ToFilePath()
248248
if err != nil {
249249
return nil
250250
}

pkg/downloader/source.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ func (local *Local) IsLocalKPath() bool {
109109
}
110110

111111
func (local *Local) IsDir() bool {
112+
if local == nil {
113+
return false
114+
}
112115
fileInfo, err := os.Stat(local.Path)
113116
if err != nil {
114117
return false

0 commit comments

Comments
 (0)