https://pantsbuild.org/ logo
#general
Title
# general
d

dazzling-diamond-4749

10/01/2021, 3:56 AM
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

happy-kitchen-89482

10/01/2021, 4:02 AM
d

dazzling-diamond-4749

10/01/2021, 4:03 AM
no, haha, I was looking under rules API. πŸ™
h

hundreds-father-404

10/01/2021, 4:07 AM
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

curved-television-6568

10/01/2021, 10:44 AM
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

dazzling-diamond-4749

10/07/2021, 8:38 PM
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

curved-television-6568

10/07/2021, 8:47 PM
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

hundreds-father-404

10/07/2021, 8:59 PM
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

dazzling-diamond-4749

10/07/2021, 9:00 PM
I can probably do it with a macro +
experimental_shell_command
πŸ‘ 1
c

curved-television-6568

10/08/2021, 10:57 AM
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.
4 Views