@@ -13,74 +13,42 @@ import (
13
13
14
14
"github.com/lima-vm/lima/pkg/debugutil"
15
15
"github.com/lima-vm/lima/pkg/limayaml"
16
+ . "github.com/lima-vm/lima/pkg/must"
16
17
"github.com/sirupsen/logrus"
17
18
)
18
19
19
20
// executable is a variable that can be overridden in tests.
20
21
var executable = os .Executable
22
+ var self = Must (os .Executable ())
21
23
22
24
func Dir () (string , error ) {
23
- self , err := executable ()
24
- if err != nil {
25
- return "" , err
26
- }
27
25
selfSt , err := os .Stat (self )
28
26
if err != nil {
29
27
return "" , err
30
28
}
31
- if selfSt .Mode ()& fs .ModeSymlink != 0 {
29
+ selfDir := filepath .Dir (self )
30
+ if selfSt .Mode ()& os .ModeSymlink != 0 {
32
31
self , err = os .Readlink (self )
33
32
if err != nil {
34
33
return "" , err
35
34
}
35
+ if ! filepath .IsAbs (self ) {
36
+ self = filepath .Join (selfDir , self )
37
+ }
38
+ selfDir = filepath .Dir (self )
36
39
}
37
-
38
- ostype := limayaml .NewOS ("linux" )
39
- arch := limayaml .NewArch (runtime .GOARCH )
40
- if arch == "" {
41
- return "" , fmt .Errorf ("failed to get arch for %q" , runtime .GOARCH )
42
- }
43
-
44
- // self: /usr/local/bin/limactl
45
- selfDir := filepath .Dir (self )
46
- selfDirDir := filepath .Dir (selfDir )
47
- gaCandidates := []string {
48
- // candidate 0:
49
- // - self: /Applications/Lima.app/Contents/MacOS/limactl
50
- // - agent: /Applications/Lima.app/Contents/MacOS/lima-guestagent.Linux-x86_64
51
- // - dir: /Applications/Lima.app/Contents/MacOS
52
- filepath .Join (selfDir , "lima-guestagent." + ostype + "-" + arch ),
53
- // candidate 1:
54
- // - self: /usr/local/bin/limactl
55
- // - agent: /usr/local/share/lima/lima-guestagent.Linux-x86_64
56
- // - dir: /usr/local/share/lima
57
- filepath .Join (selfDirDir , "share/lima/lima-guestagent." + ostype + "-" + arch ),
58
- // TODO: support custom path
59
- }
60
- if debugutil .Debug {
61
- // candidate 2: launched by `~/go/bin/dlv dap`
62
- // - self: ${workspaceFolder}/cmd/limactl/__debug_bin_XXXXXX
63
- // - agent: ${workspaceFolder}/_output/share/lima/lima-guestagent.Linux-x86_64
64
- // - dir: ${workspaceFolder}/_output/share/lima
65
- candidateForDebugBuild := filepath .Join (filepath .Dir (selfDirDir ), "_output/share/lima/lima-guestagent." + ostype + "-" + arch )
66
- gaCandidates = append (gaCandidates , candidateForDebugBuild )
67
- logrus .Infof ("debug mode detected, adding more guest agent candidates: %v" , candidateForDebugBuild )
40
+ binDir := filepath .Join (selfDir , "bin" )
41
+ gaBinary := filepath .Join (binDir , "lima-guestagent." + limayaml .Arch )
42
+ if _ , err := os .Stat (gaBinary ); err == nil {
43
+ return binDir , nil
68
44
}
69
- for _ , gaCandidate := range gaCandidates {
70
- if _ , err := os .Stat (gaCandidate ); err == nil {
71
- return filepath .Dir (gaCandidate ), nil
72
- } else if ! errors .Is (err , os .ErrNotExist ) {
73
- return "" , err
74
- }
75
- if _ , err := os .Stat (gaCandidate + ".gz" ); err == nil {
76
- return filepath .Dir (gaCandidate ), nil
77
- } else if ! errors .Is (err , os .ErrNotExist ) {
78
- return "" , err
79
- }
45
+ shareDir := filepath .Join (selfDir , "share" , "lima" )
46
+ gaBinary = filepath .Join (shareDir , "bin" , "lima-guestagent." + limayaml .Arch )
47
+ if _ , err := os .Stat (gaBinary ); err == nil {
48
+ return filepath .Join (shareDir , "bin" ), nil
80
49
}
81
-
82
- return "" , fmt .Errorf ("failed to find \" lima-guestagent.%s-%s\" binary for %q, attempted %v" ,
83
- ostype , arch , self , gaCandidates )
50
+ debugutil .Logger ().WithField ("gaBinary" , gaBinary ).Warn ("Guest agent binary not found" )
51
+ return "" , nil
84
52
}
85
53
86
54
func GuestAgentBinary (ostype limayaml.OS , arch limayaml.Arch ) (string , error ) {
0 commit comments