summaryrefslogtreecommitdiff
path: root/libgo/go/go/build/build.go
diff options
context:
space:
mode:
Diffstat (limited to 'libgo/go/go/build/build.go')
-rw-r--r--libgo/go/go/build/build.go96
1 files changed, 49 insertions, 47 deletions
diff --git a/libgo/go/go/build/build.go b/libgo/go/go/build/build.go
index 78e95c14880..cb053ebbed2 100644
--- a/libgo/go/go/build/build.go
+++ b/libgo/go/go/build/build.go
@@ -76,8 +76,9 @@ type Context struct {
// If IsDir is nil, Import calls os.Stat and uses the result's IsDir method.
IsDir func(path string) bool
- // HasSubdir reports whether dir is a subdirectory of
- // (perhaps multiple levels below) root.
+ // HasSubdir reports whether dir is lexically a subdirectory of
+ // root, perhaps multiple levels below. It does not try to check
+ // whether dir exists.
// If so, HasSubdir sets rel to a slash-separated path that
// can be joined to root to produce a path equivalent to dir.
// If HasSubdir is nil, Import uses an implementation built on
@@ -256,37 +257,23 @@ func (ctxt *Context) SrcDirs() []string {
// if set, or else the compiled code's GOARCH, GOOS, and GOROOT.
var Default Context = defaultContext()
-// Also known to cmd/dist/build.go.
-var cgoEnabled = map[string]bool{
- "darwin/386": true,
- "darwin/amd64": true,
- "darwin/arm": true,
- "darwin/arm64": true,
- "dragonfly/amd64": true,
- "freebsd/386": true,
- "freebsd/amd64": true,
- "freebsd/arm": true,
- "linux/386": true,
- "linux/alpha": true,
- "linux/amd64": true,
- "linux/arm": true,
- "linux/arm64": true,
- "linux/ppc": true,
- "linux/ppc64": true,
- "linux/ppc64le": true,
- "linux/s390": true,
- "linux/s390x": true,
- "android/386": true,
- "android/amd64": true,
- "android/arm": true,
- "netbsd/386": true,
- "netbsd/amd64": true,
- "netbsd/arm": true,
- "openbsd/386": true,
- "openbsd/amd64": true,
- "solaris/amd64": true,
- "windows/386": true,
- "windows/amd64": true,
+func defaultGOPATH() string {
+ env := "HOME"
+ if runtime.GOOS == "windows" {
+ env = "USERPROFILE"
+ } else if runtime.GOOS == "plan9" {
+ env = "home"
+ }
+ if home := os.Getenv(env); home != "" {
+ def := filepath.Join(home, "go")
+ if def == runtime.GOROOT() {
+ // Don't set the default GOPATH to GOROOT,
+ // as that will trigger warnings from the go tool.
+ return ""
+ }
+ return def
+ }
+ return ""
}
func defaultContext() Context {
@@ -295,7 +282,7 @@ func defaultContext() Context {
c.GOARCH = envOr("GOARCH", runtime.GOARCH)
c.GOOS = envOr("GOOS", runtime.GOOS)
c.GOROOT = pathpkg.Clean(runtime.GOROOT())
- c.GOPATH = envOr("GOPATH", "")
+ c.GOPATH = envOr("GOPATH", defaultGOPATH())
c.Compiler = runtime.Compiler
// Each major Go release in the Go 1.x series should add a tag here.
@@ -303,9 +290,14 @@ func defaultContext() Context {
// in all releases >= Go 1.x. Code that requires Go 1.x or later should
// say "+build go1.x", and code that should only be built before Go 1.x
// (perhaps it is the stub to use in that case) should say "+build !go1.x".
- c.ReleaseTags = []string{"go1.1", "go1.2", "go1.3", "go1.4", "go1.5", "go1.6", "go1.7"}
-
- switch os.Getenv("CGO_ENABLED") {
+ c.ReleaseTags = []string{"go1.1", "go1.2", "go1.3", "go1.4", "go1.5", "go1.6", "go1.7", "go1.8"}
+
+ env := os.Getenv("CGO_ENABLED")
+ // No defaultCGO_ENABLED in gccgo.
+ // if env == "" {
+ // env = defaultCGO_ENABLED
+ // }
+ switch env {
case "1":
c.CgoEnabled = true
case "0":
@@ -313,7 +305,8 @@ func defaultContext() Context {
default:
// cgo must be explicitly enabled for cross compilation builds
if runtime.GOARCH == c.GOARCH && runtime.GOOS == c.GOOS {
- c.CgoEnabled = cgoEnabled[c.GOOS+"/"+c.GOARCH]
+ // Always enabled for gccgo.
+ c.CgoEnabled = true
break
}
c.CgoEnabled = false
@@ -369,6 +362,11 @@ const (
// See golang.org/s/go15vendor for more information.
//
// Setting IgnoreVendor ignores vendor directories.
+ //
+ // In contrast to the package's ImportPath,
+ // the returned package's Imports, TestImports, and XTestImports
+ // are always the exact import paths from the source files:
+ // Import makes no attempt to resolve or check those paths.
IgnoreVendor
)
@@ -414,15 +412,15 @@ type Package struct {
CgoPkgConfig []string // Cgo pkg-config directives
// Dependency information
- Imports []string // imports from GoFiles, CgoFiles
+ Imports []string // import paths from GoFiles, CgoFiles
ImportPos map[string][]token.Position // line information for Imports
// Test information
TestGoFiles []string // _test.go files in package
- TestImports []string // imports from TestGoFiles
+ TestImports []string // import paths from TestGoFiles
TestImportPos map[string][]token.Position // line information for TestImports
XTestGoFiles []string // _test.go files outside package
- XTestImports []string // imports from XTestGoFiles
+ XTestImports []string // import paths from XTestGoFiles
XTestImportPos map[string][]token.Position // line information for XTestImports
}
@@ -669,7 +667,7 @@ func (ctxt *Context) Import(path string, srcDir string, mode ImportMode) (*Packa
format = "\t%s"
}
if len(tried.gopath) == 0 {
- paths = append(paths, "\t($GOPATH not set)")
+ paths = append(paths, "\t($GOPATH not set. For more details see: 'go help gopath')")
}
return p, fmt.Errorf("cannot find package %q in any of:\n%s", path, strings.Join(paths, "\n"))
}
@@ -1096,10 +1094,14 @@ func (ctxt *Context) matchFile(dir, name string, returnImports bool, allTags map
}
// Look for +build comments to accept or reject the file.
- if !ctxt.shouldBuild(data, allTags, binaryOnly) && !ctxt.UseAllFiles {
+ var sawBinaryOnly bool
+ if !ctxt.shouldBuild(data, allTags, &sawBinaryOnly) && !ctxt.UseAllFiles {
return
}
+ if binaryOnly != nil && sawBinaryOnly {
+ *binaryOnly = true
+ }
match = true
return
}
@@ -1143,9 +1145,8 @@ var binaryOnlyComment = []byte("//go:binary-only-package")
//
// marks the file as applicable only on Windows and Linux.
//
-// If shouldBuild finds a //go:binary-only-package comment in a file that
-// should be built, it sets *binaryOnly to true. Otherwise it does
-// not change *binaryOnly.
+// If shouldBuild finds a //go:binary-only-package comment in the file,
+// it sets *binaryOnly to true. Otherwise it does not change *binaryOnly.
//
func (ctxt *Context) shouldBuild(content []byte, allTags map[string]bool, binaryOnly *bool) bool {
sawBinaryOnly := false
@@ -1315,7 +1316,8 @@ func expandSrcDir(str string, srcdir string) (string, bool) {
// We never pass these arguments to a shell (just to programs we construct argv for), so this should be okay.
// See golang.org/issue/6038.
// The @ is for OS X. See golang.org/issue/13720.
-const safeString = "+-.,/0123456789=ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz:$@"
+// The % is for Jenkins. See golang.org/issue/16959.
+const safeString = "+-.,/0123456789=ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz:$@%"
const safeSpaces = " "
var safeBytes = []byte(safeSpaces + safeString)