Skip to content
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

BXL: format ctx.output.print_json() arguments #759

Open
cbarrete opened this issue Aug 29, 2024 · 3 comments
Open

BXL: format ctx.output.print_json() arguments #759

cbarrete opened this issue Aug 29, 2024 · 3 comments

Comments

@cbarrete
Copy link
Contributor

Objects like cmd_args or RunInfo are formatted when dumped with ctx.output.write_json(). Is there a way to do the same thing with ctx.output.print_json()? If not, would this be accepted as a new feature, via an optional argument that defaults to False?

@Nero5023
Copy link
Contributor

Nero5023 commented Sep 2, 2024

You mean actions.write_json here for ctx.output.write_json()?

I am not very sure what do you mean here. You mean you want the feature that the output of ctx.output.print_json() for objects like cmd_args or RunInfo be the same as actions.write_json?

Right now the output of ctx.output.print_json() for object cmd_args(["echo", "hello"]) is

{
  "items": [
    "\"echo\"",
    "\"hello\""
  ],
  "hidden": [],
  "options": null
}

actions.write_json:

["echo","hello"]

@cbarrete
Copy link
Contributor Author

cbarrete commented Sep 2, 2024

You mean actions.write_json here for ctx.output.write_json()?

Yes I do, my bad.

I am not very sure what do you mean here. You mean you want the feature that the output of ctx.output.print_json() for objects like cmd_args or RunInfo be the same as actions.write_json?

Yes, I made a POC at main...cbarrete:buck2:print-json. I'm sure it wouldn't be merged as is because it just makes a lot of private APIs public for convenience, but the point is that it renders e.g. cmd_args as strings or lists of strings, artifacts as paths, etc.

I think that this behavior makes sense for most use cases? If someone is to output data as JSON, surely it is for something else to consume it, and the debug representation of starlark objects is unusable for those.

A concrete example is compilation database generation in C++: without this feature, one needs to write the JSON out to a file, print its path and have the user copy that file, as opposed to "just" redirecting stdout to the desired location.

@Nero5023
Copy link
Contributor

Nero5023 commented Sep 5, 2024

Yeah, it makes sense. I will look into this. Thank you for reporting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants