Fixed #163: Was detecting std lib packages when the GOROOT was different at runtime than compile time.
diff --git a/CHANGELOG.md b/CHANGELOG.md
index e2d44b7..585c017 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,8 @@
+# Release 0.8.1 (xxxx-xx-xx)
+
+- Fixed #163: Was detecting std lib packages when the GOROOT was different at
+  runtime than compile time.
+
 # Release 0.8.0 (2015-12-10)
 
 - Issues #156 and #85: Added lockfile support (glide.lock). This file records
diff --git a/cmd/flatten.go b/cmd/flatten.go
index 3866df2..ace0815 100644
--- a/cmd/flatten.go
+++ b/cmd/flatten.go
@@ -283,7 +283,7 @@
 func mergeGuess(dir, pkg string, f *flattening, scanned map[string]bool) ([]string, bool) {
 	deps := f.deps
 	Info("Scanning %s for dependencies.", pkg)
-	buildContext, err := GetBuildContext()
+	buildContext, err := util.GetBuildContext()
 	if err != nil {
 		Warn("Could not scan package %q: %s", pkg, err)
 		return []string{}, false
diff --git a/cmd/guess_deps.go b/cmd/guess_deps.go
index 2b59533..1ab3ebc 100644
--- a/cmd/guess_deps.go
+++ b/cmd/guess_deps.go
@@ -18,7 +18,7 @@
 //  - dirname (string): Directory to use as the base. Default: "."
 //  - skipImport (book): Whether to skip importing from Godep, GPM, and gb
 func GuessDeps(c cookoo.Context, p *cookoo.Params) (interface{}, cookoo.Interrupt) {
-	buildContext, err := GetBuildContext()
+	buildContext, err := util.GetBuildContext()
 	if err != nil {
 		return nil, err
 	}
@@ -122,7 +122,7 @@
 
 // Attempt to guess at the package name at the top level. When unable to detect
 // a name goes to default of "main".
-func guessPackageName(b *BuildCtxt, base string) string {
+func guessPackageName(b *util.BuildCtxt, base string) string {
 	cwd, err := os.Getwd()
 	if err != nil {
 		return "main"
diff --git a/cmd/tree.go b/cmd/tree.go
index ecd4435..4df1205 100644
--- a/cmd/tree.go
+++ b/cmd/tree.go
@@ -11,11 +11,12 @@
 	"github.com/Masterminds/cookoo"
 	"github.com/Masterminds/glide/dependency"
 	"github.com/Masterminds/glide/msg"
+	"github.com/Masterminds/glide/util"
 )
 
 // Tree prints a tree representing dependencies.
 func Tree(c cookoo.Context, p *cookoo.Params) (interface{}, cookoo.Interrupt) {
-	buildContext, err := GetBuildContext()
+	buildContext, err := util.GetBuildContext()
 	if err != nil {
 		return nil, err
 	}
@@ -96,7 +97,7 @@
 	return nil, nil
 }
 
-func listDeps(b *BuildCtxt, info map[string]*pinfo, name, path string) {
+func listDeps(b *util.BuildCtxt, info map[string]*pinfo, name, path string) {
 	found := findPkg(b, name, path)
 	switch found.PType {
 	case ptypeUnknown:
@@ -116,7 +117,7 @@
 	}
 }
 
-func displayTree(b *BuildCtxt, basedir, myName string, level int, core bool, l *list.List) {
+func displayTree(b *util.BuildCtxt, basedir, myName string, level int, core bool, l *list.List) {
 	deps := walkDeps(b, basedir, myName)
 	for _, name := range deps {
 		found := findPkg(b, name, basedir)
@@ -177,7 +178,7 @@
 	Vendored   bool
 }
 
-func findPkg(b *BuildCtxt, name, cwd string) *pinfo {
+func findPkg(b *util.BuildCtxt, name, cwd string) *pinfo {
 	var fi os.FileInfo
 	var err error
 	var p string
@@ -241,7 +242,7 @@
 	return fi.Mode()&os.ModeSymlink == os.ModeSymlink
 }
 
-func walkDeps(b *BuildCtxt, base, myName string) []string {
+func walkDeps(b *util.BuildCtxt, base, myName string) []string {
 	externalDeps := []string{}
 	filepath.Walk(base, func(path string, fi os.FileInfo, err error) error {
 		if excludeSubtree(path, fi) {
diff --git a/cmd/util.go b/cmd/util.go
index 3a27e63..43bcda9 100644
--- a/cmd/util.go
+++ b/cmd/util.go
@@ -2,7 +2,6 @@
 
 import (
 	"fmt"
-	"go/build"
 	"io"
 	"os"
 	"os/exec"
@@ -130,28 +129,6 @@
 	return filepath.SplitList(p)
 }
 
-// BuildCtxt is a convenience wrapper for not having to import go/build
-// anywhere else
-type BuildCtxt struct {
-	build.Context
-}
-
-// GetBuildContext returns a build context from go/build. When the $GOROOT
-// variable is not set in the users environment it sets the context's root
-// path to the path returned by 'go env GOROOT'.
-func GetBuildContext() (*BuildCtxt, error) {
-	buildContext := &BuildCtxt{build.Default}
-	if goRoot := os.Getenv("GOROOT"); len(goRoot) == 0 {
-		out, err := exec.Command("go", "env", "GOROOT").Output()
-		if goRoot = strings.TrimSpace(string(out)); len(goRoot) == 0 || err != nil {
-			return nil, fmt.Errorf("Please set the $GOROOT environment " +
-				"variable to use this command\n")
-		}
-		buildContext.GOROOT = goRoot
-	}
-	return buildContext, nil
-}
-
 func fileExist(name string) (bool, error) {
 	_, err := os.Stat(name)
 	if err == nil {
diff --git a/cmd/yaml.go b/cmd/yaml.go
index 4432a86..60d3cb1 100644
--- a/cmd/yaml.go
+++ b/cmd/yaml.go
@@ -160,7 +160,7 @@
 	// Fastpath check if a name in the GOROOT. There is an issue when a pkg
 	// is in the GOROOT and GetRootFromPackage tries to look it up because it
 	// expects remote names.
-	b, err := GetBuildContext()
+	b, err := util.GetBuildContext()
 	if err == nil {
 		p := filepath.Join(b.GOROOT, "src", name)
 		if _, err := os.Stat(p); err == nil {
diff --git a/dependency/resolver.go b/dependency/resolver.go
index 943c3aa..516f689 100644
--- a/dependency/resolver.go
+++ b/dependency/resolver.go
@@ -2,13 +2,13 @@
 
 import (
 	"container/list"
-	"go/build"
 	"os"
 	"path/filepath"
 	"strings"
 
 	"github.com/Masterminds/glide/cfg"
 	"github.com/Masterminds/glide/msg"
+	"github.com/Masterminds/glide/util"
 )
 
 // MissingPackageHandler handles the case where a package is missing during scanning.
@@ -82,7 +82,7 @@
 	Handler      MissingPackageHandler
 	basedir      string
 	VendorDir    string
-	BuildContext build.Context
+	BuildContext *util.BuildCtxt
 	seen         map[string]bool
 
 	// Items already in the queue.
@@ -108,11 +108,16 @@
 	}
 	vdir := filepath.Join(basedir, "vendor")
 
+	buildContext, err := util.GetBuildContext()
+	if err != nil {
+		return nil, err
+	}
+
 	r := &Resolver{
 		Handler:      &DefaultMissingPackageHandler{Missing: []string{}, Gopath: []string{}},
 		basedir:      basedir,
 		VendorDir:    vdir,
-		BuildContext: build.Default,
+		BuildContext: buildContext,
 		seen:         map[string]bool{},
 		alreadyQ:     map[string]bool{},
 		findCache:    map[string]*PkgInfo{},
diff --git a/util/util.go b/util/util.go
index dd624b2..fb8267a 100644
--- a/util/util.go
+++ b/util/util.go
@@ -3,9 +3,12 @@
 import (
 	"encoding/xml"
 	"fmt"
+	"go/build"
 	"io"
 	"net/http"
 	"net/url"
+	"os"
+	"os/exec"
 	"regexp"
 	"strings"
 
@@ -218,3 +221,25 @@
 		pattern: `^(?P<rootpkg>(?P<repo>([a-z0-9.\-]+\.)+[a-z0-9.\-]+(:[0-9]+)?/[A-Za-z0-9_.\-/]*?)\.(bzr|git|hg|svn))(/[A-Za-z0-9_.\-]+)*$`,
 	},
 }
+
+// BuildCtxt is a convenience wrapper for not having to import go/build
+// anywhere else
+type BuildCtxt struct {
+	build.Context
+}
+
+// GetBuildContext returns a build context from go/build. When the $GOROOT
+// variable is not set in the users environment it sets the context's root
+// path to the path returned by 'go env GOROOT'.
+func GetBuildContext() (*BuildCtxt, error) {
+	buildContext := &BuildCtxt{build.Default}
+	if goRoot := os.Getenv("GOROOT"); len(goRoot) == 0 {
+		out, err := exec.Command("go", "env", "GOROOT").Output()
+		if goRoot = strings.TrimSpace(string(out)); len(goRoot) == 0 || err != nil {
+			return nil, fmt.Errorf("Please set the $GOROOT environment " +
+				"variable to use this command\n")
+		}
+		buildContext.GOROOT = goRoot
+	}
+	return buildContext, nil
+}