MCPcopy Index your code
hub / github.com/go-python/gopy / loadPackage

Function loadPackage

gen.go:88–130  ·  view source on GitHub ↗
(path string, buildFirst bool, buildTags string)

Source from the content-addressed store, hash-verified

86}
87
88func loadPackage(path string, buildFirst bool, buildTags string) (*packages.Package, error) {
89 cwd, err := os.Getwd()
90 if err != nil {
91 return nil, err
92 }
93
94 if buildFirst {
95 args := []string{"build"}
96 if buildTags != "" {
97 buildTagStr := fmt.Sprintf("\"%s\"", strings.Join(strings.Split(buildTags, ","), " "))
98 args = append(args, "-tags", buildTagStr)
99 }
100 args = append(args, "-v", path)
101 fmt.Printf("go %s\n", strings.Join(args, " "))
102 cmd := exec.Command("go", args...)
103 cmd.Stdin = os.Stdin
104 cmd.Stdout = os.Stdout
105 cmd.Stderr = os.Stderr
106 cmd.Dir = cwd
107
108 err = cmd.Run()
109 if err != nil {
110 log.Printf("Note: there was an error building [%s] -- will continue but it may fail later: %v\n",
111 path,
112 err,
113 )
114 }
115 }
116
117 // golang.org/x/tools/go/packages supports modules or GOPATH etc
118 mode := packages.NeedName | packages.NeedFiles | packages.NeedCompiledGoFiles | packages.NeedDeps | packages.NeedImports | packages.NeedTypes | packages.NeedTypesSizes
119 bpkgs, err := packages.Load(&packages.Config{Mode: mode}, path)
120 if err != nil {
121 log.Printf("error resolving import path [%s]: %v\n",
122 path,
123 err,
124 )
125 return nil, err
126 }
127
128 bpkg := bpkgs[0] // only ever have one at a time
129 return bpkg, nil
130}
131
132func parsePackage(bpkg *packages.Package) (*bind.Package, error) {
133 if len(bpkg.GoFiles) == 0 {

Callers 3

buildPkgRecurseFunction · 0.85
gopyRunCmdGenFunction · 0.85
gopyRunCmdBuildFunction · 0.85

Calls 1

PrintfMethod · 0.80

Tested by

no test coverage detected