alecbenson / nulecule-go

A golang port of the nulecule spec implementation
GNU Lesser General Public License v3.0
3 stars 4 forks source link

Weird build experience #1

Open vpavlin opened 9 years ago

vpavlin commented 9 years ago

If I call make cmd it fails with message

go test -v ./...
main.go:4:2: cannot find package "github.com/alecbenson/nulecule-go/atomicapp/cli" in any of:
    /usr/lib/golang/src/github.com/alecbenson/nulecule-go/atomicapp/cli (from $GOROOT)
    /vagrant_data/nulecule-go/atomicapp/src/github.com/alecbenson/nulecule-go/atomicapp/cli (from $GOPATH)
cli/command.go:6:2: cannot find package "github.com/Sirupsen/logrus" in any of:
    /usr/lib/golang/src/github.com/Sirupsen/logrus (from $GOROOT)
    /vagrant_data/nulecule-go/atomicapp/src/github.com/Sirupsen/logrus (from $GOPATH)
cli/general.go:7:2: cannot find package "github.com/alecbenson/nulecule-go/atomicapp/logging" in any of:
    /usr/lib/golang/src/github.com/alecbenson/nulecule-go/atomicapp/logging (from $GOROOT)
    /vagrant_data/nulecule-go/atomicapp/src/github.com/alecbenson/nulecule-go/atomicapp/logging (from $GOPATH)
cli/install.go:7:2: cannot find package "github.com/alecbenson/nulecule-go/atomicapp/nulecule" in any of:
    /usr/lib/golang/src/github.com/alecbenson/nulecule-go/atomicapp/nulecule (from $GOROOT)
    /vagrant_data/nulecule-go/atomicapp/src/github.com/alecbenson/nulecule-go/atomicapp/nulecule (from $GOPATH)
container/container.go:5:2: cannot find package "github.com/alecbenson/nulecule-go/atomicapp/constants" in any of:
    /usr/lib/golang/src/github.com/alecbenson/nulecule-go/atomicapp/constants (from $GOROOT)
    /vagrant_data/nulecule-go/atomicapp/src/github.com/alecbenson/nulecule-go/atomicapp/constants (from $GOPATH)
container/container.go:6:2: cannot find package "github.com/alecbenson/nulecule-go/atomicapp/utils" in any of:
    /usr/lib/golang/src/github.com/alecbenson/nulecule-go/atomicapp/utils (from $GOROOT)
    /vagrant_data/nulecule-go/atomicapp/src/github.com/alecbenson/nulecule-go/atomicapp/utils (from $GOPATH)
nulecule/install.go:10:2: cannot find package "github.com/alecbenson/nulecule-go/atomicapp/container" in any of:
    /usr/lib/golang/src/github.com/alecbenson/nulecule-go/atomicapp/container (from $GOROOT)
    /vagrant_data/nulecule-go/atomicapp/src/github.com/alecbenson/nulecule-go/atomicapp/container (from $GOPATH)
nulecule/answers.go:10:2: cannot find package "github.com/alecbenson/nulecule-go/atomicapp/parser" in any of:
    /usr/lib/golang/src/github.com/alecbenson/nulecule-go/atomicapp/parser (from $GOROOT)
    /vagrant_data/nulecule-go/atomicapp/src/github.com/alecbenson/nulecule-go/atomicapp/parser (from $GOPATH)
nulecule/run.go:8:2: cannot find package "github.com/alecbenson/nulecule-go/atomicapp/provider" in any of:
    /usr/lib/golang/src/github.com/alecbenson/nulecule-go/atomicapp/provider (from $GOROOT)
    /vagrant_data/nulecule-go/atomicapp/src/github.com/alecbenson/nulecule-go/atomicapp/provider (from $GOPATH)
nulecule/answers.go:12:2: cannot find package "gopkg.in/yaml.v1" in any of:
    /usr/lib/golang/src/gopkg.in/yaml.v1 (from $GOROOT)
    /vagrant_data/nulecule-go/atomicapp/src/gopkg.in/yaml.v1 (from $GOPATH)
make: *** [test] Error 1

i.e. target all shouldn't depend on target test as there is nothing to test when you try to build for the first time

Second thing is that when I remove the test dependency from Makedfile, I get this:

go build -o atomicgo .
main.go:4:2: cannot find package "github.com/alecbenson/nulecule-go/atomicapp/cli" in any of:
    /usr/lib/golang/src/github.com/alecbenson/nulecule-go/atomicapp/cli (from $GOROOT)
    /vagrant_data/nulecule-go/atomicapp/src/github.com/alecbenson/nulecule-go/atomicapp/cli (from $GOPATH)
make: *** [all] Error 1

Doing go get github.com/alecbenson/nulecule-go/atomicapp/cli fixes it, but it feels weird to have to go get the package that is part of the application first..logrus and yaml are pulled just fine.

Last thing is that even when the build passes (after doing go get and go build), make test still fails with

go test -v ./...
src/github.com/Sirupsen/logrus/hooks/airbrake/airbrake.go:8:2: cannot find package "github.com/tobi/airbrake-go" in any of:
    /usr/lib/golang/src/github.com/tobi/airbrake-go (from $GOROOT)
    /vagrant_data/nulecule-go/atomicapp/src/github.com/tobi/airbrake-go (from $GOPATH)
src/github.com/Sirupsen/logrus/hooks/bugsnag/bugsnag.go:7:2: cannot find package "github.com/bugsnag/bugsnag-go" in any of:
    /usr/lib/golang/src/github.com/bugsnag/bugsnag-go (from $GOROOT)
    /vagrant_data/nulecule-go/atomicapp/src/github.com/bugsnag/bugsnag-go (from $GOPATH)
src/github.com/Sirupsen/logrus/hooks/sentry/sentry.go:9:2: cannot find package "github.com/getsentry/raven-go" in any of:
    /usr/lib/golang/src/github.com/getsentry/raven-go (from $GOROOT)
    /vagrant_data/nulecule-go/atomicapp/src/github.com/getsentry/raven-go (from $GOPATH)
make: *** [test] Error 1
alecbenson commented 9 years ago

You are correct about the makefile trying to invoke test when there's nothing to build for the first time. That should definitely not be there. I will fix that. Not quite sure why the CLI package is not installing correctly. What steps did you take to install?

As for the last point, Sirupsen's logrus is also a dependency for installing -- which I forgot to include in the readme. I will add that.

vpavlin commented 9 years ago

No steps taken:-) Just

git clone https://github.com/alecbenson/nulecule-go/
cd nulecule-go/atomicapp
make

As described above, when is do go get for nulecule-go/cli, I get logrus pulled in as well..

alecbenson commented 9 years ago

When you are cloning the repo, are you cloning it to a directory within your $GOPATH? If not, that might explain why you need to do a go get in order to be able to use the program.

vpavlin commented 9 years ago

I might be confused, but I think I have it there:

[root@localhost atomicapp]# export GOPATH=/vagrant_data/nulecule-go/
[root@localhost atomicapp]# make clean
rm atomicgo
[root@localhost atomicapp]# make
go build -o atomicgo .
main.go:4:2: cannot find package "github.com/alecbenson/nulecule-go/atomicapp/cli" in any of:
    /usr/lib/golang/src/github.com/alecbenson/nulecule-go/atomicapp/cli (from $GOROOT)
    /vagrant_data/nulecule-go/src/github.com/alecbenson/nulecule-go/atomicapp/cli (from $GOPATH)
make: *** [all] Error 1
[root@localhost atomicapp]# pwd
/vagrant_data/nulecule-go/atomicapp
alecbenson commented 9 years ago

Okay, I think I see what the issue is. Your $GOPATH should point to where Golang is installed on your machine. So for example, my $GOPATH points to /home/abenson/go/bin

All of your Go projects should reside within the go directory (Go development is kind of odd in this way :) ). So when you are trying to build with make, Go is looking for the different Go packages (like CLI, for example), in a folder in /usr/lib/golang/src/github.com/alecbenson/nulecule-go/atomicapp/cli. When you do a go get github.com/alecbenson/nulecule-go/atomicapp/cli, things start working because go installs the project into the folder that it expects to find it in (which is /usr/lib/golang/src/github.com/alecbenson/nulecule-go/atomicapp/cli).

Here's how I would fix the problem you are having:

  1. set your $GOPATH to /usr/lib/golang/bin
  2. Add your GOPATH to your $PATH (export PATH=$PATH:$GOPATH)
  3. Clone the nulecule-go repo to /usr/lib/golang/src/github.com/alecbenson/

It's convenient to add these to your bashrc so that you don't have to adjust your environment variables each time.

That should get things up and running. Fingers are crossed, let me know if you bump into any problems.