Query an attribute of a target.
(buck2: str, target: str, attribute: str)
| 27 | |
| 28 | |
| 29 | def query(buck2: str, target: str, attribute: str) -> str: |
| 30 | """Query an attribute of a target.""" |
| 31 | output = run([buck2, "cquery", target, "--output-attribute", attribute]) |
| 32 | |
| 33 | try: |
| 34 | output_json = json.loads(output) |
| 35 | return output_json[next(iter(output_json))][attribute] |
| 36 | except (json.JSONDecodeError, KeyError) as e: |
| 37 | print(f"Failed to parse JSON from query({target}, {attribute}): {output}") |
| 38 | raise SystemExit("Error: " + str(e)) |
| 39 | |
| 40 | |
| 41 | # Cache to store results for exported headers per target. |
no test coverage detected