From 4f48b5a337cf60fd59feabfc46052a9e4bdc219f Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sat, 15 Jun 2024 10:28:59 -0700 Subject: [PATCH] Reorganize implementation of cquery_deps Summary: Minor rearrangement to make the handling of the 3 cases of Thrift/Protobuf/other make more sense to me and prepare for changes I need to make here for D58537292. Reviewed By: davidbarsky Differential Revision: D58632004 fbshipit-source-id: e9c9c58348f6e9b2041380e77a8ade163a6e0913 --- rust/rust-analyzer/resolve_deps.bxl | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/rust/rust-analyzer/resolve_deps.bxl b/rust/rust-analyzer/resolve_deps.bxl index ef08ff8a4..7437ab050 100644 --- a/rust/rust-analyzer/resolve_deps.bxl +++ b/rust/rust-analyzer/resolve_deps.bxl @@ -41,8 +41,7 @@ def materialize( def _process_target_config( ctx: BxlContext, target: bxl.ConfiguredTargetNode, - in_workspace: bool, - out_dir: bxl.EnsuredArtifact | None = None) -> TargetInfo: + in_workspace: bool) -> TargetInfo: # convert all source paths to absolute paths resolved_attrs = target.resolved_attrs_eager(ctx) @@ -105,8 +104,6 @@ def _process_target_config( copy["project_relative_buildfile"] = ctx.fs.project_rel_path(target.buildfile_path) copy["kind"] = target.rule_type copy["in_workspace"] = in_workspace - if out_dir: - copy["out_dir"] = out_dir return copy @@ -133,6 +130,12 @@ def cquery_deps( if candidate_workspace.raw_target() in workspaces: in_workspace = True + target_info = _process_target_config( + ctx = ctx, + target = target, + in_workspace = in_workspace, + ) + labels = attrs.get("labels") if "thrift_library-rust" in labels.value(): for src, dest in attrs.get("mapped_srcs").value().items(): @@ -141,12 +144,11 @@ def cquery_deps( src = src, dest = dest, )) - out[target.label.raw_target()] = _process_target_config(ctx, target, in_workspace) elif "generated_protobuf_library_rust" in labels.value(): protobuf_out_dir = materialize_generated_protobufs(ctx, target, actions, seen) - out[target.label.raw_target()] = _process_target_config(ctx, target, in_workspace, protobuf_out_dir) - else: - out[target.label.raw_target()] = _process_target_config(ctx, target, in_workspace) + target_info["out_dir"] = protobuf_out_dir + + out[target.label.raw_target()] = target_info materialize_generated_thrift(ctx, actions, mapped_srcs, out)