Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

go/packages: can't resolve golang_org vendored packages #28912

Closed
dave opened this issue Nov 21, 2018 · 1 comment
Closed

go/packages: can't resolve golang_org vendored packages #28912

dave opened this issue Nov 21, 2018 · 1 comment

Comments

@dave
Copy link
Contributor

dave commented Nov 21, 2018

What version of Go are you using (go version)?

$ go version
go version go1.11 darwin/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/dave/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/dave"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/qx/ypfpz5jd4jqc9r2r1z_mzpwm0000gn/T/go-build540247940=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

The golang.org/x/tools/go/packages package is not able to resolve the golang_org vendored packages in src/vendor - e.g. this import. Is this expected? Is there a work-around?

package main

import (
	"go/build"
	"path/filepath"
	"testing"

	"golang.org/x/tools/go/packages"
)

func TestVendor(t *testing.T) {

	importPath := "golang_org/x/crypto/chacha20poly1305"
	fromDir := filepath.Join(build.Default.GOROOT, "src", "crypto/tls")

	cfg := &packages.Config{
		Dir:   fromDir,
		Mode:  packages.LoadTypes,
		Tests: false,
	}

	pkgs, err := packages.Load(cfg, "pattern="+importPath)
	if err != nil {
		t.Fatal(err)
	}

	if len(pkgs) != 1 {
		t.Fatalf("expected 1 package, found %d", len(pkgs))
	}

	p := pkgs[0]

	if len(p.Errors) > 0 {
		for _, err := range p.Errors {
			t.Error(err)
		}
	}

	if p.Name != "chacha20poly1305" {
		t.Fatalf("expected chacha20poly1305, found %s", p.Name)
	}
}

Output:

=== RUN   TestVendor
--- FAIL: TestVendor (0.03s)
    vendor_test.go:35: -: cannot find package "golang_org/x/crypto/chacha20poly1305" in any of:
        	/usr/local/go/src/golang_org/x/crypto/chacha20poly1305 (from $GOROOT)
        	/Users/dave/src/golang_org/x/crypto/chacha20poly1305 (from $GOPATH)
    vendor_test.go:40: expected chacha20poly1305, found 
FAIL
@heschi
Copy link
Contributor

heschi commented Nov 21, 2018

Dupe of #28375, which was duped to #26924. I just stopped looking at anything in $GOROOT/.../vendor, but I haven't thought about how good a general solution that is.

@heschi heschi closed this as completed Nov 21, 2018
@golang golang locked and limited conversation to collaborators Nov 21, 2019
@rsc rsc unassigned matloob Jun 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants