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: don't warn about "no non-test Go files" when building/installing wildcard #22409

Closed
clintmod opened this issue Oct 23, 2017 · 16 comments
Closed
Labels
FrozenDueToAge NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made.
Milestone

Comments

@clintmod
Copy link

clintmod commented Oct 23, 2017

Please answer these questions before submitting your issue. Thanks!

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

go version go1.9.1 darwin/amd64

Does this issue reproduce with the latest release?

yes

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

GOARCH="amd64"
GOBIN="/Users/clint/code/go/bin"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/clint/code/go"
GORACE=""
GOROOT="/usr/local/Cellar/go/1.9.1/libexec"
GOTOOLDIR="/usr/local/Cellar/go/1.9.1/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/tr/j87dsghd3fsdh1m98b76fjrw0000gn/T/go-build293369783=/tmp/go-build -gno-record-gcc-switches -fno-common"
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"

What did you do?

  • cd $GOPATH
  • go get github.com/clintmod/goBuildBug
  • cd $GOPATH/src/github.com/clintmod/goBuildBug
  • go install ./...

What did you expect to see?

The build to succeed.

What did you see instead?

go build github.com/clintmod/goBuildBug/tests: no non-test Go files in github.com/clintmod/goBuildBug/tests

@davecheney
Copy link
Contributor

cd $GOPATH/github.com/clintmod/goBuildBug

^ this is the wrong path, did you mean

cd $GOPATH/src/github.com/clintmod/goBuildBug

@clintmod
Copy link
Author

@davecheney yep… fixed

@gbbr
Copy link
Member

gbbr commented Oct 24, 2017

yep… fixed

Based on the above reply by the OP. I assume this can now be closed.

@gbbr gbbr closed this as completed Oct 24, 2017
@clintmod
Copy link
Author

can we reopen?
I was correcting the bad path in the steps to repro… the expected behavior is that the build should not fail because there are only test files in the dir.

@gbbr
Copy link
Member

gbbr commented Oct 24, 2017

Sure, I've just assumed based on your answer that it was fixed. Please close it yourself if it all works out.

@gbbr gbbr reopened this Oct 24, 2017
@iand
Copy link
Contributor

iand commented Nov 13, 2017

Duplicate of #8279

@ianlancetaylor ianlancetaylor changed the title Go build error: no non-test Go files in <dir> cmd/go: don't warn about "no non-test Go files" when building/installing wildcard Mar 29, 2018
@ianlancetaylor
Copy link
Contributor

ianlancetaylor commented Mar 29, 2018

I think it's clear that go install github.com/clintmod/goBuildBug/tests should fail with the "no non-test Go files" error. So I think what you are saying is that you expect go install ./... to succeed even if some of the packages named by ./... can not be built. I've updated the issue title accordingly. I don't know whether this is a good idea or not. The current approach is easy to understand.

@ianlancetaylor ianlancetaylor added the NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. label Mar 29, 2018
@ianlancetaylor ianlancetaylor added this to the Unplanned milestone Mar 29, 2018
@karalabe
Copy link
Contributor

Just to add my 2c, I've hit this exact issue just now.

My use case is that I'm doing some code generation in a CI build step, and as a last sanity check I try to build a huge repository to make sure that all dependencies (for the generated code too) are correctly vendored in. The simplest way is to do go install ./..., however this fails the CI build step, since there's a folder which only contains tests.

I fully agree that a warning for this scenario is nice. But does it really make sense to fail the entire process for it? I'd expect ./... to build what make sense, and skip what doesn't.

@powerman
Copy link

Same here, also in CI for caching deps:

+ CGO_ENABLED=0
+ go install -v -installsuffix static all
github.com/go-playground/form/benchmarks
go build github.com/go-playground/form/benchmarks: no non-test Go files in /go/src/github.com/go-playground/form/benchmarks

@agnivade
Copy link
Contributor

@powerman - You are directly trying to install the benchmarks package. That will always fail.

This issue is about trying to install/build a repo with a ./.. and not fail the entire step because an internal folder contains only _test files.

This can be solved with a simple workaround of adding any dummy file with a non _test suffix in the same package. Just have a ignore.go file with a one-liner package tests, and everything works.

In general, our approach towards warnings have been to avoid them in the first place by fixing them. And if it cannot be fixed, throw an error. So, I am not sure whether we should throw a warning. Even if the above workaround is not feasible in some cases, you can always do a go list and install the packages separately.

@powerman
Copy link

You are directly trying to install the benchmarks package.

No, I'm not. It's go install all trying to install that package, not me. All I want is to compile and cache all already downloaded packages in a docker image, which will be later used as base image for building my projects in CI - to avoid re-compiling most of my project's dependencies to speedup CI build. Thus I use go install all - is there any better way to do this? ./... doesn't differs much from all in this sense - reason why I use all is to rebuild also stdlib (to get stdlib cached both with and without CGO_ENABLED=0, because some projects supports it and worth using with alpine docker image while others do not).

This can be solved with a simple workaround of adding any dummy file with a non _test suffix

Sure, but it's not my package - it just one of often used dependencies.

@agnivade
Copy link
Contributor

Ah that's right. It is all which is doing it. But all applies to all packages under GOPATH. I would guess you know the dependencies needed by your app ? You can just go get those. And use that docker image in your CI. Or am I missing something here ?

Sure, but it's not my package - it just one of often used dependencies.

Yep, I mentioned this above. In that case, you have to install the sub-packages separately.

Maybe @ianlancetaylor has a better solution.

@powerman
Copy link

I would guess you know the dependencies needed by your app?

More or less. It's a base image shared between several projects with different dependencies, so it include most common ones.

You can just go get those. And use that docker image in your CI.

I do go get those. And everything is fine, so far.

Or am I missing something here?

Probably this issue happens because after I did go get I wanna rebuild all these packages plus stdlib once again, this time with CGO_ENABLED=0, so I run this: CGO_ENABLED=0 go install -v -installsuffix static all … and it usually fails, for one reason or another, because it tries to install every downloaded package, and not just ones which was installed by go get. So when it fails I run go get -v -t all, then go install again… and repeat that few times until success. 😄

Probably only way to avoid these issues is give up on using all - just run same go get twice, with and without CGO_ENABLED=0, plus also run CGO_ENABLED=0 go install -v -installsuffix static std.

But all of this just means all target is currently mostly useless.

@clintmod
Copy link
Author

@ianlancetaylor

I think it's clear that go install github.com/clintmod/goBuildBug/tests should fail with the "no non-test Go files" error.

Why is it clear? If there's nothing to do then it should do nothing and exit 0. It's fine to print a warning but why should it exit non-zero?

@ianlancetaylor
Copy link
Contributor

@clintmod I think it should fail because the command explicitly requests installing a specific package that can not be installed. I don't consider this a case where there is nothing to be done. I consider it a case where the user requested an action that is impossible.

@gopherbot
Copy link

Change https://golang.org/cl/121196 mentions this issue: cmd/go: ignore wildcard-matched test-only packages in go build

@golang golang locked and limited conversation to collaborators Jun 29, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made.
Projects
None yet
Development

No branches or pull requests

9 participants