mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-20 02:11:09 +00:00
Update srcimporter.go to golang/go@5f0a9ba
Also move to third_party/ as it's copied code.
This commit is contained in:
parent
31601caa8d
commit
8574c38f81
@ -17,7 +17,7 @@ go_library(
|
||||
srcs = ["main.go"],
|
||||
importpath = "k8s.io/kubernetes/test/typecheck",
|
||||
deps = [
|
||||
"//test/typecheck/srcimporter:go_default_library",
|
||||
"//third_party/go-srcimporter:go_default_library",
|
||||
"//vendor/golang.org/x/crypto/ssh/terminal:go_default_library",
|
||||
],
|
||||
)
|
||||
@ -31,10 +31,7 @@ filegroup(
|
||||
|
||||
filegroup(
|
||||
name = "all-srcs",
|
||||
srcs = [
|
||||
":package-srcs",
|
||||
"//test/typecheck/srcimporter:all-srcs",
|
||||
],
|
||||
srcs = [":package-srcs"],
|
||||
tags = ["automanaged"],
|
||||
)
|
||||
|
||||
|
@ -37,7 +37,7 @@ import (
|
||||
|
||||
"golang.org/x/crypto/ssh/terminal"
|
||||
|
||||
"k8s.io/kubernetes/test/typecheck/srcimporter"
|
||||
srcimporter "k8s.io/kubernetes/third_party/go-srcimporter"
|
||||
)
|
||||
|
||||
var (
|
||||
|
1
third_party/BUILD
vendored
1
third_party/BUILD
vendored
@ -26,6 +26,7 @@ filegroup(
|
||||
"//third_party/forked/golang/reflect:all-srcs",
|
||||
"//third_party/forked/golang/template:all-srcs",
|
||||
"//third_party/forked/gonum/graph:all-srcs",
|
||||
"//third_party/go-srcimporter:all-srcs",
|
||||
],
|
||||
tags = ["automanaged"],
|
||||
)
|
||||
|
@ -1,9 +1,11 @@
|
||||
load("@io_bazel_rules_go//go:def.bzl", "go_library")
|
||||
|
||||
licenses(["notice"])
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = ["srcimporter.go"],
|
||||
importpath = "k8s.io/kubernetes/test/typecheck/srcimporter",
|
||||
importpath = "k8s.io/kubernetes/third_party/go-srcimporter",
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
27
third_party/go-srcimporter/LICENSE
vendored
Normal file
27
third_party/go-srcimporter/LICENSE
vendored
Normal file
@ -0,0 +1,27 @@
|
||||
Copyright (c) 2009 The Go Authors. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are
|
||||
met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above
|
||||
copyright notice, this list of conditions and the following disclaimer
|
||||
in the documentation and/or other materials provided with the
|
||||
distribution.
|
||||
* Neither the name of Google Inc. nor the names of its
|
||||
contributors may be used to endorse or promote products derived from
|
||||
this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
6
third_party/go-srcimporter/OWNERS
vendored
Normal file
6
third_party/go-srcimporter/OWNERS
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
reviewers:
|
||||
- cblecker
|
||||
- rmmh
|
||||
approvers:
|
||||
- cblecker
|
||||
- rmmh
|
4
third_party/go-srcimporter/README.kubernetes
vendored
Normal file
4
third_party/go-srcimporter/README.kubernetes
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
Files copied from https://github.com/golang/go/blob/5f0a9ba1342674b3209c13035b5aa39a96dbd80c/src/go/internal/srcimporter/srcimporter.go at commit 5f0a9ba1342674b3209c13035b5aa39a96dbd80c.
|
||||
|
||||
Used in k8s.io/kubernetes/test/typecheck. Need to copy here, as it's marked as a go/internal library.
|
||||
Only modification is to remove the go/internal/srcimporter import alias.
|
@ -1,21 +1,3 @@
|
||||
/*
|
||||
Copyright 2018 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
// Forked from go's go/internal/srcimporter
|
||||
|
||||
// Copyright 2017 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
@ -31,6 +13,8 @@ import (
|
||||
"go/parser"
|
||||
"go/token"
|
||||
"go/types"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sync"
|
||||
)
|
||||
@ -43,7 +27,7 @@ type Importer struct {
|
||||
packages map[string]*types.Package
|
||||
}
|
||||
|
||||
// New returns a new Importer for the given context, file set, and map
|
||||
// NewImporter returns a new Importer for the given context, file set, and map
|
||||
// of packages. The context is used to resolve import paths to package paths,
|
||||
// and identifying the files belonging to the package. If the context provides
|
||||
// non-nil file system functions, they are used instead of the regular package
|
||||
@ -62,9 +46,9 @@ func New(ctxt *build.Context, fset *token.FileSet, packages map[string]*types.Pa
|
||||
// for a package that is in the process of being imported.
|
||||
var importing types.Package
|
||||
|
||||
// Import (path) is a shortcut for ImportFrom(path, "", 0).
|
||||
// Import(path) is a shortcut for ImportFrom(path, ".", 0).
|
||||
func (p *Importer) Import(path string) (*types.Package, error) {
|
||||
return p.ImportFrom(path, "", 0)
|
||||
return p.ImportFrom(path, ".", 0) // use "." rather than "" (see issue #24441)
|
||||
}
|
||||
|
||||
// ImportFrom imports the package with the given import path resolved from the given srcDir,
|
||||
@ -78,23 +62,10 @@ func (p *Importer) ImportFrom(path, srcDir string, mode types.ImportMode) (*type
|
||||
panic("non-zero import mode")
|
||||
}
|
||||
|
||||
// determine package path (do vendor resolution)
|
||||
var bp *build.Package
|
||||
var err error
|
||||
switch {
|
||||
default:
|
||||
if abs, err := p.absPath(srcDir); err == nil { // see issue #14282
|
||||
srcDir = abs
|
||||
}
|
||||
bp, err = p.ctxt.Import(path, srcDir, build.FindOnly)
|
||||
|
||||
case build.IsLocalImport(path):
|
||||
// "./x" -> "srcDir/x"
|
||||
bp, err = p.ctxt.ImportDir(filepath.Join(srcDir, path), build.FindOnly)
|
||||
|
||||
case p.isAbsPath(path):
|
||||
return nil, fmt.Errorf("invalid absolute import path %q", path)
|
||||
if abs, err := p.absPath(srcDir); err == nil { // see issue #14282
|
||||
srcDir = abs
|
||||
}
|
||||
bp, err := p.ctxt.Import(path, srcDir, 0)
|
||||
if err != nil {
|
||||
return nil, err // err may be *build.NoGoError - return as is
|
||||
}
|
||||
@ -131,11 +102,6 @@ func (p *Importer) ImportFrom(path, srcDir string, mode types.ImportMode) (*type
|
||||
}
|
||||
}()
|
||||
|
||||
// collect package files
|
||||
bp, err = p.ctxt.ImportDir(bp.Dir, 0)
|
||||
if err != nil {
|
||||
return nil, err // err may be *build.NoGoError - return as is
|
||||
}
|
||||
var filenames []string
|
||||
filenames = append(filenames, bp.GoFiles...)
|
||||
filenames = append(filenames, bp.CgoFiles...)
|
||||
@ -180,7 +146,11 @@ func (p *Importer) ImportFrom(path, srcDir string, mode types.ImportMode) (*type
|
||||
}
|
||||
|
||||
func (p *Importer) parseFiles(dir string, filenames []string) ([]*ast.File, error) {
|
||||
open := p.ctxt.OpenFile // possibly nil
|
||||
// use build.Context's OpenFile if there is one
|
||||
open := p.ctxt.OpenFile
|
||||
if open == nil {
|
||||
open = func(name string) (io.ReadCloser, error) { return os.Open(name) }
|
||||
}
|
||||
|
||||
files := make([]*ast.File, len(filenames))
|
||||
errors := make([]error, len(filenames))
|
||||
@ -190,22 +160,13 @@ func (p *Importer) parseFiles(dir string, filenames []string) ([]*ast.File, erro
|
||||
for i, filename := range filenames {
|
||||
go func(i int, filepath string) {
|
||||
defer wg.Done()
|
||||
if open != nil {
|
||||
src, err := open(filepath)
|
||||
if err != nil {
|
||||
errors[i] = fmt.Errorf("opening package file %s failed (%v)", filepath, err)
|
||||
return
|
||||
}
|
||||
files[i], errors[i] = parser.ParseFile(p.fset, filepath, src, 0)
|
||||
src.Close() // ignore Close error - parsing may have succeeded which is all we need
|
||||
} else {
|
||||
// Special-case when ctxt doesn't provide a custom OpenFile and use the
|
||||
// parser's file reading mechanism directly. This appears to be quite a
|
||||
// bit faster than opening the file and providing an io.ReaderCloser in
|
||||
// both cases.
|
||||
// TODO(gri) investigate performance difference (issue #19281)
|
||||
files[i], errors[i] = parser.ParseFile(p.fset, filepath, nil, 0)
|
||||
src, err := open(filepath)
|
||||
if err != nil {
|
||||
errors[i] = err // open provides operation and filename in error
|
||||
return
|
||||
}
|
||||
files[i], errors[i] = parser.ParseFile(p.fset, filepath, src, 0)
|
||||
src.Close() // ignore Close error - parsing may have succeeded which is all we need
|
||||
}(i, p.joinPath(dir, filename))
|
||||
}
|
||||
wg.Wait()
|
Loading…
Reference in New Issue
Block a user