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: quick build flag that discards result #12359

Closed
gsalgado opened this issue Aug 27, 2015 · 11 comments
Closed

cmd/go: quick build flag that discards result #12359

gsalgado opened this issue Aug 27, 2015 · 11 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@gsalgado
Copy link

I've been looking into ways of getting my builds (mostly for the benefit of tools like the syntastic vim plugin) under 1.5 to be as fast as in 1.4, and one of the tricks I've found to help is to pass -buildmode=archive. It works for go build, but not for go test, which gives me the following error:

$ go test -c -buildmode="archive" ./
# testmain
invalid value "" for flag -buildmode: invalid buildmode: ""
usage: link [options] main.o
  -B note
        add an ELF NT_GNU_BUILD_ID note when using ELF
[...]
@ianlancetaylor ianlancetaylor changed the title go test errors out when passed -buildmode=archive cmd/go: go test errors out when passed -buildmode=archive Aug 27, 2015
@ianlancetaylor ianlancetaylor added this to the Go1.6 milestone Aug 27, 2015
@ianlancetaylor
Copy link
Contributor

We'll look into this, but the resolution might be that the go tool gives a better error message. It's not clear that it makes sense to build a test as an archive file.

@minux
Copy link
Member

minux commented Aug 27, 2015 via email

@gsalgado
Copy link
Author

Build test files without actually running the tests, just to check for
errors. This is what the syntastic plugin for vim does when you use it on a
_test.go file

On 27 August 2015 at 17:46, Minux Ma notifications@github.com wrote:

I don't think -buildmode=archive makes sense for go test. What are you
trying to achieve?


Reply to this email directly or view it on GitHub
#12359 (comment).

@ianlancetaylor
Copy link
Contributor

You can build the test files just using "test -c". I guess you are using the -buildmode=archive to skip the link step. If this is a useful feature, I think it would make more sense to file a separate issue asking for a cmd/go option to just build, and discard the output, and not link. This would be in effect a way to make sure that the files compile.

@minux
Copy link
Member

minux commented Aug 27, 2015 via email

@davecheney
Copy link
Contributor

You can build tests without running them like this.

go test -run=XXX ./...

On Fri, 28 Aug 2015 02:52 Guilherme Salgado notifications@github.com
wrote:

Build test files without actually running the tests, just to check for
errors. This is what the syntastic plugin for vim does when you use it on a
_test.go file

On 27 August 2015 at 17:46, Minux Ma notifications@github.com wrote:

I don't think -buildmode=archive makes sense for go test. What are you
trying to achieve?


Reply to this email directly or view it on GitHub
#12359 (comment).


Reply to this email directly or view it on GitHub
#12359 (comment).

@gsalgado
Copy link
Author

My main motivation is to be able to have something that runs real quick and reports errors when a developer saves a file they're editing. Ideally it should also report errors on other files within the same project, say, if I rename a function that is used somewhere else.

The reason why I started experimenting with -buildmode=archive is because in 1.5 builds became much slower; before 1.5, the hook was just doing a 'go test -c', which was fast enough in most cases.

If the check doesn't catch linking errors it's not a big deal, but yeah, it'd be nice if we could have 'go test -c' as fast as in pre-1.5 days

@rsc rsc modified the milestones: Go1.6Maybe, Go1.6 Dec 17, 2015
@rsc rsc changed the title cmd/go: go test errors out when passed -buildmode=archive cmd/go: no way to compile but not link test code Jan 6, 2016
@rsc rsc modified the milestones: Go1.7Early, Go1.6Maybe Jan 6, 2016
@bradfitz bradfitz modified the milestones: Go1.8, Go1.7Early May 6, 2016
@quentinmit quentinmit added the NeedsFix The path to resolution is known, but the work has not been done. label Oct 6, 2016
@rsc rsc modified the milestones: Go1.9Early, Go1.8 Oct 21, 2016
@rsc rsc changed the title cmd/go: no way to compile but not link test code cmd/go: quick build flag that discards result Oct 21, 2016
@josharian
Copy link
Contributor

If you just want to check that the code is syntactically correct and typechecks correctly, it will almost certainly be faster to use something go/types-based, such as gotype (although gotype needs updating to use go/loader).

@myitcv
Copy link
Member

myitcv commented Jan 30, 2017

👍 to @josharian's suggestion

(although gotype needs updating to use go/loader).

We currently work around this by running run the two-step process of go install on the transitive set of all dependencies (including test) for a package spec, then concurrently running gotype -a on each package in the package spec (although we did get bitten by #18799).

@bradfitz
Copy link
Contributor

bradfitz commented May 3, 2017

I'm going to close this. It sounds like gotype is the solution. Also, each compiler release since Go 1.5 has gotten faster, and Go 1.9 is faster than Go 1.8.

@bradfitz bradfitz closed this as completed May 3, 2017
@josharian
Copy link
Contributor

Also, starting with Go 1.9, if you want to stick with cmd/compile and cmd/go, you can add -gcflags="-dolinkobj=false", which will speed things up considerably.

@golang golang locked and limited conversation to collaborators May 3, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

10 participants