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: skip finding external test dependencies for go build #29725

Closed
anjmao opened this issue Jan 14, 2019 · 5 comments

Comments

Projects
None yet
3 participants
@anjmao
Copy link

commented Jan 14, 2019

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

go version go1.11.2 darwin/amd64

What did you do?

  1. I'm using go-nio/nio http library which doesn't have any external runtime dependencies. It only uses testify for unit tests.
package main

import (
	"net/http"
	"github.com/go-nio/nio"
)

func main() {
	n := nio.New()
	http.ListenAndServe(":80", n)
}
  1. Now I'm build my app using go build for production. I'm not running any go-nio/nio library tests.

What did you expect to see?

Now I expect go build output to show only runtime dependencies.

go: finding github.com/go-nio/nio v1.0.2
go: downloading github.com/go-nio/nio v1.0.2

What did you see instead?

Instead I see all dependencies including external library test dependencies.

go: finding github.com/go-nio/nio v1.0.2
go: finding github.com/stretchr/testify v1.3.0
go: finding github.com/stretchr/testify v1.2.2
go: finding github.com/pmezard/go-difflib v1.0.0
go: finding github.com/davecgh/go-spew v1.1.1
go: finding github.com/stretchr/objx v0.1.1
go: finding github.com/davecgh/go-spew v1.1.0
go: finding github.com/stretchr/objx v0.1.0
go: downloading github.com/go-nio/nio v1.0.2
@mvdan

This comment has been minimized.

Copy link
Member

commented Jan 14, 2019

/cc @bcmills

@bcmills

This comment has been minimized.

Copy link
Member

commented Jan 14, 2019

All modules in the module graph can affect the selected versions of other modules, so we must have at least the go.mod file (but not necessarily the rest of the source code) for each module in order to resolve version selection.

Test dependencies must be included in the module graph: without them, test results are not reproducible.

The go build output is certainly too chatty (#26152), but beyond that this is working as designed.

@bcmills bcmills closed this Jan 14, 2019

@anjmao

This comment has been minimized.

Copy link
Author

commented Jan 15, 2019

@bcmills Thanks for response. But as you said

Test dependencies must be included in the module graph: without them, test results are not reproducible.

As I mentioned I'm not running any tests, that tests results do you have in mind?

The problem is that there is no way to describe dependency as being used only for tests. Why not add special comment like test so go build can skip fetching go.mod files for whose packages?

require (
	github.com/davecgh/go-spew v1.1.1 // test indirect
	github.com/pmezard/go-difflib v1.0.0 // test indirect
	github.com/stretchr/objx v0.1.1 // test indirect
	github.com/stretchr/testify v1.2.2 // test
)
@bcmills

This comment has been minimized.

Copy link
Member

commented Jan 15, 2019

go build can't skip the process of deciding which versions to use, and “test-only” dependencies can affect that decision.

Those go.mod files should be tiny, and they'll stay in your module cache after the first time you fetch them.

@bcmills

This comment has been minimized.

Copy link
Member

commented Jan 16, 2019

The problem is that there is no way to describe dependency as being used only for tests.

See #26955.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.