Commit 492aad6d authored by Tim Hockin's avatar Tim Hockin

update third_party go/build to go1.6

parent 9a83015e
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
package build package build
import ( import (
"internal/testenv"
"io" "io"
"os" "os"
"path/filepath" "path/filepath"
...@@ -109,7 +110,6 @@ func TestMultiplePackageImport(t *testing.T) { ...@@ -109,7 +110,6 @@ func TestMultiplePackageImport(t *testing.T) {
} }
func TestLocalDirectory(t *testing.T) { func TestLocalDirectory(t *testing.T) {
return // go1.3 not happy with this test.
if runtime.GOOS == "darwin" { if runtime.GOOS == "darwin" {
switch runtime.GOARCH { switch runtime.GOARCH {
case "arm", "arm64": case "arm", "arm64":
...@@ -126,8 +126,8 @@ func TestLocalDirectory(t *testing.T) { ...@@ -126,8 +126,8 @@ func TestLocalDirectory(t *testing.T) {
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
if p.ImportPath != "k8s.io/kubernetes/third_party/golang/go/build" { if p.ImportPath != "go/build" {
t.Fatalf("ImportPath=%q, want %q", p.ImportPath, "k8s.io/kubernetes/third_party/golang/go/build") t.Fatalf("ImportPath=%q, want %q", p.ImportPath, "go/build")
} }
} }
...@@ -231,7 +231,6 @@ func TestMatchFile(t *testing.T) { ...@@ -231,7 +231,6 @@ func TestMatchFile(t *testing.T) {
} }
func TestImportCmd(t *testing.T) { func TestImportCmd(t *testing.T) {
return // go1.3 not happy with this test
if runtime.GOOS == "darwin" { if runtime.GOOS == "darwin" {
switch runtime.GOARCH { switch runtime.GOARCH {
case "arm", "arm64": case "arm", "arm64":
...@@ -269,7 +268,7 @@ var expandSrcDirTests = []struct { ...@@ -269,7 +268,7 @@ var expandSrcDirTests = []struct {
func TestExpandSrcDir(t *testing.T) { func TestExpandSrcDir(t *testing.T) {
for _, test := range expandSrcDirTests { for _, test := range expandSrcDirTests {
output := expandSrcDir(test.input, expandSrcDirPath) output, _ := expandSrcDir(test.input, expandSrcDirPath)
if output != test.expected { if output != test.expected {
t.Errorf("%q expands to %q with SRCDIR=%q when %q is expected", test.input, output, expandSrcDirPath, test.expected) t.Errorf("%q expands to %q with SRCDIR=%q when %q is expected", test.input, output, expandSrcDirPath, test.expected)
} else { } else {
...@@ -277,3 +276,73 @@ func TestExpandSrcDir(t *testing.T) { ...@@ -277,3 +276,73 @@ func TestExpandSrcDir(t *testing.T) {
} }
} }
} }
func TestShellSafety(t *testing.T) {
tests := []struct {
input, srcdir, expected string
result bool
}{
{"-I${SRCDIR}/../include", "/projects/src/issue 11868", "-I/projects/src/issue 11868/../include", true},
{"-X${SRCDIR}/1,${SRCDIR}/2", "/projects/src/issue 11868", "-X/projects/src/issue 11868/1,/projects/src/issue 11868/2", true},
{"-I/tmp -I/tmp", "/tmp2", "-I/tmp -I/tmp", false},
{"-I/tmp", "/tmp/[0]", "-I/tmp", true},
{"-I${SRCDIR}/dir", "/tmp/[0]", "-I/tmp/[0]/dir", false},
}
for _, test := range tests {
output, ok := expandSrcDir(test.input, test.srcdir)
if ok != test.result {
t.Errorf("Expected %t while %q expands to %q with SRCDIR=%q; got %t", test.result, test.input, output, test.srcdir, ok)
}
if output != test.expected {
t.Errorf("Expected %q while %q expands with SRCDIR=%q; got %q", test.expected, test.input, test.srcdir, output)
}
}
}
func TestImportVendor(t *testing.T) {
t.Skip("skipping; hpack has moved to internal for now; golang.org/issue/14047")
testenv.MustHaveGoBuild(t) // really must just have source
ctxt := Default
ctxt.GOPATH = ""
p, err := ctxt.Import("golang.org/x/net/http2/hpack", filepath.Join(ctxt.GOROOT, "src/net/http"), 0)
if err != nil {
t.Fatalf("cannot find vendored golang.org/x/net/http2/hpack from net/http directory: %v", err)
}
want := "vendor/golang.org/x/net/http2/hpack"
if p.ImportPath != want {
t.Fatalf("Import succeeded but found %q, want %q", p.ImportPath, want)
}
}
func TestImportVendorFailure(t *testing.T) {
testenv.MustHaveGoBuild(t) // really must just have source
ctxt := Default
ctxt.GOPATH = ""
p, err := ctxt.Import("x.com/y/z", filepath.Join(ctxt.GOROOT, "src/net/http"), 0)
if err == nil {
t.Fatalf("found made-up package x.com/y/z in %s", p.Dir)
}
e := err.Error()
if !strings.Contains(e, " (vendor tree)") {
t.Fatalf("error on failed import does not mention GOROOT/src/vendor directory:\n%s", e)
}
}
func TestImportVendorParentFailure(t *testing.T) {
testenv.MustHaveGoBuild(t) // really must just have source
ctxt := Default
ctxt.GOPATH = ""
// This import should fail because the vendor/golang.org/x/net/http2 directory has no source code.
p, err := ctxt.Import("golang.org/x/net/http2", filepath.Join(ctxt.GOROOT, "src/net/http"), 0)
if err == nil {
t.Fatalf("found empty parent in %s", p.Dir)
}
if p != nil && p.Dir != "" {
t.Fatalf("decided to use %s", p.Dir)
}
e := err.Error()
if !strings.Contains(e, " (vendor tree)") {
t.Fatalf("error on failed import does not mention GOROOT/src/vendor directory:\n%s", e)
}
}
...@@ -34,17 +34,21 @@ import ( ...@@ -34,17 +34,21 @@ import (
// //
var pkgDeps = map[string][]string{ var pkgDeps = map[string][]string{
// L0 is the lowest level, core, nearly unavoidable packages. // L0 is the lowest level, core, nearly unavoidable packages.
"errors": {}, "errors": {},
"io": {"errors", "sync"}, "io": {"errors", "sync"},
"runtime": {"unsafe"}, "runtime": {"unsafe", "runtime/internal/atomic", "runtime/internal/sys"},
"sync": {"runtime", "sync/atomic", "unsafe"}, "runtime/internal/sys": {},
"sync/atomic": {"unsafe"}, "runtime/internal/atomic": {"unsafe", "runtime/internal/sys"},
"unsafe": {}, "internal/race": {"runtime", "unsafe"},
"sync": {"internal/race", "runtime", "sync/atomic", "unsafe"},
"sync/atomic": {"unsafe"},
"unsafe": {},
"L0": { "L0": {
"errors", "errors",
"io", "io",
"runtime", "runtime",
"runtime/internal/atomic",
"sync", "sync",
"sync/atomic", "sync/atomic",
"unsafe", "unsafe",
...@@ -128,17 +132,16 @@ var pkgDeps = map[string][]string{ ...@@ -128,17 +132,16 @@ var pkgDeps = map[string][]string{
// End of linear dependency definitions. // End of linear dependency definitions.
// Operating system access. // Operating system access.
"syscall": {"L0", "unicode/utf16"}, "syscall": {"L0", "internal/race", "internal/syscall/windows/sysdll", "unicode/utf16"},
"internal/syscall/unix": {"L0", "syscall"}, "internal/syscall/unix": {"L0", "syscall"},
"internal/syscall/windows": {"L0", "syscall"}, "internal/syscall/windows": {"L0", "syscall", "internal/syscall/windows/sysdll"},
"internal/syscall/windows/registry": {"L0", "syscall", "unicode/utf16"}, "internal/syscall/windows/registry": {"L0", "syscall", "internal/syscall/windows/sysdll", "unicode/utf16"},
"time": {"L0", "syscall", "internal/syscall/windows/registry"}, "time": {"L0", "syscall", "internal/syscall/windows/registry"},
"os": {"L1", "os", "syscall", "time", "internal/syscall/windows"}, "os": {"L1", "os", "syscall", "time", "internal/syscall/windows"},
"path/filepath": {"L2", "os", "syscall"}, "path/filepath": {"L2", "os", "syscall"},
"io/ioutil": {"L2", "os", "path/filepath", "time"}, "io/ioutil": {"L2", "os", "path/filepath", "time"},
"os/exec": {"L2", "os", "path/filepath", "syscall"}, "os/exec": {"L2", "os", "path/filepath", "syscall"},
"os/signal": {"L2", "os", "syscall"}, "os/signal": {"L2", "os", "syscall"},
"internal/syscall": {"L2", "runtime", "syscall", "sync/atomic", "unsafe"},
// OS enables basic operating system functionality, // OS enables basic operating system functionality,
// but not direct use of package syscall, nor os/signal. // but not direct use of package syscall, nor os/signal.
...@@ -162,7 +165,7 @@ var pkgDeps = map[string][]string{ ...@@ -162,7 +165,7 @@ var pkgDeps = map[string][]string{
"runtime/trace": {"L0"}, "runtime/trace": {"L0"},
"text/tabwriter": {"L2"}, "text/tabwriter": {"L2"},
"testing": {"L2", "flag", "fmt", "os", "runtime/pprof", "runtime/trace", "time"}, "testing": {"L2", "flag", "fmt", "os", "runtime/debug", "runtime/pprof", "runtime/trace", "time"},
"testing/iotest": {"L2", "log"}, "testing/iotest": {"L2", "log"},
"testing/quick": {"L2", "flag", "fmt", "reflect"}, "testing/quick": {"L2", "flag", "fmt", "reflect"},
"internal/testenv": {"L2", "os", "testing"}, "internal/testenv": {"L2", "os", "testing"},
...@@ -215,7 +218,7 @@ var pkgDeps = map[string][]string{ ...@@ -215,7 +218,7 @@ var pkgDeps = map[string][]string{
"database/sql": {"L4", "container/list", "database/sql/driver"}, "database/sql": {"L4", "container/list", "database/sql/driver"},
"database/sql/driver": {"L4", "time"}, "database/sql/driver": {"L4", "time"},
"debug/dwarf": {"L4"}, "debug/dwarf": {"L4"},
"debug/elf": {"L4", "OS", "debug/dwarf"}, "debug/elf": {"L4", "OS", "debug/dwarf", "compress/zlib"},
"debug/gosym": {"L4"}, "debug/gosym": {"L4"},
"debug/macho": {"L4", "OS", "debug/dwarf"}, "debug/macho": {"L4", "OS", "debug/dwarf"},
"debug/pe": {"L4", "OS", "debug/dwarf"}, "debug/pe": {"L4", "OS", "debug/dwarf"},
...@@ -257,6 +260,8 @@ var pkgDeps = map[string][]string{ ...@@ -257,6 +260,8 @@ var pkgDeps = map[string][]string{
}, },
// Cgo. // Cgo.
// If you add a dependency on CGO, you must add the package to
// cgoPackages in cmd/dist/test.go.
"runtime/cgo": {"L0", "C"}, "runtime/cgo": {"L0", "C"},
"CGO": {"C", "runtime/cgo"}, "CGO": {"C", "runtime/cgo"},
...@@ -264,16 +269,17 @@ var pkgDeps = map[string][]string{ ...@@ -264,16 +269,17 @@ var pkgDeps = map[string][]string{
// that shows up in programs that use cgo. // that shows up in programs that use cgo.
"C": {}, "C": {},
// Race detector uses cgo. // Race detector/MSan uses cgo.
"runtime/race": {"C"}, "runtime/race": {"C"},
"runtime/msan": {"C"},
// Plan 9 alone needs io/ioutil and os. // Plan 9 alone needs io/ioutil and os.
"os/user": {"L4", "CGO", "io/ioutil", "os", "syscall"}, "os/user": {"L4", "CGO", "io/ioutil", "os", "syscall"},
// Basic networking. // Basic networking.
// Because net must be used by any package that wants to // Because net must be used by any package that wants to
// do networking portably, it must have a small dependency set: just L1+basic os. // do networking portably, it must have a small dependency set: just L0+basic os.
"net": {"L1", "CGO", "os", "syscall", "time", "internal/syscall/windows", "internal/singleflight"}, "net": {"L0", "CGO", "math/rand", "os", "sort", "syscall", "time", "internal/syscall/windows", "internal/singleflight", "internal/race"},
// NET enables use of basic network-related packages. // NET enables use of basic network-related packages.
"NET": { "NET": {
...@@ -312,7 +318,7 @@ var pkgDeps = map[string][]string{ ...@@ -312,7 +318,7 @@ var pkgDeps = map[string][]string{
// Random byte, number generation. // Random byte, number generation.
// This would be part of core crypto except that it imports // This would be part of core crypto except that it imports
// math/big, which imports fmt. // math/big, which imports fmt.
"crypto/rand": {"L4", "CRYPTO", "OS", "math/big", "syscall", "internal/syscall/unix", "internal/syscall"}, "crypto/rand": {"L4", "CRYPTO", "OS", "math/big", "syscall", "internal/syscall/unix"},
// Mathematical crypto: dependencies on fmt (L4) and math/big. // Mathematical crypto: dependencies on fmt (L4) and math/big.
// We could avoid some of the fmt, but math/big imports fmt anyway. // We could avoid some of the fmt, but math/big imports fmt anyway.
...@@ -334,7 +340,7 @@ var pkgDeps = map[string][]string{ ...@@ -334,7 +340,7 @@ var pkgDeps = map[string][]string{
// SSL/TLS. // SSL/TLS.
"crypto/tls": { "crypto/tls": {
"L4", "CRYPTO-MATH", "CGO", "OS", "L4", "CRYPTO-MATH", "OS",
"container/list", "crypto/x509", "encoding/pem", "net", "syscall", "container/list", "crypto/x509", "encoding/pem", "net", "syscall",
}, },
"crypto/x509": { "crypto/x509": {
...@@ -352,6 +358,7 @@ var pkgDeps = map[string][]string{ ...@@ -352,6 +358,7 @@ var pkgDeps = map[string][]string{
"L4", "NET", "OS", "L4", "NET", "OS",
"compress/gzip", "crypto/tls", "mime/multipart", "runtime/debug", "compress/gzip", "crypto/tls", "mime/multipart", "runtime/debug",
"net/http/internal", "net/http/internal",
"internal/golang.org/x/net/http2/hpack",
}, },
"net/http/internal": {"L4"}, "net/http/internal": {"L4"},
...@@ -360,7 +367,7 @@ var pkgDeps = map[string][]string{ ...@@ -360,7 +367,7 @@ var pkgDeps = map[string][]string{
"net/http/cgi": {"L4", "NET", "OS", "crypto/tls", "net/http", "regexp"}, "net/http/cgi": {"L4", "NET", "OS", "crypto/tls", "net/http", "regexp"},
"net/http/cookiejar": {"L4", "NET", "net/http"}, "net/http/cookiejar": {"L4", "NET", "net/http"},
"net/http/fcgi": {"L4", "NET", "OS", "net/http", "net/http/cgi"}, "net/http/fcgi": {"L4", "NET", "OS", "net/http", "net/http/cgi"},
"net/http/httptest": {"L4", "NET", "OS", "crypto/tls", "flag", "net/http"}, "net/http/httptest": {"L4", "NET", "OS", "crypto/tls", "flag", "net/http", "net/http/internal"},
"net/http/httputil": {"L4", "NET", "OS", "net/http", "net/http/internal"}, "net/http/httputil": {"L4", "NET", "OS", "net/http", "net/http/internal"},
"net/http/pprof": {"L4", "OS", "html/template", "net/http", "runtime/pprof", "runtime/trace"}, "net/http/pprof": {"L4", "OS", "html/template", "net/http", "runtime/pprof", "runtime/trace"},
"net/rpc": {"L4", "NET", "encoding/gob", "html/template", "net/http"}, "net/rpc": {"L4", "NET", "encoding/gob", "html/template", "net/http"},
...@@ -441,7 +448,6 @@ func listStdPkgs(goroot string) ([]string, error) { ...@@ -441,7 +448,6 @@ func listStdPkgs(goroot string) ([]string, error) {
} }
func TestDependencies(t *testing.T) { func TestDependencies(t *testing.T) {
return // go1.3 is really not happy with this test
iOS := runtime.GOOS == "darwin" && (runtime.GOARCH == "arm" || runtime.GOARCH == "arm64") iOS := runtime.GOOS == "darwin" && (runtime.GOARCH == "arm" || runtime.GOARCH == "arm64")
if runtime.GOOS == "nacl" || iOS { if runtime.GOOS == "nacl" || iOS {
// Tests run in a limited file system and we do not // Tests run in a limited file system and we do not
...@@ -456,26 +462,23 @@ func TestDependencies(t *testing.T) { ...@@ -456,26 +462,23 @@ func TestDependencies(t *testing.T) {
} }
sort.Strings(all) sort.Strings(all)
test := func(mustImport bool) { for _, pkg := range all {
for _, pkg := range all { imports, err := findImports(pkg)
imports, err := findImports(pkg) if err != nil {
if err != nil { t.Error(err)
t.Error(err) continue
continue }
} ok := allowed(pkg)
ok := allowed(pkg) var bad []string
var bad []string for _, imp := range imports {
for _, imp := range imports { if !ok[imp] {
if !ok[imp] { bad = append(bad, imp)
bad = append(bad, imp)
}
}
if bad != nil {
t.Errorf("unexpected dependency: %s imports %v", pkg, bad)
} }
} }
if bad != nil {
t.Errorf("unexpected dependency: %s imports %v", pkg, bad)
}
} }
test(true)
} }
var buildIgnore = []byte("\n// +build ignore") var buildIgnore = []byte("\n// +build ignore")
......
...@@ -102,6 +102,7 @@ ...@@ -102,6 +102,7 @@
// - "go1.3", from Go version 1.3 onward // - "go1.3", from Go version 1.3 onward
// - "go1.4", from Go version 1.4 onward // - "go1.4", from Go version 1.4 onward
// - "go1.5", from Go version 1.5 onward // - "go1.5", from Go version 1.5 onward
// - "go1.6", from Go version 1.6 onward
// - any additional words listed in ctxt.BuildTags // - any additional words listed in ctxt.BuildTags
// //
// If a file's name, after stripping the extension and a possible _test suffix, // If a file's name, after stripping the extension and a possible _test suffix,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment