Skip to content

Commit

Permalink
extract preresolve_literals_and_build_universe
Browse files Browse the repository at this point in the history
Summary:
Small refactoring for the implementation of `buck2 build --target-universe` in the following diff D40254000.

The idea is that `buck2 build --target-universe` should resolve universe literals exactly how `buck2 cquery --target-universe` is implemented, so this code should be reused even if it is relatively simple.

Reviewed By: scottcao

Differential Revision: D40254558

fbshipit-source-id: 4e4b4d456d863c5ac5c3e1d61f90bd2d0cc59bea
  • Loading branch information
stepancheg authored and facebook-github-bot committed Oct 13, 2022
1 parent c7709e4 commit 1dfd552
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions buck2_build_api/src/query/cquery/evaluator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,8 @@ impl CqueryEvaluator<'_> {
eval_query(&self.functions, query, query_args, async move |literals| {
let (universe, resolved_literals) = match target_universe {
None => {
let resolved_literals = PreresolvedQueryLiterals::pre_resolve(
&*self.dice_query_delegate,
&literals,
)
.await;
let universe = CqueryUniverse::build(&resolved_literals.literals()?).await?;
(universe, resolved_literals)
preresolve_literals_and_build_universe(&self.dice_query_delegate, &literals)
.await?
}
Some(universe) => {
resolve_literals_in_universe(&self.dice_query_delegate, &literals, universe)
Expand All @@ -72,6 +67,19 @@ impl CqueryEvaluator<'_> {
}
}

async fn preresolve_literals_and_build_universe(
dice_query_delegate: &DiceQueryDelegate<'_>,
literals: &[String],
) -> anyhow::Result<(
CqueryUniverse,
PreresolvedQueryLiterals<ConfiguredTargetNode>,
)> {
let resolved_literals =
PreresolvedQueryLiterals::pre_resolve(dice_query_delegate, literals).await;
let universe = CqueryUniverse::build(&resolved_literals.literals()?).await?;
Ok((universe, resolved_literals))
}

/// Evaluates some query expression. TargetNodes are resolved via the interpreter from
/// the provided DiceCtx.
pub async fn get_cquery_evaluator<'a, 'c: 'a>(
Expand Down

0 comments on commit 1dfd552

Please sign in to comment.