aboutsummaryrefslogtreecommitdiff
path: root/development/tools/cargo-workspace2/src/models/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'development/tools/cargo-workspace2/src/models/mod.rs')
-rw-r--r--development/tools/cargo-workspace2/src/models/mod.rs50
1 files changed, 50 insertions, 0 deletions
diff --git a/development/tools/cargo-workspace2/src/models/mod.rs b/development/tools/cargo-workspace2/src/models/mod.rs
new file mode 100644
index 000000000000..759b2703f9f0
--- /dev/null
+++ b/development/tools/cargo-workspace2/src/models/mod.rs
@@ -0,0 +1,50 @@
+//! Collection of cargo workspace data models.
+//!
+//! To start parsing types, construct a `CargoWorkspace`, which you
+//! can then modify with commands found in [`ops`](../ops/index.html).
+
+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;
+
+/// A fully parsed workspace
+pub struct Workspace {
+ pub root: PathBuf,
+ dgraph: DepGraph,
+}
+
+impl Workspace {
+ /// Create a parsed workspace by passing in the stage1 parse data
+ 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 }
+ }
+
+ /// Execute a query on this workspace to find crate IDs
+ pub fn query(&self, q: Query) -> Vec<CrateId> {
+ q.execute(&self.dgraph)
+ }
+
+ /// Execute an operation on a set of crates this in workspace
+ pub fn execute(&mut self, op: Op, target: Vec<CrateId>) {
+ op.execute(target, self.root.clone(), &mut self.dgraph)
+ }
+}