Skip to content

Commit 79faa77

Browse files
committed
removed unnecessary code
1 parent 6e46a8f commit 79faa77

File tree

1 file changed

+15
-74
lines changed

1 file changed

+15
-74
lines changed

src/dfx/src/lib/models/canister.rs

Lines changed: 15 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use petgraph::graph::{DiGraph, NodeIndex};
2424
use rand::{thread_rng, RngCore};
2525
use slog::{error, info, trace, warn, Logger};
2626
use std::cell::RefCell;
27-
use std::collections::{BTreeMap, HashMap, HashSet};
27+
use std::collections::{HashMap, HashSet};
2828
use std::convert::TryFrom;
2929
use std::ffi::OsStr;
3030
use std::io::Read;
@@ -554,90 +554,31 @@ impl CanisterPool {
554554
}
555555

556556
/// Build only dependencies relevant for `canisters_to_build`.
557+
///
558+
/// FIXME: unused argument.
557559
#[context("Failed to build dependencies graph for canister pool.")]
558-
fn build_dependencies_graph(&self, canisters_to_build: Option<Vec<String>>) -> DfxResult<DiGraph<CanisterId, ()>> {
559-
let mut graph: DiGraph<CanisterId, ()> = DiGraph::new(); // TODO: hack: we below transform DiGraph<MotokoImport> to DiGraph<CanisterId>
560-
let mut id_set: BTreeMap<CanisterId, NodeIndex<u32>> = BTreeMap::new();
561-
562-
// TODO: Can be done faster by not using `collect` and/or `clone`?
563-
// `real_canisters_to_build` are canisters that user explicitly requested to build.
564-
let real_canisters_to_build = if let Some(canisters_to_build) = canisters_to_build {
565-
let canisters_to_build_map: HashMap<&str, ()> = canisters_to_build.iter().map(|e| (e.as_str(), ())).collect();
566-
self.canisters.iter()
567-
.filter(|c| canisters_to_build_map.contains_key(c.get_name()))
568-
.map(|c| c.clone()).collect::<Vec<_>>()
569-
} else {
570-
self.canisters.iter().map(|c| c.clone()).collect::<Vec<_>>()
571-
};
572-
573-
// [DO NOT] Add all the canisters as nodes.
574-
// for canister in &self.canisters {
575-
// let canister_id = canister.info.get_canister_id()?;
576-
// id_set.insert(canister_id, graph.add_node(canister_id));
577-
// }
578-
579-
// FIXME: Verify after graph creation (and that creation does not stuck in an infinite loop).
580-
// Verify the graph has no cycles.
581-
// if let Err(err) = petgraph::algo::toposort(&graph, None) {
582-
// let message = match graph.node_weight(err.node_id()) {
583-
// Some(canister_id) => match self.get_canister_info(canister_id) {
584-
// Some(info) => info.get_name().to_string(),
585-
// None => format!("<{}>", canister_id.to_text()),
586-
// },
587-
// None => "<Unknown>".to_string(),
588-
// };
589-
// return Err(DfxError::new(BuildError::DependencyError(format!(
590-
// "Found circular dependency: {}",
591-
// message
592-
// ))))
593-
// }
594-
595-
// Traverse, creating the graph of dependencies starting from `real_canisters_to_build` set.
596-
// let mut current_canisters_to_build =
597-
// HashMap::from_iter(real_canisters_to_build.iter().map(|c| (c.canister_id(), ())));
598-
// for canister_id in current_canisters_to_build.keys() {
599-
// id_set.entry(*canister_id).or_insert_with(|| graph.add_node(*canister_id));
600-
// // id_set.insert(*canister_id, graph.add_node(*canister_id)); // TODO: Use this, instead.
601-
// }
602-
// loop {
603-
// let mut current_canisters_to_build2 = HashMap::new();
604-
// // println!("self.canisters.len(): {}", self.canisters.len());
605-
for canister in &self.canisters { // a little inefficient
606-
// if !current_canisters_to_build.contains_key(&canister.canister_id()) {
607-
// continue;
608-
// }
609-
let canister_id = canister.canister_id();
610-
let canister_info = &canister.info;
611-
// FIXME: Is `unwrap()` in the next operator correct?
612-
let deps: Vec<CanisterId> = canister.builder.get_dependencies(self, canister_info)?
613-
.into_iter().filter(|d| *d != canister_info.get_canister_id().unwrap()).collect(); // TODO: This is a hack.
614-
// println!("PARENT: {}, DEPS: {:?}", canister.get_info().get_canister_id()?.to_text(), deps.iter().map(|c| c.to_text()).collect::<Vec<_>>()); // FIXME
615-
// let node_ix = *id_set.entry(canister_id).or_insert_with(|| graph.add_node(canister_id));
616-
// for d in deps {
617-
// let dep_ix = *id_set.entry(d).or_insert_with(|| graph.add_node(d));
618-
// graph.add_edge(node_ix, dep_ix, ());
619-
// current_canisters_to_build2.insert(d, ());
620-
// println!("canister_id={} -> d={}", canister_id, d);
621-
// }
622-
}
623-
// println!("NEXT CYCLE"); // FIXME: Remove.
624-
// if current_canisters_to_build2.is_empty() { // passed to the end of the graph
625-
// break;
560+
fn build_dependencies_graph(&self, _canisters_to_build: Option<Vec<String>>) -> DfxResult<DiGraph<CanisterId, ()>> {
561+
for canister in &self.canisters { // a little inefficient
562+
// if !current_canisters_to_build.contains_key(&canister.canister_id()) {
563+
// continue;
626564
// }
627-
// current_canisters_to_build = current_canisters_to_build2;
628-
// }
565+
let canister_info = &canister.info;
566+
// FIXME: Is `unwrap()` in the next operator correct?
567+
// TODO: Ignored return value is a hack
568+
let _deps: Vec<CanisterId> = canister.builder.get_dependencies(self, canister_info)?
569+
.into_iter().filter(|d| *d != canister_info.get_canister_id().unwrap()).collect(); // TODO: This is a hack.
570+
}
629571

630-
// Ok(graph)
631572
Ok(self.imports.borrow().graph.filter_map(
632-
|node_index, node_weight| {
573+
|_node_index, node_weight| {
633574
// B::from(node_weight)
634575
match node_weight {
635576
// TODO: `get_first_canister_with_name` is a hack
636577
MotokoImport::Canister(name) => Some(self.get_first_canister_with_name(&name).unwrap().canister_id()),
637578
_ => None,
638579
}
639580
},
640-
|edge_index, edge_weight| {
581+
|_edge_index, _edge_weight| {
641582
Some(())
642583
}
643584
))

0 commit comments

Comments
 (0)