golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
123.02k stars 17.54k forks source link

x/tools/gopls: Does GOPACKAGESDRIVER support custom packages ? #69501

Open ViolaPioggia opened 4 days ago

ViolaPioggia commented 4 days ago

gopls version

gopls -v version Build info

golang.org/x/tools/gopls v0.16.1 golang.org/x/tools/gopls@v0.16.1 h1:1hO/dCeUvjEYx3V0rVvCtOkwnpEpqS29paE+Jw4dcAc= github.com/BurntSushi/toml@v1.2.1 h1:9F2/+DoOYIOksmaJFPw1tGFy1eDnIJXg+UHjuD8lTak= github.com/google/go-cmp@v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= golang.org/x/exp/typeparams@v0.0.0-20221212164502-fae10dda9338 h1:2O2DON6y3XMJiQRAS1UWU+54aec2uopH3x7MAiqGW6Y= golang.org/x/mod@v0.18.0 h1:5+9lSbEzPSdWkH32vYPBwEpX8KwDbM52Ud9xBUvNlb0= golang.org/x/sync@v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= golang.org/x/telemetry@v0.0.0-20240607193123-221703e18637 h1:3Wt8mZlbFwG8llny+t18kh7AXxyWePFycXMuVdHxnyM= golang.org/x/text@v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4= golang.org/x/tools@v0.22.1-0.20240628205440-9c895dd76b34 h1:Kd+Z5Pm6uwYx3T2KEkeHMHUMZxDPb/q6b1m+zEcy62c= golang.org/x/vuln@v1.0.4 h1:SP0mPeg2PmGCu03V+61EcQiOjmpri2XijexKdzv8Z1I= honnef.co/go/tools@v0.4.7 h1:9MDAWxMoSnB6QoSqiVr7P5mtkT9pOc1kSxchzPCnqJs= mvdan.cc/gofumpt@v0.6.0 h1:G3QvahNDmpD+Aek/bNOLrFR2XC6ZAdo62dZu65gmwGo= mvdan.cc/xurls/v2@v2.5.0 h1:lyBNOm8Wo71UknhUs4QTFUNNMyxy2JEIaKKo0RWOh+8= go: go1.22.6

go env

go env
GO111MODULE='on'
GOARCH='arm64'
GOBIN=''
GOCACHE='/Users/violapioggia/Library/Caches/go-build'
GOENV='/Users/violapioggia/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/violapioggia/go/pkg/mod'
GONOPROXY='talkcheap.xiaoeknow.com'
GONOSUMDB='talkcheap.xiaoeknow.com'
GOOS='darwin'
GOPATH='/Users/violapioggia/go'
GOPRIVATE='talkcheap.xiaoeknow.com'
GOPROXY='https://goproxy.cn,direct'
GOROOT='/usr/local/go'
GOSUMDB='off'
GOTMPDIR=''
GOTOOLCHAIN=''
GOTOOLDIR='/usr/local/go/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.21.1'
GCCGO='gccgo'
AR='ar'
CC='clang'
CXX='clang++'
CGO_ENABLED='1'
GOMOD='/Users/violapioggia/GolandProjects/rgo/go.mod'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/2y/q5hfz55n7yx__bgtrj0pwgpw0000gn/T/go-build2651212672=/tmp/go-build -gno-record-gcc-switches -fno-common'

What did you do?

I use GOPACKAGESDRIVER to build a custom package which name's github.com/xxx/xxx

What did you see happen?

when I execute go mod tidy ,it will throw an error:

(base) ViolaPioggiadeMacBook-Air:rgo_test violapioggia$ go mod tidy go: finding module for package github.com/xxx go: test imports github.com/xxx: cannot find module providing package github.com/xxx: module github.com/xxx: git ls-remote -q origin in /Users/violapioggia/go/pkg/mod/cache/vcs/6d9364d47d76a0951f605c504e9f49ac68af057ddde3e30b0f18dcf04c652806: exit status 128: remote: Repository not found. fatal: repository 'https://github.com/xxx: not found

What did you expect to see?

I want I can import custom_pacakge github.com/xxx by GOPACKAGESDRIVER like normal package and execute go mod tidy won't throw an error

Editor and settings

{ "go.toolsEnvVars": { "GOPACKAGESDRIVER": "${env:GOPATH}/bin/mypackagesdriver" }, }

Logs

No response

gabyhelp commented 4 days ago

Related Issues and Documentation

(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)

li-jin-gou commented 3 days ago

Hello @findleyr , can you help us look into this issue? I'm not sure if this capability is supported now.

adonovan commented 2 days ago

As far as I can tell, you want the go command to somehow use a custom GOPACKAGESDRIVER, but the go command knows nothing of this concept: it is part of https://pkg.go.dev/golang.org/x/tools/go/packages, which is a library for loading Go project metadata by running build tools like go list, or alternatives such as like bazel, buck, and pants. And I don't see how this relates at all to gopls.

Could you explain the problem in more detail?

li-jin-gou commented 2 days ago

Sorry @adonovan ,it may have mentioned the wrong issue category.

We use GOPACKAGESDRIVER in the hope of injecting three-way packages, in the form of github.com/hertz_gen/a, but using go mod tidy will go and pull the packages remotely, resulting in a package does not exist error.

I'm currently wondering if GOPACKAGESDRIVER supports emulating three-way packages and go mod tidy doesn't report an error?

We can resubmit an issue to the correct category.

adonovan commented 2 days ago

We use GOPACKAGESDRIVER in the hope of injecting three-way packages, in the form of github.com/hertz_gen/a, but using go mod tidy will go and pull the packages remotely, resulting in a package does not exist error. I'm currently wondering if GOPACKAGESDRIVER supports emulating three-way packages and go mod tidy doesn't report an error?

I have not heard the term "three-way package" before. What does it mean?

li-jin-gou commented 2 days ago

We use GOPACKAGESDRIVER in the hope of injecting three-way packages, in the form of github.com/hertz_gen/a, but using go mod tidy will go and pull the packages remotely, resulting in a package does not exist error. I'm currently wondering if GOPACKAGESDRIVER supports emulating three-way packages and go mod tidy doesn't report an error?

I have not heard the term "three-way package" before. What does it mean?

sry,it is Third-Party Packages😞 such as github.com/protoc_gen/service package

ViolaPioggia commented 2 days ago

sry,it is Third-Party Packages😞 such as github.com/protoc_gen/service package

It is exactly what I mean, when I using gopackgesdriver to build a pacakge like this, go mod tidy will try to download from github.com but not load from my local env

adonovan commented 1 day ago

GOPACKAGESDRIVER is for when you are using a build system other than the Go command. In general, other build systems are not compatible (or fully compatible) with the Go command's module system--some don't really use modules at all--so go mod tidy will not work as expected.

What build system are you using? What program is GOPACKAGESDRIVER set to? Neither of the two GitHub repos you mentioned (github.com/protoc_gen/service and github.com/hertz_gen/a) are readable to me. Do they require authentication? Are you trying to use GOPACKAGESDRIVER as some kind of authentication proxy?

ViolaPioggia commented 4 hours ago

GOPACKAGESDRIVER is for when you are using a build system other than the Go command. In general, other build systems are not compatible (or fully compatible) with the Go command's module system--some don't really use modules at all--so go mod tidy will not work as expected.

What build system are you using? What program is GOPACKAGESDRIVER set to? Neither of the two GitHub repos you mentioned (github.com/protoc_gen/service and github.com/hertz_gen/a) are readable to me. Do they require authentication? Are you trying to use GOPACKAGESDRIVER as some kind of authentication proxy?

Thanks for replying, I dont't want to use GOPACKAGESDRIVER as some kind of authentication proxy, I just want to use GOPACKAGESDRIVER to build a package which prefix is "github.com/xxx" and when I execute 'go mod tidy',because of this package is not managed by go module ,so it will throw an error like below picture

image