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.go84
1 files changed, 47 insertions, 37 deletions
diff --git a/libgo/go/go/build/build.go b/libgo/go/go/build/build.go
index e9247274b6e..42f11655b39 100644
--- a/libgo/go/go/build/build.go
+++ b/libgo/go/go/build/build.go
@@ -256,10 +256,12 @@ 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,
- "dragonfly/386": true,
+ "darwin/arm": true,
+ "darwin/arm64": true,
"dragonfly/amd64": true,
"freebsd/386": true,
"freebsd/amd64": true,
@@ -282,6 +284,7 @@ var cgoEnabled = map[string]bool{
"netbsd/arm": true,
"openbsd/386": true,
"openbsd/amd64": true,
+ "solaris/amd64": true,
"windows/386": true,
"windows/amd64": true,
}
@@ -300,11 +303,7 @@ 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".
- //
- // When we reach Go 1.5 the line will read
- // c.ReleaseTags = []string{"go1.1", "go1.2", "go1.3", "go1.4", "go1.5"}
- // and so on.
- c.ReleaseTags = []string{"go1.1", "go1.2", "go1.3", "go1.4"}
+ c.ReleaseTags = []string{"go1.1", "go1.2", "go1.3", "go1.4", "go1.5"}
switch os.Getenv("CGO_ENABLED") {
case "1":
@@ -361,6 +360,7 @@ type Package struct {
Root string // root of Go tree where this package lives
SrcRoot string // package source root directory ("" if unknown)
PkgRoot string // package install root directory ("" if unknown)
+ PkgTargetRoot string // architecture dependent install root directory ("" if unknown)
BinDir string // command install directory ("" if unknown)
Goroot bool // package found in Go root
PkgObj string // installed .a file
@@ -469,18 +469,21 @@ func (ctxt *Context) Import(path string, srcDir string, mode ImportMode) (*Packa
return p, fmt.Errorf("import %q: invalid import path", path)
}
+ var pkgtargetroot string
var pkga string
var pkgerr error
+ suffix := ""
+ if ctxt.InstallSuffix != "" {
+ suffix = "_" + ctxt.InstallSuffix
+ }
switch ctxt.Compiler {
case "gccgo":
+ pkgtargetroot = "pkg/gccgo_" + ctxt.GOOS + "_" + ctxt.GOARCH + suffix
dir, elem := pathpkg.Split(p.ImportPath)
- pkga = "pkg/gccgo_" + ctxt.GOOS + "_" + ctxt.GOARCH + "/" + dir + "lib" + elem + ".a"
+ pkga = pkgtargetroot + "/" + dir + "lib" + elem + ".a"
case "gc":
- suffix := ""
- if ctxt.InstallSuffix != "" {
- suffix = "_" + ctxt.InstallSuffix
- }
- pkga = "pkg/" + ctxt.GOOS + "_" + ctxt.GOARCH + suffix + "/" + p.ImportPath + ".a"
+ pkgtargetroot = "pkg/" + ctxt.GOOS + "_" + ctxt.GOARCH + suffix
+ pkga = pkgtargetroot + "/" + p.ImportPath + ".a"
default:
// Save error for end of function.
pkgerr = fmt.Errorf("import %q: unknown compiler %q", path, ctxt.Compiler)
@@ -496,9 +499,13 @@ func (ctxt *Context) Import(path string, srcDir string, mode ImportMode) (*Packa
p.Dir = ctxt.joinPath(srcDir, path)
}
// Determine canonical import path, if any.
+ // Exclude results where the import path would include /testdata/.
+ inTestdata := func(sub string) bool {
+ return strings.Contains(sub, "/testdata/") || strings.HasSuffix(sub, "/testdata") || strings.HasPrefix(sub, "testdata/") || sub == "testdata"
+ }
if ctxt.GOROOT != "" {
root := ctxt.joinPath(ctxt.GOROOT, "src")
- if sub, ok := ctxt.hasSubdir(root, p.Dir); ok {
+ if sub, ok := ctxt.hasSubdir(root, p.Dir); ok && !inTestdata(sub) {
p.Goroot = true
p.ImportPath = sub
p.Root = ctxt.GOROOT
@@ -508,7 +515,7 @@ func (ctxt *Context) Import(path string, srcDir string, mode ImportMode) (*Packa
all := ctxt.gopath()
for i, root := range all {
rootsrc := ctxt.joinPath(root, "src")
- if sub, ok := ctxt.hasSubdir(rootsrc, p.Dir); ok {
+ if sub, ok := ctxt.hasSubdir(rootsrc, p.Dir); ok && !inTestdata(sub) {
// We found a potential import path for dir,
// but check that using it wouldn't find something
// else first.
@@ -597,6 +604,7 @@ Found:
p.PkgRoot = ctxt.joinPath(p.Root, "pkg")
p.BinDir = ctxt.joinPath(p.Root, "bin")
if pkga != "" {
+ p.PkgTargetRoot = ctxt.joinPath(p.Root, pkgtargetroot)
p.PkgObj = ctxt.joinPath(p.Root, pkga)
}
}
@@ -695,7 +703,11 @@ Found:
p.Name = pkg
firstFile = name
} else if pkg != p.Name {
- return p, &MultiplePackageError{p.Dir, []string{firstFile, name}, []string{p.Name, pkg}}
+ return p, &MultiplePackageError{
+ Dir: p.Dir,
+ Packages: []string{p.Name, pkg},
+ Files: []string{firstFile, name},
+ }
}
if pf.Doc != nil && p.Doc == "" {
p.Doc = doc.Synopsis(pf.Doc.Text())
@@ -962,7 +974,7 @@ func (ctxt *Context) matchFile(dir, name string, returnImports bool, allTags map
}
if strings.HasSuffix(filename, ".go") {
- data, err = readImports(f, false)
+ data, err = readImports(f, false, nil)
} else {
data, err = readComments(f)
}
@@ -1075,9 +1087,6 @@ func (ctxt *Context) shouldBuild(content []byte, allTags map[string]bool) bool {
// saveCgo saves the information from the #cgo lines in the import "C" comment.
// These lines set CFLAGS, CPPFLAGS, CXXFLAGS and LDFLAGS and pkg-config directives
// that affect the way cgo's C code is built.
-//
-// TODO(rsc): This duplicates code in cgo.
-// Once the dust settles, remove this code from cgo.
func (ctxt *Context) saveCgo(filename string, di *Package, cg *ast.CommentGroup) error {
text := cg.Text()
for _, line := range strings.Split(text, "\n") {
@@ -1123,10 +1132,12 @@ func (ctxt *Context) saveCgo(filename string, di *Package, cg *ast.CommentGroup)
if err != nil {
return fmt.Errorf("%s: invalid #cgo line: %s", filename, orig)
}
- for _, arg := range args {
+ for i, arg := range args {
+ arg = expandSrcDir(arg, di.Dir)
if !safeCgoName(arg) {
return fmt.Errorf("%s: malformed #cgo argument: %s", filename, arg)
}
+ args[i] = arg
}
switch verb {
@@ -1147,6 +1158,14 @@ func (ctxt *Context) saveCgo(filename string, di *Package, cg *ast.CommentGroup)
return nil
}
+func expandSrcDir(str string, srcdir string) string {
+ // "\" delimited paths cause safeCgoName to fail
+ // so convert native paths with a different delimeter
+ // to "/" before starting (eg: on windows)
+ srcdir = filepath.ToSlash(srcdir)
+ return strings.Replace(str, "${SRCDIR}", srcdir, -1)
+}
+
// NOTE: $ is not safe for the shell, but it is allowed here because of linker options like -Wl,$ORIGIN.
// 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.
@@ -1225,7 +1244,7 @@ func splitQuoted(s string) (r []string, err error) {
return args, err
}
-// match returns true if the name is one of:
+// match reports whether the name is one of:
//
// $GOOS
// $GOARCH
@@ -1316,7 +1335,7 @@ func (ctxt *Context) goodOSArchFile(name string, allTags map[string]bool) bool {
// build tag "linux" in that file. For Go 1.4 and beyond, we require this
// auto-tagging to apply only to files with a non-empty prefix, so
// "foo_linux.go" is tagged but "linux.go" is not. This allows new operating
- // sytems, such as android, to arrive without breaking existing code with
+ // systems, such as android, to arrive without breaking existing code with
// innocuous source code in "android.go". The easiest fix: cut everything
// in the name before the initial _.
i := strings.Index(name, "_")
@@ -1390,20 +1409,11 @@ func IsLocalImport(path string) bool {
strings.HasPrefix(path, "./") || strings.HasPrefix(path, "../")
}
-// ArchChar returns the architecture character for the given goarch.
-// For example, ArchChar("amd64") returns "6".
+// ArchChar returns "?" and an error.
+// In earlier versions of Go, the returned string was used to derive
+// the compiler and linker tool names, the default object file suffix,
+// and the default linker output name. As of Go 1.5, those strings
+// no longer vary by architecture; they are compile, link, .o, and a.out, respectively.
func ArchChar(goarch string) (string, error) {
- switch goarch {
- case "386":
- return "8", nil
- case "amd64", "amd64p32":
- return "6", nil
- case "arm":
- return "5", nil
- case "arm64":
- return "7", nil
- case "ppc64", "ppc64le":
- return "9", nil
- }
- return "", errors.New("unsupported GOARCH " + goarch)
+ return "?", errors.New("architecture letter no longer used")
}