Debian Codegraph @

interp/src.go

raw symbols SCIP
1 package interpscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/
2
3 import (
4 "errorsscip-go gomod github.com/golang/go/src go1.21 errors/"
5 "fmtscip-go gomod github.com/golang/go/src go1.21 fmt/"
6 "io/fsscip-go gomod github.com/golang/go/src go1.21 `io/fs`/"
7 "pathscip-go gomod github.com/golang/go/src go1.21 path/"
8 "path/filepathscip-go gomod github.com/golang/go/src go1.21 `path/filepath`/"
9 "stringsscip-go gomod github.com/golang/go/src go1.21 strings/"
10 )
11
12 // importSrc calls gta on the source code for the package identified by
13 // importPath. rPath is the relative path to the directory containing the source
14 // code for the package. It can also be "main" as a special value.
15 func (interp *Interpreterscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/Interpreter#) importSrcscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/Interpreter#importSrc().(rPath, importPath string, skipTest bool) (string, error) {
16 var dir string
17 var err error
18
19 if interp.srcPkgscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/Interpreter#srcPkg.[importPath] != nil {
20 name, ok := interp.pkgNamesscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/Interpreter#pkgNames.[importPath]
21 if !ok {
22 return "", fmtscip-go gomod github.com/golang/go/src go1.21 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.21 fmt/Errorf().("inconsistent knowledge about %s", importPath)
23 }
24 return name, nil
25 }
26
27 // For relative import paths in the form "./xxx" or "../xxx", the initial
28 // base path is the directory of the interpreter input file, or "." if no file
29 // was provided.
30 // In all other cases, absolute import paths are resolved from the GOPATH
31 // and the nested "vendor" directories.
32 if isPathRelativescip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/isPathRelative().(importPath) {
33 if rPath == mainIDscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/mainID. {
34 rPath = "."
35 }
36 dir = pathscip-go gomod github.com/golang/go/src go1.21 path/.Joinscip-go gomod github.com/golang/go/src go1.21 path/Join().(pathscip-go gomod github.com/golang/go/src go1.21 path/.Dirscip-go gomod github.com/golang/go/src go1.21 path/Dir().(interp.namescip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/Interpreter#name.), rPath, importPath)
37 } else if dir, rPath, err = interp.pkgDirscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/Interpreter#pkgDir().(filepathscip-go gomod github.com/golang/go/src go1.21 `path/filepath`/.ToSlashscip-go gomod github.com/golang/go/src go1.21 `path/filepath`/ToSlash().(interp.contextscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/opt#context..GOPATHscip-go gomod github.com/golang/go/src go1.21 `go/build`/Context#GOPATH.), rPath, importPath); err != nil {
38 // Try again, assuming a root dir at the source location.
39 if rPath, err = interp.rootFromSourceLocationscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/Interpreter#rootFromSourceLocation().(); err != nil {
40 return "", err
41 }
42 if dir, rPath, err = interp.pkgDirscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/Interpreter#pkgDir().(filepathscip-go gomod github.com/golang/go/src go1.21 `path/filepath`/.ToSlashscip-go gomod github.com/golang/go/src go1.21 `path/filepath`/ToSlash().(interp.contextscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/opt#context..GOPATHscip-go gomod github.com/golang/go/src go1.21 `go/build`/Context#GOPATH.), rPath, importPath); err != nil {
43 return "", err
44 }
45 }
46
47 if interp.rdirscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/Interpreter#rdir.[importPath] {
48 return "", fmtscip-go gomod github.com/golang/go/src go1.21 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.21 fmt/Errorf().("import cycle not allowed\n\timports %s", importPath)
49 }
50 interp.rdirscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/Interpreter#rdir.[importPath] = true
51
52 files, err := fsscip-go gomod github.com/golang/go/src go1.21 `io/fs`/.ReadDirscip-go gomod github.com/golang/go/src go1.21 `io/fs`/ReadDir().(interp.optscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/Interpreter#opt..filesystemscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/opt#filesystem., dir)
53 if err != nil {
54 return "", err
55 }
56
57 var initNodes []*nodescip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/node#
58 var rootNodes []*nodescip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/node#
59 revisit := make(map[string][]*nodescip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/node#)
60
61 var root *nodescip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/node#
62 var pkgName string
63
64 // Parse source files.
65 for _, file := range files {
66 name := file.Namescip-go gomod github.com/golang/go/src go1.21 `io/fs`/DirEntry#Name().()
67 if skipFilescip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/skipFile().(&interp.contextscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/opt#context., name, skipTest) {
68 continue
69 }
70
71 name = pathscip-go gomod github.com/golang/go/src go1.21 path/.Joinscip-go gomod github.com/golang/go/src go1.21 path/Join().(dir, name)
72 var buf []byte
73 if buf, err = fsscip-go gomod github.com/golang/go/src go1.21 `io/fs`/.ReadFilescip-go gomod github.com/golang/go/src go1.21 `io/fs`/ReadFile().(interp.optscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/Interpreter#opt..filesystemscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/opt#filesystem., name); err != nil {
74 return "", err
75 }
76
77 n, err := interp.parsescip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/Interpreter#parse().(string(buf), name, false)
78 if err != nil {
79 return "", err
80 }
81 if n == nil {
82 continue
83 }
84
85 var pname string
86 if pname, root, err = interp.astscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/Interpreter#ast().(n); err != nil {
87 return "", err
88 }
89 if root == nil {
90 continue
91 }
92
93 if interp.astDotscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/opt#astDot. {
94 dotCmd := interp.dotCmdscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/opt#dotCmd.
95 if dotCmd == "" {
96 dotCmd = defaultDotCmdscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/defaultDotCmd().(name, "yaegi-ast-")
97 }
98 root.astDotscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/node#astDot().(dotWriterscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/dotWriter().(dotCmd), name)
99 }
100 if pkgName == "" {
101 pkgName = pname
102 } else if pkgName != pname && skipTest {
103 return "", fmtscip-go gomod github.com/golang/go/src go1.21 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.21 fmt/Errorf().("found packages %s and %s in %s", pkgName, pname, dir)
104 }
105 rootNodes = append(rootNodes, root)
106
107 subRPath := effectivePkgscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/effectivePkg().(rPath, importPath)
108 var list []*nodescip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/node#
109 list, err = interp.gtascip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/Interpreter#gta().(root, subRPath, importPath, pkgName)
110 if err != nil {
111 return "", err
112 }
113 revisit[subRPath] = append(revisit[subRPath], list...)
114 }
115
116 // Revisit incomplete nodes where GTA could not complete.
117 for _, nodes := range revisit {
118 if err = interp.gtaRetryscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/Interpreter#gtaRetry().(nodes, importPath, pkgName); err != nil {
119 return "", err
120 }
121 }
122
123 // Generate control flow graphs.
124 for _, root := range rootNodes {
125 var nodes []*nodescip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/node#
126 if nodes, err = interp.cfgscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/Interpreter#cfg().(root, nil, importPath, pkgName); err != nil {
127 return "", err
128 }
129 initNodes = append(initNodes, nodes...)
130 }
131
132 // Register source package in the interpreter. The package contains only
133 // the global symbols in the package scope.
134 interp.mutexscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/Interpreter#mutex..Lockscip-go gomod github.com/golang/go/src go1.21 sync/RWMutex#Lock().()
135 gs := interp.scopesscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/Interpreter#scopes.[importPath]
136 if gs == nil {
137 interp.mutexscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/Interpreter#mutex..Unlockscip-go gomod github.com/golang/go/src go1.21 sync/RWMutex#Unlock().()
138 // A nil scope means that no even an empty package is created from source.
139 return "", fmtscip-go gomod github.com/golang/go/src go1.21 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.21 fmt/Errorf().("no Go files in %s", dir)
140 }
141 interp.srcPkgscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/Interpreter#srcPkg.[importPath] = gs.symscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/scope#sym.
142 interp.pkgNamesscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/Interpreter#pkgNames.[importPath] = pkgName
143
144 interp.framescip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/Interpreter#frame..mutexscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/frame#mutex..Lockscip-go gomod github.com/golang/go/src go1.21 sync/RWMutex#Lock().()
145 interp.resizeFramescip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/Interpreter#resizeFrame().()
146 interp.framescip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/Interpreter#frame..mutexscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/frame#mutex..Unlockscip-go gomod github.com/golang/go/src go1.21 sync/RWMutex#Unlock().()
147 interp.mutexscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/Interpreter#mutex..Unlockscip-go gomod github.com/golang/go/src go1.21 sync/RWMutex#Unlock().()
148
149 // Once all package sources have been parsed, execute entry points then init functions.
150 for _, n := range rootNodes {
151 if err = genRunscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/genRun().(n); err != nil {
152 return "", err
153 }
154 interp.runscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/Interpreter#run().(n, nil)
155 }
156
157 // Wire and execute global vars in global scope gs.
158 n, err := genGlobalVarsscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/genGlobalVars().(rootNodes, gs)
159 if err != nil {
160 return "", err
161 }
162 interp.runscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/Interpreter#run().(n, nil)
163
164 // Add main to list of functions to run, after all inits.
165 if m := gs.symscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/scope#sym.[mainIDscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/mainID.]; pkgName == mainIDscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/mainID. && m != nil && skipTest {
166 initNodes = append(initNodes, m.nodescip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/symbol#node.)
167 }
168
169 for _, n := range initNodes {
170 interp.runscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/Interpreter#run().(n, interp.framescip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/Interpreter#frame.)
171 }
172
173 return pkgName, nil
174 }
175
176 // rootFromSourceLocation returns the path to the directory containing the input
177 // Go file given to the interpreter, relative to $GOPATH/src.
178 // It is meant to be called in the case when the initial input is a main package.
179 func (interp *Interpreterscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/Interpreter#) rootFromSourceLocationscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/Interpreter#rootFromSourceLocation().() (string, error) {
180 sourceFile := interp.namescip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/Interpreter#name.
181 if sourceFile == DefaultSourceNamescip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/DefaultSourceName. {
182 return "", nil
183 }
184
185 _, isRealFS := interp.optscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/Interpreter#opt..filesystemscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/opt#filesystem..(*realFSscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/realFS#)
186 if isRealFS {
187 // In the "real" FS, GOPATH will be an absolute path, so we need to convert
188 // the source file to an absolute path to compare them.
189 absPath, err := filepathscip-go gomod github.com/golang/go/src go1.21 `path/filepath`/.Absscip-go gomod github.com/golang/go/src go1.21 `path/filepath`/Abs().(filepathscip-go gomod github.com/golang/go/src go1.21 `path/filepath`/.FromSlashscip-go gomod github.com/golang/go/src go1.21 `path/filepath`/FromSlash().(sourceFile))
190 if err != nil {
191 return "", err
192 }
193 sourceFile = filepathscip-go gomod github.com/golang/go/src go1.21 `path/filepath`/.ToSlashscip-go gomod github.com/golang/go/src go1.21 `path/filepath`/ToSlash().(absPath)
194 }
195 pkgDir := pathscip-go gomod github.com/golang/go/src go1.21 path/.Dirscip-go gomod github.com/golang/go/src go1.21 path/Dir().(sourceFile)
196 goPath := pathscip-go gomod github.com/golang/go/src go1.21 path/.Joinscip-go gomod github.com/golang/go/src go1.21 path/Join().(filepathscip-go gomod github.com/golang/go/src go1.21 `path/filepath`/.ToSlashscip-go gomod github.com/golang/go/src go1.21 `path/filepath`/ToSlash().(interp.contextscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/opt#context..GOPATHscip-go gomod github.com/golang/go/src go1.21 `go/build`/Context#GOPATH.), "src") + "/"
197 if !stringsscip-go gomod github.com/golang/go/src go1.21 strings/.HasPrefixscip-go gomod github.com/golang/go/src go1.21 strings/HasPrefix().(pkgDir, goPath) {
198 return "", fmtscip-go gomod github.com/golang/go/src go1.21 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.21 fmt/Errorf().("package location %s not in GOPATH", pkgDir)
199 }
200 return stringsscip-go gomod github.com/golang/go/src go1.21 strings/.TrimPrefixscip-go gomod github.com/golang/go/src go1.21 strings/TrimPrefix().(pkgDir, goPath), nil
201 }
202
203 // pkgDir returns the absolute path in filesystem for a package given its import path
204 // and the root of the subtree dependencies.
205 func (interp *Interpreterscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/Interpreter#) pkgDirscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/Interpreter#pkgDir().(goPath string, root, importPath string) (string, string, error) {
206 rPath := pathscip-go gomod github.com/golang/go/src go1.21 path/.Joinscip-go gomod github.com/golang/go/src go1.21 path/Join().(root, "vendor")
207 dir := pathscip-go gomod github.com/golang/go/src go1.21 path/.Joinscip-go gomod github.com/golang/go/src go1.21 path/Join().(goPath, "src", rPath, importPath)
208
209 if _, err := fsscip-go gomod github.com/golang/go/src go1.21 `io/fs`/.Statscip-go gomod github.com/golang/go/src go1.21 `io/fs`/Stat().(interp.optscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/Interpreter#opt..filesystemscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/opt#filesystem., dir); err == nil {
210 return dir, rPath, nil // found!
211 }
212
213 dir = pathscip-go gomod github.com/golang/go/src go1.21 path/.Joinscip-go gomod github.com/golang/go/src go1.21 path/Join().(goPath, "src", effectivePkgscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/effectivePkg().(root, importPath))
214
215 if _, err := fsscip-go gomod github.com/golang/go/src go1.21 `io/fs`/.Statscip-go gomod github.com/golang/go/src go1.21 `io/fs`/Stat().(interp.optscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/Interpreter#opt..filesystemscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/opt#filesystem., dir); err == nil {
216 return dir, root, nil // found!
217 }
218
219 if root == "" {
220 if interp.contextscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/opt#context..GOPATHscip-go gomod github.com/golang/go/src go1.21 `go/build`/Context#GOPATH. == "" {
221 return "", "", fmtscip-go gomod github.com/golang/go/src go1.21 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.21 fmt/Errorf().("unable to find source related to: %q. Either the GOPATH environment variable, or the Interpreter.Options.GoPath needs to be set", importPath)
222 }
223 return "", "", fmtscip-go gomod github.com/golang/go/src go1.21 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.21 fmt/Errorf().("unable to find source related to: %q", importPath)
224 }
225
226 rootPath := pathscip-go gomod github.com/golang/go/src go1.21 path/.Joinscip-go gomod github.com/golang/go/src go1.21 path/Join().(goPath, "src", root)
227 prevRoot, err := previousRootscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/previousRoot().(interp.optscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/Interpreter#opt..filesystemscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/opt#filesystem., rootPath, root)
228 if err != nil {
229 return "", "", err
230 }
231
232 return interp.pkgDirscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/Interpreter#pkgDir().(goPath, prevRoot, importPath)
233 }
234
235 const vendorscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/vendor. = "vendor"
236
237 // Find the previous source root (vendor > vendor > ... > GOPATH).
238 func previousRootscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/previousRoot().(filesystem fsscip-go gomod github.com/golang/go/src go1.21 `io/fs`/.FSscip-go gomod github.com/golang/go/src go1.21 `io/fs`/FS#, rootPath, root string) (string, error) {
239 rootPath = pathscip-go gomod github.com/golang/go/src go1.21 path/.Cleanscip-go gomod github.com/golang/go/src go1.21 path/Clean().(rootPath)
240 parent, final := pathscip-go gomod github.com/golang/go/src go1.21 path/.Splitscip-go gomod github.com/golang/go/src go1.21 path/Split().(rootPath)
241 parent = pathscip-go gomod github.com/golang/go/src go1.21 path/.Cleanscip-go gomod github.com/golang/go/src go1.21 path/Clean().(parent)
242
243 // TODO(mpl): maybe it works for the special case main, but can't be bothered for now.
244 if root != mainIDscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/mainID. && final != vendorscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/vendor. {
245 root = stringsscip-go gomod github.com/golang/go/src go1.21 strings/.TrimSuffixscip-go gomod github.com/golang/go/src go1.21 strings/TrimSuffix().(root, "/")
246 prefix := stringsscip-go gomod github.com/golang/go/src go1.21 strings/.TrimSuffixscip-go gomod github.com/golang/go/src go1.21 strings/TrimSuffix().(stringsscip-go gomod github.com/golang/go/src go1.21 strings/.TrimSuffixscip-go gomod github.com/golang/go/src go1.21 strings/TrimSuffix().(rootPath, root), "/")
247
248 // look for the closest vendor in one of our direct ancestors, as it takes priority.
249 var vendored string
250 for {
251 fi, err := fsscip-go gomod github.com/golang/go/src go1.21 `io/fs`/.Statscip-go gomod github.com/golang/go/src go1.21 `io/fs`/Stat().(filesystem, pathscip-go gomod github.com/golang/go/src go1.21 path/.Joinscip-go gomod github.com/golang/go/src go1.21 path/Join().(parent, vendorscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/vendor.))
252 if err == nil && fi.IsDirscip-go gomod github.com/golang/go/src go1.21 `io/fs`/FileInfo#IsDir().() {
253 vendored = stringsscip-go gomod github.com/golang/go/src go1.21 strings/.TrimPrefixscip-go gomod github.com/golang/go/src go1.21 strings/TrimPrefix().(stringsscip-go gomod github.com/golang/go/src go1.21 strings/.TrimPrefixscip-go gomod github.com/golang/go/src go1.21 strings/TrimPrefix().(parent, prefix), "/")
254 break
255 }
256 if !errorsscip-go gomod github.com/golang/go/src go1.21 errors/.Isscip-go gomod github.com/golang/go/src go1.21 errors/Is().(err, fsscip-go gomod github.com/golang/go/src go1.21 `io/fs`/.ErrNotExistscip-go gomod github.com/golang/go/src go1.21 `io/fs`/ErrNotExist.) {
257 return "", err
258 }
259 // stop when we reach GOPATH/src
260 if parent == prefix {
261 break
262 }
263
264 // stop when we reach GOPATH/src/blah
265 parent = pathscip-go gomod github.com/golang/go/src go1.21 path/.Dirscip-go gomod github.com/golang/go/src go1.21 path/Dir().(parent)
266 if parent == prefix {
267 break
268 }
269
270 // just an additional failsafe, stop if we reach the filesystem root, or dot (if
271 // we are dealing with relative paths).
272 // TODO(mpl): It should probably be a critical error actually,
273 // as we shouldn't have gone that high up in the tree.
274 // TODO(dennwc): This partially fails on Windows, since it cannot recognize drive letters as "root".
275 if parent == "/" || parent == "." || parent == "" {
276 break
277 }
278 }
279
280 if vendored != "" {
281 return vendored, nil
282 }
283 }
284
285 // TODO(mpl): the algorithm below might be redundant with the one above,
286 // but keeping it for now. Investigate/simplify/remove later.
287 splitRoot := stringsscip-go gomod github.com/golang/go/src go1.21 strings/.Splitscip-go gomod github.com/golang/go/src go1.21 strings/Split().(root, "/")
288 var index int
289 for i := len(splitRoot) - 1; i >= 0; i-- {
290 if splitRoot[i] == "vendor" {
291 index = i
292 break
293 }
294 }
295
296 if index == 0 {
297 return "", nil
298 }
299
300 return pathscip-go gomod github.com/golang/go/src go1.21 path/.Joinscip-go gomod github.com/golang/go/src go1.21 path/Join().(splitRoot[:index]...), nil
301 }
302
303 func effectivePkgscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/effectivePkg().(root, p string) string {
304 splitRoot := stringsscip-go gomod github.com/golang/go/src go1.21 strings/.Splitscip-go gomod github.com/golang/go/src go1.21 strings/Split().(root, "/")
305 splitPath := stringsscip-go gomod github.com/golang/go/src go1.21 strings/.Splitscip-go gomod github.com/golang/go/src go1.21 strings/Split().(p, "/")
306
307 var result []string
308
309 rootIndex := 0
310 prevRootIndex := 0
311 for i := 0; i < len(splitPath); i++ {
312 part := splitPath[len(splitPath)-1-i]
313
314 index := len(splitRoot) - 1 - rootIndex
315 if index > 0 && part == splitRoot[index] && i != 0 {
316 prevRootIndex = rootIndex
317 rootIndex++
318 } else if prevRootIndex == rootIndex {
319 result = append(result, part)
320 }
321 }
322
323 var frag string
324 for i := len(result) - 1; i >= 0; i-- {
325 frag = pathscip-go gomod github.com/golang/go/src go1.21 path/.Joinscip-go gomod github.com/golang/go/src go1.21 path/Join().(frag, result[i])
326 }
327
328 return pathscip-go gomod github.com/golang/go/src go1.21 path/.Joinscip-go gomod github.com/golang/go/src go1.21 path/Join().(root, frag)
329 }
330
331 // isPathRelative returns true if path starts with "./" or "../".
332 // It is intended for use on import paths, where "/" is always the directory separator.
333 func isPathRelativescip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/isPathRelative().(s string) bool {
334 return stringsscip-go gomod github.com/golang/go/src go1.21 strings/.HasPrefixscip-go gomod github.com/golang/go/src go1.21 strings/HasPrefix().(s, "./") || stringsscip-go gomod github.com/golang/go/src go1.21 strings/.HasPrefixscip-go gomod github.com/golang/go/src go1.21 strings/HasPrefix().(s, "../")
335 }