diff --git a/app/buck2_anon_target/src/anon_target_attr.rs b/app/buck2_anon_target/src/anon_target_attr.rs index 7c963db8865f..8e88ade90053 100644 --- a/app/buck2_anon_target/src/anon_target_attr.rs +++ b/app/buck2_anon_target/src/anon_target_attr.rs @@ -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), @@ -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), diff --git a/app/buck2_anon_target/src/anon_target_attr_resolve.rs b/app/buck2_anon_target/src/anon_target_attr_resolve.rs index d5e5735bc89d..feed424b0db6 100644 --- a/app/buck2_anon_target/src/anon_target_attr_resolve.rs +++ b/app/buck2_anon_target/src/anon_target_attr_resolve.rs @@ -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,