Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix wrong root path with 'kcl run' #386

Merged
merged 1 commit into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pkg/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1760,6 +1760,7 @@ func TestRunLocalWithoutArgs(t *testing.T) {
{"run_5", true, "", "kcl_6: KCL 6\na: sub6\nkcl_7: KCL 7\nb: sub7"},
{filepath.Join("run_6", "main"), true, "", "The_sub_kcl_program: Hello Sub World!\nThe_first_kcl_program: Hello World!"},
{"run_7", true, "", "hello: Hello World!\nThe_first_kcl_program: Hello World!"},
{filepath.Join("run_8", "sub"), true, "", "sub: Hello Sub !"},
}

for _, test := range tests {
Expand Down
12 changes: 12 additions & 0 deletions pkg/client/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,18 @@ func (o *RunOptions) getRootPkgSource() (*downloader.Source, error) {
}
}
}

if rootPkgSource.IsLocalKPath() || rootPkgSource.IsDir() {
rootPath, err = rootPkgSource.FindRootPath()
if err != nil {
return nil, err
}

rootPkgSource, err = downloader.NewSourceFromStr(rootPath)
if err != nil {
return nil, err
}
}
}

if rootPkgSource == nil {
Expand Down
5 changes: 5 additions & 0 deletions pkg/client/test_data/test_run_options/no_args/run_8/kcl.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[package]
name = "run_7"
edition = "v0.9.0"
version = "0.0.1"

Empty file.
1 change: 1 addition & 0 deletions pkg/client/test_data/test_run_options/no_args/run_8/main.k
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hello = 'Hello World!'
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sub = 'Hello Sub !'
4 changes: 2 additions & 2 deletions pkg/client/visitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (vpv *VirtualPkgVisitor) Visit(s *downloader.Source, v visitFunc) error {
return fmt.Errorf("source is not local")
}

sourcePath, err := s.FindRootPath()
sourcePath, err := s.ToFilePath()
if err != nil {
return err
}
Expand Down Expand Up @@ -244,7 +244,7 @@ func NewVisitor(source downloader.Source, kpmcli *KpmClient) Visitor {
} else if source.IsLocalTarPath() || source.IsLocalTgzPath() {
return NewArchiveVisitor(NewPkgVisitor(kpmcli))
} else if source.IsLocalPath() {
rootPath, err := source.FindRootPath()
rootPath, err := source.ToFilePath()
if err != nil {
return nil
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/downloader/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ func (local *Local) IsLocalKPath() bool {
}

func (local *Local) IsDir() bool {
if local == nil {
return false
}
fileInfo, err := os.Stat(local.Path)
if err != nil {
return false
Expand Down
Loading