awesome. Precisely the material i was missing, thanks!
On Sunday, December 25, 2016 at 3:28:06 PM UTC+1, [email protected] wrote: > > On Friday, 23 December 2016 14:01:15 UTC-5, [email protected] wrote: >> >> Hi, >> >> i m looking for the right way to load and parse an ast.ImportSpec >> referenced into an ast.File object. >> >> Its mostly about the path resolution, I can t find a method like >> >> parse(baseDir string, pkgPath string)... >> >> where baseDir (is not necessarily the same as the ast.File path, in my >> understanding) would be the directory which may contain the vendor folder, >> and pkgPath something like `go/ast`. >> >> Or maybe its ok to just test that the directory exists at, >> - baseDir / vendor / pkgPath >> - goroot / src / pkgPath >> ? >> >> Seems to me its a bit more complex than that. >> > > Indeed it is. The interpretation of an import path string depends on the > build tool. Most open-source Go projects use the 'go build' command and > its conventions for workspace layout. The core of this tool is exposed as a > library in the standard "go/build" package. Its build.Context type > abstracts a workspace, and most applications use the default value > build.Default to find packages relative to the directories specified by the > GOROOT and GOPATH environment variables. The (*Context).Import function > locates a package given its import path: > > https://golang.org/pkg/go/build/#Context.Import > > This function returns a build.Package, from which you can find the set of > source files that make up the package. > > Most applications must either recursively process source code for imported > packages, or load type information from export data files (.a) written by > the compiler. For source, use the golang.org/x/tools/go/loader package. > For export data, use golang.org/x/tools/go/gcexportdata. See the > examples in each package for details. There is a also a tutorial for the > type checker at htps://github.com/golang/example/tree/master/gotypes. > > <https://www.google.com/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#> > > > <https://webcache.googleusercontent.com/search?q=cache:cbCcFxv6mjwJ:https://github.com/golang/example/tree/master/gotypes+&cd=1&hl=en&ct=clnk&gl=us> > > <https://www.google.com/search?espv=2&biw=1128&bih=603&q=related:https://github.com/golang/example/tree/master/gotypes+go+types+tutorial&tbo=1&sa=X&ved=0ahUKEwi0uOOhxo_RAhXISyYKHXSqBKYQHwghMAA> > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
