2022-06-18 21:56:31 -07:00
|
|
|
use super::*;
|
2019-12-07 04:03:03 -08:00
|
|
|
|
|
|
|
pub(crate) type UnresolvedRecipe<'src> = Recipe<'src, UnresolvedDependency<'src>>;
|
|
|
|
|
|
|
|
impl<'src> UnresolvedRecipe<'src> {
|
|
|
|
pub(crate) fn resolve(
|
|
|
|
self,
|
|
|
|
resolved: Vec<Rc<Recipe<'src>>>,
|
2021-07-26 01:26:06 -07:00
|
|
|
) -> CompileResult<'src, Recipe<'src>> {
|
2021-07-22 00:20:25 -07:00
|
|
|
assert_eq!(
|
|
|
|
self.dependencies.len(),
|
|
|
|
resolved.len(),
|
|
|
|
"UnresolvedRecipe::resolve: dependency count not equal to resolved count: {} != {}",
|
|
|
|
self.dependencies.len(),
|
|
|
|
resolved.len()
|
|
|
|
);
|
|
|
|
|
2019-12-07 04:03:03 -08:00
|
|
|
for (unresolved, resolved) in self.dependencies.iter().zip(&resolved) {
|
|
|
|
assert_eq!(unresolved.recipe.lexeme(), resolved.name.lexeme());
|
|
|
|
if !resolved
|
|
|
|
.argument_range()
|
|
|
|
.contains(&unresolved.arguments.len())
|
|
|
|
{
|
2021-07-26 01:26:06 -07:00
|
|
|
return Err(
|
|
|
|
unresolved
|
|
|
|
.recipe
|
|
|
|
.error(CompileErrorKind::DependencyArgumentCountMismatch {
|
|
|
|
dependency: unresolved.recipe.lexeme(),
|
2021-09-16 06:44:40 -07:00
|
|
|
found: unresolved.arguments.len(),
|
|
|
|
min: resolved.min_arguments(),
|
|
|
|
max: resolved.max_arguments(),
|
2021-07-26 01:26:06 -07:00
|
|
|
}),
|
|
|
|
);
|
2019-12-07 04:03:03 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let dependencies = self
|
|
|
|
.dependencies
|
|
|
|
.into_iter()
|
|
|
|
.zip(resolved)
|
|
|
|
.map(|(unresolved, resolved)| Dependency {
|
2021-09-16 06:44:40 -07:00
|
|
|
recipe: resolved,
|
2019-12-07 04:03:03 -08:00
|
|
|
arguments: unresolved.arguments,
|
|
|
|
})
|
|
|
|
.collect();
|
|
|
|
|
|
|
|
Ok(Recipe {
|
2023-12-28 16:55:36 -08:00
|
|
|
attributes: self.attributes,
|
2019-12-07 04:03:03 -08:00
|
|
|
body: self.body,
|
2023-12-28 16:55:36 -08:00
|
|
|
dependencies,
|
2021-07-22 00:20:25 -07:00
|
|
|
doc: self.doc,
|
2024-05-18 23:38:57 -07:00
|
|
|
file_depth: self.file_depth,
|
2024-01-08 13:26:33 -08:00
|
|
|
file_path: self.file_path,
|
2019-12-07 04:03:03 -08:00
|
|
|
name: self.name,
|
2024-01-08 13:26:33 -08:00
|
|
|
namepath: self.namepath,
|
2019-12-07 04:03:03 -08:00
|
|
|
parameters: self.parameters,
|
2023-12-28 16:55:36 -08:00
|
|
|
priors: self.priors,
|
2019-12-07 04:03:03 -08:00
|
|
|
private: self.private,
|
|
|
|
quiet: self.quiet,
|
|
|
|
shebang: self.shebang,
|
2024-05-18 23:38:57 -07:00
|
|
|
submodule_depth: self.submodule_depth,
|
2024-01-11 19:00:38 -08:00
|
|
|
working_directory: self.working_directory,
|
2019-12-07 04:03:03 -08:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|