Hi, is there a way to make sure a BUILD rule is al...
# general
m
Hi, is there a way to make sure a BUILD rule is always executed fresh and never cached? I have a very simple and fast code generator that i just call with a
shell_command
rule. The generator pulls in metadata from the environment at build time. I want this metadata to always be fresh when someone runs
pants run
or
pants package
on anything that uses this rule, even if none of the inputs to the
shell_command
rule have changed. Is there a way to do this? It somewhat breaks pants' purity assumption, but I would like to know if this is a viable solution to get access to "build time environment state".
f
One solution would be this PR: https://github.com/pantsbuild/pants/pull/21245
It allows setting
cache_scope="session"
on
shell_command
and
adhoc_tool
targets which has the effect of rerunning the process for each Pants invocation.
I had only written it as a debug tool for in-workspace executions (which default to session scope), but it sounds like you could take advantage of this PR. That said, the "better" solution would be a Pants plugin which could monitor for changes in the relevant build environment state and only invalidate rules when it changes.
What metadata is this tool consuming?
And is it stored in files?
m
Thanks for the reply. Yes
cache_scope="session"
sounds like exactly what I would need here. For now I worked around it by generating a random file from
.pants.bootstrap
and depending on its contents as a "do_not_cache" rule. Feels very hacky, but it does the job.
The metadata right now is a bunch of git repo information (more than what
vcs_version
encodes) that we want to have available from Python for versioning and for generating useful user warnings depending on some internal best practices. This must be retained even after PEX packaging, so computing it during the Pants build seemed appropriate.