cannot find package "bufio" in any of - go

I have get go1.11.5 installed by downloading precompiled binary package directly on my ubuntu18.04. Now i want to install go1.12 by building from source, so i follow with Installing Go from source.
I set GOROOT_BOOTSTRAP=~/goroot_bootstrap
$ mkdir -p ~/goroot_bootstrap/bin
$ cp /usr/local/go/bin/go ~/goroot_bootstrap/bin/
$ echo "export GOROOT_BOOTSTRAP=~/goroot_bootstrap" >> ~/.bashrc
$ source ~/.bashrc
Then, get source
$ git clone -b release-branch.go1.12 https://github.com/golang/go.git ~/github.com/golang/go
Build
$ cd ~/github.com/golang/go/src
$ ./all.bash
It failed, and tips:
Building Go cmd/dist using /home/pi/goroot_bootstrap.
cmd/dist/imports.go:12.2: cannot find package "bufio" in any of:
/home/pi/goroot_bootstrap/src/bufio (from $GOROOT)
/home/pi/go/src/bufio (from $GOPATH)
...
But if i set GOROOT_BOOTSTRAP=/usr/local/go, it will success.
Then, i read source code at src/make.bash.
166 rm -f cmd/dist/dist
167 GOROOT="$GOROOT_BOOTSTRAP" GOOS="" GOARCH="" GO111MODULE=off "$GOROOT_BOOTSTRAP/bin/go" build -o cmd/dist/dist ./cmd/dist
The bootstrap toolchains build cmd/dist with GOROOT="$GOROOT_BOOTSTRAP" at line 167.
If i have GOROOT_BOOTSTRAP=/usr/local/go set and success, which means building still depending old package such as bufio.
So, why it failed when setting GOROOT_BOOTSTRAP=~/goroot_bootstrap?
Do building depends old package if setting GOROOT_BOOTSTRAP=/usr/local/go?
Which one is the right method to install from source?
Any help will be grateful.

Related

Singularity v3.9.4 Installation - mconfig not inside a git repository and no VERSION file found

I'm trying to install Singularity after installing Go. I've confirmed that Go has been installed successfully:
$ go version
go version go1.17.6 linux/amd64
After that, I run the following commands:
$ export VERSION=3.9.4
$ wget https://github.com/sylabs/singularity/archive/refs/tags/v${VERSION}.tar.gz
$ tar -xzf v${VERSION}.tar.gz
$ cd singularity-${VERSION}
$ ./mconfig # This is where it fails
E: Not inside a git repository and no VERSION file found. Abort.
The tarball you are downloading is the one generated automatically for a tag, not the release tarball. From the release page:
Source Code
Please use the singularity-ce-3.9.4.tar.gz download below to obtain and install SingularityCE 3.9.4. The GitHub auto-generated 'Source Code' downloads do not include required dependencies etc.
Working snippet using the correct url:
export VERSION=3.9.4
wget https://github.com/sylabs/singularity/releases/download/v${VERSION}/singularity-ce-${VERSION}.tar.gz && \
tar xf singularity-ce-${VERSION}.tar.gz && \
cd singularity-ce-${VERSION} && \
./mconfig

Cannot build open-source project

I'd like to contribute to an OSS project built with go, but I'm having hard time compiling it. It looks as if I'm missing something obvious.
I think the problem is related to how go is installed on my computer, and not to the project itself, thus I'm posting it here on StackOverflow, instead of project's "Issues" section.
Below is what I'm doing.
I've installed go using homebrew:
$ brew install go
Updating Homebrew...
==> Auto-updated Homebrew!
Updated 1 tap (homebrew/core).
==> Updated Formulae
libebml
==> Downloading https://homebrew.bintray.com/bottles/go-1.8.3.sierra.bottle.tar.gz
Already downloaded: /Users/gmile/Library/Caches/Homebrew/go-1.8.3.sierra.bottle.tar.gz
==> Pouring go-1.8.3.sierra.bottle.tar.gz
==> Caveats
A valid GOPATH is required to use the `go get` command.
If $GOPATH is not specified, $HOME/go will be used by default:
https://golang.org/doc/code.html#GOPATH
You may wish to add the GOROOT-based install location to your PATH:
export PATH=$PATH:/usr/local/opt/go/libexec/bin
==> Summary
🍺 /usr/local/Cellar/go/1.8.3: 7,035 files, 282.0MB
$
Then I cloned the repo:
$ hub clone lucapette/fakedata
I ran make setup (per instruction), which at first did not complete successfully:
$ make setup
go get -u github.com/alecthomas/gometalinter
gometalinter --install
make: gometalinter: No such file or directory
make: *** [setup] Error 1
$
I figured that is because gometalinter is nowhere in my $PATH, so have added it (I'm using fish-shell):
$ set fish_user_paths /Users/gmile/go/bin
running make setup seem to have succeeded now. This is the output:
$ make setup
go get -u github.com/alecthomas/gometalinter
gometalinter --install
Installing:
aligncheck
deadcode
dupl
errcheck
gas
goconst
gocyclo
goimports
golint
gosimple
gotype
ineffassign
interfacer
lll
megacheck
misspell
safesql
staticcheck
structcheck
unconvert
unparam
unused
varcheck
$
Running make build fails:
$ make build
go build
main.go:11:2: cannot find package"github.com/lucapette/fakedata/pkg/fakedata" in any of:
/usr/local/Cellar/go/1.8.3/libexec/src/github.com/lucapette/fakedata/pkg/fakedata (from $GOROOT)
/Users/gmile/go/src/github.com/lucapette/fakedata/pkg/fakedata (from $GOPATH)
main.go:12:2: cannot find package "github.com/spf13/pflag" in any of:
/usr/local/Cellar/go/1.8.3/libexec/src/github.com/spf13/pflag (from $GOROOT)
/Users/gmile/go/src/github.com/spf13/pflag (from $GOPATH)
make: *** [build] Error 1
$
So either Contributing guideline is incomplete, or I'm missing something obvious about installing and managing go packages.
Your path when cloning the source must be on the golang PATH like :
/home/gujarat/golang/src/github.com/lucapette/fakedata
as you can see my Path to golang path is : /home/gujarat/golang/.
You can also print your golang path in your terminal by entering : $GOPATH.
And the git clone should be in the following the exact as above path : src/github.com/lucapette/.
cd $GOPATH/src/github.com/
mkdir lucaptte
cd lucapette
git clone https://github.com/lucapette/fakedata.git
When you are running the make command which trigger go build this command will look the $GOPATH and your $GOROOT folder.
Your go source should in your gopath - here it is Users/gmile/src. Use go get to fetch the pkg you want to work on instead and it should work.

Install "context" package in golang?

I'm trying to install the context package in golang, which I did like this :
go get golang.org/x/net/context
But when I do an import "context", I still get the following error :
cannot find package "context" in any of:
/usr/lib/go-1.6/src/context (from $GOROOT)
/home/saurabh/work/src/context (from $GOPATH)
Can anyone suggest how to install this package ? I'm currently using version go1.6.2.
change import "context" to import "golang.org/x/net/context".
but after go 1.7 you can use import "context", as it had become a standard library.
Go 1.7 moves the golang.org/x/net/context package into the standard library as context.
see 1.7 release notes: https://golang.org/doc/go1.7#context
I faced similar issue , below are the steps to fix:
Download the latest version https://golang.org/doc/install?download=go1.9.2.linux-arm64.tar.gz
Extract the tar to /usr/local/ .
Use Command ->
tar -xzvf go1.9.2.linux-arm64.tar.gz -C /usr/local
Replace the symlink pointing to go:
sudo rm /usr/bin/go
sudo ln -s /usr/local/go/bin/go /usr/bin/go
Reference: https://github.com/DieterReuter/arm64-docker-builder/issues/7

Resolving 'cannot find package' error with vendor in go 1.7

I have a project structure which looks like below:-
session-service
_libs //Contains all the external dependencies
api
constants
exceptions
idgen
jsonDecoder
log
model
monitor
persistence
redis
routes
src/bddtest/servicetest
util
Content of _libs looks like below:-
github.com
golang.org
x
net
gopkg.in
My Makefile looks like below:-
.PHONY: deploy
LOGLEVEL ?= 1
CONFIGFILE ?= 2
GOFLAGS ?= $(GOFLAGS:)
PWD = $(shell pwd)
export GOPATH = $(shell echo $$GOPATH):$(PWD)/_libs:$(PWD)
export GOBIN = $(PWD)/bin
export GOROOT = $(shell echo $$GOROOT)
deploy: clean build install
build:
#rm -rf pkg/ 2>/dev/null
#rm -rf _libs/pkg/ 2>/dev/null
#go build $(GOFLAGS) ./...
install:
#go install ./...
clean:
#go clean $(GOFLAGS) -i ./...
## EOF
Everything is working fine. Now I am thinking of moving to vendor. So I renamed my _libs to vendor and modified my Makefile like below:-
export GOPATH = $(shell echo $$GOPATH):$(PWD)
But after this I started getting the following error:-
vendor/golang.org/x/net/html/charset/charset.go:20:2: cannot find package "golang.org/x/text/encoding" in any of:
/Users/debraj/golang/src/b/m/session-service/vendor/golang.org/x/text/encoding (vendor tree)
/usr/local/go/src/golang.org/x/text/encoding (from $GOROOT)
/Users/debraj/golang/src/golang.org/x/text/encoding (from $GOPATH)
/Users/debraj/golang/src/b/m/session-service/src/golang.org/x/text/encoding
vendor/golang.org/x/net/html/charset/charset.go:21:2: cannot find package "golang.org/x/text/encoding/charmap" in any of:
/Users/debraj/golang/src/b/m/session-service/vendor/golang.org/x/text/encoding/charmap (vendor tree)
/usr/local/go/src/golang.org/x/text/encoding/charmap (from $GOROOT)
/Users/debraj/golang/src/golang.org/x/text/encoding/charmap (from $GOPATH)
/Users/debraj/golang/src/b/m/session-service/src/golang.org/x/text/encoding/charmap
vendor/golang.org/x/net/html/charset/charset.go:22:2: cannot find package "golang.org/x/text/encoding/htmlindex" in any of:
/Users/debraj/golang/src/b/m/session-service/vendor/golang.org/x/text/encoding/htmlindex (vendor tree)
/usr/local/go/src/golang.org/x/text/encoding/htmlindex (from $GOROOT)
/Users/debraj/golang/src/golang.org/x/text/encoding/htmlindex (from $GOPATH)
/Users/debraj/golang/src/b/m/session-service/src/golang.org/x/text/encoding/htmlindex
vendor/golang.org/x/net/html/charset/charset.go:23:2: cannot find package "golang.org/x/text/transform" in any of:
/Users/debraj/golang/src/b/m/session-service/vendor/golang.org/x/text/transform (vendor tree)
/usr/local/go/src/golang.org/x/text/transform (from $GOROOT)
/Users/debraj/golang/src/golang.org/x/text/transform (from $GOPATH)
/Users/debraj/golang/src/b/m/session-service/src/golang.org/x/text/transform
vendor/golang.org/x/net/http2/h2i/h2i.go:38:2: cannot find package "golang.org/x/crypto/ssh/terminal" in any of:
/Users/debraj/golang/src/b/m/session-service/vendor/golang.org/x/crypto/ssh/terminal (vendor tree)
/usr/local/go/src/golang.org/x/crypto/ssh/terminal (from $GOROOT)
/Users/debraj/golang/src/golang.org/x/crypto/ssh/terminal (from $GOPATH)
/Users/debraj/golang/src/b/m/session-service/src/golang.org/x/crypto/ssh/terminal
Environment:-
go version go1.7.3 darwin/amd64
Mac OS X 10.11.6
Can someone let me know why I am getting the above errors with vendor but everything works fine with _libs?
UPDATE
In my local the newlines in the output of $(go list ./... | grep -v /vendor/) was causing some problem. So to resolve this I had to modify the jimb 's solution a bit. I introduced a variable in Makefile PKG = $(shell go list ./... | grep -v /vendor/ | tr "\n" " ") and then used that variable in go install & go build like #go build $(GOFLAGS) $(PKG)
The _libs directory starts with _, and is ignored by the go tool. When you move the packages to vendor/, the ./... wildcard now includes all packages in the vendor directory.
You should explicitly list the package you want to install, rather than rely on the ./... wildcard. If you still want the wildcard behavior, you can use go list ./... and filter any package containing a vendor/ directory in their path. Depending on your specific needs, this could be as simple as:
go install $(go list ./... | grep -v vendor/)

Go install: “Can't load package” (even though GOPATH is set)

I'm just getting started with the Go programming language and installed Go using the Windows installer from the website. I tested installation by using go run hello.go and that works. The problem comes when I try to build my first program:
$ echo $GOROOT
C:\Go\
$ echo $GOPATH
/cygdrive/c/Users/Paul/Documents/Home/go
mkdir -p $GOPATH/src/hello
Inside that directory I have a simple hello.go program:
package main
import "fmt"
func main() {
fmt.Printf("Hello, world.\n")
}
The problem comes when I try to build and install:
$ go install hello
can't load package: package hello: cannot find package "hello" in any of:
C:\Go\src\hello (from $GOROOT)
\cygdrive\c\Users\Paul\Documents\Home\go\src\hello (from $GOPATH)
GOPATH environment variable must contain valid path.
\cygdrive\c\Users\Paul\Documents\Home\go\src\hello is not a valid path on Windows.
Try setting GOPATH=c:\Users\Paul\Documents\Home\go instead.

Resources