skelterjohn/go-gb

Dependency order problem

cdunn2001 opened this issue · 3 comments

We have a strange problem. gb works great from a sub-dir, but not the parent dir, where it builds out of order. I don't see anything in the parent dir which should cause a problem.

I can give you a test-case, but it requires doozer. Using the release (not latest) golang:

goinstall github.com/ha/doozer
git clone git://github.com/bketelsen/skynet.git
cd skynet
git checkout cdbcab72  # if tip moves
cd skynet/examples/GetWidgets
gb  # This should succeed.
gb -c
cd ..  # problem occurs in both root and examples dirs
gb

You'll see this:

mangoInitiator.go: 10: can't find import: myStartup

For reference.

What are we doing wrong, John?

(I'm not positive it requires doozer. That might be runtime-only.)

One good way to figure out why gb doesn't give access to the import you want is to run "gb -s". It prints out the target for all local packages. My guess is that to get to myStartup from where you run gb, it has to go through an intermediate directory (the sub-dir you mentioned).

gb assigns import paths to packages by looking at the relative path to the package's source directory. There are some ways to override this (discussed in the doc) but I recommend you don't (to main compatibility with goinstall).

Another thing you can do is create a file called 'workspace.gb' that contains one line - the absolute or relative path to your workspace directory. This allows you to execute gb from within one directory, and have it pretend it is running from another directory (your workspace). The relative paths from the workspace directory are then used to determine import paths.

In summary - gb cares about where you run it from, and "gb -s" can help you get your import paths right.

Thanks. -S (capitalized) helped.

It was already working in the sub-dir, so workspace.gb didn't help. The problem was the reverse: an unnamespaced package in a sub-dir. What worked was either:

//target:myStartup
package myStartup

in examples/GetWidgets/myStartup/package.go, or

myStartup

in examples/GetWidgets/myStartup/target.gb.

Thanks!

A note in the docs on the syntax could help. The following does not work:

//target: myStartup

The space after the colon breaks it. Nor does this work:

//target:myStartup -- needed for go-gb

The trailing comment kills it, even though it follows whitespace.

An example is clear, so I added one. I'll send you a pull-request.

One other question: Do you have any idea why gb does not work on gb itself when it was installed by goinstall inside go/src/pkg/github.com/...?

cd pkg/github.com/skelterjohn/go-gb
gb -s

Shows only:

goroot cmd "gb" (installed)

So I cannot build the examples from within that directory. I had to do a fresh git clone elsewhere. Not a problem. Just curious.