Skip to content

Commit

Permalink
AnonTargetAttrTraversal
Browse files Browse the repository at this point in the history
Summary:
This is a bit unfortuante - we already have a `traverse()` function, but it takes in a `dyn ConfiguredAttrTraversal` which lives in the buck2_node crate, which doesn't have access to promise artifacts.

Adding a separate function seems like the easiest way to implement this - we just need to traverse the anon target attrs to get all the promise artifact attrs. Let me know if there are other suggestions, like moving the promise artifact attr into the buck2_node crate, or something like that

Reviewed By: cjhopman

Differential Revision: D52741553

fbshipit-source-id: bed794ba0b56c8ef0ad073fb0c3a9506a0055cb6
  • Loading branch information
wendy728 authored and facebook-github-bot committed Jan 19, 2024
1 parent 59da8c7 commit 31930eb
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
44 changes: 44 additions & 0 deletions app/buck2_anon_target/src/anon_target_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ use serde::Serialize;
use serde::Serializer;
use serde_json::to_value;

use crate::anon_target_attr_resolve::AnonTargetAttrTraversal;

#[derive(Debug, Clone, PartialEq, Eq, Hash, Allocative)]
pub enum AnonTargetAttr {
Bool(BoolLiteral),
Expand Down Expand Up @@ -178,6 +180,48 @@ impl AnonTargetAttr {
}
}

#[allow(unused)]
pub fn traverse_anon_attr<'a>(
&'a self,
_traversal: &mut dyn AnonTargetAttrTraversal,
) -> anyhow::Result<()> {
match self {
AnonTargetAttr::Bool(_) => Ok(()),
AnonTargetAttr::Int(_) => Ok(()),
AnonTargetAttr::String(_) => Ok(()),
AnonTargetAttr::EnumVariant(_) => Ok(()),
AnonTargetAttr::List(list) => {
for v in list.iter() {
v.traverse_anon_attr(_traversal)?;
}
Ok(())
}
AnonTargetAttr::Tuple(list) => {
for v in list.iter() {
v.traverse_anon_attr(_traversal)?;
}
Ok(())
}
AnonTargetAttr::Dict(dict) => {
for (k, v) in dict.iter() {
k.traverse_anon_attr(_traversal)?;
v.traverse_anon_attr(_traversal)?;
}
Ok(())
}
AnonTargetAttr::None => Ok(()),
AnonTargetAttr::OneOf(l, _) => l.traverse_anon_attr(_traversal),
AnonTargetAttr::Dep(_) => Ok(()),
AnonTargetAttr::Artifact(_) => Ok(()),
AnonTargetAttr::Arg(_) => Ok(()),
AnonTargetAttr::PromiseArtifact(_) => {
// TODO(@wendyy) - use traversal here after updating the attr type
Ok(())
}
AnonTargetAttr::Label(_) => Ok(()),
}
}

pub fn _unpack_list(&self) -> Option<&[AnonTargetAttr]> {
match self {
AnonTargetAttr::List(list) => Some(list),
Expand Down
4 changes: 4 additions & 0 deletions app/buck2_anon_target/src/anon_target_attr_resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ pub(crate) struct AnonTargetDependentAnalysisResults<'v> {
pub(crate) promised_artifacts: HashMap<&'v PromiseArtifactAttr, Artifact>,
}

pub(crate) trait AnonTargetAttrTraversal {
fn promise_artifact(&mut self, promise_artifact: &PromiseArtifactAttr) -> anyhow::Result<()>;
}

impl AnonTargetDependents {
pub(crate) fn get_dependents(
anon_target: &AnonTargetKey,
Expand Down

0 comments on commit 31930eb

Please sign in to comment.