MCPcopy Create free account
hub / github.com/nsf/gocode / build_package

Function build_package

declcache.go:221–253  ·  view source on GitHub ↗

build_package builds the package by calling `go install package/import`. If everything compiles correctly, the newly compiled package should then be in the usual place in the `$GOPATH/pkg` directory, and gocode will pick it up from there.

(p *build.Package)

Source from the content-addressed store, hash-verified

219// correctly, the newly compiled package should then be in the usual place in the `$GOPATH/pkg`
220// directory, and gocode will pick it up from there.
221func build_package(p *build.Package) error {
222 if *g_debug {
223 log.Printf("-------------------")
224 log.Printf("rebuilding package %s", p.Name)
225 log.Printf("package import: %s", p.ImportPath)
226 log.Printf("package object: %s", p.PkgObj)
227 log.Printf("package source dir: %s", p.Dir)
228 log.Printf("package source files: %v", p.GoFiles)
229 log.Printf("GOPATH: %v", g_daemon.context.GOPATH)
230 log.Printf("GOROOT: %v", g_daemon.context.GOROOT)
231 }
232 env := os.Environ()
233 for i, v := range env {
234 if strings.HasPrefix(v, "GOPATH=") {
235 env[i] = "GOPATH=" + g_daemon.context.GOPATH
236 } else if strings.HasPrefix(v, "GOROOT=") {
237 env[i] = "GOROOT=" + g_daemon.context.GOROOT
238 }
239 }
240
241 cmd := exec.Command("go", "install", p.ImportPath)
242 cmd.Env = env
243
244 // TODO: Should read STDERR rather than STDOUT.
245 out, err := cmd.CombinedOutput()
246 if err != nil {
247 return err
248 }
249 if *g_debug {
250 log.Printf("build out: %s\n", string(out))
251 }
252 return nil
253}
254
255// executes autobuild function if autobuild option is enabled, logs error and
256// ignores it

Callers 1

autobuildFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected