1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
mod cargo;
pub use cargo::{CargoCrate, CargoWorkspace};
mod _crate;
pub use _crate::Crate;
mod publish;
pub use publish::{MutationSet, PubMutation};
mod graph;
pub use graph::DepGraph;
pub type CrateId = usize;
use crate::{ops::Op, query::Query};
use std::path::PathBuf;
pub struct Workspace {
pub root: PathBuf,
dgraph: DepGraph,
}
impl Workspace {
pub fn process(cws: CargoWorkspace) -> Self {
let CargoWorkspace { root, crates } = cws;
let mut dgraph = DepGraph::new();
crates.into_iter().for_each(|cc| dgraph.add_crate(cc));
dgraph.finalise();
Self { root, dgraph }
}
pub fn query(&self, q: Query) -> Vec<CrateId> {
q.execute(&self.dgraph)
}
pub fn execute(&mut self, op: Op, target: Vec<CrateId>) {
op.execute(target, self.root.clone(), &mut self.dgraph)
}
}