Returns the BuildTargets matching the query, keyed by target name.
(query: str)
| 36 | |
| 37 | |
| 38 | def query_targets(query: str) -> Dict[str, BuildTarget]: |
| 39 | """Returns the BuildTargets matching the query, keyed by target name.""" |
| 40 | args: List[str] = [ |
| 41 | "buck2", |
| 42 | "cquery", |
| 43 | query, |
| 44 | "--output-attribute", |
| 45 | "exported_deps", |
| 46 | "--output-attribute", |
| 47 | "exported_headers", |
| 48 | "--output-attribute", |
| 49 | "visibility", |
| 50 | ] |
| 51 | cp: subprocess.CompletedProcess = subprocess.run( |
| 52 | args, capture_output=True, cwd=BUCK_CWD, check=True |
| 53 | ) |
| 54 | # stdout should be a JSON object like P643366873. |
| 55 | targets: dict = json.loads(cp.stdout) |
| 56 | |
| 57 | ret: Dict[str, BuildTarget] = {} |
| 58 | for name, info in targets.items(): |
| 59 | # Target strings may have an extra " (mode//config/string)" at the end. |
| 60 | name = name.split(" ", 1)[0] |
| 61 | exported_deps = [d.split(" ", 1)[0] for d in info.get("exported_deps", [])] |
| 62 | ret[name] = BuildTarget( |
| 63 | name=name, |
| 64 | exported_deps=exported_deps, |
| 65 | exported_headers=info.get("exported_headers", []), |
| 66 | visibility=info.get("visibility", []), |
| 67 | ) |
| 68 | return ret |
| 69 | |
| 70 | |
| 71 | def targets_exported_by( |