@@ -11,7 +11,6 @@ import (
1111 "path/filepath"
1212 "runtime"
1313
14- "github.com/lima-vm/lima/pkg/debugutil"
1514 "github.com/lima-vm/lima/pkg/limayaml"
1615 "github.com/sirupsen/logrus"
1716)
@@ -30,54 +29,23 @@ func Dir() (string, error) {
3029 if err != nil {
3130 return "" , err
3231 }
32+ if ! filepath .IsAbs (self ) {
33+ self = filepath .Join (selfDir , self )
34+ }
35+ selfDir = filepath .Dir (self )
3336 }
34-
35- ostype := limayaml .NewOS ("linux" )
36- arch := limayaml .NewArch (runtime .GOARCH )
37- if arch == "" {
38- return "" , fmt .Errorf ("failed to get arch for %q" , runtime .GOARCH )
39- }
40-
41- // self: /usr/local/bin/limactl
42- selfDir := filepath .Dir (self )
43- selfDirDir := filepath .Dir (selfDir )
44- gaCandidates := []string {
45- // candidate 0:
46- // - self: /Applications/Lima.app/Contents/MacOS/limactl
47- // - agent: /Applications/Lima.app/Contents/MacOS/lima-guestagent.Linux-x86_64
48- // - dir: /Applications/Lima.app/Contents/MacOS
49- filepath .Join (selfDir , "lima-guestagent." + ostype + "-" + arch ),
50- // candidate 1:
51- // - self: /usr/local/bin/limactl
52- // - agent: /usr/local/share/lima/lima-guestagent.Linux-x86_64
53- // - dir: /usr/local/share/lima
54- filepath .Join (selfDirDir , "share/lima/lima-guestagent." + ostype + "-" + arch ),
55- // TODO: support custom path
37+ binDir := filepath .Join (selfDir , "bin" )
38+ gaBinary := filepath .Join (binDir , "lima-guestagent." + limayaml .Arch )
39+ if _ , err := os .Stat (gaBinary ); err == nil {
40+ return binDir , nil
5641 }
57- if debugutil .Debug {
58- // candidate 2: launched by `~/go/bin/dlv dap`
59- // - self: ${workspaceFolder}/cmd/limactl/__debug_bin_XXXXXX
60- // - agent: ${workspaceFolder}/_output/share/lima/lima-guestagent.Linux-x86_64
61- // - dir: ${workspaceFolder}/_output/share/lima
62- candidateForDebugBuild := filepath .Join (filepath .Dir (selfDirDir ), "_output/share/lima/lima-guestagent." + ostype + "-" + arch )
63- gaCandidates = append (gaCandidates , candidateForDebugBuild )
64- logrus .Infof ("debug mode detected, adding more guest agent candidates: %v" , candidateForDebugBuild )
42+ shareDir := filepath .Join (selfDir , "share" , "lima" )
43+ gaBinary = filepath .Join (shareDir , "bin" , "lima-guestagent." + limayaml .Arch )
44+ if _ , err := os .Stat (gaBinary ); err == nil {
45+ return filepath .Join (shareDir , "bin" ), nil
6546 }
66- for _ , gaCandidate := range gaCandidates {
67- if _ , err := os .Stat (gaCandidate ); err == nil {
68- return filepath .Dir (gaCandidate ), nil
69- } else if ! errors .Is (err , os .ErrNotExist ) {
70- return "" , err
71- }
72- if _ , err := os .Stat (gaCandidate + ".gz" ); err == nil {
73- return filepath .Dir (gaCandidate ), nil
74- } else if ! errors .Is (err , os .ErrNotExist ) {
75- return "" , err
76- }
77- }
78-
79- return "" , fmt .Errorf ("failed to find \" lima-guestagent.%s-%s\" binary for %q, attempted %v" ,
80- ostype , arch , self , gaCandidates )
47+ debugutil .Logger ().WithField ("gaBinary" , gaBinary ).Warn ("Guest agent binary not found" )
48+ return "" , nil
8149}
8250
8351func GuestAgentBinary (ostype limayaml.OS , arch limayaml.Arch ) (string , error ) {
0 commit comments