golang revel app failing to compile after upgrading OSX command line tools - macos

i was playing around with the revel sample bookings app (http://robfig.github.io/revel/samples/booking.html) and everything was working fine.
after upgrading my OSX command line tools from the apple developer site, the app refuses to start:
INFO 2014/03/10 23:33:46 harness.go:165: Listening on :9000
TRACE 2014/03/10 23:34:00 harness.go:126: Rebuild
TRACE 2014/03/10 23:34:00 build.go:127: Exec: [/usr/local/bin/git describe --always --dirty]
TRACE 2014/03/10 23:34:00 build.go:77: Exec: [/usr/local/bin/go build -ldflags -X github.com/robfig/revel/samples/booking/app.APP_VERSION "git-930a54f" -tags gorp -o /Users/nrser/dev/gopath/bin/booking github.com/robfig/revel/samples/booking/app/tmp]
ERROR 2014/03/10 23:34:02 build.go:84: # github.com/robfig/revel/samples/booking/app/tmp
xcrun: Error: failed to exec real xcrun. (No such file or directory)
go install github.com/robfig/revel/samples/booking/app/tmp: build output "/Users/nrser/dev/gopath/bin/booking" already exists and is not an object file
ERROR 2014/03/10 23:34:02 build.go:247: Failed to parse build errors:
# github.com/robfig/revel/samples/booking/app/tmp
xcrun: Error: failed to exec real xcrun. (No such file or directory)
go install github.com/robfig/revel/samples/booking/app/tmp: build output "/Users/nrser/dev/gopath/bin/booking" already exists and is not an object file
i tried rm /Users/nrser/dev/gopath/bin/booking, but then get this when attempting revel run github.com/robfig/revel/samples/booking:
INFO 2014/03/10 23:38:13 harness.go:165: Listening on :9000
TRACE 2014/03/10 23:38:16 harness.go:126: Rebuild
TRACE 2014/03/10 23:38:16 build.go:127: Exec: [/usr/local/bin/git describe --always --dirty]
TRACE 2014/03/10 23:38:16 build.go:77: Exec: [/usr/local/bin/go build -ldflags -X github.com/robfig/revel/samples/booking/app.APP_VERSION "git-930a54f" -tags gorp -o /Users/nrser/dev/gopath/bin/booking github.com/robfig/revel/samples/booking/app/tmp]
TRACE 2014/03/10 23:38:18 app.go:56: Exec app: /Users/nrser/dev/gopath/bin/booking [/Users/nrser/dev/gopath/bin/booking -port=56507 -importPath=github.com/robfig/revel/samples/booking -runMode=dev]
ERROR 2014/03/10 23:38:18 app.go:58: Error running: fork/exec /Users/nrser/dev/gopath/bin/booking: exec format error
i'm assuming this has something to do with some stuff being built using the old command line tools and some stuff with the new version, but i don't know how to clean the binaries out or force a rebuild of all the packages or whatever would be required. any help much appreciated.
some possibly relevant dumps:
uname -a
Darwin mba2 12.5.0 Darwin Kernel Version 12.5.0: Sun Sep 29 13:33:47 PDT 2013; root:xnu-2050.48.12~1/RELEASE_X86_64 x86_64
go env
GOARCH="amd64"
GOBIN=""
GOCHAR="6"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/nrser/dev/gopath"
GORACE=""
GOROOT="/usr/local/Cellar/go/1.2/libexec"
GOTOOLDIR="/usr/local/Cellar/go/1.2/libexec/pkg/tool/darwin_amd64"
TERM="dumb"
CC="/usr/local/bin/gcc-4.2"
GOGCCFLAGS="-g -O2 -fPIC -m64 -pthread -fno-common"
CXX="clang++"
CGO_ENABLED="1"
go was just installed via homebrew,
go version
go version go1.2 darwin/amd64

Related

Cannot install revel framework form Go

I tried to install Revel Framework. I followed all the steps as given in the documentation but whenever I tried to run the Revel command it throws panic error.
Following are the steps which I am performing
Enviormental path:
export GOROOT=/usr/local/go
export GOPATH=/Users/<username>/Desktop/gocode
export PATH="/Users/<username>/gocode/bin:$PATH"
To install Revel
go get github.com/revel/revel
go get github.com/revel/cmd/revel
export PATH="$PATH:$GOPATH/bin"
when I run revel version it shows:
panic: runtime error: slice bounds out of range
goroutine 1 [running]:
github.com/revel/cmd/model.(*CommandConfig).UpdateImportPath(0xc4200961c0, 0x20)
/Users/amitsharma/Desktop/gocode/src/github.com/revel/cmd/model/command_config.go:122 +0x907
main.main()
/Users/amitsharma/Desktop/gocode/src/github.com/revel/cmd/revel/revel.go:133 +0x243
When I run
revel run -a my-app
It shows
ERROR 19:34:59 harness.go:231: Could not start application error="revel/harness: app died reason: exit status 2"
INFO 19:34:59 watcher.go:272: Watcher: Recording error last build, setting rebuild on error="App failed to start up: revel/harness: app died reason: exit status 2"
INFO 19:34:59 watcher.go:277: Rebuilt, result error="App failed to start up: revel/harness: app died reason: exit status 2"
My go version
go version go1.10.3 darwin/amd64
My go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/amitsharma/Library/Caches/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/<username>/Desktop/gocode"
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/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/0d/pkfrs5cj0v57xgsnwvb2kb580000gn/T/go-build028697826=/tmp/go-build -gno-record-gcc-switches -fno-common"
Try re-install the revel
Here is how I have tried and it works for me.
Set the go path ($GOPATH):
export GOPATH=/var/projects/go
Install revel & cmd:
go get github.com/revel/revel
go get github.com/revel/cmd/revel
Link revel cmd to bin directory. So the command could be executable.
export PATH="$PATH:$GOPATH/bin
Check revel is working or not. Just type revel in command line
Output would be like this
Usage:
revel [OPTIONS] <command>
Application Options:
-v, --debug If set the logger is set to verbose
--historic-run-mode If set the runmode is passed a string not json
-X, --build-flags= These flags will be used when building the application. May be specified multiple times, only applicable for Build, Run,
Package, Test commands
Available commands:
build
clean
new
package
run
test
version
Check revel version:
revel version
Output
Revel executing: displays the Revel Framework and Go version
Revel Framework : 0.21.0 (0.21.0 remote master branch)
Revel Cmd : 0.21.1 (0.21.1 remote master branch)
Revel Modules : 0.21.0 (0.21.0 remote master branch)
Now, You can create first project using command
revel new myapp
Output
Revel executing: create a skeleton Revel application
Your application has been created in:
/var/projects/go/src/myapp
You can run it with:
revel run -a myapp

go install fail to generate binary

There are two folds to this problem:
1) Go install not able to generate binary
go version go1.7.3 linux/amd64
go env:
GOARCH="amd64" GOBIN="" GOEXE="" GOHOSTARCH="amd64" GOHOSTOS="linux" GOOS="linux" GOPATH="/opt/gopath" GORACE="" GOROOT="/opt/go" GOTOOLDIR="/opt/go/pkg/tool/linux_amd64" CC="gcc" GOGCCFLAGS="-fPIC
-m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build831334660=/tmp/go-build -gno-record-gcc-switches" CXX="g++" CGO_ENABLED="1"
Source of the program: https://github.com/hyperledger/fabric
Working dir: /opt/gopath/src/github.com/hyperledger/fabric
Main program to build: /opt/gopath/src/github.com/hyperledger/fabric/peer/main.go
Build command:
CGO_ENABLED=0 GOBIN=/opt/gopath/bin go install -x -ldflags " -X github.com/hyperledger/fabric/common/metadata.Version=1.0.0-snapshot-d6fbfcf -X github.com/hyperledger/fabric/common/metadata.BaseVersion=0.3.0 -X github.com/hyperledger/fabric/common/metadata.BaseDockerLabel=org.hyperledger.fabric -X github.com/hyperledger/fabric/common/metadata.DockerNamespace=hyperledger -X github.com/hyperledger/fabric/common/metadata.BaseDockerNamespace=hyperledger -linkmode external -extldflags -static -lpthread" github.com/hyperledger/fabric/peer
I expect the binary built in /opt/gopath/bin but there was nothing there.
It shows on the console that series of .a files were built and moved to /opt/gopath/pkg/linux_amd64/
Eventually program stopped and no binary was built.
This is true regardless CGO_ENABLED was set to 0 or 1.
Somehow the program thoughts it was done, without linking the object files and building the binary? Any other debugging measures that I can use to look further into it?
2) The 'Go install' command was taken from Makefile
#$(DRUN) \
-v $(abspath build/docker/bin):/opt/gopath/bin \
-v $(abspath build/docker/$(TARGET)/pkg):/opt/gopath/pkg \
hyperledger/fabric-baseimage:$(BASE_DOCKER_TAG) \
go install -compiler gccgo -ldflags "$(DOCKER_GO_LDFLAGS)" $(pkgmap.$(#F))
where
DRUN = docker run -i --rm $(DOCKER_RUN_FLAGS) \
-v $(abspath .):/opt/gopath/src/$(PKGNAME) \
-w /opt/gopath/src/$(PKGNAME)
The 'Go install' command was run inside a docker container, which was started the same way the Makefile specified. The only difference was that I was doing it manually, in two shots, i.e. start docker container + go install. If I were to build it with Makefile in one shot, it would work just fine.
Is there any catch/caveat on using this 'docker run <image> go install <args>' style command?

Go tool unable to find binary. go tool: no such tool "vet"

I'm running golang in a docker container. And 'go tool' is unable to find 'vet'. Could you give me ideas on how to debug this?
I've used the Dockerfile for 1.5 as a template. https://github.com/docker-library/golang/blob/51d6eacd41fe80d41105142b9ad32f575082970f/1.5/Dockerfile
ENV GOLANG_VERSION 1.5.1
ENV GOLANG_DOWNLOAD_URL https://golang.org/dl/go$GOLANG_VERSION.linux- amd64.tar.gz
ENV GOLANG_DOWNLOAD_SHA1 46eecd290d8803887dec718c691cc243f2175fe0
RUN curl -fsSL "$GOLANG_DOWNLOAD_URL" -o golang.tar.gz \
&& echo "$GOLANG_DOWNLOAD_SHA1 golang.tar.gz" | sha1sum -c - \
&& tar -C /usr/local -xzf golang.tar.gz \
&& rm golang.tar.gz
ENV GOPATH /go
ENV PATH $GOPATH/bin:/usr/local/go/bin:$PATH
However, when I install govet with
go get golang.org/x/tools/cmd/vet
and try
bash-4.3# go tool vet
go tool: no such tool "vet"
I have the following go environment set up:
$PATH includes $GOPATH/bin /usr/lib/go/bin:/go/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
bash# go env
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/go"
GORACE=""
GOROOT="/usr/lib/go"
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
GO15VENDOREXPERIMENT=""
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0"
CXX="g++"
CGO_ENABLED="1"
bash# ls $GOPATH/bin
fgt go-junit-report godep golint mt-content-blogs vet
bash# ls $GOROOT/bin/
go gofmt
The crux of the issue is that go tools does not list vet, even after installing it with go get golang.org/x/tools/cmd/vet
bash# go tool
addr2line
api
asm
cgo
compile
dist
doc
fix
link
nm
objdump
pack
pprof
trace
yacc
Warning: starting Go 1.12 (February 2019, 3.5 years later), go tool vet won't be available at all. Only go vet.
See go 1.12 release notes:
The go vet command has been rewritten to serve as the base for a range of different source code analysis tools. See the golang.org/x/tools/go/analysis package for details.
A side-effect is that go tool vet is no longer supported.
External tools that use go tool vet must be changed to use go vet.
Using go vet instead of go tool vet should work with all supported versions of Go.
As part of this change, the experimental -shadow option is no longer available with go vet.
Checking for variable shadowing may now be done using:
go install golang.org/x/tools/go/analysis/passes/shadow/cmd/shadow
go vet -vettool=$(which shadow)
Figured out the issue. It appears that I had missed installing go tools on the base docker image that I was using.
RUN apk --update-cache --allow-untrusted \
--repository http://dl-3.alpinelinux.org/alpine/edge/community/ \
--arch=x86_64 add \
go=${GOLANG_VERSION}-r3 \
go-tools=${GOLANG_VERSION}-r3 \
git \
&& rm -rf /var/cache/apk/* \
&& mkdir -p /go/src /go/bin \
&& chmod -R 777 /go

Go is printing xgcc version but not go installed version

On go version : It prints
go version xgcc (Ubuntu 4.9.1-0ubuntu1) 4.9.1 linux/amd64
My installed version is the latest one and i.e 1.4.2
which got installed from the tar version : go1.4.2.linux-amd64.tar.gz
GO Environmental variables looks exactly like this:
GOARCH="amd64"
GOBIN="/home/user/coding/golang/gocnew/goc/bin"
GOCHAR="6"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/user/coding/golang/gocnew/goc"
GORACE=""
GOROOT="/home/user/go"
GOTOOLDIR="/home/user/go/pkg/tool/linux_amd64"
TERM="dumb"
CC="gcc"
GOGCCFLAGS="-g -O2 -fPIC -m64 -pthread"
CXX="g++"
CGO_ENABLED="1"
I expect go version to be printed as 1.4.2, so how that can be achieved?
Looks like you have two versions of Go installed. One from ubuntu package manager and one you installed from source tar.
To confirm kindly try to remove gccgo :
sudo apt-get remove gccgo
I got the same issue and i fixed it by this way:
Access to go folder: /usr/local/go (The installation folder of go)
Execute these commands:
Added by Go Path
echo 'export GOROOT=/usr/local/go' >> ~/.bashrc
echo 'export GOPATH=$HOME/go' >> ~/.bashrc
echo 'export PATH=$PATH:$GOROOT/bin:$GOPATH/bin' >> ~/.bashrc
And then go to the source folder and check go version:
go version go1.12.2 linux/amd64 it will be displayed the same version in go folder and you can work with go commands.

Go lang installation issues with ./make.bash ubuntu->windows

I have tried to search and found a lot of topics which are related to my problem, but none of them I could follow to success.
I can go run and go get with no issues, but I need to compile into windows and there I have problems please see bellow
mikhail#mikhail-desktop:/usr/lib/go/src$ sudo ./make.bash
# Building C bootstrap tool.
cmd/dist
go tool dist: $GOROOT is not set correctly or not exported
GOROOT=/usr/share/go
/usr/share/go/include/u.h does not exist
mikhail#mikhail-desktop:/usr/lib/go/src$ go env
GOARCH="amd64"
GOBIN=""
GOCHAR="6"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/mikhail/Documents/FL/0go"
GORACE=""
GOROOT="/usr/lib/go"
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
TERM="dumb"
CC="gcc"
GOGCCFLAGS="-g -O2 -fPIC -m64 -pthread"
CXX="g++"
CGO_ENABLED="1"
mikhail#mikhail-desktop:/usr/lib/go/src$
By some reasons it thinks the GOROOT is /usr/share/go while it actually /usr/lib/go
sudo can clean environment variables, to check if that is the case here, run sudo $(which go) env and check if the output is what you expect. If not, you can keep the enviroment of your user by using the -E flag: sudo -E ./make.bash.
I think it somehow connected to Debian/Ubuntu thing. I seen such issues but related to 0.9. version.
I have installed go from source into ~/go and then everything went quite OK, now I can compile to windows from ubuntu with help Introduction to cross compilation with go and LiteIDE.

Resources