facebook / facebook/buck2

How can you get a library's output path from bxl?

Open
#528 7 comments 0 reactions 0 assignees View on GitHub
bxl
Dominant language
Rust
Stars
4.4k
Forks
394
PR merge metrics
No merged PRs in 30d

Description

I want the equivalent of `buck2 targets root//:foo --show-output` but implemented from bxl.

Things I tried:

Assume that in all of the following cases, I have `output = ctx.analysis(target).providers()[DefaultInfo].default_outputs[0]`

1. `output`: This gives is an `artifact` object, but there appears to be no way (that I can find anyway) to get the path of that artifact in the output directory.

2. `ctx.output.ensure(output)`: That returns an `ensured_artifact` which have `abs_path()` and `rel_path()` methods, but those methods dont' return strings, they just appear to return the original `ensured_artifact`. Besides, I don't actually want to build them, I just want their paths (similar to what `buck2 targets --show-output` does).

3. `ctx.fs.abs_path_unsafe(output)`. I get the unusual error:

> Traceback (most recent call last):
> File , in
> * bxl/foo.bxl:50, in _impl
> ctx.output.print(" lib outputs: {}".format(get_lib_outputs(ctx, target)))
> * bxl/foo.bxl:14, in get_lib_outputs
> ctx.output.print(ctx.fs.abs_path_unsafe(output))
> error: Type of parameter `expr` doesn't match, expected `artifact | file_node | str`, actual `artifact`
> --> bxl/foo.bxl:14:22
> |
> 14 | ctx.output.print(ctx.fs.abs_path_unsafe(output))
> | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> |

which is complaining the expected type (`artifact`) and actual type (`artifact`) don't match.

Anything else I can try?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.