Bumping k8s dependencies to 1.13

This commit is contained in:
Cheng Xing
2018-11-16 14:08:25 -08:00
parent 305407125c
commit b4c0b68ec7
8002 changed files with 884099 additions and 276228 deletions

View File

@@ -12,9 +12,86 @@ import (
"go/types"
"golang.org/x/tools/go/loader"
"golang.org/x/tools/go/packages"
"golang.org/x/tools/go/ssa"
)
// Packages creates an SSA program for a set of packages.
//
// The packages must have been loaded from source syntax using the
// golang.org/x/tools/go/packages.Load function in LoadSyntax or
// LoadAllSyntax mode.
//
// Packages creates an SSA package for each well-typed package in the
// initial list, plus all their dependencies. The resulting list of
// packages corresponds to the list of initial packages, and may contain
// a nil if SSA code could not be constructed for the corresponding initial
// package due to type errors.
//
// Code for bodies of functions is not built until Build is called on
// the resulting Program. SSA code is constructed only for the initial
// packages with well-typed syntax trees.
//
// The mode parameter controls diagnostics and checking during SSA construction.
//
func Packages(initial []*packages.Package, mode ssa.BuilderMode) (*ssa.Program, []*ssa.Package) {
return doPackages(initial, mode, false)
}
// AllPackages creates an SSA program for a set of packages plus all
// their dependencies.
//
// The packages must have been loaded from source syntax using the
// golang.org/x/tools/go/packages.Load function in LoadAllSyntax mode.
//
// AllPackages creates an SSA package for each well-typed package in the
// initial list, plus all their dependencies. The resulting list of
// packages corresponds to the list of intial packages, and may contain
// a nil if SSA code could not be constructed for the corresponding
// initial package due to type errors.
//
// Code for bodies of functions is not built until Build is called on
// the resulting Program. SSA code is constructed for all packages with
// well-typed syntax trees.
//
// The mode parameter controls diagnostics and checking during SSA construction.
//
func AllPackages(initial []*packages.Package, mode ssa.BuilderMode) (*ssa.Program, []*ssa.Package) {
return doPackages(initial, mode, true)
}
func doPackages(initial []*packages.Package, mode ssa.BuilderMode, deps bool) (*ssa.Program, []*ssa.Package) {
var fset *token.FileSet
if len(initial) > 0 {
fset = initial[0].Fset
}
prog := ssa.NewProgram(fset, mode)
isInitial := make(map[*packages.Package]bool, len(initial))
for _, p := range initial {
isInitial[p] = true
}
ssamap := make(map[*packages.Package]*ssa.Package)
packages.Visit(initial, nil, func(p *packages.Package) {
if p.Types != nil && !p.IllTyped {
var files []*ast.File
if deps || isInitial[p] {
files = p.Syntax
}
ssamap[p] = prog.CreatePackage(p.Types, files, p.TypesInfo, true)
}
})
var ssapkgs []*ssa.Package
for _, p := range initial {
ssapkgs = append(ssapkgs, ssamap[p]) // may be nil
}
return prog, ssapkgs
}
// CreateProgram returns a new program in SSA form, given a program
// loaded from source. An SSA package is created for each transitively
// error-free package of lprog.
@@ -22,7 +99,10 @@ import (
// Code for bodies of functions is not built until Build is called
// on the result.
//
// mode controls diagnostics and checking during SSA construction.
// The mode parameter controls diagnostics and checking during SSA construction.
//
// Deprecated: use golang.org/x/tools/go/packages and the Packages
// function instead; see ssa.ExampleLoadPackages.
//
func CreateProgram(lprog *loader.Program, mode ssa.BuilderMode) *ssa.Program {
prog := ssa.NewProgram(lprog.Fset, mode)

View File

@@ -5,14 +5,17 @@
package ssautil_test
import (
"bytes"
"go/ast"
"go/importer"
"go/parser"
"go/token"
"go/types"
"os"
"strings"
"testing"
"golang.org/x/tools/go/packages"
"golang.org/x/tools/go/ssa/ssautil"
)
@@ -49,6 +52,45 @@ func TestBuildPackage(t *testing.T) {
}
}
func TestPackages(t *testing.T) {
cfg := &packages.Config{Mode: packages.LoadSyntax}
initial, err := packages.Load(cfg, "bytes")
if err != nil {
t.Fatal(err)
}
if packages.PrintErrors(initial) > 0 {
t.Fatal("there were errors")
}
prog, pkgs := ssautil.Packages(initial, 0)
bytesNewBuffer := pkgs[0].Func("NewBuffer")
bytesNewBuffer.Pkg.Build()
// We'll dump the SSA of bytes.NewBuffer because it is small and stable.
out := new(bytes.Buffer)
bytesNewBuffer.WriteTo(out)
// For determinism, sanitize the location.
location := prog.Fset.Position(bytesNewBuffer.Pos()).String()
got := strings.Replace(out.String(), location, "$GOROOT/src/bytes/buffer.go:1", -1)
want := `
# Name: bytes.NewBuffer
# Package: bytes
# Location: $GOROOT/src/bytes/buffer.go:1
func NewBuffer(buf []byte) *Buffer:
0: entry P:0 S:0
t0 = new Buffer (complit) *Buffer
t1 = &t0.buf [#0] *[]byte
*t1 = buf
return t0
`[1:]
if got != want {
t.Errorf("bytes.NewBuffer SSA = <<%s>>, want <<%s>>", got, want)
}
}
func TestBuildPackage_MissingImport(t *testing.T) {
fset := token.NewFileSet()
f, err := parser.ParseFile(fset, "bad.go", `package bad; import "missing"`, 0)
@@ -62,3 +104,17 @@ func TestBuildPackage_MissingImport(t *testing.T) {
t.Fatal("BuildPackage succeeded unexpectedly")
}
}
func TestIssue28106(t *testing.T) {
// In go1.10, go/packages loads all packages from source, not
// export data, but does not type check function bodies of
// imported packages. This test ensures that we do not attempt
// to run the SSA builder on functions without type information.
cfg := &packages.Config{Mode: packages.LoadSyntax}
pkgs, err := packages.Load(cfg, "runtime")
if err != nil {
t.Fatal(err)
}
prog, _ := ssautil.Packages(pkgs, 0)
prog.Build() // no crash
}