mirror of
https://github.com/Zenithsiz/zbuild.git
synced 2026-02-05 15:31:55 +00:00
Improved implementation of expand_target.
This commit is contained in:
parent
f25a24fce7
commit
05e74a4edc
@ -7,38 +7,30 @@ use {
|
||||
anyhow::Context,
|
||||
};
|
||||
|
||||
/// Expands a target
|
||||
/// Expands a target expression
|
||||
pub fn expand_target(
|
||||
target: &Target<Expr>,
|
||||
mut global_expr_visitor: expand_expr::GlobalVisitor,
|
||||
) -> Result<Target<String>, anyhow::Error> {
|
||||
let target = match target {
|
||||
// If we got a file, check which rule can make it
|
||||
Target::File { file } => {
|
||||
// Expand the file
|
||||
let file = self::expand_expr_string(file, &mut global_expr_visitor)
|
||||
.with_context(|| format!("Unable to expand expression {file:?}"))?;
|
||||
|
||||
Target::File { file }
|
||||
Target::File { file } => Target::File {
|
||||
file: self::expand_expr_string(file, &mut global_expr_visitor)
|
||||
.with_context(|| format!("Unable to expand file name {file:?}"))?,
|
||||
},
|
||||
|
||||
Target::Rule { rule, pats } => {
|
||||
// Expand the rule
|
||||
let rule = self::expand_expr_string(rule, &mut global_expr_visitor)
|
||||
.with_context(|| format!("Unable to expand expression {rule:?}"))?;
|
||||
|
||||
// Expand all patterns
|
||||
let pats = pats
|
||||
Target::Rule { rule, pats } => Target::Rule {
|
||||
rule: self::expand_expr_string(rule, &mut global_expr_visitor)
|
||||
.with_context(|| format!("Unable to expand rule name {rule:?}"))?,
|
||||
pats: pats
|
||||
.iter()
|
||||
.map(|(pat, expr)| {
|
||||
let value = self::expand_expr_string(expr, &mut global_expr_visitor)
|
||||
.with_context(|| format!("Unable to expand expression {expr:?}"))?;
|
||||
|
||||
Ok((pat.to_owned(), value))
|
||||
Ok((
|
||||
pat.to_owned(),
|
||||
self::expand_expr_string(expr, &mut global_expr_visitor)
|
||||
.with_context(|| format!("Unable to expand pattern value {expr:?}"))?,
|
||||
))
|
||||
})
|
||||
.collect::<Result<_, anyhow::Error>>()?;
|
||||
|
||||
Target::Rule { rule, pats }
|
||||
.collect::<Result<_, anyhow::Error>>()?,
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user