do packages need to be recompiled when Go is upgraded?

144 views
Skip to first unread message

Tim K

unread,
Sep 28, 2016, 9:58:10 AM9/28/16
to golang-nuts
If the Go toolchain is upgraded to a newer version, do the existing packages in $GOPATH need to be recompiled? If so, how? Just delete $GOPATH/pkg and go install everything? What about the binaries in $GOPATH/bin?
What's the easiest way to make sure that everything in $GOPATH is compiled with the latest Go?

Thank you.

Tim

Chris Hines

unread,
Sep 28, 2016, 10:43:18 AM9/28/16
to golang-nuts
I'm pretty sure that the last few versions of Go (since 1.5 maybe) are smart enough to do it automatically. I believe the .o files in the pkg tree have the compiler version embedded in their meta data for this purpose.

Tim K

unread,
Sep 28, 2016, 11:30:51 AM9/28/16
to golang-nuts
OK, so all that should happen is just re-install the binaries in $GOPATH/bin. Does anyone have any tips or helper scripts that help automate re-installing all these binaries? There's a pile of them which makes it a bit difficult to find out what exact package path they came from so they can be rebuilt.

Thanks!

andrey mirtchovski

unread,
Sep 28, 2016, 11:41:18 AM9/28/16
to Tim K, golang-nuts
use 'go list' to see which packages you have installed and which may
need upgrading (they all will, in the end). 'go help packages' will
tell you the difference between 'go list std', 'go list all', and also
how to query individual folders inside GOPATH.

"go build -i" will ensure that prerequisite library dependencies are
also installed, which will populate the entire pkg/* directory.
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Micky

unread,
Sep 28, 2016, 11:41:31 AM9/28/16
to Tim K, golang-nuts
go list ...
go build ...


It will build only if it it needs to! Otherwise add -a to force.

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.

Tim K

unread,
Sep 28, 2016, 5:19:29 PM9/28/16
to golang-nuts, tim....@gmail.com
If I want to start from the executables in $GOPATH/bin and recompile only those, is there a way to tell what package an executable comes from so I can easily automate the process? E.g. goimports is the result of "go install golang.org/x/tools/cmd/goimports", etc.

Dave Cheney

unread,
Sep 28, 2016, 5:26:20 PM9/28/16
to golang-nuts
s/go build/go install/g
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.

andrey mirtchovski

unread,
Sep 28, 2016, 5:31:44 PM9/28/16
to Tim K, golang-nuts
> go list -f '{{.ImportPath}}: {{.Target}}' all | grep $GOPATH/bin

mistyped GOPATH, sorry.

andrey mirtchovski

unread,
Sep 28, 2016, 5:31:44 PM9/28/16
to Tim K, golang-nuts
> If I want to start from the executables in $GOPATH/bin and recompile only
> those, is there a way to tell what package an executable comes from so I can
> easily automate the process? E.g. goimports is the result of "go install
> golang.org/x/tools/cmd/goimports", etc.

you can do it by listing the target and import path or directory for
each package and filter out the executables you're interested in. 'go
help list' gives you a lot of options. example:

go list -f '{{.Dir}}: {{.Target}}' all | grep yourbinaryfile

or, to see the import path for every binary in your GOPATH/bin:

go list -f '{{.ImportPath}}: {{.Target}}' all | grep $GOPARH/bin

Tim K

unread,
Sep 28, 2016, 6:56:26 PM9/28/16
to golang-nuts, tim....@gmail.com

Thanks for the pointer in the right direction. I can work with that to automate it. There are some things to take care of such as same package being vendored but that can be solved by picking the shortest Dir. Maybe this is a good tool to write in Go.

Micky

unread,
Sep 28, 2016, 10:15:53 PM9/28/16
to Dave Cheney, golang-nuts
Thanks for the correction :-)

To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages