Skip to content

Commit

Permalink
ninja: introduce NinjaBuildBuilder::from_rule()
Browse files Browse the repository at this point in the history
  • Loading branch information
kaspar030 committed Jan 5, 2024
1 parent 9499c3f commit e5734b0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
12 changes: 4 additions & 8 deletions src/generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -731,8 +731,7 @@ fn configure_build(

// 4. render ninja "build:" snippet and add to this build's
// ninja statement set
let build = NinjaBuildBuilder::default()
.with_rule(&rule)
let build = NinjaBuildBuilder::from_rule(&rule)
.inputs(sources)
.outs(outs.clone())
.deps(combined_build_deps)
Expand Down Expand Up @@ -830,8 +829,7 @@ fn configure_build(

// 4. render ninja "build:" snippet and add to this build's
// ninja statement set
let build = NinjaBuildBuilder::default()
.with_rule(&ninja_rule)
let build = NinjaBuildBuilder::from_rule(&ninja_rule)
.input(Cow::from(srcpath.as_path()))
.deps(combined_build_deps.clone())
.out(object.as_path())
Expand Down Expand Up @@ -903,8 +901,7 @@ fn configure_build(
{
let ninja_link_rule = render_rule_with(get_rule("LINK", rules)?, &global_env_flattened);
// build ninja link target
let ninja_link_build = NinjaBuildBuilder::default()
.with_rule(&ninja_link_rule)
let ninja_link_build = NinjaBuildBuilder::from_rule(&ninja_link_rule)
.inputs(objects)
.deps(global_build_dep_files)
.out(outfile.as_path())
Expand All @@ -924,8 +921,7 @@ fn configure_build(
anyhow!("POST_LINK rule has no \"out\" extension configured")
})?);
let post_link_rule = render_rule_with(rule, &global_env_flattened);
let post_link_build = NinjaBuildBuilder::default()
.with_rule(&post_link_rule)
let post_link_build = NinjaBuildBuilder::from_rule(&post_link_rule)
.input(outfile)
.out(new_outfile.as_path())
.build()
Expand Down
6 changes: 6 additions & 0 deletions src/ninja/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,12 @@ impl<'a> NinjaBuildBuilder<'a> {
pub fn with_rule(&mut self, rule: &'a NinjaRule) -> &mut Self {
self.rule(&*rule.name).always(rule.always)
}

pub fn from_rule(rule: &'a NinjaRule) -> Self {
let mut res = Self::default();
res.with_rule(rule);
res
}
}

impl<'a> fmt::Display for NinjaBuild<'a> {
Expand Down

0 comments on commit e5734b0

Please sign in to comment.