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

x/vgo: go.mod files in subdirectories are ignored when building the whole directory #24605

Closed
blueimp opened this issue Mar 30, 2018 · 6 comments

Comments

@blueimp
Copy link

commented Mar 30, 2018

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

go version go1.10 darwin/amd64 vgo:2018-02-20.1

Does this issue reproduce with the latest release?

Yes

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

GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/blueimp/Library/Caches/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/blueimp/Development/gocode"
GORACE=""
GOROOT="/usr/local/Cellar/go/1.10/libexec"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.10/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
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/pp/2fr7691n1j741m0xfz7pklx00000gn/T/go-build670014762=/tmp/go-build -gno-record-gcc-switches -fno-common"
VGOMODROOT=""

What did you do?

In a new directory, create a simple go file and a go.mod file and use vgo to build it:

mkdir main
cd main
nano main.go
package main // import "example.org/main"
func main(){}
touch go.mod
vgo build
cat go.mod

The output is as expected:

module "example.org/main"

Next, in a subdirectory add another vgo module and build it:

mkdir sub
cd sub
nano sub.go
package sub // import "example.org/main/sub"
import (
	"fmt"
	"rsc.io/quote"
)
func main() {
	fmt.Println(quote.Hello())
}
touch go.mod
vgo build
cat go.mod

The output is as expected:

module "example.org/main/sub"

require "rsc.io/quote" v1.5.2

Now back in the parent directory, execute vgo build ./... and retrieve the now unexpectedly changed contents of the go.mod file:

cd ..
vgo build ./...
cat go.mod

What did you expect to see?

module "example.org/main"

What did you see instead?

module "example.org/main"

require "rsc.io/quote" v1.5.2

@gopherbot gopherbot added this to the vgo milestone Mar 30, 2018

@rsc

This comment has been minimized.

Copy link
Contributor

commented Mar 30, 2018

Nice bug.

The problem is that each build always runs in the context of a single top-level repo. There's no direct connection between the parent dir and the sub dir (it's not like the parent dir mentions the sub dir in a replace directive or other connection).

At least for now I think the answer is that ./... should stop matching when it finds a directory containing a go.mod. That is, ./... can only match packages in the module where "." is, and sub would therefore be excluded.

@rsc rsc added the NeedsFix label Mar 30, 2018

@blueimp

This comment has been minimized.

Copy link
Author

commented Mar 30, 2018

Thanks for the quick response!

I think ideally, running vgo build ./... would build all the modules in the directory, with automatic dependency resolution for each module separately.

But I'm also not 100% sure what users expect as outcome for building this way with multiple modules in the directory.

@freddy33

This comment has been minimized.

Copy link

commented Jun 6, 2018

Same need here on this repo: https://github.com/JFrogDev/gofrog
Like to have a go.mod for each folder creating 5 separate modules.

@tcolgate

This comment has been minimized.

Copy link
Contributor

commented Jun 7, 2018

Same here, don't want deps for individual adapters to pollute the top level https://github.com/tcolgate/hugot. (will push go.mod attempt later today if I get a chance)

@gopherbot

This comment has been minimized.

Copy link

commented Jun 7, 2018

Change https://golang.org/cl/117257 mentions this issue: cmd/go/internal/vgo: do not scan submodules in file system scans

@gopherbot

This comment has been minimized.

Copy link

commented Jul 5, 2018

Change https://golang.org/cl/122397 mentions this issue: cmd/go/internal/search: ignore submodules in ./... patterns

gopherbot pushed a commit to golang/vgo that referenced this issue Jul 12, 2018
cmd/go/internal/search: ignore submodules in ./... patterns
CL 117257 handled path patterns like ... or x/...
but not file system patterns like ./... or ./x/... .

Fixes golang/go#24605 again.

Change-Id: Ia5337a3490dfb3626b0af35199ae732fca0ed476
Reviewed-on: https://go-review.googlesource.com/122397
Reviewed-by: Bryan C. Mills <bcmills@google.com>

@golang golang locked and limited conversation to collaborators Jul 5, 2019

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
5 participants
You can’t perform that action at this time.