Hi folks, I'm wondering if there is a tutorial on ...
# general
d
Hi folks, I'm wondering if there is a tutorial on how to write a codegen rule and target? I got a little lost trying to read how protobuf codegen works πŸ˜… I'm trying to add a target + rules that generate files using templated params from the target.
h
d
no, haha, I was looking under rules API. πŸ™
h
Let us know if you have any questions! It sounds like the
relocated_files
target might also be a better example for you https://github.com/pantsbuild/pants/blob/3dde4f922c4f539003f64f24091f1f76169e149f/src/python/pants/core/target_types.py#L80-L204 It too "generates"
files
based on fields from the target, and it doesn't actually have
sources
. It only registers a private field called
_sources
in order to use the plugin hook
πŸ™ 1
c
Depending on how advanced etc this is, maybe the coming
experimental_shell_command
could be useful (to at least know about) .. ?
A little bit more info about it here: https://github.com/pantsbuild/pants/pull/12878
d
Just saw this, this is awesome.
experimental_shell_command
is exactly what I need. πŸ™ Any chance for a future
python_command
? So we can plug in more complicated logic.
πŸ‘Œ 1
c
I will have to try this tomorrow, but I think you could add a dependency on a pex binary for instance, the execute that with your shell command..
πŸ™ 2
h
Good idea Andreas! I'd encourage not adding python_command, especially because you can use inline Bash in the BUILD file to invoke the pex_binary Better to not have multiple ways of doing the same thing imo
d
I can probably do it with a macro +
experimental_shell_command
πŸ‘ 1
c
Yea, agree, let’s make the
experimental_shell_command
do what we need to instead.. πŸ™‚ PR for pex support here: https://github.com/pantsbuild/pants/pull/13168
There may still be a few rough edges on the pex execution support, would love to get some feedback on that. Most notably I think is what you need to put into your
tools
field.