Skip to content

Commit

Permalink
Update _tools and install google.golang.org/protobuf, generate one of…
Browse files Browse the repository at this point in the history
… the test folders to try out
  • Loading branch information
marioizquierdo committed Apr 13, 2021
1 parent 4f24a7b commit 46da134
Show file tree
Hide file tree
Showing 164 changed files with 40,859 additions and 692 deletions.
102 changes: 102 additions & 0 deletions _tools/src/golang.org/x/sys/execabs/execabs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
// Copyright 2020 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.

// Package execabs is a drop-in replacement for os/exec
// that requires PATH lookups to find absolute paths.
// That is, execabs.Command("cmd") runs the same PATH lookup
// as exec.Command("cmd"), but if the result is a path
// which is relative, the Run and Start methods will report
// an error instead of running the executable.
//
// See https://blog.golang.org/path-security for more information
// about when it may be necessary or appropriate to use this package.
package execabs

import (
"context"
"fmt"
"os/exec"
"path/filepath"
"reflect"
"unsafe"
)

// ErrNotFound is the error resulting if a path search failed to find an executable file.
// It is an alias for exec.ErrNotFound.
var ErrNotFound = exec.ErrNotFound

// Cmd represents an external command being prepared or run.
// It is an alias for exec.Cmd.
type Cmd = exec.Cmd

// Error is returned by LookPath when it fails to classify a file as an executable.
// It is an alias for exec.Error.
type Error = exec.Error

// An ExitError reports an unsuccessful exit by a command.
// It is an alias for exec.ExitError.
type ExitError = exec.ExitError

func relError(file, path string) error {
return fmt.Errorf("%s resolves to executable in current directory (.%c%s)", file, filepath.Separator, path)
}

// LookPath searches for an executable named file in the directories
// named by the PATH environment variable. If file contains a slash,
// it is tried directly and the PATH is not consulted. The result will be
// an absolute path.
//
// LookPath differs from exec.LookPath in its handling of PATH lookups,
// which are used for file names without slashes. If exec.LookPath's
// PATH lookup would have returned an executable from the current directory,
// LookPath instead returns an error.
func LookPath(file string) (string, error) {
path, err := exec.LookPath(file)
if err != nil {
return "", err
}
if filepath.Base(file) == file && !filepath.IsAbs(path) {
return "", relError(file, path)
}
return path, nil
}

func fixCmd(name string, cmd *exec.Cmd) {
if filepath.Base(name) == name && !filepath.IsAbs(cmd.Path) {
// exec.Command was called with a bare binary name and
// exec.LookPath returned a path which is not absolute.
// Set cmd.lookPathErr and clear cmd.Path so that it
// cannot be run.
lookPathErr := (*error)(unsafe.Pointer(reflect.ValueOf(cmd).Elem().FieldByName("lookPathErr").Addr().Pointer()))
if *lookPathErr == nil {
*lookPathErr = relError(name, cmd.Path)
}
cmd.Path = ""
}
}

// CommandContext is like Command but includes a context.
//
// The provided context is used to kill the process (by calling os.Process.Kill)
// if the context becomes done before the command completes on its own.
func CommandContext(ctx context.Context, name string, arg ...string) *exec.Cmd {
cmd := exec.CommandContext(ctx, name, arg...)
fixCmd(name, cmd)
return cmd

}

// Command returns the Cmd struct to execute the named program with the given arguments.
// See exec.Command for most details.
//
// Command differs from exec.Command in its handling of PATH lookups,
// which are used when the program name contains no slashes.
// If exec.Command would have returned an exec.Cmd configured to run an
// executable from the current directory, Command instead
// returns an exec.Cmd that will return an error from Start or Run.
func Command(name string, arg ...string) *exec.Cmd {
cmd := exec.Command(name, arg...)
fixCmd(name, cmd)
return cmd
}
5 changes: 3 additions & 2 deletions _tools/src/golang.org/x/tools/go/ast/astutil/imports.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,9 +275,10 @@ func DeleteNamedImport(fset *token.FileSet, f *ast.File, name, path string) (del

// We deleted an entry but now there may be
// a blank line-sized hole where the import was.
if line-lastLine > 1 {
if line-lastLine > 1 || !gen.Rparen.IsValid() {
// There was a blank line immediately preceding the deleted import,
// so there's no need to close the hole.
// so there's no need to close the hole. The right parenthesis is
// invalid after AddImport to an import statement without parenthesis.
// Do nothing.
} else if line != fset.File(gen.Rparen).LineCount() {
// There was no blank line. Close the hole.
Expand Down
4 changes: 4 additions & 0 deletions _tools/src/golang.org/x/tools/go/ast/astutil/util.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Copyright 2015 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.

package astutil

import "go/ast"
Expand Down
4 changes: 4 additions & 0 deletions _tools/src/golang.org/x/tools/go/buildutil/fakecontext.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Copyright 2015 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.

package buildutil

import (
Expand Down
2 changes: 1 addition & 1 deletion _tools/src/golang.org/x/tools/go/buildutil/overlay.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func OverlayContext(orig *build.Context, overlay map[string][]byte) *build.Conte
//
// The archive consists of a series of files. Each file consists of a
// name, a decimal file size and the file contents, separated by
// newlinews. No newline follows after the file contents.
// newlines. No newline follows after the file contents.
func ParseOverlayArchive(archive io.Reader) (map[string][]byte, error) {
overlay := make(map[string][]byte)
r := bufio.NewReader(archive)
Expand Down
4 changes: 4 additions & 0 deletions _tools/src/golang.org/x/tools/go/buildutil/tags.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Copyright 2015 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.

package buildutil

// This logic was copied from stringsFlag from $GOROOT/src/cmd/go/build.go.
Expand Down
14 changes: 7 additions & 7 deletions _tools/src/golang.org/x/tools/go/internal/cgo/cgo.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package cgo

// This file handles cgo preprocessing of files containing `import "C"`.
// Package cgo handles cgo preprocessing of files containing `import "C"`.
//
// DESIGN
//
Expand Down Expand Up @@ -51,6 +49,8 @@ package cgo
// its handling of function calls, analogous to the treatment of map
// lookups in which y=m[k] and y,ok=m[k] are both legal.

package cgo

import (
"fmt"
"go/ast"
Expand All @@ -60,10 +60,11 @@ import (
"io/ioutil"
"log"
"os"
"os/exec"
"path/filepath"
"regexp"
"strings"

exec "golang.org/x/sys/execabs"
)

// ProcessFiles invokes the cgo preprocessor on bp.CgoFiles, parses
Expand Down Expand Up @@ -159,14 +160,13 @@ func Run(bp *build.Package, pkgdir, tmpdir string, useabs bool) (files, displayF
}

args := stringList(
"go", "tool", "cgo", "-objdir", tmpdir, cgoflags, "--",
"go", "tool", "cgo", "-srcdir", pkgdir, "-objdir", tmpdir, cgoflags, "--",
cgoCPPFLAGS, cgoexeCFLAGS, cgoFiles,
)
if false {
log.Printf("Running cgo for package %q: %s (dir=%s)", bp.ImportPath, args, pkgdir)
log.Printf("Running cgo for package %q: %s", bp.ImportPath, args)
}
cmd := exec.Command(args[0], args[1:]...)
cmd.Dir = pkgdir
cmd.Stdout = os.Stderr
cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"errors"
"fmt"
"go/build"
"os/exec"
exec "golang.org/x/sys/execabs"
"strings"
)

Expand Down
5 changes: 2 additions & 3 deletions _tools/src/golang.org/x/tools/go/loader/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
// of dependencies. The ASTs and the derived facts are retained for
// later use.
//
// THIS INTERFACE IS EXPERIMENTAL AND IS LIKELY TO CHANGE.
// Deprecated: This is an older API and does not have support
// for modules. Use golang.org/x/tools/go/packages instead.
//
// The package defines two primary types: Config, which specifies a
// set of initial packages to load and various other options; and
Expand Down Expand Up @@ -201,5 +202,3 @@ package loader
// the error.
//
// The result of using concurrency is about a 2.5x speedup for stdlib_test.

// TODO(adonovan): overhaul the package documentation.
56 changes: 28 additions & 28 deletions _tools/src/golang.org/x/tools/go/loader/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -811,7 +811,15 @@ func (imp *importer) doImport(from *PackageInfo, to string) (*types.Package, err
// Import of incomplete package: this indicates a cycle.
fromPath := from.Pkg.Path()
if cycle := imp.findPath(path, fromPath); cycle != nil {
cycle = append([]string{fromPath}, cycle...)
// Normalize cycle: start from alphabetically largest node.
pos, start := -1, ""
for i, s := range cycle {
if pos < 0 || s > start {
pos, start = i, s
}
}
cycle = append(cycle, cycle[:pos]...)[pos:] // rotate cycle to start from largest
cycle = append(cycle, cycle[0]) // add start node to end to show cycliness
return nil, fmt.Errorf("import cycle: %s", strings.Join(cycle, " -> "))
}

Expand Down Expand Up @@ -861,21 +869,6 @@ func (imp *importer) findPackage(importPath, fromDir string, mode build.ImportMo
// caused these imports.
//
func (imp *importer) importAll(fromPath, fromDir string, imports map[string]bool, mode build.ImportMode) (infos []*PackageInfo, errors []importError) {
// TODO(adonovan): opt: do the loop in parallel once
// findPackage is non-blocking.
var pending []*importInfo
for importPath := range imports {
bp, err := imp.findPackage(importPath, fromDir, mode)
if err != nil {
errors = append(errors, importError{
path: importPath,
err: err,
})
continue
}
pending = append(pending, imp.startLoad(bp))
}

if fromPath != "" {
// We're loading a set of imports.
//
Expand All @@ -887,29 +880,36 @@ func (imp *importer) importAll(fromPath, fromDir string, imports map[string]bool
deps = make(map[string]bool)
imp.graph[fromPath] = deps
}
for _, ii := range pending {
deps[ii.path] = true
for importPath := range imports {
deps[importPath] = true
}
imp.graphMu.Unlock()
}

for _, ii := range pending {
var pending []*importInfo
for importPath := range imports {
if fromPath != "" {
if cycle := imp.findPath(ii.path, fromPath); cycle != nil {
// Cycle-forming import: we must not await its
// completion since it would deadlock.
//
// We don't record the error in ii since
// the error is really associated with the
// cycle-forming edge, not the package itself.
// (Also it would complicate the
// invariants of importPath completion.)
if cycle := imp.findPath(importPath, fromPath); cycle != nil {
// Cycle-forming import: we must not check it
// since it would deadlock.
if trace {
fmt.Fprintf(os.Stderr, "import cycle: %q\n", cycle)
}
continue
}
}
bp, err := imp.findPackage(importPath, fromDir, mode)
if err != nil {
errors = append(errors, importError{
path: importPath,
err: err,
})
continue
}
pending = append(pending, imp.startLoad(bp))
}

for _, ii := range pending {
ii.awaitCompletion()
infos = append(infos, ii.info)
}
Expand Down
Loading

0 comments on commit 46da134

Please sign in to comment.