Skip to content

Commit b0dbc7c

Browse files
Implement generating graphs of the build steps
1 parent f4620a3 commit b0dbc7c

File tree

4 files changed

+69
-4
lines changed

4 files changed

+69
-4
lines changed

src/Cargo.lock

Lines changed: 23 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/bootstrap/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ serde_json = "1.0.2"
4242
toml = "0.4"
4343
lazy_static = "0.2"
4444
time = "0.1"
45+
petgraph = "0.4.12"
4546

4647
[dev-dependencies]
4748
pretty_assertions = "0.5"

src/bootstrap/builder.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use std::ops::Deref;
1919
use std::path::{Path, PathBuf};
2020
use std::process::Command;
2121
use std::time::{Instant, Duration};
22+
use std::collections::HashMap;
2223

2324
use compile;
2425
use install;
@@ -35,6 +36,9 @@ use native;
3536

3637
pub use Compiler;
3738

39+
use petgraph::Graph;
40+
use petgraph::graph::NodeIndex;
41+
3842
pub struct Builder<'a> {
3943
pub build: &'a Build,
4044
pub top_stage: u32,
@@ -43,6 +47,9 @@ pub struct Builder<'a> {
4347
stack: RefCell<Vec<Box<Any>>>,
4448
time_spent_on_dependencies: Cell<Duration>,
4549
pub paths: Vec<PathBuf>,
50+
graph_nodes: RefCell<HashMap<String, NodeIndex>>,
51+
graph: RefCell<Graph<String, bool>>,
52+
parent: Cell<Option<NodeIndex>>,
4653
}
4754

4855
impl<'a> Deref for Builder<'a> {
@@ -353,6 +360,9 @@ impl<'a> Builder<'a> {
353360
stack: RefCell::new(Vec::new()),
354361
time_spent_on_dependencies: Cell::new(Duration::new(0, 0)),
355362
paths: vec![],
363+
graph_nodes: RefCell::new(HashMap::new()),
364+
graph: RefCell::new(Graph::new()),
365+
parent: Cell::new(None),
356366
};
357367

358368
let builder = &builder;
@@ -389,6 +399,9 @@ impl<'a> Builder<'a> {
389399
stack: RefCell::new(Vec::new()),
390400
time_spent_on_dependencies: Cell::new(Duration::new(0, 0)),
391401
paths: paths.to_owned(),
402+
graph_nodes: RefCell::new(HashMap::new()),
403+
graph: RefCell::new(Graph::new()),
404+
parent: Cell::new(None),
392405
};
393406

394407
if kind == Kind::Dist {
@@ -833,12 +846,37 @@ impl<'a> Builder<'a> {
833846
if let Some(out) = self.cache.get(&step) {
834847
self.build.verbose(&format!("{}c {:?}", " ".repeat(stack.len()), step));
835848

849+
{
850+
let mut graph = self.graph.borrow_mut();
851+
let parent = self.parent.get();
852+
let us = *self.graph_nodes.borrow_mut()
853+
.entry(format!("{:?}", step))
854+
.or_insert_with(|| graph.add_node(format!("{:?}", step)));
855+
if let Some(parent) = parent {
856+
graph.add_edge(parent, us, false);
857+
}
858+
}
859+
836860
return out;
837861
}
838862
self.build.verbose(&format!("{}> {:?}", " ".repeat(stack.len()), step));
839863
stack.push(Box::new(step.clone()));
840864
}
841865

866+
let prev_parent = self.parent.get();
867+
868+
{
869+
let mut graph = self.graph.borrow_mut();
870+
let parent = self.parent.get();
871+
let us = *self.graph_nodes.borrow_mut()
872+
.entry(format!("{:?}", step))
873+
.or_insert_with(|| graph.add_node(format!("{:?}", step)));
874+
self.parent.set(Some(us));
875+
if let Some(parent) = parent {
876+
graph.add_edge(parent, us, true);
877+
}
878+
}
879+
842880
let (out, dur) = {
843881
let start = Instant::now();
844882
let zero = Duration::new(0, 0);
@@ -849,6 +887,8 @@ impl<'a> Builder<'a> {
849887
(out, dur - deps)
850888
};
851889

890+
self.parent.set(prev_parent);
891+
852892
if self.build.config.print_step_timings && dur > Duration::from_millis(100) {
853893
println!("[TIMING] {:?} -- {}.{:03}",
854894
step,

src/bootstrap/lib.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ extern crate getopts;
131131
extern crate num_cpus;
132132
extern crate toml;
133133
extern crate time;
134+
extern crate petgraph;
134135

135136
#[cfg(test)]
136137
#[macro_use]
@@ -600,14 +601,14 @@ impl Build {
600601

601602
/// Runs a command, printing out nice contextual information if it fails.
602603
fn run(&self, cmd: &mut Command) {
603-
if cfg!(test) { return; }
604+
if self.config.dry_run { return; }
604605
self.verbose(&format!("running: {:?}", cmd));
605606
run_silent(cmd)
606607
}
607608

608609
/// Runs a command, printing out nice contextual information if it fails.
609610
fn run_quiet(&self, cmd: &mut Command) {
610-
if cfg!(test) { return; }
611+
if self.config.dry_run { return; }
611612
self.verbose(&format!("running: {:?}", cmd));
612613
run_suppressed(cmd)
613614
}
@@ -616,7 +617,7 @@ impl Build {
616617
/// Exits if the command failed to execute at all, otherwise returns its
617618
/// `status.success()`.
618619
fn try_run(&self, cmd: &mut Command) -> bool {
619-
if cfg!(test) { return true; }
620+
if self.config.dry_run { return true; }
620621
self.verbose(&format!("running: {:?}", cmd));
621622
try_run_silent(cmd)
622623
}
@@ -625,7 +626,7 @@ impl Build {
625626
/// Exits if the command failed to execute at all, otherwise returns its
626627
/// `status.success()`.
627628
fn try_run_quiet(&self, cmd: &mut Command) -> bool {
628-
if cfg!(test) { return true; }
629+
if self.config.dry_run { return true; }
629630
self.verbose(&format!("running: {:?}", cmd));
630631
try_run_suppressed(cmd)
631632
}

0 commit comments

Comments
 (0)