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

cmd/go: default -mod=vendor behavior unexpectedly present in workspace mode #54130

Closed
h31 opened this issue Jul 29, 2022 · 3 comments
Closed
Assignees
Labels
FrozenDueToAge GoCommand cmd/go modules NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@h31
Copy link

h31 commented Jul 29, 2022

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

$ go version
go version go1.19rc2 darwin/amd64

Does this issue reproduce with the latest release?

Yes (also reproduces on 1.18.4)

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

go env Output
$ go env
GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/artyom/Library/Caches/go-build"
GOENV="/Users/artyom/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/artyom/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/artyom/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/Users/artyom/go/go1.19rc2"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/Users/artyom/go/go1.19rc2/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="go1.19rc2"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/artyom/GoTestProjects/Workspace/WorkspaceWithVendoring/go.mod"
GOWORK="/Users/artyom/GoTestProjects/Workspace/WorkspaceWithVendoring/go.work"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/pr/5k6c2yx97cjb9t5fh0httxv80000gn/T/go-build3616914050=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

  1. Clone https://github.com/h31/WorkspaceWithVendoring
  • a simple project with go.work file and vendor directory containing a fake library
  • link to a file with faked code
  1. Run go build, and then ./my_workspace

What did you expect to see?

The documentation implies that workspace mode and vendoring are incompatible:

  • By default, if the go version in go.mod is 1.14 or higher and a vendor directory is present, the go command acts as if -mod=vendor were used. from Go Modules Reference
  • A manual run of go build -mod=vendor produces an error:
go: -mod may only be set to readonly when in workspace mode, but it is set to "vendor"
        Remove the -mod flag to use the default readonly value,
        or set GOWORK=off to disable workspace mode.

The original workspace proposal explicitly stated that vendoring is ignored in workspace mode:

Module vendoring is ignored in workspace mode because it is not clear which modules' vendor directories should be respected if there are multiple workpace modules with vendor directories containing the same dependencies.

What did you see instead?

$ go build
$ ./my_workspace
Fake library is used

Explicitly specifying -mod=readonly (which theoretically is the only option value compatible with workspace mode):

$ go build -mod=readonly
$ ./my_workspace
Testphrase
@cherrymui cherrymui added Documentation NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Jul 29, 2022
@cherrymui cherrymui added this to the Backlog milestone Jul 29, 2022
@cherrymui
Copy link
Member

cc @bcmills

@cherrymui cherrymui modified the milestones: Backlog, Go1.19 Jul 29, 2022
@bcmills bcmills changed the title cmd/go: vendoring behavior in workspace mode should be clarified cmd/go: default -mod=vendor behavior unexpectedly present in workspace mode Aug 17, 2022
@bcmills bcmills modified the milestones: Backlog, Go1.20 Aug 17, 2022
@matloob matloob self-assigned this Oct 5, 2022
@matloob
Copy link
Contributor

matloob commented Oct 5, 2022

@h31 thanks for finding this! I've prepared a fix cl: https://go-review.git.corp.google.com/c/go/+/439415

@gopherbot
Copy link

Change https://go.dev/cl/439415 mentions this issue: cmd/go: fix bug putting workspace in vendor mode

romaindoumenc pushed a commit to TroutSoftware/go that referenced this issue Nov 3, 2022
Workspaces with a single module would enter mod=vendor mode even when
in workspace mode. Fix that by explicitly checking that we're not in
workspace mode when deciding whether to enter vendor mode.

Fixes golang#54130

Change-Id: I03fcd9db4160c9872aa2b7957a80f24d49f787d0
Reviewed-on: https://go-review.googlesource.com/c/go/+/439415
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
Run-TryBot: Michael Matloob <matloob@golang.org>
@golang golang locked and limited conversation to collaborators Oct 13, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge GoCommand cmd/go modules NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

5 participants