go_remote_library usage in Pants

149 views Asked by At

I am currently attempting to use the go_remote_library target??, package??, plugin?? in Pants. Real simple question, here:

If in my code I have the import listed as:

import(
  "github.com/golang/groupcache"
)

is it valid for me to specify a name of simply "groupcache" instead of the full import path? Here is what my BUILD file looks like:

go_remote_library(name="groupcache",
  rev="d781998583680cda80cf61e0b37dd0cd8da2eb52"
)

Am I doing this right? As a side note, is there a Pants target that I can use to test that my BUILD file is valid? Thanks!

1

There are 1 answers

0
John Sirois On BEST ANSWER

You are doing it right. All of the go targets - go_remote_library in this case, but also go_library and go_binary - currently take a name parameter and it must be the name of the directory the BUILD file lives in. The next release of pants (0.0.44) should remove the name parameter taking the choice away from you.

The 1st line of defense is the BUILD Dictionary. For go_remote_library you'll find this doc.

As to testing, the simplest test is checking syntax, and for that this does the trick:

./pants list path/to/BUILD:

Note the trailing colon attached to the path

This says "List all the targets defined in path/to/BUILD. Here the : means all - its equivalent to the * wildcard in bourne shells for pants targets in BUILD files.

If you want to check more targets all at once you could say:

./pants list ::

Here the recursive glob is used - equivalent to ** in zsh, and so this asks pants to list all the targets in the repo.

If the syntax checks out, you may still have more subtle issues, like defining a go_remote_library that does not point to a valid github project. These issues will only show up when you try to do more than act on the target's metadata like list and depmap goals do. For a go_remote_library, the simplest way to exercise it is to try and resolve the library:

./pants resolve 3rdparty/go/github.com/bitly/go-simplejson2

If you have this BUILD file contents at that path:

go_remote_library(name='go-simplejson2')

Running the resolve will fail since no such github repo exists.

You can do a similar higher-level check with go_library and go_binary targets, instead running ./pants compile .... This will smoke out whether you're missing any required go_remote_library BUILD files or dependencies.