Skip to content

Commit

Permalink
Move functions around
Browse files Browse the repository at this point in the history
Summary:
Moving some methods to functions.
Make `audit classpath` call `get_from_template_placeholder_info` so that it doesn't need to create an `AnalysisConfiguredGraphQueryDelegate` anymore.

Reviewed By: bobyangyf

Differential Revision: D44769837

fbshipit-source-id: dfe02ddf1e46ff64eb43ac481ff5393f3fa11523
  • Loading branch information
Scott Cao authored and facebook-github-bot committed Apr 8, 2023
1 parent d93c74d commit a23205b
Show file tree
Hide file tree
Showing 2 changed files with 193 additions and 251 deletions.
87 changes: 7 additions & 80 deletions app/buck2_build_api/src/analysis/configured_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,9 @@ use std::collections::VecDeque;
use std::sync::Arc;

use async_trait::async_trait;
use buck2_core::provider::label::ConfiguredProvidersLabel;
use buck2_core::provider::label::ProvidersName;
use buck2_core::target::label::ConfiguredTargetLabel;
use buck2_node::nodes::configured::ConfiguredTargetNode;
use buck2_node::nodes::configured_ref::ConfiguredGraphNodeRef;
use buck2_query::query::compatibility::MaybeCompatible;
use buck2_query::query::syntax::simple::eval::set::TargetSet;
use dice::DiceComputations;
use dupe::Dupe;
Expand All @@ -26,15 +23,7 @@ use dupe::OptionDupedExt;
use indexmap::IndexMap;

use crate::actions::artifact::artifact_type::Artifact;
use crate::analysis::calculation::RuleAnalysisCalculation;
use crate::artifact_groups::deferred::DeferredTransitiveSetData;
use crate::artifact_groups::deferred::TransitiveSetKey;
use crate::artifact_groups::ArtifactGroup;
use crate::deferred::calculation::DeferredCalculation;
use crate::deferred::types::DeferredValueReady;
use crate::interpreter::rule_defs::cmd_args::CommandLineArgLike;
use crate::interpreter::rule_defs::cmd_args::SimpleCommandLineArtifactVisitor;
use crate::interpreter::rule_defs::provider::builtin::template_placeholder_info::TemplatePlaceholderInfo;
use crate::query::analysis::environment::get_from_template_placeholder_info;
use crate::query::analysis::environment::ConfiguredGraphQueryEnvironmentDelegate;

pub struct AnalysisDiceQueryDelegate<'c> {
Expand All @@ -61,79 +50,17 @@ impl<'a> ConfiguredGraphQueryEnvironmentDelegate for AnalysisConfiguredGraphQuer
.ok_or_else(|| anyhow::anyhow!(""))
}

async fn dice_lookup_transitive_set(
&self,
key: TransitiveSetKey,
) -> anyhow::Result<DeferredValueReady<DeferredTransitiveSetData>> {
self.dice_query_delegate
.ctx
.compute_deferred_data(&key)
.await
}

async fn get_template_info_provider_artifacts(
&self,
configured_label: &ConfiguredTargetLabel,
template_name: &str,
) -> anyhow::Result<Vec<ArtifactGroup>> {
let providers_label =
ConfiguredProvidersLabel::new(configured_label.dupe(), ProvidersName::Default);

let providers = self
.dice_query_delegate
.ctx()
.get_providers(&providers_label);

let mut artifacts = vec![];

match providers.await? {
MaybeCompatible::Incompatible(reason) => {
eprintln!("{}", reason.skipping_message(configured_label));
}
MaybeCompatible::Compatible(providers) => {
let providers_collection = providers.provider_collection();

if let Some(template_placeholder_info) =
TemplatePlaceholderInfo::from_providers(providers_collection)
{
if let Some(template_info) = template_placeholder_info
.keyed_variables()
.get(template_name)
{
let mut cmd_visitor = SimpleCommandLineArtifactVisitor::new();
if let either::Either::Left(command_line_arg) = template_info {
CommandLineArgLike::visit_artifacts(
command_line_arg.as_ref(),
&mut cmd_visitor,
)?;
} else if let either::Either::Right(map) = template_info {
for (_, command_line_arg) in map.iter() {
CommandLineArgLike::visit_artifacts(
command_line_arg.as_ref(),
&mut cmd_visitor,
)?;
}
}

for input in cmd_visitor.inputs {
artifacts.push(input);
}
}
}
}
}

Ok(artifacts)
}

async fn get_targets_from_template_placeholder_info(
&self,
template_name: &'static str,
targets: TargetSet<ConfiguredGraphNodeRef>,
) -> anyhow::Result<TargetSet<ConfiguredGraphNodeRef>> {
let label_to_artifact = self
.get_from_template_placeholder_info(template_name, &targets)
.await?;
let label_to_artifact = get_from_template_placeholder_info(
self.dice_query_delegate.ctx(),
template_name,
&targets,
)
.await?;
find_target_nodes(targets, label_to_artifact)
}
}
Expand Down
Loading

0 comments on commit a23205b

Please sign in to comment.