-
Notifications
You must be signed in to change notification settings - Fork 224
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How do I make a BXL script depend on file contents? #748
Comments
Main thing: More things:
I am running a bit of an old Buck2. Maybe those first two BXL issues have been fixed since. All in all, this works: def _cat_files_impls(ctx: BxlContext):
actions = ctx.bxl_actions().actions
# Each target expression expands to a list of targets, so we flatten the
# input into a flat list of targets.
targets = []
for t in ctx.cli_args.targets:
targets += t
# The inputs() returns a file_set, which is a set of bxl.FileNode.
# We need these as source artifacts.
files = [ctx.fs.source(file) for file in ctx.uquery().inputs(targets)]
report_file = actions.declare_output("all.txt")
script = actions.write(
"cat_files.sh",
[
"OUTPUT=\"$1\"",
"shift",
'cat "$@" > "$OUTPUT"',
],
is_executable = True,
)
actions.run(
cmd_args("/bin/sh", script, report_file.as_output(), files),
category = "cat_files",
)
ensured = ctx.output.ensure(report_file)
ctx.output.print(ensured)
# buck2 bxl cat_files.bxl:cat_files -- --targets thing//:main | xargs cat
cat_files = bxl_main(
impl = _cat_files_impls,
cli_args = {
"targets": cli_args.list(cli_args.target_expr()),
},
)
|
Fantatic! I understood the root cause but had not found this As to your other points:
|
For (2), it is used all over the prelude, like when putting together rustc argfiles. Those scripts are linked to a specific compile step, and only need rewriting when the dependency lists / rust flags change. That involves writing many flags conditionally, so it's useful for Buck to track which ones were actually used. I think it's just slightly less often useful in BXL, but you might do it for (5). The main benefit of getting dependencies written into the script itself is that you can open that file and see what buck is doing. |
I'm writing a BXL script for linting C++ files with clang-tidy. The script itself is very simple:
(I left out some irrelevant details)
This works well enough as a prototype, except that successes are cached even if I edit a source file and add an error on purpose. I get why this is happening: the build graph doesn't change, so my
uquery
is cached, so the whole script is cached.I've tried to add dependencies wherever I could via
cmd_args
'hidden
parameter, but no dice (heh). Buck nags me with abut won't let me easily depend on that change.
Is there a way that I can someone add a dependency on the contents of the input files that doesn't involve e.g. reading them via a dynamic action and some hashing?
The text was updated successfully, but these errors were encountered: