I'm writing a pants plugin and need to call out to...
# plugins
m
I'm writing a pants plugin and need to call out to Go program for some processing. I'm building the program in the same
BUILD
file as the plugin itself (and have added it to
dependencies
) but I can't quite figure out how I should reference it in order to create a
Process
🤔
f
The plugin will need to request that the Go backend build the binary within the plugin code.
The integration test in https://github.com/pantsbuild/pants/blob/6bcd56853a823c3d51a735e6c0977076076df68a/[…]ython/pants/backend/go/goals/package_binary_integration_test.py is an example with
RuleRunner
of asking the engine to package a
go_binary
target and then running it programmatically.
However, that only works for user code. If your plugin wants to package Go code to run, then you will have to use the workflow used by the Go backend itself for its own Go helper binaries. Take a look at
LoadedGoBinary
in https://github.com/pantsbuild/pants/blob/5580f808ceea83b15bbc85498f0a55b78362772a/src/python/pants/backend/go/go_sources/load_go_binary.py
(and the files which use the
LoadedGoBinary
rules)
That workflow is used to build the "package analyer" and the test main generator (among other uses)
m
Thanks! I managed to figure it out 🙏